Search in sources :

Example 6 with LocalAuthenticatorConfig

use of org.wso2.carbon.identity.application.common.model.xsd.LocalAuthenticatorConfig 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()]));
        }
    }
}
Also used : LocalAndOutboundAuthenticationConfig(org.wso2.carbon.identity.application.common.model.xsd.LocalAndOutboundAuthenticationConfig) FederatedAuthenticatorConfig(org.wso2.carbon.identity.application.common.model.xsd.FederatedAuthenticatorConfig) ArrayList(java.util.ArrayList) LocalAuthenticatorConfig(org.wso2.carbon.identity.application.common.model.xsd.LocalAuthenticatorConfig) AuthenticationStep(org.wso2.carbon.identity.application.common.model.xsd.AuthenticationStep) IdentityProvider(org.wso2.carbon.identity.application.common.model.xsd.IdentityProvider)

Example 7 with LocalAuthenticatorConfig

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

the class ApplicationBean method setStepZeroAuthenticatorName.

public void setStepZeroAuthenticatorName(String type, String name) {
    if (AUTH_TYPE_LOCAL.equalsIgnoreCase(type)) {
        LocalAuthenticatorConfig localAuthenticator = new LocalAuthenticatorConfig();
        localAuthenticator.setName(name);
        AuthenticationStep authStep = new AuthenticationStep();
        authStep.setLocalAuthenticatorConfigs(new LocalAuthenticatorConfig[] { localAuthenticator });
    }
}
Also used : LocalAuthenticatorConfig(org.wso2.carbon.identity.application.common.model.xsd.LocalAuthenticatorConfig) AuthenticationStep(org.wso2.carbon.identity.application.common.model.xsd.AuthenticationStep)

Example 8 with LocalAuthenticatorConfig

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

the class FrameworkServiceComponent method setAuthenticator.

@Reference(name = "application.authenticator", service = ApplicationAuthenticator.class, cardinality = ReferenceCardinality.AT_LEAST_ONE, policy = ReferencePolicy.DYNAMIC, unbind = "unsetAuthenticator")
protected void setAuthenticator(ApplicationAuthenticator authenticator) {
    FrameworkServiceDataHolder.getInstance().getAuthenticators().add(authenticator);
    Property[] configProperties = null;
    List<Property> configurationProperties = authenticator.getConfigurationProperties();
    if (configurationProperties == null) {
        configurationProperties = new ArrayList<>();
    }
    if (authenticator instanceof AuthenticationFlowHandler) {
        Property handlerProperty = new Property();
        handlerProperty.setName(IS_HANDLER);
        handlerProperty.setValue(TRUE);
        configurationProperties.add(handlerProperty);
    }
    if (!configurationProperties.isEmpty()) {
        configProperties = configurationProperties.toArray(new Property[0]);
    }
    if ((authenticator instanceof LocalApplicationAuthenticator) || (authenticator instanceof AuthenticationFlowHandler)) {
        LocalAuthenticatorConfig localAuthenticatorConfig = new LocalAuthenticatorConfig();
        localAuthenticatorConfig.setName(authenticator.getName());
        localAuthenticatorConfig.setProperties(configProperties);
        localAuthenticatorConfig.setDisplayName(authenticator.getFriendlyName());
        localAuthenticatorConfig.setTags(authenticator.getTags());
        AuthenticatorConfig fileBasedConfig = getAuthenticatorConfig(authenticator.getName());
        localAuthenticatorConfig.setEnabled(fileBasedConfig.isEnabled());
        ApplicationAuthenticatorService.getInstance().addLocalAuthenticator(localAuthenticatorConfig);
    } else if (authenticator instanceof FederatedApplicationAuthenticator) {
        FederatedAuthenticatorConfig federatedAuthenticatorConfig = new FederatedAuthenticatorConfig();
        federatedAuthenticatorConfig.setName(authenticator.getName());
        federatedAuthenticatorConfig.setProperties(configProperties);
        federatedAuthenticatorConfig.setDisplayName(authenticator.getFriendlyName());
        federatedAuthenticatorConfig.setTags(authenticator.getTags());
        ApplicationAuthenticatorService.getInstance().addFederatedAuthenticator(federatedAuthenticatorConfig);
    } else if (authenticator instanceof RequestPathApplicationAuthenticator) {
        RequestPathAuthenticatorConfig reqPathAuthenticatorConfig = new RequestPathAuthenticatorConfig();
        reqPathAuthenticatorConfig.setName(authenticator.getName());
        reqPathAuthenticatorConfig.setProperties(configProperties);
        reqPathAuthenticatorConfig.setDisplayName(authenticator.getFriendlyName());
        reqPathAuthenticatorConfig.setTags(authenticator.getTags());
        AuthenticatorConfig fileBasedConfig = getAuthenticatorConfig(authenticator.getName());
        reqPathAuthenticatorConfig.setEnabled(fileBasedConfig.isEnabled());
        ApplicationAuthenticatorService.getInstance().addRequestPathAuthenticator(reqPathAuthenticatorConfig);
    }
    if (log.isDebugEnabled()) {
        log.debug("Added application authenticator : " + authenticator.getName());
    }
}
Also used : RequestPathAuthenticatorConfig(org.wso2.carbon.identity.application.common.model.RequestPathAuthenticatorConfig) LocalAuthenticatorConfig(org.wso2.carbon.identity.application.common.model.LocalAuthenticatorConfig) AuthenticatorConfig(org.wso2.carbon.identity.application.authentication.framework.config.model.AuthenticatorConfig) FederatedAuthenticatorConfig(org.wso2.carbon.identity.application.common.model.FederatedAuthenticatorConfig) FederatedAuthenticatorConfig(org.wso2.carbon.identity.application.common.model.FederatedAuthenticatorConfig) RequestPathApplicationAuthenticator(org.wso2.carbon.identity.application.authentication.framework.RequestPathApplicationAuthenticator) AuthenticationFlowHandler(org.wso2.carbon.identity.application.authentication.framework.AuthenticationFlowHandler) LocalAuthenticatorConfig(org.wso2.carbon.identity.application.common.model.LocalAuthenticatorConfig) RequestPathAuthenticatorConfig(org.wso2.carbon.identity.application.common.model.RequestPathAuthenticatorConfig) Property(org.wso2.carbon.identity.application.common.model.Property) LocalApplicationAuthenticator(org.wso2.carbon.identity.application.authentication.framework.LocalApplicationAuthenticator) FederatedApplicationAuthenticator(org.wso2.carbon.identity.application.authentication.framework.FederatedApplicationAuthenticator) Reference(org.osgi.service.component.annotations.Reference)

