Java Code Examples for org.wso2.carbon.identity.application.common.model.Property#setName()

The following examples show how to use org.wso2.carbon.identity.application.common.model.Property#setName() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: FrameworkUtils.java    From carbon-identity-framework with Apache License 2.0 6 votes vote down vote up
/**
 * Get the configurations of a tenant from cache or database
 *
 * @param tenantDomain Domain name of the tenant
 * @return Configurations belong to the tenant
 */
private static Property[] getResidentIdpConfiguration(String tenantDomain) throws FrameworkException {

    IdpManager identityProviderManager = IdentityProviderManager.getInstance();
    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 FrameworkException(errorMsg, e);
    }
    IdentityProviderProperty[] identityMgtProperties = residentIdp.getIdpProperties();
    Property[] configMap = new Property[identityMgtProperties.length];
    int index = 0;
    for (IdentityProviderProperty identityMgtProperty : identityMgtProperties) {
        if (ALREADY_WRITTEN_PROPERTY.equals(identityMgtProperty.getName())) {
            continue;
        }
        Property property = new Property();
        property.setName(identityMgtProperty.getName());
        property.setValue(identityMgtProperty.getValue());
        configMap[index] = property;
        index++;
    }
    return configMap;
}
 
Example 2
Source File: RandomPasswordProcessor.java    From carbon-identity-framework with Apache License 2.0 6 votes vote down vote up
private Property[] addUniqueIdProperty(Property[] properties) {

        if (ArrayUtils.isEmpty(properties)) {
            return new Property[0];
        }

        String uuid = UUID.randomUUID().toString();
        Property uniqueIdProperty = new Property();
        uniqueIdProperty.setName(IdentityApplicationConstants.UNIQUE_ID_CONSTANT);
        uniqueIdProperty.setValue(uuid);
        if (log.isDebugEnabled()) {
            log.debug("Adding uniqueId property: " + uuid);
        }
        properties = (Property[]) ArrayUtils.add(properties, uniqueIdProperty);

        return properties;
    }
 
Example 3
Source File: YahooOpenIDAuthenticator.java    From carbon-identity with Apache License 2.0 6 votes vote down vote up
/**
 * Get Configuration Properties
 *
 * @return
 */
@Override
public List<Property> getConfigurationProperties() {

    List<Property> configProperties = new ArrayList<Property>();

    Property oauthEndpoint = new Property();
    oauthEndpoint.setDisplayName("Yahoo Authentication Endpoint");
    oauthEndpoint.setName(YahooOpenIDAuthenticatorConstants.YAHOO_AUTHZ_URL);
    oauthEndpoint.setValue(IdentityApplicationConstants.YAHOO_AUTHZ_URL);
    oauthEndpoint.setDescription("Enter value corresponding to yahoo oauth endpoint.");
    oauthEndpoint.setDisplayOrder(1);
    configProperties.add(oauthEndpoint);

    return configProperties;
}
 
Example 4
Source File: RandomPasswordProcessor.java    From carbon-identity with Apache License 2.0 6 votes vote down vote up
private Property[] addUniqueIdProperty(Property [] properties) {

        if (ArrayUtils.isEmpty(properties)){
            return new Property[0];
        }

        String uuid = UUID.randomUUID().toString();
        Property uniqueIdProperty = new Property();
        uniqueIdProperty.setName(IdentityApplicationConstants.UNIQUE_ID_CONSTANT);
        uniqueIdProperty.setValue(uuid);
        if (log.isDebugEnabled()){
            log.debug("Adding uniqueId property: " + uuid);
        }
        properties = (Property[]) ArrayUtils.add(properties, uniqueIdProperty);

        return properties;
    }
 
Example 5
Source File: CustomInboundFunctions.java    From identity-api-server with Apache License 2.0 5 votes vote down vote up
private static Property buildProperty(PropertyModel modelProperty) {

        Property property = new Property();
        property.setName(modelProperty.getKey());
        property.setValue(modelProperty.getValue());
        return property;
    }
 
