Search in sources :

Example 6 with IdentityProviderManager

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

the class JITProvisioningPostAuthenticationHandler method setIDPData.

/**
 * Set the IDP releated data in the receipt service input.
 *
 * @param tenantDomain        Tenant domain.
 * @param receiptServiceInput Relevant receipt service input which the
 * @throws PostAuthenticationFailedException Post Authentication Failed Exception.
 */
private void setIDPData(String tenantDomain, ReceiptServiceInput receiptServiceInput) throws PostAuthenticationFailedException {
    String resideIdpDescription = "Resident IDP";
    IdentityProviderManager idpManager = IdentityProviderManager.getInstance();
    IdentityProvider residentIdP = null;
    try {
        residentIdP = idpManager.getResidentIdP(tenantDomain);
    } catch (IdentityProviderManagementException e) {
        handleExceptions(String.format(ErrorMessages.ERROR_WHILE_SETTING_IDP_DATA.getMessage(), tenantDomain), ErrorMessages.ERROR_WHILE_SETTING_IDP_DATA.getCode(), e);
    }
    if (residentIdP == null) {
        throw new PostAuthenticationFailedException(ErrorMessages.ERROR_WHILE_SETTING_IDP_DATA_IDP_IS_NULL.getCode(), String.format(ErrorMessages.ERROR_WHILE_SETTING_IDP_DATA_IDP_IS_NULL.getMessage(), tenantDomain));
    }
    if (StringUtils.isEmpty(receiptServiceInput.getService())) {
        if (log.isDebugEnabled()) {
            log.debug("No service name found. Hence adding resident IDP home realm ID");
        }
        receiptServiceInput.setService(residentIdP.getHomeRealmId());
    }
    if (StringUtils.isEmpty(receiptServiceInput.getTenantDomain())) {
        receiptServiceInput.setTenantDomain(tenantDomain);
    }
    if (StringUtils.isEmpty(receiptServiceInput.getSpDescription())) {
        if (StringUtils.isNotEmpty(residentIdP.getIdentityProviderDescription())) {
            receiptServiceInput.setSpDescription(residentIdP.getIdentityProviderDescription());
        } else {
            receiptServiceInput.setSpDescription(resideIdpDescription);
        }
    }
    if (StringUtils.isEmpty(receiptServiceInput.getSpDisplayName())) {
        if (StringUtils.isNotEmpty(residentIdP.getDisplayName())) {
            receiptServiceInput.setSpDisplayName(residentIdP.getDisplayName());
        } else {
            receiptServiceInput.setSpDisplayName(resideIdpDescription);
        }
    }
}
Also used : IdentityProvider(org.wso2.carbon.identity.application.common.model.IdentityProvider) IdentityProviderManager(org.wso2.carbon.idp.mgt.IdentityProviderManager) PostAuthenticationFailedException(org.wso2.carbon.identity.application.authentication.framework.exception.PostAuthenticationFailedException) IdentityProviderManagementException(org.wso2.carbon.idp.mgt.IdentityProviderManagementException)

Example 7 with IdentityProviderManager

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

the class IdentityProviderDAOImpl method getAllIdentityProviders.

@Override
public /**
 */
List<IdentityProvider> getAllIdentityProviders() throws IdentityApplicationManagementException {
    IdentityProviderManager idpManager = IdentityProviderManager.getInstance();
    List<IdentityProvider> idps;
    try {
        idps = idpManager.getIdPs(CarbonContext.getThreadLocalCarbonContext().getTenantDomain());
    } catch (IdentityProviderManagementException e) {
        throw new IdentityApplicationManagementException("Error when retrieving all identity providers in " + CarbonContext.getThreadLocalCarbonContext().getTenantDomain() + " tenant domain.", e);
    }
    List<IdentityProvider> federatedIdentityProviders = new ArrayList<IdentityProvider>();
    if (idps != null && !idps.isEmpty()) {
        for (IdentityProvider idp : idps) {
            federatedIdentityProviders.add(getIdentityProvider(idp.getIdentityProviderName()));
        }
    }
    return federatedIdentityProviders;
}
Also used : 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)

Example 8 with IdentityProviderManager

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

the class ApplicationIdentityProviderMgtListener method doPostUpdateIdP.