Example 9 with LocalAuthenticatorConfig

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

the class DefaultApplicationValidator method validateLocalAndOutBoundAuthenticationConfig.

/**
 * Validate local and outbound authenticator related configurations and append to the validation msg list.
 *
 * @param validationMsg                        validation error messages
 * @param localAndOutBoundAuthenticationConfig local and out bound authentication config
 * @param tenantDomain                         tenant domain
 * @throws IdentityApplicationManagementException Identity Application Management Exception when unable to get the
 *                                                authenticator params
 */
private void validateLocalAndOutBoundAuthenticationConfig(List<String> validationMsg, LocalAndOutboundAuthenticationConfig localAndOutBoundAuthenticationConfig, String tenantDomain) throws IdentityApplicationManagementException {
    if (localAndOutBoundAuthenticationConfig == null) {
        return;
    }
    AuthenticationStep[] authenticationSteps = localAndOutBoundAuthenticationConfig.getAuthenticationSteps();
    if (authenticationSteps == null || authenticationSteps.length == 0) {
        return;
    }
    ApplicationManagementService applicationMgtService = ApplicationManagementService.getInstance();
    Map<String, Property[]> allLocalAuthenticators = Arrays.stream(applicationMgtService.getAllLocalAuthenticators(tenantDomain)).collect(Collectors.toMap(LocalAuthenticatorConfig::getName, LocalAuthenticatorConfig::getProperties));
    AtomicBoolean isAuthenticatorIncluded = new AtomicBoolean(false);
    for (AuthenticationStep authenticationStep : authenticationSteps) {
        for (IdentityProvider idp : authenticationStep.getFederatedIdentityProviders()) {
            validateFederatedIdp(idp, isAuthenticatorIncluded, validationMsg, tenantDomain);
        }
        for (LocalAuthenticatorConfig localAuth : authenticationStep.getLocalAuthenticatorConfigs()) {
            if (!allLocalAuthenticators.containsKey(localAuth.getName())) {
                validationMsg.add(String.format(AUTHENTICATOR_NOT_AVAILABLE, localAuth.getName()));
            } else if (!isAuthenticatorIncluded.get()) {
                Property[] properties = allLocalAuthenticators.get(localAuth.getName());
                if (properties.length == 0) {
                    isAuthenticatorIncluded.set(true);
                } else {
                    for (Property property : properties) {
                        if (!(IS_HANDLER.equals(property.getName()) && Boolean.parseBoolean(property.getValue()))) {
                            isAuthenticatorIncluded.set(true);
                        }
                    }
                }
            }
        }
    }
    if (!isAuthenticatorIncluded.get()) {
        validationMsg.add("No authenticator have been registered in the authentication flow.");
    }
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) LocalAuthenticatorConfig(org.wso2.carbon.identity.application.common.model.LocalAuthenticatorConfig) AuthenticationStep(org.wso2.carbon.identity.application.common.model.AuthenticationStep) IdentityProvider(org.wso2.carbon.identity.application.common.model.IdentityProvider) ApplicationManagementService(org.wso2.carbon.identity.application.mgt.ApplicationManagementService) Property(org.wso2.carbon.identity.application.common.model.Property)

