Search in sources :

Example 46 with FederatedAuthenticatorConfig

use of org.wso2.carbon.identity.application.common.model.xsd.FederatedAuthenticatorConfig in project product-is by wso2.

the class SelfRegistrationTestCase method updateFederatedAuthenticators.

private void updateFederatedAuthenticators(IdentityProvider identityProvider) {
    List<FederatedAuthenticatorConfig> updatedConfigs = new ArrayList<>();
    for (FederatedAuthenticatorConfig config : identityProvider.getFederatedAuthenticatorConfigs()) {
        if ("samlsso".equals(config.getName())) {
            updatedConfigs.add(config);
        } else if ("openidconnect".equals(config.getName())) {
            updatedConfigs.add(config);
        } else if ("passivests".equals(config.getName())) {
            updatedConfigs.add(config);
        }
    }
    identityProvider.setFederatedAuthenticatorConfigs(updatedConfigs.toArray(new FederatedAuthenticatorConfig[0]));
}
Also used : FederatedAuthenticatorConfig(org.wso2.carbon.identity.application.common.model.idp.xsd.FederatedAuthenticatorConfig) ArrayList(java.util.ArrayList)

Example 47 with FederatedAuthenticatorConfig

use of org.wso2.carbon.identity.application.common.model.xsd.FederatedAuthenticatorConfig in project identity-api-server by wso2.

the class ServerIdpManagementService method createFederatedAuthenticatorResponse.

private FederatedAuthenticatorListResponse createFederatedAuthenticatorResponse(IdentityProvider idp) {
    FederatedAuthenticatorConfig[] fedAuthConfigs = idp.getFederatedAuthenticatorConfigs();
    FederatedAuthenticatorListResponse fedAuthIDPResponse = new FederatedAuthenticatorListResponse();
    List<FederatedAuthenticatorListItem> authenticators = new ArrayList<>();
    for (FederatedAuthenticatorConfig fedAuthConfig : fedAuthConfigs) {
        FederatedAuthenticatorListItem fedAuthListItem = new FederatedAuthenticatorListItem();
        fedAuthListItem.setAuthenticatorId(base64URLEncode(fedAuthConfig.getName()));
        fedAuthListItem.setName(fedAuthConfig.getName());
        fedAuthListItem.setIsEnabled(fedAuthConfig.isEnabled());
        FederatedAuthenticatorConfig federatedAuthenticatorConfig = ApplicationAuthenticatorService.getInstance().getFederatedAuthenticatorByName(fedAuthConfig.getName());
        if (federatedAuthenticatorConfig != null) {
            String[] tags = federatedAuthenticatorConfig.getTags();
            if (ArrayUtils.isNotEmpty(tags)) {
                fedAuthListItem.setTags(Arrays.asList(tags));
            }
        }
        fedAuthListItem.setSelf(ContextLoader.buildURIForBody(String.format(V1_API_PATH_COMPONENT + IDP_PATH_COMPONENT + "/%s/federated-authenticators/%s", idp.getResourceId(), base64URLEncode(fedAuthConfig.getName()))).toString());
        authenticators.add(fedAuthListItem);
    }
    fedAuthIDPResponse.setDefaultAuthenticatorId(idp.getDefaultAuthenticatorConfig() != null ? base64URLEncode(idp.getDefaultAuthenticatorConfig().getName()) : null);
    fedAuthIDPResponse.setAuthenticators(authenticators);
    return fedAuthIDPResponse;
}
Also used : FederatedAuthenticatorConfig(org.wso2.carbon.identity.application.common.model.FederatedAuthenticatorConfig) ArrayList(java.util.ArrayList) MetaFederatedAuthenticatorListItem(org.wso2.carbon.identity.api.server.idp.v1.model.MetaFederatedAuthenticatorListItem) FederatedAuthenticatorListItem(org.wso2.carbon.identity.api.server.idp.v1.model.FederatedAuthenticatorListItem) FederatedAuthenticatorListResponse(org.wso2.carbon.identity.api.server.idp.v1.model.FederatedAuthenticatorListResponse)

Example 48 with FederatedAuthenticatorConfig

use of org.wso2.carbon.identity.application.common.model.xsd.FederatedAuthenticatorConfig in project identity-api-server by wso2.

the class ServerIdpManagementService method createMetaFederatedAuthenticatorListItem.