@Override
public boolean doPostUpdateIdP(String oldIdPName, IdentityProvider identityProvider, String tenantDomain) throws IdentityProviderManagementException {
    try {
        IdentityProviderManager identityProviderManager = IdentityProviderManager.getInstance();
        ConnectedAppsResult connectedApplications;
        String updatedIdpId = identityProvider.getResourceId();
        ApplicationDAO applicationDAO = ApplicationMgtSystemConfig.getInstance().getApplicationDAO();
        int offset = 0;
        do {
            connectedApplications = identityProviderManager.getConnectedApplications(updatedIdpId, null, offset, tenantDomain);
            for (String appResourceId : connectedApplications.getApps()) {
                ServiceProvider serviceProvider = applicationDAO.getApplicationByResourceId(appResourceId, tenantDomain);
                applicationDAO.clearApplicationFromCache(serviceProvider, tenantDomain);
            }
            offset = connectedApplications.getOffSet() + connectedApplications.getLimit();
        } while (connectedApplications.getTotalAppCount() > offset);
    } catch (IdentityApplicationManagementException e) {
        throw new IdentityProviderManagementException("Error while running post IDP update tasks.", e);
    }
    return true;
}
Also used : ConnectedAppsResult(org.wso2.carbon.idp.mgt.model.ConnectedAppsResult) ServiceProvider(org.wso2.carbon.identity.application.common.model.ServiceProvider) IdentityApplicationManagementException(org.wso2.carbon.identity.application.common.IdentityApplicationManagementException) IdentityProviderManager(org.wso2.carbon.idp.mgt.IdentityProviderManager) CacheBackedApplicationDAO(org.wso2.carbon.identity.application.mgt.dao.impl.CacheBackedApplicationDAO) ApplicationDAO(org.wso2.carbon.identity.application.mgt.dao.ApplicationDAO) IdentityProviderManagementException(org.wso2.carbon.idp.mgt.IdentityProviderManagementException)

Example 9 with IdentityProviderManager

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

the class IdentityGovernanceServiceImpl method getConfiguration.

@Override
public Property[] getConfiguration(String tenantDomain) throws IdentityGovernanceException {
    IdpManager identityProviderManager = IdentityMgtServiceDataHolder.getInstance().getIdpManager();
    IdentityProvider residentIdp = null;
    try {
        residentIdp = identityProviderManager.getResidentIdP(tenantDomain);
    } catch (IdentityProviderManagementException e) {
        String errorMsg = String.format("Error while retrieving resident Idp for %s tenant.", tenantDomain);
        throw new IdentityGovernanceException(errorMsg, e);
    }
    IdentityProviderProperty[] identityMgtProperties = residentIdp.getIdpProperties();
    Property[] configMap = new Property[identityMgtProperties.length];
    int index = 0;
    for (IdentityProviderProperty identityMgtProperty : identityMgtProperties) {
        if (IdentityEventConstants.PropertyConfig.ALREADY_WRITTEN_PROPERTY_KEY.equals(identityMgtProperty.getName())) {
            continue;
        }
        Property property = new Property();
        property.setName(identityMgtProperty.getName());
        property.setValue(identityMgtProperty.getValue());
        configMap[index] = property;
        index++;
    }
    return configMap;
}
Also used : IdentityProviderProperty(org.wso2.carbon.identity.application.common.model.IdentityProviderProperty) IdpManager(org.wso2.carbon.idp.mgt.IdpManager) IdentityProvider(org.wso2.carbon.identity.application.common.model.IdentityProvider) IdentityProviderManagementException(org.wso2.carbon.idp.mgt.IdentityProviderManagementException) Property(org.wso2.carbon.identity.application.common.model.Property) IdentityProviderProperty(org.wso2.carbon.identity.application.common.model.IdentityProviderProperty)

Example 10 with IdentityProviderManager

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

the class IdentityGovernanceUtil method saveConnectorDefaultProperties.

