Search in sources :

Example 1 with DefaultAuthenticationSequence

use of org.wso2.carbon.identity.application.common.model.DefaultAuthenticationSequence 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));
    });
}
Also used : DefaultAuthenticationSequence(org.wso2.carbon.identity.application.common.model.DefaultAuthenticationSequence) LocalAndOutboundAuthenticationConfig(org.wso2.carbon.identity.application.common.model.LocalAndOutboundAuthenticationConfig) ByteArrayInputStream(java.io.ByteArrayInputStream) SQLException(java.sql.SQLException) PreparedStatement(java.sql.PreparedStatement) IOException(java.io.IOException) ObjectInputStream(java.io.ObjectInputStream)

Example 2 with DefaultAuthenticationSequence

use of org.wso2.carbon.identity.application.common.model.DefaultAuthenticationSequence in project carbon-identity-framework by wso2.

the class ApplicationManagementServiceImpl method setDefaultAuthenticationSeq.

private void setDefaultAuthenticationSeq(String sequenceName, String tenantDomain, ServiceProvider serviceProvider) throws IdentityApplicationManagementException {
    // if "Authentication Type" is "Default", get the tenant wise default authentication sequence if
    // available, otherwise the authentication sequence and adaptive script configuration in default SP
    DefaultAuthSeqMgtService seqMgtService = DefaultAuthSeqMgtServiceImpl.getInstance();
    DefaultAuthenticationSequence sequence;
    try {
        sequence = seqMgtService.getDefaultAuthenticationSeq(sequenceName, tenantDomain);
    } catch (DefaultAuthSeqMgtException e) {
        throw new IdentityApplicationManagementException("Error when retrieving default " + "authentication sequence in tenant: " + tenantDomain, e);
    }
    if (sequence != null && sequence.getContent() != null) {
        serviceProvider.getLocalAndOutBoundAuthenticationConfig().setAuthenticationSteps(sequence.getContent().getAuthenticationSteps());
        serviceProvider.getLocalAndOutBoundAuthenticationConfig().setAuthenticationScriptConfig(sequence.getContent().getAuthenticationScriptConfig());
    } else {
        ServiceProvider defaultSP = ApplicationManagementServiceComponent.getFileBasedSPs().get(IdentityApplicationConstants.DEFAULT_SP_CONFIG);
        serviceProvider.getLocalAndOutBoundAuthenticationConfig().setAuthenticationSteps(defaultSP.getLocalAndOutBoundAuthenticationConfig().getAuthenticationSteps());
        serviceProvider.getLocalAndOutBoundAuthenticationConfig().setAuthenticationScriptConfig(defaultSP.getLocalAndOutBoundAuthenticationConfig().getAuthenticationScriptConfig());
    }
}
Also used : DefaultAuthenticationSequence(org.wso2.carbon.identity.application.common.model.DefaultAuthenticationSequence) DefaultAuthSeqMgtService(org.wso2.carbon.identity.application.mgt.defaultsequence.DefaultAuthSeqMgtService) DefaultAuthSeqMgtException(org.wso2.carbon.identity.application.mgt.defaultsequence.DefaultAuthSeqMgtException) IdentityApplicationManagementException(org.wso2.carbon.identity.application.common.IdentityApplicationManagementException) ServiceProvider(org.wso2.carbon.identity.application.common.model.ServiceProvider)

Example 3 with DefaultAuthenticationSequence

use of org.wso2.carbon.identity.application.common.model.DefaultAuthenticationSequence in project carbon-identity-framework by wso2.

the class DefaultAuthSeqMgtServiceImpl method doGetDefaultAuthenticationSeqInfo.

private DefaultAuthenticationSequence doGetDefaultAuthenticationSeqInfo(String sequenceName, String tenantDomain) throws DefaultAuthSeqMgtException {
    DefaultAuthenticationSequence sequence = getDefaultAuthSeqFromCache(sequenceName, tenantDomain);
    if (sequence == null) {
        DefaultAuthSeqMgtDAO seqMgtDAO = new DefaultAuthSeqMgtDAOImpl();
        sequence = seqMgtDAO.getDefaultAuthenticationSeqInfo(sequenceName, tenantDomain);
    }
    return sequence;
}
Also used : DefaultAuthenticationSequence(org.wso2.carbon.identity.application.common.model.DefaultAuthenticationSequence) DefaultAuthSeqMgtDAOImpl(org.wso2.carbon.identity.application.mgt.dao.impl.DefaultAuthSeqMgtDAOImpl) DefaultAuthSeqMgtDAO(org.wso2.carbon.identity.application.mgt.dao.DefaultAuthSeqMgtDAO)

Example 4 with DefaultAuthenticationSequence

use of org.wso2.carbon.identity.application.common.model.DefaultAuthenticationSequence in project carbon-identity-framework by wso2.

the class DefaultAuthSeqMgtServiceImpl method addDefaultAuthSeqToCache.

