Skip to content

Commit

Permalink
GluuFederation#785 add authentication method api
Browse files Browse the repository at this point in the history
  • Loading branch information
earezki committed Aug 3, 2018
1 parent 97efcb9 commit 52b1899
Show file tree
Hide file tree
Showing 52 changed files with 2,456 additions and 2,131 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@
import org.gluu.oxtrust.model.OxIDPAuthConf;
import org.gluu.oxtrust.model.SimpleCustomPropertiesListModel;
import org.gluu.oxtrust.model.SimplePropertiesListModel;
import org.gluu.oxtrust.service.config.authentication.AuthenticationMethod;
import org.gluu.oxtrust.service.config.authentication.AuthenticationMethodService;
import org.gluu.oxtrust.service.config.authentication.PassportAuthenticationMethod;
import org.gluu.oxtrust.service.config.ldap.ConnectionStatus;
import org.gluu.oxtrust.service.config.ldap.LdapConfigurationService;
import org.gluu.oxtrust.service.config.ldap.LdapConnectionData;
import org.gluu.oxtrust.util.OxTrustConstants;
import org.gluu.persist.exception.BasePersistenceException;
import org.gluu.persist.ldap.operation.impl.LdapConnectionProvider;
Expand All @@ -57,7 +63,7 @@

/**
* Action class for configuring person authentication
*
*
* @author Yuriy Movchan Date: 16/11/2010
*/
@Named("managePersonAuthenticationAction")
Expand All @@ -68,6 +74,9 @@ public class ManagePersonAuthenticationAction

private static final long serialVersionUID = -4470460481895022468L;

private static final String DEFAULT_AUTHENTICATION_MODE = "auth_ldap_server";
private static final String DEFAULT_OX_TRUST_AUTHENTICATION_MODE = null;

@Inject
private Logger log;

Expand All @@ -92,6 +101,15 @@ public class ManagePersonAuthenticationAction
@Inject
private EncryptionService encryptionService;

@Inject
transient private LdapConfigurationService ldapConfigurationService;

@Inject
transient private AuthenticationMethodService authenticationMethodService;

@Inject
transient private ConnectionStatus connectionStatus;

private boolean existLdapConfigIdpAuthConf;

private List<CustomScript> customScripts;
Expand All @@ -100,17 +118,12 @@ public class ManagePersonAuthenticationAction

private GluuLdapConfiguration activeLdapConfig;

private String authenticationMode = "auth_ldap_server";
private String oxTrustAuthenticationMode;
private AuthenticationMethod authenticationMethod;

private List<String> customAuthenticationConfigNames;

private boolean initialized;

private GluuBoolean passportEnable = GluuBoolean.DISABLED;

private LdapOxPassportConfiguration ldapOxPassportConfiguration;

private List<PassportConfiguration> ldapPassportConfigurations;