Example 6
Source File: ApiModelToCustomInbound.java    From identity-api-server with Apache License 2.0 5 votes vote down vote up
private Property buildProperty(PropertyModel modelProperty) {

        Property property = new Property();
        property.setName(modelProperty.getKey());
        property.setValue(modelProperty.getValue());
        return property;
    }
 
Example 7
Source File: PassiveSTSInboundFunctions.java    From identity-api-server with Apache License 2.0 5 votes vote down vote up
public static InboundAuthenticationRequestConfig createPassiveSTSInboundConfig(PassiveStsConfiguration config) {

        InboundAuthenticationRequestConfig passiveStsInbound = new InboundAuthenticationRequestConfig();
        passiveStsInbound.setInboundAuthType(StandardInboundProtocols.PASSIVE_STS);
        passiveStsInbound.setInboundAuthKey(config.getRealm());

        Property passiveStsReplyUrl = new Property();
        passiveStsReplyUrl.setName(IdentityApplicationConstants.PassiveSTS.PASSIVE_STS_REPLY_URL);
        passiveStsReplyUrl.setValue(config.getReplyTo());

        passiveStsInbound.setProperties(new Property[]{passiveStsReplyUrl});
        return passiveStsInbound;
    }
 
Example 8
Source File: OAuthApplicationMgtListener.java    From carbon-identity with Apache License 2.0 5 votes vote down vote up
private void addClientSecret(ServiceProvider serviceProvider) throws IdentityApplicationManagementException {

        if (serviceProvider == null) {
            return ; // if service provider is not present no need to add this information
        }

        try {
            InboundAuthenticationConfig inboundAuthenticationConfig = serviceProvider.getInboundAuthenticationConfig();
            if (inboundAuthenticationConfig != null) {
                InboundAuthenticationRequestConfig[] inboundRequestConfigs = inboundAuthenticationConfig.
                        getInboundAuthenticationRequestConfigs();
                if (inboundRequestConfigs != null) {
                    for (InboundAuthenticationRequestConfig inboundRequestConfig : inboundRequestConfigs) {
                        if (inboundRequestConfig.getInboundAuthType().equals(OAUTH2)) {
                            Property[] props = inboundRequestConfig.getProperties();
                            Property property = new Property();
                            property.setName(OAUTH2_CONSUMER_SECRET);
                            property.setValue(getClientSecret(inboundRequestConfig.getInboundAuthKey()));
                            props = (Property[]) ArrayUtils.add(props, property);
                            inboundRequestConfig.setProperties(props);
                            continue;// we are interested only on oauth2 config. Only one will be present.
                        } else {
                            //ignore
                        }
                    }
                } else {
                    //ignore
                }
            } else {
                //nothing to do
            }
        } catch (IdentityOAuthAdminException e) {
            throw new IdentityApplicationManagementException("Injecting client secret failed.", e);
        }


        return;
    }
 
Example 9
Source File: IdentityProviderManager.java    From carbon-identity-framework with Apache License 2.0 5 votes vote down vote up
private Property buildDestinationURLProperty(String destinationURL, int index) {

        Property destinationURLProperty = new Property();
        destinationURLProperty.setName(IdentityApplicationConstants.Authenticator.SAML2SSO.DESTINATION_URL_PREFIX +
                IdentityApplicationConstants.MULTIVALUED_PROPERTY_CHARACTER + index);
        destinationURLProperty.setValue(destinationURL);
        return destinationURLProperty;
    }
 