private void addDefaultAuthSeqToCache(DefaultAuthenticationSequence sequence, String tenantDomain) {
    if (DefaultAuthSeqMgtCache.getInstance().isEnabled()) {
        DefaultAuthSeqMgtCacheEntry entry = new DefaultAuthSeqMgtCacheEntry(sequence);
        DefaultAuthSeqMgtCache.getInstance().addToCache(sequence.getName(), entry, tenantDomain);
        if (log.isDebugEnabled()) {
            log.debug("Default authentication sequence for tenant: " + tenantDomain + " is added to cache.");
        }
    }
}
Also used : DefaultAuthSeqMgtCacheEntry(org.wso2.carbon.identity.application.mgt.cache.DefaultAuthSeqMgtCacheEntry)

Example 5 with DefaultAuthenticationSequence

use of org.wso2.carbon.identity.application.common.model.DefaultAuthenticationSequence in project carbon-identity-framework by wso2.

the class DefaultAuthSeqMgtServiceImpl method validateAuthSeqConfiguration.

private void validateAuthSeqConfiguration(DefaultAuthenticationSequence sequence, String tenantDomain, String errorMsg) throws DefaultAuthSeqMgtException {
    List<String> validationMsg = new ArrayList<>();
    LocalAndOutboundAuthenticationConfig authenticationConfig = sequence.getContent();
    if (authenticationConfig == null) {
        return;
    }
    AuthenticationStep[] authenticationSteps = authenticationConfig.getAuthenticationSteps();
    if (authenticationSteps == null || authenticationSteps.length == 0) {
        return;
    }
    Map<String, Property[]> allLocalAuthenticators;
    try {
        allLocalAuthenticators = getAllLocalAuthenticators(tenantDomain);
    } catch (IdentityApplicationManagementException e) {
        throw new DefaultAuthSeqMgtServerException(errorMsg, e);
    }
    AtomicBoolean isAuthenticatorIncluded = new AtomicBoolean(false);
    for (AuthenticationStep authenticationStep : authenticationSteps) {
        if (authenticationStep == null || (authenticationStep.getFederatedIdentityProviders() == null && authenticationStep.getLocalAuthenticatorConfigs() == null)) {
            validationMsg.add("Some authentication steps do not have authenticators.");
            break;
        }
        for (IdentityProvider idp : authenticationStep.getFederatedIdentityProviders()) {
            validateFederatedIdp(idp, isAuthenticatorIncluded, validationMsg, tenantDomain);
        }
        validateLocalAuthenticatorConfig(validationMsg, allLocalAuthenticators, isAuthenticatorIncluded, authenticationStep);
    }
    if (!isAuthenticatorIncluded.get()) {
        validationMsg.add("No authenticator have been registered in the authentication flow.");
    }
    if (!validationMsg.isEmpty()) {
        log.error(errorMsg + tenantDomain);
        for (String msg : validationMsg) {
            log.error(msg);
        }
        throw new DefaultAuthSeqMgtException(validationMsg.toArray(new String[0]));
    }
    removeUnsupportedConfigurations(authenticationConfig);
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) LocalAndOutboundAuthenticationConfig(org.wso2.carbon.identity.application.common.model.LocalAndOutboundAuthenticationConfig) IdentityApplicationManagementException(org.wso2.carbon.identity.application.common.IdentityApplicationManagementException) ArrayList(java.util.ArrayList) AuthenticationStep(org.wso2.carbon.identity.application.common.model.AuthenticationStep) IdentityProvider(org.wso2.carbon.identity.application.common.model.IdentityProvider)

Aggregations

DefaultAuthenticationSequence (org.wso2.carbon.identity.application.common.model.xsd.DefaultAuthenticationSequence)9 Test (org.testng.annotations.Test)8 IdentityDefaultSeqManagementServiceDefaultAuthSeqMgtException (org.wso2.carbon.identity.application.mgt.defaultsequence.stub.IdentityDefaultSeqManagementServiceDefaultAuthSeqMgtException)8 ISIntegrationTest (org.wso2.identity.integration.common.utils.ISIntegrationTest)8 IOException (java.io.IOException)6 DefaultAuthenticationSequence (org.wso2.carbon.identity.application.common.model.DefaultAuthenticationSequence)6 URISyntaxException (java.net.URISyntaxException)5 DefaultAuthSeqMgtDAO (org.wso2.carbon.identity.application.mgt.dao.DefaultAuthSeqMgtDAO)5 DefaultAuthSeqMgtDAOImpl (org.wso2.carbon.identity.application.mgt.dao.impl.DefaultAuthSeqMgtDAOImpl)5 PreparedStatement (java.sql.PreparedStatement)2 IdentityApplicationManagementException (org.wso2.carbon.identity.application.common.IdentityApplicationManagementException)2 LocalAndOutboundAuthenticationConfig (org.wso2.carbon.identity.application.common.model.LocalAndOutboundAuthenticationConfig)2 DefaultAuthSeqMgtCacheEntry (org.wso2.carbon.identity.application.mgt.cache.DefaultAuthSeqMgtCacheEntry)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ObjectInputStream (java.io.ObjectInputStream)1 SQLException (java.sql.SQLException)1 ArrayList (java.util.ArrayList)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 AuthenticationStep (org.wso2.carbon.identity.application.common.model.AuthenticationStep)1 IdentityProvider (org.wso2.carbon.identity.application.common.model.IdentityProvider)1