Search in sources :

Example 71 with Property

use of org.wso2.carbon.user.api.Property in project carbon-identity-framework by wso2.

the class IdPManagementUIUtil method buildOpenIDConnectAuthenticationConfiguration.

/**
 * @param fedIdp
 * @param paramMap
 * @throws IdentityApplicationManagementException
 */
private static void buildOpenIDConnectAuthenticationConfiguration(IdentityProvider fedIdp, Map<String, String> paramMap) throws IdentityApplicationManagementException {
    FederatedAuthenticatorConfig oidcAuthnConfig = new FederatedAuthenticatorConfig();
    oidcAuthnConfig.setName("OpenIDConnectAuthenticator");
    oidcAuthnConfig.setDisplayName("openidconnect");
    if ("on".equals(paramMap.get("oidcEnabled"))) {
        oidcAuthnConfig.setEnabled(true);
    }
    if ("on".equals(paramMap.get("oidcDefault"))) {
        fedIdp.setDefaultAuthenticatorConfig(oidcAuthnConfig);
    }
    Property[] properties = new Property[10];
    Property property = new Property();
    property.setName(IdentityApplicationConstants.Authenticator.Facebook.CLIENT_ID);
    property.setValue(paramMap.get("clientId"));
    properties[0] = property;
    property = new Property();
    property.setName(IdentityApplicationConstants.Authenticator.OIDC.OAUTH2_AUTHZ_URL);
    property.setValue(paramMap.get("authzUrl"));
    properties[1] = property;
    property = new Property();
    property.setName(IdentityApplicationConstants.Authenticator.OIDC.OAUTH2_TOKEN_URL);
    property.setValue(paramMap.get("tokenUrl"));
    properties[2] = property;
    property = new Property();
    property.setName(IdentityApplicationConstants.Authenticator.OIDC.CLIENT_SECRET);
    property.setValue(paramMap.get("clientSecret"));
    property.setConfidential(true);
    properties[3] = property;
    property = new Property();
    property.setName(IdentityApplicationConstants.Authenticator.OIDC.IS_USER_ID_IN_CLAIMS);
    properties[4] = property;
    if ("1".equals(paramMap.get("oidc_user_id_location"))) {
        property.setValue("true");
        ;
    } else {
        property.setValue("false");
    }
    property = new Property();
    property.setName("commonAuthQueryParams");
    if (paramMap.get("oidcQueryParam") != null && paramMap.get("oidcQueryParam").trim().length() > 0) {
        property.setValue(paramMap.get("oidcQueryParam"));
    }
    properties[5] = property;
    property = new Property();
    property.setName(IdentityApplicationConstants.Authenticator.OIDC.CALLBACK_URL);
    property.setValue(paramMap.get("callbackUrl"));
    properties[6] = property;
    property = new Property();
    property.setName(IdentityApplicationConstants.Authenticator.OIDC.USER_INFO_URL);
    property.setValue(paramMap.get("userInfoEndpoint"));
    properties[7] = property;
    property = new Property();
    property.setName(IdentityApplicationConstants.Authenticator.OIDC.OIDC_LOGOUT_URL);
    property.setValue(paramMap.get("logoutUrlOIDC"));
    properties[8] = property;
    property = new Property();
    property.setName(IdentityApplicationConstants.Authenticator.OIDC.IS_BASIC_AUTH_ENABLED);
    if (paramMap.get("oidcBasicAuthEnabled") != null && "on".equals(paramMap.get("oidcBasicAuthEnabled"))) {
        property.setValue("true");
    } else {
        property.setValue("false");
    }
    properties[9] = property;
    oidcAuthnConfig.setProperties(properties);
    FederatedAuthenticatorConfig[] authenticators = fedIdp.getFederatedAuthenticatorConfigs();
    if (paramMap.get("authzUrl") != null && !"".equals(paramMap.get("authzUrl")) && paramMap.get("tokenUrl") != null && !"".equals(paramMap.get("tokenUrl")) && paramMap.get("clientId") != null && !"".equals(paramMap.get("clientId")) && paramMap.get("clientSecret") != null && !"".equals(paramMap.get("clientSecret"))) {
        if (authenticators == null || authenticators.length == 0) {
            fedIdp.setFederatedAuthenticatorConfigs(new FederatedAuthenticatorConfig[] { oidcAuthnConfig });
        } else {
            fedIdp.setFederatedAuthenticatorConfigs(concatArrays(new FederatedAuthenticatorConfig[] { oidcAuthnConfig }, authenticators));
        }
    }
}
Also used : FederatedAuthenticatorConfig(org.wso2.carbon.identity.application.common.model.idp.xsd.FederatedAuthenticatorConfig) Property(org.wso2.carbon.identity.application.common.model.idp.xsd.Property) IdentityProviderProperty(org.wso2.carbon.identity.application.common.model.idp.xsd.IdentityProviderProperty)