Example 10
Source File: WindowsLiveOAuth2Authenticator.java    From carbon-identity with Apache License 2.0 5 votes vote down vote up
@Override
public List<Property> getConfigurationProperties() {

    List<Property> configProperties = new ArrayList<Property>();

    Property callbackUrl = new Property();
    callbackUrl.setDisplayName("Callback Url");
    callbackUrl.setName(IdentityApplicationConstants.OAuth2.CALLBACK_URL);
    callbackUrl.setDescription("Enter value corresponding to callback url.");
    callbackUrl.setDisplayOrder(3);
    configProperties.add(callbackUrl);

    Property clientId = new Property();
    clientId.setName(OIDCAuthenticatorConstants.CLIENT_ID);
    clientId.setDisplayName("Client Id");
    clientId.setRequired(true);
    clientId.setDescription("Enter Microsoft Live client identifier value");
    clientId.setDisplayOrder(1);
    configProperties.add(clientId);

    Property clientSecret = new Property();
    clientSecret.setName(OIDCAuthenticatorConstants.CLIENT_SECRET);
    clientSecret.setDisplayName("Client Secret");
    clientSecret.setRequired(true);
    clientSecret.setConfidential(true);
    clientSecret.setDescription("Enter Microsoft Live client secret value");
    clientSecret.setDisplayOrder(2);
    configProperties.add(clientSecret);

    return configProperties;
}
 
Example 11
Source File: GoogleOAuth2Authenticator.java    From carbon-identity with Apache License 2.0 5 votes vote down vote up
/**
 * Get Configuration Properties
 *
 * @return
 */
@Override
public List<Property> getConfigurationProperties() {

    List<Property> configProperties = new ArrayList<Property>();

    Property clientId = new Property();
    clientId.setName(OIDCAuthenticatorConstants.CLIENT_ID);
    clientId.setDisplayName("Client Id");
    clientId.setRequired(true);
    clientId.setDescription("Enter Google IDP client identifier value");
    clientId.setDisplayOrder(1);
    configProperties.add(clientId);

    Property clientSecret = new Property();
    clientSecret.setName(OIDCAuthenticatorConstants.CLIENT_SECRET);
    clientSecret.setDisplayName("Client Secret");
    clientSecret.setRequired(true);
    clientSecret.setConfidential(true);
    clientSecret.setDescription("Enter Google IDP client secret value");
    clientSecret.setDisplayOrder(2);
    configProperties.add(clientSecret);

    Property callbackUrl = new Property();
    callbackUrl.setDisplayName("Callback Url");
    callbackUrl.setName(IdentityApplicationConstants.OAuth2.CALLBACK_URL);
    callbackUrl.setDescription("Enter value corresponding to callback url.");
    callbackUrl.setDisplayOrder(3);
    configProperties.add(callbackUrl);

    Property scope = new Property();
    scope.setDisplayName("Additional Query Parameters");
    scope.setName("AdditionalQueryParameters");
    scope.setValue("scope=openid email profile");
    scope.setDescription("Additional query parameters. e.g: paramName1=value1");
    scope.setDisplayOrder(4);
    configProperties.add(scope);

    return configProperties;
}
 
Example 12
Source File: YahooOAuth2Authenticator.java    From carbon-identity with Apache License 2.0 5 votes vote down vote up
/**
 * Get configuration properties.
 *
 * @return Properties list.
 */
@Override
public List<Property> getConfigurationProperties() {

    List<Property> configProperties = new ArrayList<>();

    Property clientId = new Property();
    clientId.setName(OIDCAuthenticatorConstants.CLIENT_ID);
    clientId.setDisplayName("Client Id");
    clientId.setRequired(true);
    clientId.setDescription("Enter Yahoo IDP client identifier value");
    clientId.setDisplayOrder(1);
    configProperties.add(clientId);

    Property clientSecret = new Property();
    clientSecret.setName(OIDCAuthenticatorConstants.CLIENT_SECRET);
    clientSecret.setDisplayName("Client Secret");
    clientSecret.setRequired(true);
    clientSecret.setConfidential(true);
    clientSecret.setDescription("Enter Yahoo IDP client secret value");
    clientSecret.setDisplayOrder(2);
    configProperties.add(clientSecret);

    Property callbackUrl = new Property();
    callbackUrl.setDisplayName("Callback URL");
    callbackUrl.setName(IdentityApplicationConstants.OAuth2.CALLBACK_URL);
    callbackUrl.setDescription("Enter value corresponding to callback url.");
    callbackUrl.setDisplayOrder(3);
    configProperties.add(callbackUrl);

    return configProperties;
}
 