private MetaFederatedAuthenticatorListItem createMetaFederatedAuthenticatorListItem(FederatedAuthenticatorConfig authenticatorConfig) {
    MetaFederatedAuthenticatorListItem metaFederatedAuthenticator = new MetaFederatedAuthenticatorListItem();
    String authenticatorId = base64URLEncode(authenticatorConfig.getName());
    metaFederatedAuthenticator.setName(authenticatorConfig.getName());
    metaFederatedAuthenticator.setAuthenticatorId(authenticatorId);
    FederatedAuthenticatorConfig federatedAuthenticatorConfig = ApplicationAuthenticatorService.getInstance().getFederatedAuthenticatorByName(authenticatorConfig.getName());
    if (federatedAuthenticatorConfig != null) {
        String[] tags = federatedAuthenticatorConfig.getTags();
        if (ArrayUtils.isNotEmpty(tags)) {
            metaFederatedAuthenticator.setTags(Arrays.asList(tags));
        }
    }
    metaFederatedAuthenticator.setSelf(ContextLoader.buildURIForBody(String.format(V1_API_PATH_COMPONENT + IDP_PATH_COMPONENT + "/meta/federated-authenticators/%s", authenticatorId)).toString());
    return metaFederatedAuthenticator;
}
Also used : MetaFederatedAuthenticatorListItem(org.wso2.carbon.identity.api.server.idp.v1.model.MetaFederatedAuthenticatorListItem) FederatedAuthenticatorConfig(org.wso2.carbon.identity.application.common.model.FederatedAuthenticatorConfig)

Example 49 with FederatedAuthenticatorConfig

use of org.wso2.carbon.identity.application.common.model.xsd.FederatedAuthenticatorConfig in project identity-api-server by wso2.

the class ServerIdpManagementService method createFederatedAuthenticator.

/**
 * Create API Federated Authenticator model using internal FederatedAuthenticatorConfig.
 *
 * @param authenticatorId  Federated Authenticator ID.
 * @param identityProvider Identity Provider information.
 * @return FederatedAuthenticator.
 */
private FederatedAuthenticator createFederatedAuthenticator(String authenticatorId, IdentityProvider identityProvider) {
    FederatedAuthenticatorConfig[] authConfigs = identityProvider.getFederatedAuthenticatorConfigs();
    if (ArrayUtils.isEmpty(authConfigs)) {
        return null;
    }
    FederatedAuthenticatorConfig config = null;
    boolean isDefaultAuthenticator = false;
    String authenticatorName = base64URLDecode(authenticatorId);
    for (FederatedAuthenticatorConfig authConfig : authConfigs) {
        if (StringUtils.equals(authConfig.getName(), authenticatorName)) {
            config = authConfig;
        }
    }
    if (identityProvider.getDefaultAuthenticatorConfig() != null && StringUtils.equals(identityProvider.getDefaultAuthenticatorConfig().getName(), authenticatorName)) {
        isDefaultAuthenticator = true;
    }
    FederatedAuthenticator federatedAuthenticator = new FederatedAuthenticator();
    if (config != null) {
        federatedAuthenticator.setAuthenticatorId(authenticatorId);
        federatedAuthenticator.setName(config.getName());
        federatedAuthenticator.setIsEnabled(config.isEnabled());
        federatedAuthenticator.setIsDefault(isDefaultAuthenticator);
        FederatedAuthenticatorConfig federatedAuthenticatorConfig = ApplicationAuthenticatorService.getInstance().getFederatedAuthenticatorByName(config.getName());
        if (federatedAuthenticatorConfig != null) {
            String[] tags = federatedAuthenticatorConfig.getTags();
            if (ArrayUtils.isNotEmpty(tags)) {
                federatedAuthenticator.setTags(Arrays.asList(tags));
            }
        }
        List<org.wso2.carbon.identity.api.server.idp.v1.model.Property> properties = Arrays.stream(config.getProperties()).map(propertyToExternal).collect(Collectors.toList());
        federatedAuthenticator.setProperties(properties);
    }
    return federatedAuthenticator;
}
Also used : FederatedAuthenticatorConfig(org.wso2.carbon.identity.application.common.model.FederatedAuthenticatorConfig) FederatedAuthenticator(org.wso2.carbon.identity.api.server.idp.v1.model.FederatedAuthenticator) MetaFederatedAuthenticator(org.wso2.carbon.identity.api.server.idp.v1.model.MetaFederatedAuthenticator) IdentityProviderProperty(org.wso2.carbon.identity.application.common.model.IdentityProviderProperty) Property(org.wso2.carbon.identity.application.common.model.Property) SubProperty(org.wso2.carbon.identity.application.common.model.SubProperty) MetaProperty(org.wso2.carbon.identity.api.server.idp.v1.model.MetaProperty)

Example 50 with FederatedAuthenticatorConfig

use of org.wso2.carbon.identity.application.common.model.xsd.FederatedAuthenticatorConfig in project identity-api-server by wso2.

the class ServerIdpManagementService method getFederatedAuthenticators.

/**
 * Returns configured federated authenticators of a specific identity provider.
 *
 * @param idpId Identity provider resource ID.
 * @return FederatedAuthenticatorListResponse Federated authenticator list.
 */