Example 72 with Property

use of org.wso2.carbon.user.api.Property in project carbon-identity-framework by wso2.

the class IdPManagementUIUtil method buildFederatedIdentityProvider.

/**
 * Build a federated identity provider.
 *
 * @param request    HttpServletRequest
 * @param oldIdpName This value will be populated if there is an old IDP.
 * @return IdentityProvider
 * @throws Exception
 */
public static IdentityProvider buildFederatedIdentityProvider(HttpServletRequest request, StringBuilder oldIdpName) throws Exception {
    IdentityProvider fedIdp = new IdentityProvider();
    if (ServletFileUpload.isMultipartContent(request)) {
        ServletRequestContext servletContext = new ServletRequestContext(request);
        FileItemFactory factory = new DiskFileItemFactory();
        ServletFileUpload upload = new ServletFileUpload(factory);
        List items = upload.parseRequest(servletContext);
        Map<String, String> paramMap = new HashMap<>();
        List<String> idpClaims = new ArrayList<>();
        List<String> idpRoles = new ArrayList<>();
        List<String> customAuthenticatorNames = new ArrayList<>();
        List<String> proConnectorNames = new ArrayList<>();
        Map<String, List<Property>> customAuthenticatorProperties = new HashMap<>();
        Map<String, List<Property>> customProProperties = new HashMap<>();
        String idpUUID = StringUtils.EMPTY;
        StringBuilder deletedCertificateValue = new StringBuilder();
        for (Object item : items) {
            DiskFileItem diskFileItem = (DiskFileItem) item;
            if (diskFileItem != null) {
                byte[] value = diskFileItem.get();
                String key = diskFileItem.getFieldName();
                if (StringUtils.equals(key, "idpUUID")) {
                    idpUUID = diskFileItem.getString();
                }
                if (IdPManagementUIUtil.META_DATA_SAML.equals(key)) {
                    if (StringUtils.isNotEmpty(diskFileItem.getName()) && !diskFileItem.getName().trim().endsWith(".xml")) {
                        throw new CarbonException("File not supported!");
                    } else {
                        paramMap.put(key, Base64.encode(value));
                    }
                }
                if ("certFile".equals(key)) {
                    paramMap.put(key, Base64.encode(value));
                } else if (key.startsWith(IdentityApplicationConstants.CERTIFICATE_VAL)) {
                    deletedCertificateValue.append(new String(value, StandardCharsets.UTF_8));
                } else if ("google_prov_private_key".equals(key)) {
                    paramMap.put(key, Base64.encode(value));
                } else if (key.startsWith("claimrowname_")) {
                    String strValue = new String(value, StandardCharsets.UTF_8);
                    idpClaims.add(strValue);
                    paramMap.put(key, strValue);
                } else if (key.startsWith("rolerowname_")) {
                    String strValue = new String(value, StandardCharsets.UTF_8);
                    idpRoles.add(strValue);
                    paramMap.put(key, strValue);
                } else if (key.startsWith("custom_auth_name")) {
                    customAuthenticatorNames.add(new String(value, StandardCharsets.UTF_8));
                } else if (key.startsWith("custom_pro_name")) {
                    proConnectorNames.add(new String(value, StandardCharsets.UTF_8));
                } else if (key.startsWith("cust_auth_prop_")) {
                    int length = "cust_auth_prop_".length();
                    String authPropString = new String(key).substring(length);
                    if (authPropString.indexOf("#") > 0) {
                        String authName = authPropString.substring(0, authPropString.indexOf("#"));
                        String propName = authPropString.substring(authPropString.indexOf("#") + 1);
                        String propVal = new String(value, StandardCharsets.UTF_8);
                        Property prop = new Property();
                        prop.setName(propName);
                        prop.setValue(propVal);
                        List<Property> propList = null;
                        if (customAuthenticatorProperties.get(authName) == null) {
                            customAuthenticatorProperties.put(authName, new ArrayList<Property>());
                        }
                        propList = customAuthenticatorProperties.get(authName);
                        propList.add(prop);
                        customAuthenticatorProperties.put(authName, propList);
                    }
                } else if (key.startsWith("cust_pro_prop_")) {
                    int length = "cust_pro_prop_".length();
                    String provPropString = new String(key).substring(length);
                    if (provPropString.indexOf("#") > 0) {
                        String proConName = provPropString.substring(0, provPropString.indexOf("#"));
                        String propName = provPropString.substring(provPropString.indexOf("#") + 1);
                        String propVal = new String(value, StandardCharsets.UTF_8);
                        Property prop = new Property();
                        prop.setName(propName);
                        prop.setValue(propVal);
                        List<Property> propList = null;
                        if (customProProperties.get(proConName) == null) {
                            customProProperties.put(proConName, new ArrayList<Property>());
                        }
                        propList = customProProperties.get(proConName);
                        propList.add(prop);
                        customProProperties.put(proConName, propList);
                    }
                } else {
                    paramMap.put(key, new String(value, StandardCharsets.UTF_8));
                }
                String updatedValue = paramMap.get(key);
                if (updatedValue != null && updatedValue.trim().length() == 0) {
                    paramMap.put(key, null);
                }
            }
        }
        paramMap.put(IdentityApplicationConstants.CERTIFICATE_VAL, deletedCertificateValue.toString());
        IdentityProvider oldIdentityProvider = (IdentityProvider) request.getSession().getAttribute(idpUUID);
        if (oldIdentityProvider != null) {
            if (oldIdpName == null) {
                oldIdpName = new StringBuilder();
            }
            oldIdpName.append(oldIdentityProvider.getIdentityProviderName());
        }
        if (oldIdentityProvider != null && oldIdentityProvider.getCertificate() != null) {
            if (oldIdentityProvider.getCertificateInfoArray() != null && oldIdentityProvider.getCertificateInfoArray().length > 1) {
                if (log.isDebugEnabled()) {
                    log.debug("Number of old certificate for the identity provider " + oldIdentityProvider.getDisplayName() + " is " + oldIdentityProvider.getCertificateInfoArray().length);
                }
                StringBuilder multipleCertificate = new StringBuilder();
                for (CertificateInfo certificateInfo : oldIdentityProvider.getCertificateInfoArray()) {
                    multipleCertificate.append(new String(Base64.decode(certificateInfo.getCertValue()), StandardCharsets.UTF_8));
                }
                paramMap.put(IdentityApplicationConstants.OLD_CERT_FILE, Base64.encode(multipleCertificate.toString().getBytes(StandardCharsets.UTF_8)));
            } else {
                if (log.isDebugEnabled()) {
                    log.debug("Only one certificate has been found as old certificate.");
                }
                paramMap.put(IdentityApplicationConstants.OLD_CERT_FILE, oldIdentityProvider.getCertificate());
            }
        }
        if (oldIdentityProvider != null && oldIdentityProvider.getProvisioningConnectorConfigs() != null) {
            ProvisioningConnectorConfig[] provisioningConnectorConfig = oldIdentityProvider.getProvisioningConnectorConfigs();
            for (ProvisioningConnectorConfig provisioningConnector : provisioningConnectorConfig) {
                if (("googleapps").equals(provisioningConnector.getName())) {
                    Property[] googleProperties = provisioningConnector.getProvisioningProperties();
                    for (Property property : googleProperties) {
                        if (property.getName().equals("google_prov_private_key")) {
                            paramMap.put("old_google_prov_private_key", property.getValue());
                        }
                    }
                }
            }
        }
        // build identity provider basic information.
        buildBasicInformation(fedIdp, paramMap);
        // build out-bound authentication configuration.
        buildOutboundAuthenticationConfiguration(fedIdp, paramMap);
        // build custom authenticator configuration.
        buildCustomAuthenticationConfiguration(fedIdp, customAuthenticatorNames, customAuthenticatorProperties, paramMap);
        // build claim configuration.
        if (oldIdentityProvider != null && oldIdentityProvider.getClaimConfig().getClaimMappings() != null) {
            buildClaimConfiguration(fedIdp, paramMap, idpClaims, oldIdentityProvider.getClaimConfig().getClaimMappings());
        } else {
            buildClaimConfiguration(fedIdp, paramMap, idpClaims, null);
        }
        // build role configuration.
        if (oldIdentityProvider != null && oldIdentityProvider.getPermissionAndRoleConfig() != null && oldIdentityProvider.getPermissionAndRoleConfig().getRoleMappings() != null) {
            buildRoleConfiguration(fedIdp, paramMap, idpRoles, oldIdentityProvider.getPermissionAndRoleConfig().getRoleMappings());
        } else {
            buildRoleConfiguration(fedIdp, paramMap, idpRoles, null);
        }
        // build in-bound provisioning configuration.
        buildInboundProvisioningConfiguration(fedIdp, paramMap);
        // build out-bound provisioning configuration.
        buildOutboundProvisioningConfiguration(fedIdp, paramMap);
        // build custom provisioning connectors.
        buildCustomProvisioningConfiguration(fedIdp, proConnectorNames, customProProperties, paramMap);
    } else {
        throw new Exception("Invalid Content Type: Not multipart/form-data");
    }
    return fedIdp;
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) CarbonException(org.wso2.carbon.CarbonException) ServletFileUpload(org.apache.commons.fileupload.servlet.ServletFileUpload) CertificateInfo(org.wso2.carbon.identity.application.common.model.idp.xsd.CertificateInfo) ArrayList(java.util.ArrayList) List(java.util.List) Property(org.wso2.carbon.identity.application.common.model.idp.xsd.Property) IdentityProviderProperty(org.wso2.carbon.identity.application.common.model.idp.xsd.IdentityProviderProperty) ProvisioningConnectorConfig(org.wso2.carbon.identity.application.common.model.idp.xsd.ProvisioningConnectorConfig) DiskFileItem(org.apache.commons.fileupload.disk.DiskFileItem) ServletRequestContext(org.apache.commons.fileupload.servlet.ServletRequestContext) IdentityProvider(org.wso2.carbon.identity.application.common.model.idp.xsd.IdentityProvider) DiskFileItemFactory(org.apache.commons.fileupload.disk.DiskFileItemFactory) FileItemFactory(org.apache.commons.fileupload.FileItemFactory) DiskFileItemFactory(org.apache.commons.fileupload.disk.DiskFileItemFactory) IdentityApplicationManagementException(org.wso2.carbon.identity.application.common.IdentityApplicationManagementException) MalformedURLException(java.net.MalformedURLException) CarbonException(org.wso2.carbon.CarbonException)