Example 13
Source File: IdPManagementDAO.java    From carbon-identity with Apache License 2.0 4 votes vote down vote up
/**
 * @param dbConnection
 * @param idPName
 * @param tenantId
 * @return
 * @throws IdentityProviderManagementException
 * @throws SQLException
 */
private FederatedAuthenticatorConfig[] getFederatedAuthenticatorConfigs(
        Connection dbConnection, String idPName, IdentityProvider federatedIdp, int tenantId)
        throws IdentityProviderManagementException, SQLException {

    int idPId = getIdentityProviderIdentifier(dbConnection, idPName, tenantId);

    PreparedStatement prepStmt1 = null;
    PreparedStatement prepStmt2 = null;
    ResultSet rs = null;
    ResultSet proprs = null;
    String defaultAuthName = null;

    if (federatedIdp != null && federatedIdp.getDefaultAuthenticatorConfig() != null) {
        defaultAuthName = federatedIdp.getDefaultAuthenticatorConfig().getName();
    }

    String sqlStmt = IdPManagementConstants.SQLQueries.GET_ALL_IDP_AUTH_SQL;
    Set<FederatedAuthenticatorConfig> federatedAuthenticatorConfigs = new HashSet<FederatedAuthenticatorConfig>();
    try {
        prepStmt1 = dbConnection.prepareStatement(sqlStmt);
        prepStmt1.setInt(1, idPId);
        rs = prepStmt1.executeQuery();

        while (rs.next()) {
            FederatedAuthenticatorConfig authnConfig = new FederatedAuthenticatorConfig();
            int authnId = rs.getInt("ID");
            authnConfig.setName(rs.getString("NAME"));

            if ((IdPManagementConstants.IS_TRUE_VALUE).equals(rs.getString("IS_ENABLED"))) {
                authnConfig.setEnabled(true);
            } else {
                authnConfig.setEnabled(false);
            }

            authnConfig.setDisplayName(rs.getString("DISPLAY_NAME"));

            if (defaultAuthName != null && authnConfig.getName().equals(defaultAuthName)) {
                federatedIdp.getDefaultAuthenticatorConfig().setDisplayName(authnConfig.getDisplayName());
            }

            sqlStmt = IdPManagementConstants.SQLQueries.GET_IDP_AUTH_PROPS_SQL;
            prepStmt2 = dbConnection.prepareStatement(sqlStmt);
            prepStmt2.setInt(1, authnId);
            proprs = prepStmt2.executeQuery();
            Set<Property> properties = new HashSet<Property>();
            while (proprs.next()) {
                Property property = new Property();
                property.setName(proprs.getString("PROPERTY_KEY"));
                property.setValue(proprs.getString("PROPERTY_VALUE"));
                if ((IdPManagementConstants.IS_TRUE_VALUE).equals(proprs.getString("IS_SECRET"))) {
                    property.setConfidential(true);
                }
                properties.add(property);
            }
            authnConfig.setProperties(properties.toArray(new Property[properties.size()]));
            federatedAuthenticatorConfigs.add(authnConfig);
        }

        return federatedAuthenticatorConfigs
                .toArray(new FederatedAuthenticatorConfig[federatedAuthenticatorConfigs.size()]);
    } finally {
        IdentityDatabaseUtil.closeAllConnections(null, proprs, prepStmt2);
        IdentityDatabaseUtil.closeAllConnections(null, rs, prepStmt1);
    }
}
 
Example 14
Source File: AbstractProvisioningConnectorFactory.java    From carbon-identity with Apache License 2.0 4 votes vote down vote up
/**
 * @param identityProviderName
 * @param provisoningProperties
 * @param tenantDomain
 * @return
 * @throws IdentityProvisioningException
 */