Example 10 with LocalAuthenticatorConfig

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

the class ApplicationManagementServiceImplTest method addApplicationConfigurations.

private void addApplicationConfigurations(ServiceProvider serviceProvider) {
    serviceProvider.setDescription("Created for testing");
    serviceProvider.setSaasApp(TRUE);
    // Inbound Authentication Configurations.
    InboundAuthenticationConfig inboundAuthenticationConfig = new InboundAuthenticationConfig();
    InboundAuthenticationRequestConfig authRequestConfig = new InboundAuthenticationRequestConfig();
    authRequestConfig.setInboundAuthKey("auth key");
    authRequestConfig.setInboundAuthType("oauth2");
    InboundAuthenticationRequestConfig[] authRequests = new InboundAuthenticationRequestConfig[] { authRequestConfig };
    inboundAuthenticationConfig.setInboundAuthenticationRequestConfigs(authRequests);
    serviceProvider.setInboundAuthenticationConfig(inboundAuthenticationConfig);
    // Inbound Provisioning Configurations.
    InboundProvisioningConfig provisioningConfig = new InboundProvisioningConfig();
    provisioningConfig.setProvisioningUserStore("UserStore");
    serviceProvider.setInboundProvisioningConfig(provisioningConfig);
    // OutBound Provisioning Configurations.
    IdentityProvider provisioningIdP = new IdentityProvider();
    provisioningIdP.setIdentityProviderName("Provisioning IdP");
    OutboundProvisioningConfig outboundProvisioningConfig = new OutboundProvisioningConfig();
    outboundProvisioningConfig.setProvisioningIdentityProviders(new IdentityProvider[] { provisioningIdP });
    ProvisioningConnectorConfig provisioningConnectorConfig = new ProvisioningConnectorConfig();
    provisioningConnectorConfig.setName("Provisioning connector");
    provisioningIdP.setDefaultProvisioningConnectorConfig(provisioningConnectorConfig);
    serviceProvider.setOutboundProvisioningConfig(outboundProvisioningConfig);
    // Local And OutBound Authentication Configuration.
    LocalAndOutboundAuthenticationConfig authenticationConfig = new LocalAndOutboundAuthenticationConfig();
    AuthenticationStep authenticationStep = new AuthenticationStep();
    IdentityProvider identityProvider = new IdentityProvider();
    identityProvider.setIdentityProviderName(IDP_NAME_1);
    FederatedAuthenticatorConfig federatedAuthenticatorConfig = new FederatedAuthenticatorConfig();
    federatedAuthenticatorConfig.setName("Federated authenticator");
    identityProvider.setFederatedAuthenticatorConfigs(new FederatedAuthenticatorConfig[] { federatedAuthenticatorConfig });
    authenticationStep.setFederatedIdentityProviders(new IdentityProvider[] { identityProvider });
    LocalAuthenticatorConfig localAuthenticatorConfig = new LocalAuthenticatorConfig();
    localAuthenticatorConfig.setName("Local authenticator");
    authenticationStep.setLocalAuthenticatorConfigs(new LocalAuthenticatorConfig[] { localAuthenticatorConfig });
    authenticationConfig.setAuthenticationSteps(new AuthenticationStep[] { authenticationStep });
    serviceProvider.setLocalAndOutBoundAuthenticationConfig(authenticationConfig);
    // Request Path Authenticator Configuration.
    RequestPathAuthenticatorConfig requestPathAuthenticatorConfig = new RequestPathAuthenticatorConfig();
    requestPathAuthenticatorConfig.setName("Request path authenticator");
    serviceProvider.setRequestPathAuthenticatorConfigs(new RequestPathAuthenticatorConfig[] { requestPathAuthenticatorConfig });
    // Claim Configurations.
    ClaimConfig claimConfig = new ClaimConfig();
    claimConfig.setRoleClaimURI("Role claim uri");
    claimConfig.setSpClaimDialects(new String[] { "SP claim dialect" });
    ClaimMapping claimMapping = new ClaimMapping();
    Claim localClaim = new Claim();
    localClaim.setClaimUri("Local claim uri");
    Claim remoteClaim = new Claim();
    remoteClaim.setClaimUri("Remote claim uri");
    claimMapping.setLocalClaim(localClaim);
    claimMapping.setRemoteClaim(remoteClaim);
    claimConfig.setClaimMappings(new ClaimMapping[] { claimMapping });
    serviceProvider.setClaimConfig(claimConfig);
    // Permission Role Configurations.
    PermissionsAndRoleConfig permissionsAndRoleConfig = new PermissionsAndRoleConfig();
    RoleMapping roleMapping = new RoleMapping();
    LocalRole localRole = new LocalRole("Local role");
    roleMapping.setLocalRole(localRole);
    roleMapping.setRemoteRole("Remote role");
    RoleMapping[] roleMappings = new RoleMapping[] { roleMapping };
    permissionsAndRoleConfig.setRoleMappings(roleMappings);
}
Also used : InboundProvisioningConfig(org.wso2.carbon.identity.application.common.model.InboundProvisioningConfig) InboundAuthenticationConfig(org.wso2.carbon.identity.application.common.model.InboundAuthenticationConfig) FederatedAuthenticatorConfig(org.wso2.carbon.identity.application.common.model.FederatedAuthenticatorConfig) LocalAuthenticatorConfig(org.wso2.carbon.identity.application.common.model.LocalAuthenticatorConfig) AuthenticationStep(org.wso2.carbon.identity.application.common.model.AuthenticationStep) InboundAuthenticationRequestConfig(org.wso2.carbon.identity.application.common.model.InboundAuthenticationRequestConfig) IdentityProvider(org.wso2.carbon.identity.application.common.model.IdentityProvider) RoleMapping(org.wso2.carbon.identity.application.common.model.RoleMapping) OutboundProvisioningConfig(org.wso2.carbon.identity.application.common.model.OutboundProvisioningConfig) ClaimMapping(org.wso2.carbon.identity.application.common.model.ClaimMapping) LocalAndOutboundAuthenticationConfig(org.wso2.carbon.identity.application.common.model.LocalAndOutboundAuthenticationConfig) ClaimConfig(org.wso2.carbon.identity.application.common.model.ClaimConfig) PermissionsAndRoleConfig(org.wso2.carbon.identity.application.common.model.PermissionsAndRoleConfig) RequestPathAuthenticatorConfig(org.wso2.carbon.identity.application.common.model.RequestPathAuthenticatorConfig) LocalRole(org.wso2.carbon.identity.application.common.model.LocalRole) ProvisioningConnectorConfig(org.wso2.carbon.identity.application.common.model.ProvisioningConnectorConfig) Claim(org.wso2.carbon.identity.application.common.model.Claim)