Example 73 with Property

use of org.wso2.carbon.user.api.Property in project carbon-identity-framework by wso2.

the class IdPManagementUIUtil method buildGoogleProvisioningConfiguration.

/**
 * @param fedIdp
 * @param paramMap
 * @throws IdentityApplicationManagementException
 */
private static void buildGoogleProvisioningConfiguration(IdentityProvider fedIdp, Map<String, String> paramMap) throws IdentityApplicationManagementException {
    ProvisioningConnectorConfig proConnector = new ProvisioningConnectorConfig();
    proConnector.setName("googleapps");
    Property domainName = null;
    Property emailClaim = null;
    Property givenNameClaim = null;
    Property givenNameDefaultVal = null;
    Property familyNameClaim = null;
    Property familyNameDefault = null;
    Property serviceAccEmail = null;
    Property privateKey = null;
    Property adminEmail = null;
    Property appName = null;
    Property googleProvPatten = null;
    Property googleProvSeparator = null;
    Property uniqueID = null;
    String oldGooglePvtKey = null;
    String newGooglePvtKey = null;
    if (paramMap.get("googleProvEnabled") != null && "on".equals(paramMap.get("googleProvEnabled"))) {
        proConnector.setEnabled(true);
    } else {
        proConnector.setEnabled(false);
    }
    if (paramMap.get("googleProvDefault") != null && "on".equals(paramMap.get("googleProvDefault"))) {
        fedIdp.setDefaultProvisioningConnectorConfig(proConnector);
    }
    if (paramMap.get("google_prov_domain_name") != null) {
        domainName = new Property();
        domainName.setName("google_prov_domain_name");
        domainName.setValue(paramMap.get("google_prov_domain_name"));
    }
    if (paramMap.get("google_prov_email_claim_dropdown") != null) {
        emailClaim = new Property();
        emailClaim.setName("google_prov_email_claim_dropdown");
        emailClaim.setValue(paramMap.get("google_prov_email_claim_dropdown"));
    }
    if (paramMap.get("google_prov_givenname_claim_dropdown") != null) {
        givenNameClaim = new Property();
        givenNameClaim.setName("google_prov_givenname_claim_dropdown");
        givenNameClaim.setValue(paramMap.get("google_prov_givenname_claim_dropdown"));
    }
    if (paramMap.get("google_prov_givenname") != null) {
        givenNameDefaultVal = new Property();
        givenNameDefaultVal.setName("google_prov_givenname");
        givenNameDefaultVal.setValue(paramMap.get("google_prov_givenname"));
    }
    if (paramMap.get("google_prov_familyname_claim_dropdown") != null) {
        familyNameClaim = new Property();
        familyNameClaim.setName("google_prov_familyname_claim_dropdown");
        familyNameClaim.setValue(paramMap.get("google_prov_familyname_claim_dropdown"));
    }
    if (paramMap.get("google_prov_familyname") != null) {
        familyNameDefault = new Property();
        familyNameDefault.setName("google_prov_familyname");
        familyNameDefault.setValue(paramMap.get("google_prov_familyname"));
    }
    if (paramMap.get("google_prov_service_acc_email") != null) {
        serviceAccEmail = new Property();
        serviceAccEmail.setName("google_prov_service_acc_email");
        serviceAccEmail.setValue(paramMap.get("google_prov_service_acc_email"));
    }
    if (paramMap.get("old_google_prov_private_key") != null) {
        oldGooglePvtKey = paramMap.get("old_google_prov_private_key");
    }
    // get the value of the uploaded certificate.
    if (paramMap.get("google_prov_private_key") != null) {
        newGooglePvtKey = paramMap.get("google_prov_private_key");
    }
    if (newGooglePvtKey == null && oldGooglePvtKey != null) {
        newGooglePvtKey = oldGooglePvtKey;
    }
    if (newGooglePvtKey != null) {
        privateKey = new Property();
        privateKey.setName("google_prov_private_key");
        privateKey.setValue(newGooglePvtKey);
        privateKey.setType(IdentityApplicationConstants.ConfigElements.PROPERTY_TYPE_BLOB);
    }
    if (paramMap.get("google_prov_admin_email") != null) {
        adminEmail = new Property();
        adminEmail.setName("google_prov_admin_email");
        adminEmail.setValue(paramMap.get("google_prov_admin_email"));
    }
    if (paramMap.get("google_prov_application_name") != null) {
        appName = new Property();
        appName.setName("google_prov_application_name");
        appName.setValue(paramMap.get("google_prov_application_name"));
    }
    if (paramMap.get("google_prov_pattern") != null) {
        googleProvPatten = new Property();
        googleProvPatten.setName("google_prov_pattern");
        googleProvPatten.setValue(paramMap.get("google_prov_pattern"));
    }
    if (paramMap.get("google_prov_separator") != null) {
        googleProvSeparator = new Property();
        googleProvSeparator.setName("google_prov_separator");
        googleProvSeparator.setValue(paramMap.get("google_prov_separator"));
    }
    if (paramMap.get("google-unique-id") != null) {
        uniqueID = new Property();
        uniqueID.setName("UniqueID");
        uniqueID.setValue(paramMap.get("google-unique-id"));
    }
    Property[] proProperties = new Property[] { appName, adminEmail, privateKey, serviceAccEmail, familyNameDefault, familyNameClaim, givenNameDefaultVal, givenNameClaim, emailClaim, domainName, googleProvPatten, googleProvSeparator, uniqueID };
    proConnector.setProvisioningProperties(proProperties);
    ProvisioningConnectorConfig[] proConnectors = fedIdp.getProvisioningConnectorConfigs();
    if (proConnector.getName() != null) {
        if (proConnectors == null || proConnectors.length == 0) {
            fedIdp.setProvisioningConnectorConfigs(new ProvisioningConnectorConfig[] { proConnector });
        } else {
            fedIdp.setProvisioningConnectorConfigs(concatArrays(new ProvisioningConnectorConfig[] { proConnector }, proConnectors));
        }
    }
}
Also used : Property(org.wso2.carbon.identity.application.common.model.idp.xsd.Property) IdentityProviderProperty(org.wso2.carbon.identity.application.common.model.idp.xsd.IdentityProviderProperty) ProvisioningConnectorConfig(org.wso2.carbon.identity.application.common.model.idp.xsd.ProvisioningConnectorConfig)