public AbstractOutboundProvisioningConnector getConnector(String identityProviderName,
                                                          Property[] provisoningProperties, String tenantDomain)
        throws IdentityProvisioningException {

    String tenantDomainName = null;
    int tenantId = -1234;

    if (CarbonContext.getThreadLocalCarbonContext() != null) {
        tenantDomainName = CarbonContext.getThreadLocalCarbonContext().getTenantDomain();
        tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId();
    }

    try {
        // maintain the provisioning connector cache in the super tenant.
        // at the time of provisioning there may not be an authenticated user in the system -
        // specially in the case of in-bound provisioning.
        PrivilegedCarbonContext.startTenantFlow();

        PrivilegedCarbonContext carbonContext = PrivilegedCarbonContext
                .getThreadLocalCarbonContext();
        carbonContext.setTenantId(MultitenantConstants.SUPER_TENANT_ID);
        carbonContext.setTenantDomain(MultitenantConstants.SUPER_TENANT_DOMAIN_NAME);

        ProvisioningConnectorCacheKey cacheKey = new ProvisioningConnectorCacheKey(identityProviderName, tenantDomain);
        ProvisioningConnectorCacheEntry entry = ProvisioningConnectorCache.getInstance().getValueFromCache(cacheKey);

        if (entry != null) {
            if (log.isDebugEnabled()) {
                log.debug("Provisioning cache HIT for " + identityProviderName + " of "
                        + tenantDomain);
            }
            return entry.getProvisioningConnector();
        }

        AbstractOutboundProvisioningConnector connector;

        Property idpName = new Property();
        idpName.setName("identityProviderName");
        idpName.setValue(identityProviderName);

        List<Property> provisioningPropertiesList = new ArrayList<>(Arrays.asList(provisoningProperties));

        provisioningPropertiesList.add(idpName);

        Property[] provisioningProperties = new Property[provisioningPropertiesList.size()];
        provisioningProperties = provisioningPropertiesList.toArray(provisioningProperties);

        connector = buildConnector(provisioningProperties);
        entry = new ProvisioningConnectorCacheEntry();
        entry.setProvisioningConnector(connector);
        ProvisioningConnectorCache.getInstance().addToCache(cacheKey, entry);

        return connector;
    } finally {
        PrivilegedCarbonContext.endTenantFlow();

        if (tenantDomain != null) {
            PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantDomain(
                    tenantDomainName);
            PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantId(tenantId);
        }
    }

}
 
Example 15
Source File: OutboundProvisioningManager.java    From carbon-identity with Apache License 2.0 4 votes vote down vote up
/**
 * @param fIdP
 * @param registeredConnectorFactories
 * @param tenantDomainName
 * @param enableJitProvisioning
 * @return
 * @throws IdentityProviderManagementException
 * @throws UserStoreException
 */