Aggregations

LocalAuthenticatorConfig (org.wso2.carbon.identity.application.common.model.LocalAuthenticatorConfig)19 IdentityProvider (org.wso2.carbon.identity.application.common.model.IdentityProvider)11 FederatedAuthenticatorConfig (org.wso2.carbon.identity.application.common.model.FederatedAuthenticatorConfig)9 RequestPathAuthenticatorConfig (org.wso2.carbon.identity.application.common.model.RequestPathAuthenticatorConfig)8 AuthenticationStep (org.wso2.carbon.identity.application.common.model.xsd.AuthenticationStep)8 LocalAuthenticatorConfig (org.wso2.carbon.identity.application.common.model.xsd.LocalAuthenticatorConfig)8 ArrayList (java.util.ArrayList)7 AuthenticationStep (org.wso2.carbon.identity.application.common.model.AuthenticationStep)7 LocalAndOutboundAuthenticationConfig (org.wso2.carbon.identity.application.common.model.xsd.LocalAndOutboundAuthenticationConfig)6 HashMap (java.util.HashMap)4 AuthenticatorConfig (org.wso2.carbon.identity.application.authentication.framework.config.model.AuthenticatorConfig)4 IdentityApplicationManagementException (org.wso2.carbon.identity.application.common.IdentityApplicationManagementException)4 Map (java.util.Map)3 Authenticator (org.wso2.carbon.identity.api.server.authenticators.v1.model.Authenticator)3 StepConfig (org.wso2.carbon.identity.application.authentication.framework.config.model.StepConfig)3 Property (org.wso2.carbon.identity.application.common.model.Property)3 IOException (java.io.IOException)2 PreparedStatement (java.sql.PreparedStatement)2 ResultSet (java.sql.ResultSet)2 List (java.util.List)2