Example 74 with Property

use of org.wso2.carbon.user.api.Property in project carbon-identity-framework by wso2.

the class IdPManagementUIUtil method buildPassiveSTSAuthenticationConfiguration.

/**
 * @param fedIdp
 * @param paramMap
 * @throws IdentityApplicationManagementException
 */
private static void buildPassiveSTSAuthenticationConfiguration(IdentityProvider fedIdp, Map<String, String> paramMap) throws IdentityApplicationManagementException {
    FederatedAuthenticatorConfig passiveSTSAuthnConfig = new FederatedAuthenticatorConfig();
    passiveSTSAuthnConfig.setName("PassiveSTSAuthenticator");
    passiveSTSAuthnConfig.setDisplayName("passivests");
    if ("on".equals(paramMap.get("passiveSTSEnabled"))) {
        passiveSTSAuthnConfig.setEnabled(true);
    }
    if ("on".equals(paramMap.get("passiveSTSDefault"))) {
        fedIdp.setDefaultAuthenticatorConfig(passiveSTSAuthnConfig);
    }
    Property[] properties = new Property[6];
    Property property = new Property();
    property.setName(IdentityApplicationConstants.Authenticator.PassiveSTS.REALM_ID);
    property.setValue(paramMap.get("passiveSTSRealm"));
    properties[0] = property;
    property = new Property();
    property.setName(IdentityApplicationConstants.Authenticator.PassiveSTS.IDENTITY_PROVIDER_URL);
    property.setValue(paramMap.get("passiveSTSUrl"));
    properties[1] = property;
    property = new Property();
    property.setName(IdentityApplicationConstants.Authenticator.PassiveSTS.IS_USER_ID_IN_CLAIMS);
    properties[2] = property;
    if ("1".equals(paramMap.get("passive_sts_user_id_location"))) {
        property.setValue("true");
        ;
    } else {
        property.setValue("false");
    }
    property = new Property();
    property.setName(IdentityApplicationConstants.Authenticator.PassiveSTS.IS_ENABLE_ASSERTION_SIGNATURE_VALIDATION);
    properties[3] = property;
    if ("on".equals(paramMap.get("isEnablePassiveSTSAssertionSignatureValidation"))) {
        property.setValue("true");
    } else {
        property.setValue("false");
    }
    property = new Property();
    property.setName(IdentityApplicationConstants.Authenticator.PassiveSTS.IS_ENABLE_ASSERTION_AUDIENCE_VALIDATION);
    properties[4] = property;
    if ("on".equals(paramMap.get("isEnablePassiveSTSAssertionAudienceValidation"))) {
        property.setValue("true");
    } else {
        property.setValue("false");
    }
    property = new Property();
    property.setName("commonAuthQueryParams");
    if (paramMap.get("passiveSTSQueryParam") != null && paramMap.get("passiveSTSQueryParam").trim().length() > 0) {
        property.setValue(paramMap.get("passiveSTSQueryParam"));
    }
    properties[5] = property;
    passiveSTSAuthnConfig.setProperties(properties);
    FederatedAuthenticatorConfig[] authenticators = fedIdp.getFederatedAuthenticatorConfigs();
    if (paramMap.get("passiveSTSUrl") != null && !"".equals(paramMap.get("passiveSTSUrl"))) {
        if (authenticators == null || authenticators.length == 0) {
            fedIdp.setFederatedAuthenticatorConfigs(new FederatedAuthenticatorConfig[] { passiveSTSAuthnConfig });
        } else {
            fedIdp.setFederatedAuthenticatorConfigs(concatArrays(new FederatedAuthenticatorConfig[] { passiveSTSAuthnConfig }, authenticators));
        }
    }
}
Also used : FederatedAuthenticatorConfig(org.wso2.carbon.identity.application.common.model.idp.xsd.FederatedAuthenticatorConfig) Property(org.wso2.carbon.identity.application.common.model.idp.xsd.Property) IdentityProviderProperty(org.wso2.carbon.identity.application.common.model.idp.xsd.IdentityProviderProperty)