private AbstractOutboundProvisioningConnector getOutboundProvisioningConnector(
        IdentityProvider fIdP,
        Map<String, AbstractProvisioningConnectorFactory> registeredConnectorFactories,
        String tenantDomainName, boolean enableJitProvisioning)
        throws IdentityProviderManagementException, IdentityProvisioningException {

    String idpName = fIdP.getIdentityProviderName();

    // name of the default provisioning connector.
    String connectorType = fIdP.getDefaultProvisioningConnectorConfig().getName();

    // get identity provider configuration.
    fIdP = IdentityProviderManager.getInstance().getEnabledIdPByName(idpName, tenantDomainName);

    if (fIdP == null) {
        // This is an exceptional situation. If service provider has connected to an
        // identity provider, that identity provider must be present in the system.
        // If not its an exception.
        throw new IdentityProvisioningException(
                "Provisioning identity provider not available in the system. Idp Name : "
                        + idpName);
    }

    // get a list of provisioning connectors associated with the provisioning
    // identity provider.
    ProvisioningConnectorConfig[] provisioningConfigs = fIdP.getProvisioningConnectorConfigs();

    if (provisioningConfigs != null && provisioningConfigs.length > 0) {

        for (ProvisioningConnectorConfig defaultProvisioningConfig : provisioningConfigs) {

            if (!connectorType.equals(defaultProvisioningConfig.getName())
                    || !defaultProvisioningConfig.isEnabled()) {
                // we need to find the provisioning connector selected by the service provider.
                continue;
            }

            // this is how we match the configuration to the runtime. the provisioning
            // connector factory should be registered with the system, with the exact
            // name available in the corresponding configuration.
            AbstractProvisioningConnectorFactory factory = registeredConnectorFactories
                    .get(connectorType);

            // get the provisioning properties associated with a given provisioning
            // connector.
            Property[] provisioningProperties = defaultProvisioningConfig
                    .getProvisioningProperties();

            if (enableJitProvisioning) {
                Property jitEnabled = new Property();
                jitEnabled.setName(IdentityProvisioningConstants.JIT_PROVISIONING_ENABLED);
                jitEnabled.setValue("1");
                provisioningProperties = IdentityApplicationManagementUtil.concatArrays(
                        provisioningProperties, new Property[]{jitEnabled});
            }

            Property userIdClaimURL = new Property();
            userIdClaimURL.setName("userIdClaimUri");

            if (fIdP.getClaimConfig() != null && fIdP.getClaimConfig().getUserClaimURI() != null) {
                userIdClaimURL.setValue(fIdP.getClaimConfig().getUserClaimURI());
            } else {
                userIdClaimURL.setValue("");
            }

            List<Property> provisioningPropertiesList = new ArrayList<>(Arrays.asList(provisioningProperties));

            provisioningPropertiesList.add(userIdClaimURL);

            provisioningProperties = new Property[provisioningPropertiesList.size()];
            provisioningProperties = provisioningPropertiesList.toArray(provisioningProperties);

            // get the runtime provisioning connector associate the provisioning
            // identity provider. any given time, a given provisioning identity provider
            // can only be associated with a single provisioning connector.
            return factory.getConnector(idpName, provisioningProperties, tenantDomainName);
        }
    }

    return null;
}
 
Example 16
Source File: IdPManagementDAO.java    From carbon-identity-framework with Apache License 2.0 4 votes vote down vote up
/**
 * @param dbConnection
 * @param idPName
 * @param tenantId
 * @return
 * @throws IdentityProviderManagementException
 * @throws SQLException
 */
private FederatedAuthenticatorConfig[] getFederatedAuthenticatorConfigs(
        Connection dbConnection, String idPName, IdentityProvider federatedIdp, int tenantId)
        throws IdentityProviderManagementException, SQLException {

    int idPId = getIdentityProviderIdentifier(dbConnection, idPName, tenantId);

    PreparedStatement prepStmt1 = null;
    PreparedStatement prepStmt2 = null;
    ResultSet rs = null;
    ResultSet proprs = null;
    String defaultAuthName = null;

    if (federatedIdp != null && federatedIdp.getDefaultAuthenticatorConfig() != null) {
        defaultAuthName = federatedIdp.getDefaultAuthenticatorConfig().getName();
    }

    String sqlStmt = IdPManagementConstants.SQLQueries.GET_ALL_IDP_AUTH_SQL;
    Set<FederatedAuthenticatorConfig> federatedAuthenticatorConfigs = new HashSet<FederatedAuthenticatorConfig>();
    try {
        prepStmt1 = dbConnection.prepareStatement(sqlStmt);
        prepStmt1.setInt(1, idPId);
        rs = prepStmt1.executeQuery();

        while (rs.next()) {
            FederatedAuthenticatorConfig authnConfig = new FederatedAuthenticatorConfig();
            int authnId = rs.getInt("ID");
            authnConfig.setName(rs.getString("NAME"));

            if ((IdPManagementConstants.IS_TRUE_VALUE).equals(rs.getString("IS_ENABLED"))) {
                authnConfig.setEnabled(true);
            } else {
                authnConfig.setEnabled(false);
            }

            authnConfig.setDisplayName(rs.getString("DISPLAY_NAME"));

            if (defaultAuthName != null && authnConfig.getName().equals(defaultAuthName)) {
                federatedIdp.getDefaultAuthenticatorConfig().setDisplayName(authnConfig.getDisplayName());
            }

            sqlStmt = IdPManagementConstants.SQLQueries.GET_IDP_AUTH_PROPS_SQL;
            prepStmt2 = dbConnection.prepareStatement(sqlStmt);
            prepStmt2.setInt(1, authnId);
            proprs = prepStmt2.executeQuery();
            Set<Property> properties = new HashSet<Property>();
            while (proprs.next()) {
                Property property = new Property();
                property.setName(proprs.getString("PROPERTY_KEY"));
                property.setValue(proprs.getString("PROPERTY_VALUE"));
                if ((IdPManagementConstants.IS_TRUE_VALUE).equals(proprs.getString("IS_SECRET"))) {
                    property.setConfidential(true);
                }
                properties.add(property);
            }
            authnConfig.setProperties(properties.toArray(new Property[properties.size()]));
            federatedAuthenticatorConfigs.add(authnConfig);
        }

        return federatedAuthenticatorConfigs
                .toArray(new FederatedAuthenticatorConfig[federatedAuthenticatorConfigs.size()]);
    } finally {
        IdentityDatabaseUtil.closeAllConnections(null, proprs, prepStmt2);
        IdentityDatabaseUtil.closeAllConnections(null, rs, prepStmt1);
    }
}
 
