Search in sources :

Example 11 with IdpManager

use of org.wso2.carbon.idp.mgt.IdpManager in project carbon-identity-framework by wso2.

the class IdentityProviderDAOImpl method getIdentityProvider.

@Override
public /**
 */
IdentityProvider getIdentityProvider(String idpName) throws IdentityApplicationManagementException {
    IdentityProviderManager idpManager = IdentityProviderManager.getInstance();
    try {
        IdentityProvider idp = idpManager.getIdPByName(idpName, CarbonContext.getThreadLocalCarbonContext().getTenantDomain());
        IdentityProvider identityProvider = new IdentityProvider();
        identityProvider.setIdentityProviderName(idp.getIdentityProviderName());
        FederatedAuthenticatorConfig defaultAuthenticator = new FederatedAuthenticatorConfig();
        defaultAuthenticator.setName(getDefaultAuthenticator(idp.getIdentityProviderName()));
        List<FederatedAuthenticatorConfig> federatedAuthenticators = new ArrayList<FederatedAuthenticatorConfig>();
        FederatedAuthenticatorConfig[] federatedAuthenticatorConfigs = idp.getFederatedAuthenticatorConfigs();
        if (federatedAuthenticatorConfigs != null && federatedAuthenticatorConfigs.length > 0) {
            for (FederatedAuthenticatorConfig config : federatedAuthenticatorConfigs) {
                if (config.isEnabled()) {
                    federatedAuthenticators.add(config);
                }
            }
        }
        if (CollectionUtils.isNotEmpty(federatedAuthenticators)) {
            identityProvider.setFederatedAuthenticatorConfigs(federatedAuthenticators.toArray(new FederatedAuthenticatorConfig[federatedAuthenticators.size()]));
        }
        List<ProvisioningConnectorConfig> provisioningConnectors = new ArrayList<ProvisioningConnectorConfig>();
        ProvisioningConnectorConfig[] provisioningConnectorConfigs = idp.getProvisioningConnectorConfigs();
        if (provisioningConnectorConfigs != null && provisioningConnectorConfigs.length > 0) {
            for (ProvisioningConnectorConfig config : provisioningConnectorConfigs) {
                if (config.isEnabled()) {
                    provisioningConnectors.add(config);
                }
            }
        }
        if (CollectionUtils.isNotEmpty(provisioningConnectors)) {
            identityProvider.setProvisioningConnectorConfigs(provisioningConnectors.toArray(new ProvisioningConnectorConfig[provisioningConnectors.size()]));
        }
        identityProvider.setEnable(idp.isEnable());
        return identityProvider;
    } catch (IdentityProviderManagementException e) {
        throw new IdentityApplicationManagementException("Error when retrieving identity provider " + idpName, e);
    }
}
Also used : FederatedAuthenticatorConfig(org.wso2.carbon.identity.application.common.model.FederatedAuthenticatorConfig) IdentityApplicationManagementException(org.wso2.carbon.identity.application.common.IdentityApplicationManagementException) ArrayList(java.util.ArrayList) IdentityProvider(org.wso2.carbon.identity.application.common.model.IdentityProvider) IdentityProviderManager(org.wso2.carbon.idp.mgt.IdentityProviderManager) IdentityProviderManagementException(org.wso2.carbon.idp.mgt.IdentityProviderManagementException) ProvisioningConnectorConfig(org.wso2.carbon.identity.application.common.model.ProvisioningConnectorConfig)

Example 12 with IdpManager

use of org.wso2.carbon.idp.mgt.IdpManager in project identity-governance by wso2-extensions.

the class IdentityGovernanceServiceImpl method updateConfiguration.