Example 75 with Property

use of org.wso2.carbon.user.api.Property in project carbon-identity-framework by wso2.

the class CacheBackedIdPMgtDAO method getIdPNameByMetadataProperty.

/**
 * Retrieves the first matching IDP for the given metadata property.
 * Intended to ony be used to retrieve IDP name based on a unique metadata property.
 *
 * @param dbConnection Optional. DB connection.
 * @param property IDP metadata property name.
 * @param value Value associated with given Property.
 * @param tenantId Tenant id whose information is requested.
 * @param tenantDomain Tenant domain whose information is requested.
 * @return Identity Provider name.
 * @throws IdentityProviderManagementException IdentityProviderManagementException.
 */
public String getIdPNameByMetadataProperty(Connection dbConnection, String property, String value, int tenantId, String tenantDomain) throws IdentityProviderManagementException {
    IdPMetadataPropertyCacheKey cacheKey = new IdPMetadataPropertyCacheKey(property, value);
    String idPName = idPCacheByMetadataProperty.getValueFromCache(cacheKey, tenantDomain);
    if (idPName != null) {
        if (log.isDebugEnabled()) {
            log.debug("Cache entry IDP name: " + idPName + " found for IDP metadata property name: " + property + " value: " + value);
        }
        return idPName;
    } else {
        if (log.isDebugEnabled()) {
            log.debug("Cache entry not found for IDP metadata property name: " + property + " value: " + value + ". Fetching entry from DB");
        }
    }
    idPName = idPMgtDAO.getIdPNameByMetadataProperty(dbConnection, property, value, tenantId);
    if (idPName != null) {
        if (log.isDebugEnabled()) {
            log.debug("DB entry IDP name: " + idPName + " found for IDP metadata property name: " + property + " value: " + value);
        }
        idPCacheByMetadataProperty.addToCache(cacheKey, idPName, tenantDomain);
    } else {
        if (log.isDebugEnabled()) {
            log.debug("DB entry not found for IDP metadata property name: " + property + " value: " + value);
        }
    }
    return idPName;
}
Also used : IdPMetadataPropertyCacheKey(org.wso2.carbon.idp.mgt.cache.IdPMetadataPropertyCacheKey)