Example 17
Source File: AbstractProvisioningConnectorFactory.java    From carbon-identity-framework with Apache License 2.0 4 votes vote down vote up
/**
 * @param identityProviderName
 * @param provisoningProperties
 * @param tenantDomain
 * @return
 * @throws IdentityProvisioningException
 */
public AbstractOutboundProvisioningConnector getConnector(String identityProviderName,
                                                          Property[] provisoningProperties, String tenantDomain)
        throws IdentityProvisioningException {

    String tenantDomainName = null;
    int tenantId = -1234;

    if (CarbonContext.getThreadLocalCarbonContext() != null) {
        tenantDomainName = CarbonContext.getThreadLocalCarbonContext().getTenantDomain();
        tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId();
    }

    try {
        // maintain the provisioning connector cache in the super tenant.
        // at the time of provisioning there may not be an authenticated user in the system -
        // specially in the case of in-bound provisioning.
        PrivilegedCarbonContext.startTenantFlow();

        PrivilegedCarbonContext carbonContext = PrivilegedCarbonContext
                .getThreadLocalCarbonContext();
        carbonContext.setTenantId(MultitenantConstants.SUPER_TENANT_ID);
        carbonContext.setTenantDomain(MultitenantConstants.SUPER_TENANT_DOMAIN_NAME);

        ProvisioningConnectorCacheKey cacheKey = new ProvisioningConnectorCacheKey(identityProviderName, tenantDomain);
        ProvisioningConnectorCacheEntry entry = ProvisioningConnectorCache.getInstance().getValueFromCache(cacheKey);

        if (entry != null) {
            if (log.isDebugEnabled()) {
                log.debug("Provisioning cache HIT for " + identityProviderName + " of "
                        + tenantDomain);
            }
            return entry.getProvisioningConnector();
        }

        AbstractOutboundProvisioningConnector connector;

        Property idpName = new Property();
        idpName.setName("identityProviderName");
        idpName.setValue(identityProviderName);

        List<Property> provisioningPropertiesList = new ArrayList<>(Arrays.asList(provisoningProperties));

        provisioningPropertiesList.add(idpName);

        Property[] provisioningProperties = new Property[provisioningPropertiesList.size()];
        provisioningProperties = provisioningPropertiesList.toArray(provisioningProperties);

        connector = buildConnector(provisioningProperties);
        entry = new ProvisioningConnectorCacheEntry();
        entry.setProvisioningConnector(connector);
        ProvisioningConnectorCache.getInstance().addToCache(cacheKey, entry);

        return connector;
    } finally {
        PrivilegedCarbonContext.endTenantFlow();

        if (tenantDomain != null) {
            PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantDomain(
                    tenantDomainName);
            PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantId(tenantId);
        }
    }

}
 
