Search in sources :

Example 1 with DefaultAuthSeqMgtException

use of org.wso2.carbon.identity.application.mgt.defaultsequence.DefaultAuthSeqMgtException 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 2 with DefaultAuthSeqMgtException

use of org.wso2.carbon.identity.application.mgt.defaultsequence.DefaultAuthSeqMgtException 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 3 with DefaultAuthSeqMgtException

use of org.wso2.carbon.identity.application.mgt.defaultsequence.DefaultAuthSeqMgtException 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)

Example 4 with DefaultAuthSeqMgtException

use of org.wso2.carbon.identity.application.mgt.defaultsequence.DefaultAuthSeqMgtException in project carbon-identity-framework by wso2.

the class DefaultAuthSeqMgtServiceImpl method doGetDefaultAuthSeq.

private DefaultAuthenticationSequence doGetDefaultAuthSeq(String sequenceName, String tenantDomain) throws DefaultAuthSeqMgtException {
    if (DefaultAuthSeqMgtCache.getInstance().isEnabled()) {
        DefaultAuthSeqMgtCacheEntry entry = DefaultAuthSeqMgtCache.getInstance().getValueFromCache(sequenceName, tenantDomain);
        if (entry != null) {
            if (log.isDebugEnabled()) {
                log.debug("Default authentication sequence of tenant: " + tenantDomain + " is retrieved from cache.");
            }
            return entry.getSequence();
        }
    }
    DefaultAuthSeqMgtDAO seqMgtDAO = new DefaultAuthSeqMgtDAOImpl();
    DefaultAuthenticationSequence sequence = seqMgtDAO.getDefaultAuthenticationSeq(sequenceName, tenantDomain);
    if (sequence != null) {
        addDefaultAuthSeqToCache(sequence, tenantDomain);
    }
    return sequence;
}
Also used : DefaultAuthSeqMgtCacheEntry(org.wso2.carbon.identity.application.mgt.cache.DefaultAuthSeqMgtCacheEntry) 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 5 with DefaultAuthSeqMgtException

use of org.wso2.carbon.identity.application.mgt.defaultsequence.DefaultAuthSeqMgtException in project carbon-identity-framework by wso2.

the class DefaultAuthSeqMgtServiceImpl method unmarshalDefaultAuthSeq.

/**
 * Convert xml file of default authentication sequence to object.
 *
 * @param defaultAuthSeq xml string of the default authentication sequence
 * @param tenantDomain   tenant domain name
 * @return LocalAndOutboundAuthenticationConfig instance
 * @throws DefaultAuthSeqMgtException Auth Sequence Management Client Exception
 */
private LocalAndOutboundAuthenticationConfig unmarshalDefaultAuthSeq(String defaultAuthSeq, String tenantDomain) throws DefaultAuthSeqMgtException {
    if (StringUtils.isEmpty(defaultAuthSeq)) {
        throw new DefaultAuthSeqMgtException(new String[] { "Empty default authentication sequence " + "configuration is provided" });
    }
    try {
        JAXBContext jaxbContext = JAXBContext.newInstance(LocalAndOutboundAuthenticationConfig.class);
        Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
        JAXBElement<LocalAndOutboundAuthenticationConfig> root = unmarshaller.unmarshal(new StreamSource(new ByteArrayInputStream(defaultAuthSeq.getBytes(StandardCharsets.UTF_8))), LocalAndOutboundAuthenticationConfig.class);
        if (root.getName().getLocalPart().equalsIgnoreCase(LocalAndOutboundAuthenticationConfig.class.getSimpleName())) {
            return root.getValue();
        }
        throw new DefaultAuthSeqMgtException(new String[] { "Syntax error in the provided default " + "authentication sequence" });
    } catch (JAXBException e) {
        String msg = "Error in reading default authentication sequence configuration in tenant: " + tenantDomain;
        log.error(msg, e);
        throw new DefaultAuthSeqMgtException(new String[] { msg });
    }
}
Also used : LocalAndOutboundAuthenticationConfig(org.wso2.carbon.identity.application.common.model.LocalAndOutboundAuthenticationConfig) ByteArrayInputStream(java.io.ByteArrayInputStream) StreamSource(javax.xml.transform.stream.StreamSource) JAXBException(javax.xml.bind.JAXBException) JAXBContext(javax.xml.bind.JAXBContext) Unmarshaller(javax.xml.bind.Unmarshaller)

Aggregations

DefaultAuthenticationSequence (org.wso2.carbon.identity.application.common.model.DefaultAuthenticationSequence)4 DefaultAuthSeqMgtDAO (org.wso2.carbon.identity.application.mgt.dao.DefaultAuthSeqMgtDAO)4 DefaultAuthSeqMgtDAOImpl (org.wso2.carbon.identity.application.mgt.dao.impl.DefaultAuthSeqMgtDAOImpl)4 IdentityApplicationManagementException (org.wso2.carbon.identity.application.common.IdentityApplicationManagementException)2 LocalAndOutboundAuthenticationConfig (org.wso2.carbon.identity.application.common.model.LocalAndOutboundAuthenticationConfig)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ArrayList (java.util.ArrayList)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 JAXBContext (javax.xml.bind.JAXBContext)1 JAXBException (javax.xml.bind.JAXBException)1 Unmarshaller (javax.xml.bind.Unmarshaller)1 StreamSource (javax.xml.transform.stream.StreamSource)1 AuthenticationStep (org.wso2.carbon.identity.application.common.model.AuthenticationStep)1 IdentityProvider (org.wso2.carbon.identity.application.common.model.IdentityProvider)1 ServiceProvider (org.wso2.carbon.identity.application.common.model.ServiceProvider)1 DefaultAuthSeqMgtCacheEntry (org.wso2.carbon.identity.application.mgt.cache.DefaultAuthSeqMgtCacheEntry)1 DefaultAuthSeqMgtException (org.wso2.carbon.identity.application.mgt.defaultsequence.DefaultAuthSeqMgtException)1 DefaultAuthSeqMgtService (org.wso2.carbon.identity.application.mgt.defaultsequence.DefaultAuthSeqMgtService)1