@Deprecated
public static void saveConnectorDefaultProperties(IdentityConnectorConfig identityConnectorConfig, String tenantDomain) throws ConnectorException {
    IdpManager identityProviderManager = IdentityMgtServiceDataHolder.getInstance().getIdpManager();
    try {
        IdentityProvider residentIdp = identityProviderManager.getResidentIdP(tenantDomain);
        IdentityProviderProperty[] idpProperties = residentIdp.getIdpProperties();
        String[] connectorPropertiesNames = identityConnectorConfig.getPropertyNames();
        List<IdentityProviderProperty> propertiesToAdd = new ArrayList<>();
        for (String connectorPropertyName : connectorPropertiesNames) {
            boolean propertyExists = false;
            for (IdentityProviderProperty property : idpProperties) {
                if (connectorPropertyName.equals(property.getName())) {
                    propertyExists = true;
                    break;
                }
            }
            if (!propertyExists) {
                IdentityProviderProperty newProperty = new IdentityProviderProperty();
                newProperty.setName(connectorPropertyName);
                newProperty.setDisplayName(identityConnectorConfig.getPropertyNameMapping().get(connectorPropertyName));
                Properties defaultPropertyValues = identityConnectorConfig.getDefaultPropertyValues(tenantDomain);
                newProperty.setValue(String.valueOf(defaultPropertyValues.get(connectorPropertyName)));
                propertiesToAdd.add(newProperty);
            }
        }
        // If the property list size is greater than 0, add the new properties to the database.
        if (propertiesToAdd.size() > 0) {
            String alreadyWrittenPropertyName = identityConnectorConfig.getName() + "." + IdentityEventConstants.PropertyConfig.ALREADY_WRITTEN_PROPERTY_KEY;
            boolean alreadyWrittenPropertyExists = false;
            for (IdentityProviderProperty property : idpProperties) {
                if (alreadyWrittenPropertyName.equals(property.getName())) {
                    alreadyWrittenPropertyExists = true;
                    break;
                }
            }
            if (!alreadyWrittenPropertyExists) {
                IdentityProviderProperty property = new IdentityProviderProperty();
                property.setName(alreadyWrittenPropertyName);
                property.setValue(IdentityEventConstants.PropertyConfig.ALREADY_WRITTEN_PROPERTY_VALUE);
                propertiesToAdd.add(property);
            }
            propertiesToAdd.addAll(Arrays.asList(idpProperties));
            residentIdp.setIdpProperties(propertiesToAdd.toArray(new IdentityProviderProperty[0]));
            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[0]));
            identityProviderManager.updateResidentIdP(residentIdp, tenantDomain);
            if (log.isDebugEnabled()) {
                log.debug("New resident IDP properties for tenant : " + tenantDomain + " written to database");
            }
        }
    } catch (IdentityProviderManagementException e) {
        log.error("Error while adding identity management properties to 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) Properties(java.util.Properties) IdentityProviderProperty(org.wso2.carbon.identity.application.common.model.IdentityProviderProperty) IdentityProviderManagementException(org.wso2.carbon.idp.mgt.IdentityProviderManagementException)

Aggregations

IdentityProvider (org.wso2.carbon.identity.application.common.model.IdentityProvider)27 IdentityProviderManagementException (org.wso2.carbon.idp.mgt.IdentityProviderManagementException)15 IdentityProviderManager (org.wso2.carbon.idp.mgt.IdentityProviderManager)13 IdentityProviderProperty (org.wso2.carbon.identity.application.common.model.IdentityProviderProperty)11 ArrayList (java.util.ArrayList)7 Test (org.testng.annotations.Test)6 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)5 AuthenticationContext (org.wso2.carbon.identity.application.authentication.framework.context.AuthenticationContext)5 PostAuthnHandlerFlowStatus (org.wso2.carbon.identity.application.authentication.framework.handler.request.PostAuthnHandlerFlowStatus)5 HashMap (java.util.HashMap)4 SequenceConfig (org.wso2.carbon.identity.application.authentication.framework.config.model.SequenceConfig)4 IdentityApplicationManagementException (org.wso2.carbon.identity.application.common.IdentityApplicationManagementException)4 FederatedAuthenticatorConfig (org.wso2.carbon.identity.application.common.model.FederatedAuthenticatorConfig)4 IdpManager (org.wso2.carbon.idp.mgt.IdpManager)4 AuthenticatedUser (org.wso2.carbon.identity.application.authentication.framework.model.AuthenticatedUser)3 IdentityProviderMgtListener (org.wso2.carbon.idp.mgt.listener.IdentityProviderMgtListener)3 UserRealm (org.wso2.carbon.user.core.UserRealm)3 UserStoreManager (org.wso2.carbon.user.core.UserStoreManager)3 RealmService (org.wso2.carbon.user.core.service.RealmService)3 ExternalIdPConfig (org.wso2.carbon.identity.application.authentication.framework.config.model.ExternalIdPConfig)2