Example 18
Source File: OutboundProvisioningManager.java    From carbon-identity-framework with Apache License 2.0 4 votes vote down vote up
/**
 * @param fIdP
 * @param registeredConnectorFactories
 * @param tenantDomainName
 * @param enableJitProvisioning
 * @return
 * @throws IdentityProviderManagementException
 * @throws UserStoreException
 */
private AbstractOutboundProvisioningConnector getOutboundProvisioningConnector(
        IdentityProvider fIdP,
        Map<String, AbstractProvisioningConnectorFactory> registeredConnectorFactories,
        String tenantDomainName, boolean enableJitProvisioning)
        throws IdentityProviderManagementException, IdentityProvisioningException {

    String idpName = fIdP.getIdentityProviderName();

    // name of the default provisioning connector.
    String connectorType = fIdP.getDefaultProvisioningConnectorConfig().getName();

    // get identity provider configuration.
    fIdP = IdentityProviderManager.getInstance().getEnabledIdPByName(idpName, tenantDomainName);

    if (fIdP == null) {
        // This is an exceptional situation. If service provider has connected to an
        // identity provider, that identity provider must be present in the system.
        // If not its an exception.
        throw new IdentityProvisioningException(
                "Provisioning identity provider not available in the system. Idp Name : "
                + idpName);
    }

    // get a list of provisioning connectors associated with the provisioning
    // identity provider.
    ProvisioningConnectorConfig[] provisioningConfigs = fIdP.getProvisioningConnectorConfigs();

    if (provisioningConfigs != null && provisioningConfigs.length > 0) {

        for (ProvisioningConnectorConfig defaultProvisioningConfig : provisioningConfigs) {

            if (!connectorType.equals(defaultProvisioningConfig.getName())
                || !defaultProvisioningConfig.isEnabled()) {
                // we need to find the provisioning connector selected by the service provider.
                continue;
            }

            // this is how we match the configuration to the runtime. the provisioning
            // connector factory should be registered with the system, with the exact
            // name available in the corresponding configuration.
            AbstractProvisioningConnectorFactory factory = registeredConnectorFactories
                    .get(connectorType);

            // get the provisioning properties associated with a given provisioning
            // connector.
            Property[] provisioningProperties = defaultProvisioningConfig
                    .getProvisioningProperties();

            if (enableJitProvisioning) {
                Property jitEnabled = new Property();
                jitEnabled.setName(IdentityProvisioningConstants.JIT_PROVISIONING_ENABLED);
                jitEnabled.setValue("1");
                provisioningProperties = IdentityApplicationManagementUtil.concatArrays(
                        provisioningProperties, new Property[]{jitEnabled});
            }

            Property userIdClaimURL = new Property();
            userIdClaimURL.setName("userIdClaimUri");

            if (fIdP.getClaimConfig() != null && fIdP.getClaimConfig().getUserClaimURI() != null) {
                userIdClaimURL.setValue(fIdP.getClaimConfig().getUserClaimURI());
            } else {
                userIdClaimURL.setValue("");
            }

            List<Property> provisioningPropertiesList = new ArrayList<>(Arrays.asList(provisioningProperties));

            provisioningPropertiesList.add(userIdClaimURL);

            provisioningProperties = new Property[provisioningPropertiesList.size()];
            provisioningProperties = provisioningPropertiesList.toArray(provisioningProperties);

            // get the runtime provisioning connector associate the provisioning
            // identity provider. any given time, a given provisioning identity provider
            // can only be associated with a single provisioning connector.
            return factory.getConnector(idpName, provisioningProperties, tenantDomainName);
        }
    }

    return null;
}