public List<PassportConfiguration> getLdapPassportConfigurations() {
Expand Down Expand Up @@ -144,39 +157,27 @@ public String modifyImpl() {
}

try {
GluuAppliance appliance = applianceService.getAppliance();

if (appliance == null) {
return OxTrustConstants.RESULT_FAILURE;
}
passportEnable = appliance.getPassportEnabled();
log.info("passport enabled value : '{}'", passportEnable);
this.customScripts = customScriptService.findCustomScripts(
Arrays.asList(CustomScriptType.PERSON_AUTHENTICATION), "displayName", "oxLevel", "gluuStatus");

List<OxIDPAuthConf> list = getIDPAuthConfOrNull(appliance);
this.sourceConfigs = new ArrayList<GluuLdapConfiguration>();
if (list != null) {
for (OxIDPAuthConf oxIDPAuthConf : list) {
GluuLdapConfiguration oxldapConfig = mapLdapConfig(oxIDPAuthConf.getConfig());
this.sourceConfigs.add(oxldapConfig);
}
}
this.sourceConfigs = new ArrayList<GluuLdapConfiguration>(ldapConfigurationService.findLdapConfigurations());

this.authenticationMode = appliance.getAuthenticationMode();
this.oxTrustAuthenticationMode = appliance.getOxTrustAuthenticationMode();
authenticationMethod = authenticationMethodService.findAuthenticationMode();

this.ldapPassportConfigurations = authenticationMethod.getPassportAuthenticationMethod()
.getLdapOxPassportConfiguration().getPassportConfigurations();

ldapOxPassportConfiguration = passportService.loadConfigurationFromLdap();
if (ldapOxPassportConfiguration == null) {
ldapOxPassportConfiguration = new LdapOxPassportConfiguration();
}
this.ldapPassportConfigurations = ldapOxPassportConfiguration.getPassportConfigurations();
if (ldapPassportConfigurations == null) {
ldapPassportConfigurations = new ArrayList<PassportConfiguration>();
}
} catch (Exception ex) {
log.error("Failed to load appliance configuration", ex);

if (authenticationMethod == null) {
authenticationMethod = new AuthenticationMethod(DEFAULT_AUTHENTICATION_MODE,
DEFAULT_OX_TRUST_AUTHENTICATION_MODE, PassportAuthenticationMethod.disabled());
}

return OxTrustConstants.RESULT_FAILURE;
}

Expand All @@ -195,30 +196,25 @@ public String save() throws JsonParseException, JsonMappingException, IOExceptio

String oldAuthName = getFirstConfigName(appliance.getOxIDPAuthentication());
if (oldAuthName != null) {
if (oldAuthName.equals(this.authenticationMode)) {
if (authenticationMethod.hasAuthenticationMode(oldAuthName)) {
updateAuthenticationMode = true;
}
if (oldAuthName.equals(this.oxTrustAuthenticationMode)) {
if (authenticationMethod.hasOxTrustAuthenticationMode(oldAuthName)) {
updateOxTrustAuthenticationMode = true;
}
}

updateAuthConf(appliance);
updateAuthConf();
appliance = applianceService.getAppliance();

String newAuthName = getFirstConfigName(appliance.getOxIDPAuthentication());
String updatedAuthMode = updateAuthenticationMode ? newAuthName : this.authenticationMode;
String updatedAuthMode = updateAuthenticationMode ? newAuthName : this.authenticationMethod.getAuthenticationMode();
String updatedOxTrustAuthMode = updateOxTrustAuthenticationMode ? newAuthName
: this.oxTrustAuthenticationMode;
appliance.setAuthenticationMode(updatedAuthMode);
appliance.setOxTrustAuthenticationMode(updatedOxTrustAuthMode);
: this.authenticationMethod.getOxTrustAuthenticationMode();

appliance.setPassportEnabled(passportEnable);

applianceService.updateAppliance(appliance);

ldapOxPassportConfiguration.setPassportConfigurations(ldapPassportConfigurations);

passportService.updateLdapOxPassportConfiguration(ldapOxPassportConfiguration);
authenticationMethod.getPassportAuthenticationMethod().getLdapOxPassportConfiguration().setPassportConfigurations(ldapPassportConfigurations);
authenticationMethodService.save(new AuthenticationMethod(updatedAuthMode, updatedOxTrustAuthMode,
authenticationMethod.getPassportAuthenticationMethod()));
} catch (BasePersistenceException ex) {
log.error("Failed to update appliance configuration", ex);
facesMessages.add(FacesMessage.SEVERITY_ERROR, "Failed to update appliance");
Expand All @@ -245,58 +241,23 @@ private void reset() {
this.customAuthenticationConfigNames = null;
}

private GluuLdapConfiguration mapLdapConfig(String config)
throws JsonParseException, JsonMappingException, IOException {
return (GluuLdapConfiguration) jsonToObject(config, GluuLdapConfiguration.class);
}

public String cancel() {
facesMessages.add(FacesMessage.SEVERITY_INFO, "Person authentication configuration not updated");
conversationService.endConversation();

return OxTrustConstants.RESULT_SUCCESS;
}

private Object jsonToObject(String json, Class<?> clazz)
throws JsonParseException, JsonMappingException, IOException {
ObjectMapper mapper = new ObjectMapper();
Object clazzObject = mapper.readValue(json, clazz);
return clazzObject;
}

private String objectToJson(Object obj) throws JsonGenerationException, JsonMappingException, IOException {
ObjectMapper mapper = new ObjectMapper();
return mapper.writeValueAsString(obj);
}

public boolean updateAuthConf(GluuAppliance appliance) {
public boolean updateAuthConf() {
try {
String configId = null;
List<OxIDPAuthConf> idpConf = new ArrayList<OxIDPAuthConf>();
for (GluuLdapConfiguration ldapConfig : this.sourceConfigs) {
if (idpConf.isEmpty()) {
configId = ldapConfig.getConfigId();
}
if (ldapConfig.isUseAnonymousBind()) {
ldapConfig.setBindDN(null);
}

OxIDPAuthConf ldapConfigIdpAuthConf = new OxIDPAuthConf();
ldapConfig.setConfigId(configId);
ldapConfig.updateStringsLists();
ldapConfigIdpAuthConf.setType("auth");
ldapConfigIdpAuthConf.setVersion(ldapConfigIdpAuthConf.getVersion() + 1);
ldapConfigIdpAuthConf.setName(configId);
ldapConfigIdpAuthConf.setEnabled(ldapConfig.isEnabled());
ldapConfigIdpAuthConf.setConfig(objectToJson(ldapConfig));

idpConf.add(ldapConfigIdpAuthConf);
}

appliance.setOxIDPAuthentication(idpConf);
ldapConfigurationService.save(sourceConfigs);
} catch (Exception ex) {
log.error("An Error occured ", ex);

return false;
}

Expand Down Expand Up @@ -337,28 +298,9 @@ public List<String> getPersonAuthenticationConfigurationNames() {

public String testLdapConnection(GluuLdapConfiguration ldapConfig) {
try {
FileConfiguration configuration = new FileConfiguration(ConfigurationFactory.LDAP_PROPERTIES_FILE);
if (!configuration.isLoaded()) {
configuration = new FileConfiguration(ConfigurationFactory.LDAP_DEFAULT_PROPERTIES_FILE);
}
Properties properties = configuration.getProperties();
properties.setProperty("bindDN", ldapConfig.getBindDN());
properties.setProperty("bindPassword", ldapConfig.getBindPassword());
properties.setProperty("servers", buildServersString(ldapConfig.getServers()));
properties.setProperty("useSSL", Boolean.toString(ldapConfig.isUseSSL()));

LdapConnectionProvider connectionProvider = new LdapConnectionProvider(
PropertiesDecrypter.decryptProperties(properties, configurationFactory.getCryptoConfigurationSalt()));
if (connectionProvider.isConnected()) {
connectionProvider.closeConnectionPool();

if (connectionStatus.isUp(LdapConnectionData.from(ldapConfig))) {
facesMessages.add(FacesMessage.SEVERITY_INFO, "LDAP Connection Test succeeded!");

return OxTrustConstants.RESULT_SUCCESS;

}
if (connectionProvider.getConnectionPool() != null) {
connectionProvider.closeConnectionPool();
}
} catch (Exception ex) {
log.error("Could not connect to LDAP", ex);
Expand All @@ -369,33 +311,11 @@ public String testLdapConnection(GluuLdapConfiguration ldapConfig) {
return OxTrustConstants.RESULT_FAILURE;
}

private String buildServersString(List<SimpleProperty> servers) {
StringBuilder sb = new StringBuilder();

if (servers == null) {
return sb.toString();
}

boolean first = true;
for (SimpleProperty server : servers) {
if (first) {
first = false;
} else {
sb.append(",");
}

sb.append(server.getValue());
}

return sb.toString();
}

@Deprecated
public void updateLdapBindPassword(GluuLdapConfiguration ldapConfig) {
log.info("hello setting passoword" + ldapConfig.getPrimaryKey());
for (Iterator<GluuLdapConfiguration> iterator = sourceConfigs.iterator(); iterator.hasNext();) {
GluuLdapConfiguration ldapConfig1 = iterator.next();

}
// This method does nothing.
// Should be removed.
// Is this used somewhere in the UI ?
}

public String updateLdapBindPassword(String bindPassword) {
Expand Down Expand Up @@ -429,31 +349,31 @@ public void removeItemFromSimpleProperties(List<SimpleProperty> simpleProperties
}

public String getAuthenticationMode() {
return authenticationMode;
return this.authenticationMethod.getAuthenticationMode();
}

public void setAuthenticationMode(String authenticationMode) {
this.authenticationMode = authenticationMode;
}
this.authenticationMethod.setAuthenticationMode(authenticationMode);
}

public String getOxTrustAuthenticationMode() {
return oxTrustAuthenticationMode;
return this.authenticationMethod.getOxTrustAuthenticationMode();
}

public void setOxTrustAuthenticationMode(String oxTrustAuthenticationMode) {
this.oxTrustAuthenticationMode = oxTrustAuthenticationMode;
this.authenticationMethod.setOxTrustAuthenticationMode(oxTrustAuthenticationMode);
}

public boolean isInitialized() {
return initialized;
}

public LdapOxPassportConfiguration getLdapOxPassportConfiguration() {
return ldapOxPassportConfiguration;
return authenticationMethod.getPassportAuthenticationMethod().getLdapOxPassportConfiguration();
}

public void setLdapOxPassportConfiguration(LdapOxPassportConfiguration ldapOxPassportConfiguration) {
this.ldapOxPassportConfiguration = ldapOxPassportConfiguration;
this.authenticationMethod.getPassportAuthenticationMethod().setLdapOxPassportConfiguration(ldapOxPassportConfiguration);
}

public String getId(Object obj) {
Expand All @@ -480,25 +400,11 @@ public void addField(PassportConfiguration removePassportConfiguration) {
}

public GluuBoolean getPassportEnable() {
return passportEnable;
return authenticationMethod.getPassportAuthenticationMethod().asGluuBoolean();
}

public void setPassportEnable(GluuBoolean passportEnable) {
this.passportEnable = passportEnable;
}

private List<OxIDPAuthConf> getIDPAuthConfOrNull(GluuAppliance appliance) {
List<OxIDPAuthConf> idpConfs = appliance.getOxIDPAuthentication();
List<OxIDPAuthConf> authIdpConfs = new ArrayList<OxIDPAuthConf>();
if (idpConfs != null) {
for (OxIDPAuthConf idpConf : idpConfs) {
if (idpConf.getType().equalsIgnoreCase("auth")) {
authIdpConfs.add(idpConf);
}
}
}
return authIdpConfs;

authenticationMethodService.change(authenticationMethod, passportEnable);
}

public List<GluuLdapConfiguration> getSourceConfigs() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import javax.inject.Named;

import org.gluu.oxtrust.ldap.service.Shibboleth3ConfService;
import org.gluu.oxtrust.service.config.cas.CASProtocolAvailability;
import org.gluu.oxtrust.util.ProductInstallationChecker;
import org.slf4j.Logger;
import org.xdi.service.security.Secure;
Expand All @@ -38,8 +39,7 @@ public class ProductInstallationCheckerAction implements Serializable {
private boolean showSAMLMenu = true;
private boolean showAsimbaSubmenu = true;
private boolean showSAMLSubmenu = true;
// CAS protocol through Shibboleth IDP
private boolean showIDP_CAS = true;
private CASProtocolAvailability casProtocolAvailability = CASProtocolAvailability.ENABLED;

public ProductInstallationCheckerAction() {
}
Expand All @@ -53,8 +53,8 @@ public void init() {
showAsimbaSubmenu = !ProductInstallationChecker.isGluuCE() || ProductInstallationChecker.isOxAsimbaInstalled();

showSAMLSubmenu = !ProductInstallationChecker.isGluuCE() || shibboleth3ConfService.isIdpInstalled();
showIDP_CAS = !ProductInstallationChecker.isGluuCE() || ProductInstallationChecker.isShibbolethIDP3Installed();

casProtocolAvailability = CASProtocolAvailability.get();
}

/**
Expand Down Expand Up @@ -103,14 +103,14 @@ public void setShowSAMLSubmenu(boolean showSAMLSubmenu) {
* @return the showIDP_CAS
*/
public boolean isShowIDP_CAS() {
return showIDP_CAS;
return casProtocolAvailability.isAvailable();
}

/**
* @param showIDP_CAS the showIDP_CAS to set
*/
public void setShowIDP_CAS(boolean showIDP_CAS) {
this.showIDP_CAS = showIDP_CAS;
this.casProtocolAvailability = CASProtocolAvailability.from(showIDP_CAS);
}


Expand Down
Loading

0 comments on commit 52b1899

Please sign in to comment.