Search in sources :

Example 96 with FederatedAuthenticatorConfig

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

the class ServerIdpManagementService method createFederatedAuthenticatorConfig.

/**
 * Create internal federated authenticator config from external federated authenticator PUT request.
 *
 * @param federatedAuthenticatorId Federated authenticator ID.
 * @param authenticator            Internal federated authenticator config.
 * @return Federated authenticator config of the specified ID.
 */
private FederatedAuthenticatorConfig createFederatedAuthenticatorConfig(String federatedAuthenticatorId, FederatedAuthenticatorPUTRequest authenticator) {
    FederatedAuthenticatorConfig authConfig = new FederatedAuthenticatorConfig();
    String authenticatorName = base64URLDecode(federatedAuthenticatorId);
    authConfig.setName(authenticatorName);
    authConfig.setDisplayName(getDisplayNameOfAuthenticator(authenticatorName));
    authConfig.setEnabled(authenticator.getIsEnabled());
    List<org.wso2.carbon.identity.api.server.idp.v1.model.Property> authProperties = authenticator.getProperties();
    if (IdentityApplicationConstants.Authenticator.SAML2SSO.FED_AUTH_NAME.equals(authenticatorName)) {
        validateSamlMetadata(authProperties);
    }
    List<Property> properties = authProperties.stream().map(propertyToInternal).collect(Collectors.toList());
    authConfig.setProperties(properties.toArray(new Property[0]));
    return authConfig;
}
Also used : FederatedAuthenticatorConfig(org.wso2.carbon.identity.application.common.model.FederatedAuthenticatorConfig) 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 97 with FederatedAuthenticatorConfig

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

the class ServerIdpManagementService method updateFederatedAuthenticator.

/**
 * Update federated authenticator of and IDP.
 *
 * @param idpId                    Identity Provider resource ID.
 * @param federatedAuthenticatorId Federated Authenticator ID.
 * @param authenticator            Federated Authenticator information.
 * @return FederatedAuthenticator.
 */
public FederatedAuthenticator updateFederatedAuthenticator(String idpId, String federatedAuthenticatorId, FederatedAuthenticatorPUTRequest authenticator) {
    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);
        }
        // Need to create a clone, since modifying the fields of the original object, will modify the cached
        // IDP object.
        IdentityProvider idpToUpdate = createIdPClone(idp);
        // Create new FederatedAuthenticatorConfig to store the federated authenticator information.
        FederatedAuthenticatorConfig authConfig = createFederatedAuthenticatorConfig(federatedAuthenticatorId, authenticator);
        FederatedAuthenticatorConfig[] fedAuthConfigs = createFederatedAuthenticatorArrayClone(federatedAuthenticatorId, idp.getFederatedAuthenticatorConfigs());
        int configPos = getExistingAuthConfigPosition(fedAuthConfigs, federatedAuthenticatorId);
        // If configPos != -1, modify the existing authenticatorConfig of IDP.
        if (configPos != -1) {
            fedAuthConfigs[configPos] = authConfig;
        } else {
            // If configPos is -1 add new authenticator to the list.
            if (isValidAuthenticator(federatedAuthenticatorId)) {
                List<FederatedAuthenticatorConfig> authConfigList = new ArrayList<>(Arrays.asList(fedAuthConfigs));
                authConfigList.add(authConfig);
                fedAuthConfigs = authConfigList.toArray(new FederatedAuthenticatorConfig[0]);
            } else {
                throw handleException(Response.Status.NOT_FOUND, Constants.ErrorMessage.ERROR_CODE_AUTHENTICATOR_NOT_FOUND_FOR_IDP, federatedAuthenticatorId);
            }
        }
        idpToUpdate.setFederatedAuthenticatorConfigs(fedAuthConfigs);
        if (authenticator.getIsDefault()) {
            idpToUpdate.setDefaultAuthenticatorConfig(authConfig);
        } else if (idpToUpdate.getDefaultAuthenticatorConfig() != null && idpToUpdate.getDefaultAuthenticatorConfig().getName().equals(authConfig.getName())) {
            idpToUpdate.setDefaultAuthenticatorConfig(null);
        }
        IdentityProvider updatedIdP = IdentityProviderServiceHolder.getIdentityProviderManager().updateIdPByResourceId(idpId, idpToUpdate, ContextLoader.getTenantDomainFromContext());
        return createFederatedAuthenticator(federatedAuthenticatorId, updatedIdP);
    } catch (IdentityProviderManagementException e) {
        throw handleIdPException(e, Constants.ErrorMessage.ERROR_CODE_ERROR_UPDATING_IDP_AUTHENTICATOR, federatedAuthenticatorId);
    }
}
Also used : FederatedAuthenticatorConfig(org.wso2.carbon.identity.application.common.model.FederatedAuthenticatorConfig) ArrayList(java.util.ArrayList) IdentityProvider(org.wso2.carbon.identity.application.common.model.IdentityProvider) IdentityProviderManagementException(org.wso2.carbon.idp.mgt.IdentityProviderManagementException)