public FederatedAuthenticatorListResponse getFederatedAuthenticators(String idpId) {
    FederatedAuthenticatorListResponse listResponse;
    try {
        IdentityProvider idP = IdentityProviderServiceHolder.getIdentityProviderManager().getIdPByResourceId(idpId, ContextLoader.getTenantDomainFromContext(), true);
        if (idP == null) {
            throw handleException(Response.Status.NOT_FOUND, Constants.ErrorMessage.ERROR_CODE_IDP_NOT_FOUND, idpId);
        }
        listResponse = new FederatedAuthenticatorListResponse();
        FederatedAuthenticatorConfig[] fedAuthConfigs = idP.getFederatedAuthenticatorConfigs();
        if (fedAuthConfigs != null) {
            List<FederatedAuthenticatorListItem> fedAuthList = new ArrayList<>();
            String defaultAuthenticator = null;
            for (FederatedAuthenticatorConfig config : fedAuthConfigs) {
                String fedAuthId = base64URLEncode(config.getName());
                FederatedAuthenticatorListItem listItem = new FederatedAuthenticatorListItem();
                listItem.setAuthenticatorId(fedAuthId);
                listItem.setName(config.getName());
                listItem.setIsEnabled(config.isEnabled());
                FederatedAuthenticatorConfig federatedAuthenticatorConfig = ApplicationAuthenticatorService.getInstance().getFederatedAuthenticatorByName(config.getName());
                if (federatedAuthenticatorConfig != null) {
                    String[] tags = federatedAuthenticatorConfig.getTags();
                    if (ArrayUtils.isNotEmpty(tags)) {
                        listItem.setTags(Arrays.asList(tags));
                    }
                }
                listItem.setSelf(ContextLoader.buildURIForBody(String.format(V1_API_PATH_COMPONENT + IDP_PATH_COMPONENT + "/%s/federated-authenticators/%s", idpId, fedAuthId)).toString());
                fedAuthList.add(listItem);
                if (idP.getDefaultAuthenticatorConfig() != null) {
                    defaultAuthenticator = base64URLEncode(idP.getDefaultAuthenticatorConfig().getName());
                }
            }
            listResponse.setDefaultAuthenticatorId(defaultAuthenticator);
            listResponse.setAuthenticators(fedAuthList);
        }
    } catch (IdentityProviderManagementException e) {
        throw handleIdPException(e, Constants.ErrorMessage.ERROR_CODE_ERROR_RETRIEVING_IDP_AUTHENTICATORS, idpId);
    }
    return listResponse;
}
Also used : FederatedAuthenticatorConfig(org.wso2.carbon.identity.application.common.model.FederatedAuthenticatorConfig) ArrayList(java.util.ArrayList) MetaFederatedAuthenticatorListItem(org.wso2.carbon.identity.api.server.idp.v1.model.MetaFederatedAuthenticatorListItem) FederatedAuthenticatorListItem(org.wso2.carbon.identity.api.server.idp.v1.model.FederatedAuthenticatorListItem) IdentityProvider(org.wso2.carbon.identity.application.common.model.IdentityProvider) FederatedAuthenticatorListResponse(org.wso2.carbon.identity.api.server.idp.v1.model.FederatedAuthenticatorListResponse) IdentityProviderManagementException(org.wso2.carbon.idp.mgt.IdentityProviderManagementException)

Aggregations

FederatedAuthenticatorConfig (org.wso2.carbon.identity.application.common.model.FederatedAuthenticatorConfig)60 IdentityProvider (org.wso2.carbon.identity.application.common.model.IdentityProvider)36 FederatedAuthenticatorConfig (org.wso2.carbon.identity.application.common.model.idp.xsd.FederatedAuthenticatorConfig)29 Property (org.wso2.carbon.identity.application.common.model.Property)28 IdentityProviderProperty (org.wso2.carbon.identity.application.common.model.IdentityProviderProperty)25 ArrayList (java.util.ArrayList)21 IdentityProviderManagementException (org.wso2.carbon.idp.mgt.IdentityProviderManagementException)17 IdentityProvider (org.wso2.carbon.identity.application.common.model.idp.xsd.IdentityProvider)16 Test (org.testng.annotations.Test)14 Property (org.wso2.carbon.identity.application.common.model.idp.xsd.Property)14 HashMap (java.util.HashMap)12 ProvisioningConnectorConfig (org.wso2.carbon.identity.application.common.model.ProvisioningConnectorConfig)11 LocalAuthenticatorConfig (org.wso2.carbon.identity.application.common.model.LocalAuthenticatorConfig)10 IdentityProviderProperty (org.wso2.carbon.identity.application.common.model.idp.xsd.IdentityProviderProperty)10 ClaimConfig (org.wso2.carbon.identity.application.common.model.ClaimConfig)9 ClaimMapping (org.wso2.carbon.identity.application.common.model.ClaimMapping)8 LocalRole (org.wso2.carbon.identity.application.common.model.LocalRole)8 PermissionsAndRoleConfig (org.wso2.carbon.identity.application.common.model.PermissionsAndRoleConfig)8 Map (java.util.Map)7 DataProvider (org.testng.annotations.DataProvider)7