use of org.wso2.carbon.identity.application.common.model.LocalAndOutboundAuthenticationConfig in project carbon-identity-framework by wso2.
the class UIBasedConfigurationLoader method getSequenceConfig.
@Override
public SequenceConfig getSequenceConfig(AuthenticationContext context, Map<String, String[]> parameterMap, ServiceProvider serviceProvider) throws FrameworkException {
String tenantDomain = context.getTenantDomain();
AuthenticationStep[] authenticationSteps = null;
LocalAndOutboundAuthenticationConfig localAndOutboundAuthenticationConfig = serviceProvider.getLocalAndOutBoundAuthenticationConfig();
if (localAndOutboundAuthenticationConfig.getAuthenticationSteps() != null && localAndOutboundAuthenticationConfig.getAuthenticationSteps().length > 0) {
// Use the default steps when there are no chains configured.
authenticationSteps = localAndOutboundAuthenticationConfig.getAuthenticationSteps();
}
SequenceConfig sequenceConfig = getSequence(serviceProvider, tenantDomain, authenticationSteps);
// Use script based evaluation if script is present.
if (isAuthenticationScriptBasedSequence(localAndOutboundAuthenticationConfig)) {
// Clear the sequenceConfig step map, so that it will be re-populated by Dynamic execution
Map<Integer, StepConfig> originalStepConfigMap = new HashMap<>(sequenceConfig.getStepMap());
Map<Integer, StepConfig> stepConfigMapCopy = new HashMap<>();
originalStepConfigMap.forEach((k, v) -> stepConfigMapCopy.put(k, new StepConfig(v)));
sequenceConfig.getStepMap().clear();
JsGraphBuilderFactory jsGraphBuilderFactory = FrameworkServiceDataHolder.getInstance().getJsGraphBuilderFactory();
JsGraphBuilder jsGraphBuilder = jsGraphBuilderFactory.createBuilder(context, stepConfigMapCopy);
context.setServiceProviderName(serviceProvider.getApplicationName());
AuthenticationGraph graph = jsGraphBuilder.createWith(localAndOutboundAuthenticationConfig.getAuthenticationScriptConfig().getContent()).build();
graph.setEnabled(localAndOutboundAuthenticationConfig.getAuthenticationScriptConfig().isEnabled());
sequenceConfig.setAuthenticationGraph(graph);
graph.setStepMap(originalStepConfigMap);
}
return sequenceConfig;
}
use of org.wso2.carbon.identity.application.common.model.LocalAndOutboundAuthenticationConfig in project carbon-identity-framework by wso2.
the class ApplicationDAOImpl method updateLocalAndOutboundAuthenticationConfiguration.
/**
* @param applicationId
* @param localAndOutboundAuthConfig
* @param connection
* @throws SQLException
* @throws IdentityApplicationManagementException
*/
private void updateLocalAndOutboundAuthenticationConfiguration(int applicationId, LocalAndOutboundAuthenticationConfig localAndOutboundAuthConfig, Connection connection) throws SQLException, IdentityApplicationManagementException {
int tenantID = CarbonContext.getThreadLocalCarbonContext().getTenantId();
if (localAndOutboundAuthConfig == null) {
// no local or out-bound configuration for this service provider.
return;
}
updateAuthenticationScriptConfiguration(applicationId, localAndOutboundAuthConfig, connection, tenantID);
PreparedStatement updateAuthTypePrepStmt = null;
PreparedStatement storeSendAuthListOfIdPsPrepStmt = null;
try {
storeSendAuthListOfIdPsPrepStmt = connection.prepareStatement(UPDATE_BASIC_APPINFO_WITH_SEND_AUTH_LIST_OF_IDPS);
// IS_SEND_LOCAL_SUBJECT_ID=? WHERE TENANT_ID= ? AND ID = ?
storeSendAuthListOfIdPsPrepStmt.setString(1, localAndOutboundAuthConfig.isAlwaysSendBackAuthenticatedListOfIdPs() ? "1" : "0");
storeSendAuthListOfIdPsPrepStmt.setInt(2, tenantID);
storeSendAuthListOfIdPsPrepStmt.setInt(3, applicationId);
storeSendAuthListOfIdPsPrepStmt.executeUpdate();
} finally {
IdentityApplicationManagementUtil.closeStatement(storeSendAuthListOfIdPsPrepStmt);
}
PreparedStatement storeUseTenantDomainInLocalSubjectIdStmt = null;
try {
storeUseTenantDomainInLocalSubjectIdStmt = connection.prepareStatement(UPDATE_BASIC_APPINFO_WITH_USE_TENANT_DOMAIN_LOCAL_SUBJECT_ID);
// IS_USE_TENANT_DIMAIN_LOCAL_SUBJECT_ID=? WHERE TENANT_ID= ? AND ID = ?
storeUseTenantDomainInLocalSubjectIdStmt.setString(1, localAndOutboundAuthConfig.isUseTenantDomainInLocalSubjectIdentifier() ? "1" : "0");
storeUseTenantDomainInLocalSubjectIdStmt.setInt(2, tenantID);
storeUseTenantDomainInLocalSubjectIdStmt.setInt(3, applicationId);
storeUseTenantDomainInLocalSubjectIdStmt.executeUpdate();
} finally {
IdentityApplicationManagementUtil.closeStatement(storeUseTenantDomainInLocalSubjectIdStmt);
}
PreparedStatement storeUseUserstoreDomainInLocalSubjectIdStmt = null;
try {
storeUseUserstoreDomainInLocalSubjectIdStmt = connection.prepareStatement(UPDATE_BASIC_APPINFO_WITH_USE_USERSTORE_DOMAIN_LOCAL_SUBJECT_ID);
// IS_USE_USERSTORE_DIMAIN_LOCAL_SUBJECT_ID=? WHERE TENANT_ID= ? AND ID = ?
storeUseUserstoreDomainInLocalSubjectIdStmt.setString(1, localAndOutboundAuthConfig.isUseUserstoreDomainInLocalSubjectIdentifier() ? "1" : "0");
storeUseUserstoreDomainInLocalSubjectIdStmt.setInt(2, tenantID);
storeUseUserstoreDomainInLocalSubjectIdStmt.setInt(3, applicationId);
storeUseUserstoreDomainInLocalSubjectIdStmt.executeUpdate();
} finally {
IdentityApplicationManagementUtil.closeStatement(storeUseUserstoreDomainInLocalSubjectIdStmt);
}
PreparedStatement enableAuthzStmt = null;
try {
enableAuthzStmt = connection.prepareStatement(UPDATE_BASIC_APPINFO_WITH_ENABLE_AUTHORIZATION);
enableAuthzStmt.setString(1, localAndOutboundAuthConfig.isEnableAuthorization() ? "1" : "0");
enableAuthzStmt.setInt(2, tenantID);
enableAuthzStmt.setInt(3, applicationId);
enableAuthzStmt.executeUpdate();
} finally {
IdentityApplicationManagementUtil.closeStatement(enableAuthzStmt);
}
PreparedStatement storeSubjectClaimUri = null;
try {
storeSubjectClaimUri = connection.prepareStatement(UPDATE_BASIC_APPINFO_WITH_SUBJECT_CLAIM_URI);
// SUBJECT_CLAIM_URI=? WHERE TENANT_ID= ? AND ID = ?
storeSubjectClaimUri.setString(1, localAndOutboundAuthConfig.getSubjectClaimUri());
storeSubjectClaimUri.setInt(2, tenantID);
storeSubjectClaimUri.setInt(3, applicationId);
storeSubjectClaimUri.executeUpdate();
} finally {
IdentityApplicationManagementUtil.closeStatement(storeSubjectClaimUri);
}
AuthenticationStep[] authSteps = localAndOutboundAuthConfig.getAuthenticationSteps();
if (authSteps == null || authSteps.length == 0) {
// if no authentication steps defined - it should be the default behavior.
localAndOutboundAuthConfig.setAuthenticationType(ApplicationConstants.AUTH_TYPE_DEFAULT);
}
try {
if (localAndOutboundAuthConfig.getAuthenticationType() == null) {
// no authentication type defined - set to default.
localAndOutboundAuthConfig.setAuthenticationType(ApplicationConstants.AUTH_TYPE_DEFAULT);
}
updateAuthTypePrepStmt = connection.prepareStatement(UPDATE_BASIC_APPINFO_WITH_AUTH_TYPE);
// AUTH_TYPE=? WHERE TENANT_ID= ? AND ID = ?
updateAuthTypePrepStmt.setString(1, localAndOutboundAuthConfig.getAuthenticationType());
updateAuthTypePrepStmt.setInt(2, tenantID);
updateAuthTypePrepStmt.setInt(3, applicationId);
updateAuthTypePrepStmt.execute();
} finally {
IdentityApplicationManagementUtil.closeStatement(updateAuthTypePrepStmt);
}
if (authSteps != null && authSteps.length > 0) {
// we have authentications steps defined.
PreparedStatement storeStepIDPAuthnPrepStmt = null;
storeStepIDPAuthnPrepStmt = connection.prepareStatement(STORE_STEP_IDP_AUTH);
try {
if (ApplicationConstants.AUTH_TYPE_LOCAL.equalsIgnoreCase(localAndOutboundAuthConfig.getAuthenticationType())) {
// only one local authenticator.
if (authSteps.length != 1 || authSteps[0] == null || authSteps[0].getLocalAuthenticatorConfigs() == null || authSteps[0].getLocalAuthenticatorConfigs().length != 1 || (authSteps[0].getFederatedIdentityProviders() != null && authSteps[0].getFederatedIdentityProviders().length >= 1)) {
String errorMessage = "Invalid local authentication configuration." + " For local authentication there can only be only one authentication step and" + " only one local authenticator";
throw new IdentityApplicationManagementException(errorMessage);
}
} else if (ApplicationConstants.AUTH_TYPE_FEDERATED.equalsIgnoreCase(localAndOutboundAuthConfig.getAuthenticationType())) {
// the corresponding authenticator.
if (authSteps.length != 1 || authSteps[0] == null || authSteps[0].getFederatedIdentityProviders() == null || authSteps[0].getFederatedIdentityProviders().length != 1 || authSteps[0].getLocalAuthenticatorConfigs().length > 0) {
String errorMessage = "Invalid federated authentication configuration." + " For federated authentication there can only be only one authentication step and" + " only one federated authenticator";
throw new IdentityApplicationManagementException(errorMessage);
}
IdentityProvider fedIdp = authSteps[0].getFederatedIdentityProviders()[0];
if (fedIdp.getDefaultAuthenticatorConfig() == null || fedIdp.getFederatedAuthenticatorConfigs() == null) {
IdentityProviderDAO idpDAO = ApplicationMgtSystemConfig.getInstance().getIdentityProviderDAO();
String defualtAuthName = idpDAO.getDefaultAuthenticator(fedIdp.getIdentityProviderName());
// set the default authenticator.
FederatedAuthenticatorConfig defaultAuth = new FederatedAuthenticatorConfig();
defaultAuth.setName(defualtAuthName);
fedIdp.setDefaultAuthenticatorConfig(defaultAuth);
fedIdp.setFederatedAuthenticatorConfigs(new FederatedAuthenticatorConfig[] { defaultAuth });
}
}
// iterating through each step.
for (AuthenticationStep authStep : authSteps) {
int stepId = 0;
IdentityProvider[] federatedIdps = authStep.getFederatedIdentityProviders();
// provider or a local authenticator.
if ((federatedIdps == null || federatedIdps.length == 0) && (authStep.getLocalAuthenticatorConfigs() == null || authStep.getLocalAuthenticatorConfigs().length == 0)) {
String errorMesssage = "Invalid authentication configuration." + "An authentication step should have at least one federated identity " + "provider or a local authenticator";
throw new IdentityApplicationManagementException(errorMesssage);
}
// we have valid federated identity providers.
PreparedStatement storeStepPrepStmtz = null;
ResultSet result = null;
try {
String dbProductName = connection.getMetaData().getDatabaseProductName();
storeStepPrepStmtz = connection.prepareStatement(STORE_STEP_INFO, new String[] { DBUtils.getConvertedAutoGeneratedColumnName(dbProductName, "ID") });
// TENANT_ID, STEP_ORDER, APP_ID
storeStepPrepStmtz.setInt(1, tenantID);
storeStepPrepStmtz.setInt(2, authStep.getStepOrder());
storeStepPrepStmtz.setInt(3, applicationId);
storeStepPrepStmtz.setString(4, authStep.isSubjectStep() ? "1" : "0");
storeStepPrepStmtz.setString(5, authStep.isAttributeStep() ? "1" : "0");
storeStepPrepStmtz.execute();
result = storeStepPrepStmtz.getGeneratedKeys();
if (result.next()) {
stepId = result.getInt(1);
}
} finally {
IdentityApplicationManagementUtil.closeResultSet(result);
IdentityApplicationManagementUtil.closeStatement(storeStepPrepStmtz);
}
if (authStep.getLocalAuthenticatorConfigs() != null && authStep.getLocalAuthenticatorConfigs().length > 0) {
for (LocalAuthenticatorConfig lclAuthenticator : authStep.getLocalAuthenticatorConfigs()) {
// set the identity provider name to LOCAL.
int authenticatorId = getAuthentictorID(connection, tenantID, ApplicationConstants.LOCAL_IDP_NAME, lclAuthenticator.getName());
if (authenticatorId < 0) {
authenticatorId = addAuthenticator(connection, tenantID, ApplicationConstants.LOCAL_IDP_NAME, lclAuthenticator.getName(), lclAuthenticator.getDisplayName());
}
if (authenticatorId > 0) {
// ID, TENANT_ID, AUTHENTICATOR_ID
storeStepIDPAuthnPrepStmt.setInt(1, stepId);
storeStepIDPAuthnPrepStmt.setInt(2, tenantID);
storeStepIDPAuthnPrepStmt.setInt(3, authenticatorId);
storeStepIDPAuthnPrepStmt.addBatch();
}
if (log.isDebugEnabled()) {
log.debug("Updating Local IdP of Application " + applicationId + " Step Order: " + authStep.getStepOrder() + " IdP: " + ApplicationConstants.LOCAL_IDP + " Authenticator: " + lclAuthenticator.getName());
}
}
}
// we have federated identity providers.
if (federatedIdps != null && federatedIdps.length > 0) {
// iterating through each IDP of the step
for (IdentityProvider federatedIdp : federatedIdps) {
String idpName = federatedIdp.getIdentityProviderName();
// the identity provider name wso2carbon-local-idp is reserved.
if (ApplicationConstants.LOCAL_IDP.equalsIgnoreCase(idpName)) {
throw new IdentityApplicationManagementException("The federated IdP name cannot be equal to " + ApplicationConstants.LOCAL_IDP);
}
FederatedAuthenticatorConfig[] authenticators = federatedIdp.getFederatedAuthenticatorConfigs();
if (authenticators != null && authenticators.length > 0) {
for (FederatedAuthenticatorConfig authenticator : authenticators) {
// ID, TENANT_ID, AUTHENTICATOR_ID
if (authenticator != null) {
int authenticatorId = getAuthentictorID(connection, tenantID, idpName, authenticator.getName());
if (authenticatorId > 0) {
storeStepIDPAuthnPrepStmt.setInt(1, stepId);
storeStepIDPAuthnPrepStmt.setInt(2, tenantID);
storeStepIDPAuthnPrepStmt.setInt(3, authenticatorId);
storeStepIDPAuthnPrepStmt.addBatch();
if (log.isDebugEnabled()) {
log.debug("Updating Federated IdP of Application " + applicationId + " Step Order: " + authStep.getStepOrder() + " IdP: " + idpName + " Authenticator: " + authenticator);
}
}
}
}
}
}
}
}
storeStepIDPAuthnPrepStmt.executeBatch();
} finally {
IdentityApplicationManagementUtil.closeStatement(storeStepIDPAuthnPrepStmt);
}
}
}
use of org.wso2.carbon.identity.application.common.model.LocalAndOutboundAuthenticationConfig in project carbon-identity-framework by wso2.
the class DefaultAuthSeqMgtDAOImpl method doGetDefaultAuthSeq.
private DefaultAuthenticationSequence doGetDefaultAuthSeq(String sequenceName, String tenantDomain, JdbcTemplate jdbcTemplate) throws DataAccessException {
return jdbcTemplate.fetchSingleRecord(GET_DEFAULT_SEQ, (resultSet, rowNumber) -> {
DefaultAuthenticationSequence sequence = new DefaultAuthenticationSequence();
sequence.setName(resultSet.getString(1));
sequence.setDescription(resultSet.getString(2));
try {
byte[] requestBytes = resultSet.getBytes(3);
ByteArrayInputStream bais = new ByteArrayInputStream(requestBytes);
ObjectInputStream ois = new ObjectInputStream(bais);
Object objectRead = ois.readObject();
if (objectRead instanceof LocalAndOutboundAuthenticationConfig) {
sequence.setContent((LocalAndOutboundAuthenticationConfig) objectRead);
}
} catch (IOException | ClassNotFoundException e) {
throw new SQLException("Could not get content of default authentication sequence as a " + "Blob.", e);
}
return sequence;
}, (PreparedStatement preparedStatement) -> {
preparedStatement.setString(1, sequenceName);
preparedStatement.setInt(2, getTenantID(tenantDomain));
});
}
use of org.wso2.carbon.identity.application.common.model.LocalAndOutboundAuthenticationConfig in project carbon-identity-framework by wso2.
the class ApplicationBean method updateOutBoundAuthenticationConfig.
/**
* @param request
*/
public void updateOutBoundAuthenticationConfig(HttpServletRequest request) {
String[] authSteps = request.getParameterValues("auth_step");
if (authSteps != null && authSteps.length > 0) {
List<AuthenticationStep> authStepList = new ArrayList<AuthenticationStep>();
for (String authstep : authSteps) {
AuthenticationStep authStep = new AuthenticationStep();
authStep.setStepOrder(Integer.parseInt(authstep));
boolean isSubjectStep = request.getParameter("subject_step_" + authstep) != null && "on".equals(request.getParameter("subject_step_" + authstep)) ? true : false;
authStep.setSubjectStep(isSubjectStep);
boolean isAttributeStep = request.getParameter("attribute_step_" + authstep) != null && "on".equals(request.getParameter("attribute_step_" + authstep)) ? true : false;
authStep.setAttributeStep(isAttributeStep);
String[] localAuthenticatorNames = request.getParameterValues("step_" + authstep + "_local_auth");
if (localAuthenticatorNames != null && localAuthenticatorNames.length > 0) {
List<LocalAuthenticatorConfig> localAuthList = new ArrayList<LocalAuthenticatorConfig>();
for (String name : localAuthenticatorNames) {
if (name != null) {
LocalAuthenticatorConfig localAuth = new LocalAuthenticatorConfig();
localAuth.setName(name);
if (localAuthenticatorConfigs != null) {
for (LocalAuthenticatorConfig config : localAuthenticatorConfigs) {
if (config.getName().equals(name)) {
localAuth.setDisplayName(config.getDisplayName());
break;
}
}
}
localAuthList.add(localAuth);
}
}
if (localAuthList != null && !localAuthList.isEmpty()) {
authStep.setLocalAuthenticatorConfigs(localAuthList.toArray(new LocalAuthenticatorConfig[localAuthList.size()]));
}
}
String[] federatedIdpNames = request.getParameterValues("step_" + authstep + "_fed_auth");
if (federatedIdpNames != null && federatedIdpNames.length > 0) {
List<IdentityProvider> fedIdpList = new ArrayList<>();
for (String name : federatedIdpNames) {
if (StringUtils.isNotBlank(name)) {
IdentityProvider idp = new IdentityProvider();
idp.setIdentityProviderName(name);
IdentityProvider referringIdP = federatedIdentityProvidersMap.get(name);
String authenticatorName = request.getParameter("step_" + authstep + "_idp_" + name + "_fed_authenticator");
if (StringUtils.isNotBlank(authenticatorName)) {
String authenticatorDisplayName = null;
for (FederatedAuthenticatorConfig config : referringIdP.getFederatedAuthenticatorConfigs()) {
if (authenticatorName.equals(config.getName())) {
authenticatorDisplayName = config.getDisplayName();
break;
}
}
FederatedAuthenticatorConfig authenticator = new FederatedAuthenticatorConfig();
authenticator.setName(authenticatorName);
authenticator.setDisplayName(authenticatorDisplayName);
idp.setDefaultAuthenticatorConfig(authenticator);
idp.setFederatedAuthenticatorConfigs(new FederatedAuthenticatorConfig[] { authenticator });
fedIdpList.add(idp);
}
}
}
if (fedIdpList != null && !fedIdpList.isEmpty()) {
authStep.setFederatedIdentityProviders(fedIdpList.toArray(new IdentityProvider[fedIdpList.size()]));
}
}
if ((authStep.getFederatedIdentityProviders() != null && authStep.getFederatedIdentityProviders().length > 0) || (authStep.getLocalAuthenticatorConfigs() != null && authStep.getLocalAuthenticatorConfigs().length > 0)) {
authStepList.add(authStep);
}
}
if (serviceProvider.getLocalAndOutBoundAuthenticationConfig() == null) {
serviceProvider.setLocalAndOutBoundAuthenticationConfig(new LocalAndOutboundAuthenticationConfig());
}
if (CollectionUtils.isNotEmpty(authStepList)) {
LocalAndOutboundAuthenticationConfig localAndOutboundAuthenticationConfig = serviceProvider.getLocalAndOutBoundAuthenticationConfig();
localAndOutboundAuthenticationConfig.setAuthenticationSteps(authStepList.toArray(new AuthenticationStep[authStepList.size()]));
}
}
}
use of org.wso2.carbon.identity.application.common.model.LocalAndOutboundAuthenticationConfig in project carbon-identity-framework by wso2.
the class ApplicationBean method conditionalAuthentication.
/**
* @param request
*/
public void conditionalAuthentication(HttpServletRequest request) {
AuthenticationScriptConfig authenticationScriptConfig = new AuthenticationScriptConfig();
LocalAndOutboundAuthenticationConfig localAndOutboundAuthenticationConfig = serviceProvider.getLocalAndOutBoundAuthenticationConfig();
String flawByScript = request.getParameter("scriptTextArea");
if (StringUtils.isBlank(flawByScript)) {
authenticationScriptConfig.setEnabled(false);
} else {
if ("true".equalsIgnoreCase(request.getParameter("enableScript"))) {
authenticationScriptConfig.setEnabled(true);
} else {
authenticationScriptConfig.setEnabled(false);
}
}
authenticationScriptConfig.setContent(flawByScript);
localAndOutboundAuthenticationConfig.setAuthenticationScriptConfig(authenticationScriptConfig);
}
Aggregations