Example 98 with FederatedAuthenticatorConfig

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

the class ServerIdpManagementService method getMetaFederatedAuthenticators.

/**
 * Get meta information about Identity Provider's federated authenticators.
 *
 * @return list of meta federated authenticators.
 */
public List<MetaFederatedAuthenticatorListItem> getMetaFederatedAuthenticators() {
    List<MetaFederatedAuthenticatorListItem> metaAuthenticators = new ArrayList<>();
    try {
        FederatedAuthenticatorConfig[] authenticatorConfigs = IdentityProviderServiceHolder.getIdentityProviderManager().getAllFederatedAuthenticators();
        if (ArrayUtils.isNotEmpty(authenticatorConfigs)) {
            for (FederatedAuthenticatorConfig authenticatorConfig : authenticatorConfigs) {
                MetaFederatedAuthenticatorListItem metaFederatedAuthenticator = createMetaFederatedAuthenticatorListItem(authenticatorConfig);
                metaAuthenticators.add(metaFederatedAuthenticator);
            }
        }
        return metaAuthenticators;
    } catch (IdentityProviderManagementException e) {
        throw handleIdPException(e, Constants.ErrorMessage.ERROR_CODE_ERROR_RETRIEVING_META_AUTHENTICATORS, null);
    }
}
Also used : MetaFederatedAuthenticatorListItem(org.wso2.carbon.identity.api.server.idp.v1.model.MetaFederatedAuthenticatorListItem) FederatedAuthenticatorConfig(org.wso2.carbon.identity.application.common.model.FederatedAuthenticatorConfig) ArrayList(java.util.ArrayList) IdentityProviderManagementException(org.wso2.carbon.idp.mgt.IdentityProviderManagementException)

Example 99 with FederatedAuthenticatorConfig

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

the class ServerIdpManagementService method getFederatedAuthenticator.

/**
 * Get information of a specific federated authenticator of an IDP.
 *
 * @param idpId           Identity Provider resource ID.
 * @param authenticatorId Federated Authenticator ID.
 * @return FederatedAuthenticator.
 */
public FederatedAuthenticator getFederatedAuthenticator(String idpId, String authenticatorId) {
    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);
        }
        FederatedAuthenticatorConfig[] fedAuthConfigs = idp.getFederatedAuthenticatorConfigs();
        if (fedAuthConfigs != null) {
            for (FederatedAuthenticatorConfig config : fedAuthConfigs) {
                if (StringUtils.equals(config.getName(), base64URLDecode(authenticatorId))) {
                    return createFederatedAuthenticator(authenticatorId, idp);
                }
            }
        }
        throw handleException(Response.Status.NOT_FOUND, Constants.ErrorMessage.ERROR_CODE_AUTHENTICATOR_NOT_FOUND_FOR_IDP, authenticatorId);
    } catch (IdentityProviderManagementException e) {
        throw handleIdPException(e, Constants.ErrorMessage.ERROR_CODE_ERROR_RETRIEVING_IDP_AUTHENTICATOR, authenticatorId);
    }
}
Also used : FederatedAuthenticatorConfig(org.wso2.carbon.identity.application.common.model.FederatedAuthenticatorConfig) IdentityProvider(org.wso2.carbon.identity.application.common.model.IdentityProvider) IdentityProviderManagementException(org.wso2.carbon.idp.mgt.IdentityProviderManagementException)

Example 100 with FederatedAuthenticatorConfig

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

the class ServerIdpManagementService method getMetaFederatedAuthenticator.

/**
 * Get meta information about a specific federated authenticator supported by the IDPs.
 *
 * @param id Federated authenticator ID.
 * @return MetaFederatedAuthenticator.
 */
public MetaFederatedAuthenticator getMetaFederatedAuthenticator(String id) {
    MetaFederatedAuthenticator authenticator = null;
    try {
        String authenticatorName = decodeAuthenticatorID(id);
        FederatedAuthenticatorConfig[] authenticatorConfigs = IdentityProviderServiceHolder.getIdentityProviderManager().getAllFederatedAuthenticators();
        if (ArrayUtils.isNotEmpty(authenticatorConfigs)) {
            for (FederatedAuthenticatorConfig authenticatorConfig : authenticatorConfigs) {
                if (StringUtils.equals(authenticatorConfig.getName(), authenticatorName)) {
                    authenticator = createMetaFederatedAuthenticator(authenticatorConfig);
                    break;
                }
            }
        }
        return authenticator;
    } catch (IdentityProviderManagementException e) {
        throw handleIdPException(e, Constants.ErrorMessage.ERROR_CODE_ERROR_RETRIEVING_META_AUTHENTICATOR, id);
    }
}
Also used : MetaFederatedAuthenticator(org.wso2.carbon.identity.api.server.idp.v1.model.MetaFederatedAuthenticator) FederatedAuthenticatorConfig(org.wso2.carbon.identity.application.common.model.FederatedAuthenticatorConfig) 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