public void updateConfiguration(String tenantDomain, Map<String, String> configurationDetails) throws IdentityGovernanceException {
    try {
        IdpManager identityProviderManager = IdentityMgtServiceDataHolder.getInstance().getIdpManager();
        IdentityProvider residentIdp = identityProviderManager.getResidentIdP(tenantDomain);
        IdentityProviderProperty[] identityMgtProperties = residentIdp.getIdpProperties();
        List<IdentityProviderProperty> newProperties = new ArrayList<>();
        for (IdentityProviderProperty identityMgtProperty : identityMgtProperties) {
            IdentityProviderProperty prop = new IdentityProviderProperty();
            String key = identityMgtProperty.getName();
            prop.setName(key);
            if (configurationDetails.containsKey(key)) {
                prop.setValue(configurationDetails.get(key));
            } else {
                prop.setValue(identityMgtProperty.getValue());
            }
            newProperties.add(prop);
            configurationDetails.remove(key);
        }
        for (Map.Entry<String, String> entry : configurationDetails.entrySet()) {
            IdentityProviderProperty prop = new IdentityProviderProperty();
            prop.setName(entry.getKey());
            prop.setValue(entry.getValue());
            newProperties.add(prop);
        }
        residentIdp.setIdpProperties(newProperties.toArray(new IdentityProviderProperty[newProperties.size()]));
        FederatedAuthenticatorConfig[] authenticatorConfigs = residentIdp.getFederatedAuthenticatorConfigs();
        List<FederatedAuthenticatorConfig> configsToSave = new ArrayList<>();
        for (FederatedAuthenticatorConfig authenticatorConfig : authenticatorConfigs) {
            if (IdentityApplicationConstants.Authenticator.PassiveSTS.NAME.equals(authenticatorConfig.getName()) || IdentityApplicationConstants.Authenticator.SAML2SSO.NAME.equals(authenticatorConfig.getName())) {
                configsToSave.add(authenticatorConfig);
            }
        }
        residentIdp.setFederatedAuthenticatorConfigs(configsToSave.toArray(new FederatedAuthenticatorConfig[configsToSave.size()]));
        identityProviderManager.updateResidentIdP(residentIdp, tenantDomain);
    } catch (IdentityProviderManagementException e) {
        log.error("Error while updating identityManagement Properties of Resident Idp.", e);
    }
}
Also used : FederatedAuthenticatorConfig(org.wso2.carbon.identity.application.common.model.FederatedAuthenticatorConfig) ArrayList(java.util.ArrayList) IdpManager(org.wso2.carbon.idp.mgt.IdpManager) IdentityProvider(org.wso2.carbon.identity.application.common.model.IdentityProvider) IdentityProviderProperty(org.wso2.carbon.identity.application.common.model.IdentityProviderProperty) HashMap(java.util.HashMap) Map(java.util.Map) IdentityProviderManagementException(org.wso2.carbon.idp.mgt.IdentityProviderManagementException)

Aggregations

IdentityProvider (org.wso2.carbon.identity.application.common.model.IdentityProvider)12 IdentityProviderManagementException (org.wso2.carbon.idp.mgt.IdentityProviderManagementException)11 IdentityProviderManager (org.wso2.carbon.idp.mgt.IdentityProviderManager)8 ArrayList (java.util.ArrayList)4 IdentityProviderProperty (org.wso2.carbon.identity.application.common.model.IdentityProviderProperty)4 IdpManager (org.wso2.carbon.idp.mgt.IdpManager)4 FederatedAuthenticatorConfig (org.wso2.carbon.identity.application.common.model.FederatedAuthenticatorConfig)3 ExternalIdPConfig (org.wso2.carbon.identity.application.authentication.framework.config.model.ExternalIdPConfig)2 IdentityApplicationManagementException (org.wso2.carbon.identity.application.common.IdentityApplicationManagementException)2 Property (org.wso2.carbon.identity.application.common.model.Property)2 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 IOException (java.io.IOException)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Properties (java.util.Properties)1 OMElement (org.apache.axiom.om.OMElement)1 StAXOMBuilder (org.apache.axiom.om.impl.builder.StAXOMBuilder)1 FrameworkException (org.wso2.carbon.identity.application.authentication.framework.exception.FrameworkException)1 PostAuthenticationFailedException (org.wso2.carbon.identity.application.authentication.framework.exception.PostAuthenticationFailedException)1