Aggregations

ArrayList (java.util.ArrayList)118 HashMap (java.util.HashMap)114 Property (org.wso2.carbon.identity.application.common.model.Property)105 Map (java.util.Map)62 IdentityProviderProperty (org.wso2.carbon.identity.application.common.model.IdentityProviderProperty)50 Test (org.testng.annotations.Test)42 IOException (java.io.IOException)38 UserStoreException (org.wso2.carbon.user.api.UserStoreException)38 Property (org.wso2.carbon.identity.application.common.model.idp.xsd.Property)36 InboundAuthenticationRequestConfig (org.wso2.carbon.identity.application.common.model.xsd.InboundAuthenticationRequestConfig)33 APIManagementException (org.wso2.carbon.apimgt.api.APIManagementException)32 RegistryException (org.wso2.carbon.registry.core.exceptions.RegistryException)32 List (java.util.List)31 FederatedAuthenticatorConfig (org.wso2.carbon.identity.application.common.model.FederatedAuthenticatorConfig)29 Resource (org.wso2.carbon.registry.core.Resource)29 OMElement (org.apache.axiom.om.OMElement)27 IdentityProvider (org.wso2.carbon.identity.application.common.model.IdentityProvider)27 PreparedStatement (java.sql.PreparedStatement)23 QName (javax.xml.namespace.QName)23 ProvisioningConnectorConfig (org.wso2.carbon.identity.application.common.model.ProvisioningConnectorConfig)23