Search in sources :

Example 11 with ClaimMapping

use of org.wso2.carbon.identity.application.common.model.xsd.ClaimMapping in project carbon-identity-framework by wso2.

the class DefaultAttributeFinder method getSupportedAttributes.

/*
     * (non-Javadoc)
     *
     * @see org.wso2.carbon.identity.entitlement.pip.PIPAttributeFinder#getSupportedAttributes()
     */
public Set<String> getSupportedAttributes() {
    try {
        ClaimManager claimManager = CarbonContext.getThreadLocalCarbonContext().getUserRealm().getClaimManager();
        ClaimMapping[] claims = claimManager.getAllClaimMappings(UserCoreConstants.DEFAULT_CARBON_DIALECT);
        for (ClaimMapping claim : claims) {
            supportedAttrs.add(claim.getClaim().getClaimUri());
        }
    } catch (Exception e) {
    // ignore
    }
    return supportedAttrs;
}
Also used : ClaimManager(org.wso2.carbon.user.api.ClaimManager) ClaimMapping(org.wso2.carbon.user.api.ClaimMapping) UserStoreException(org.wso2.carbon.user.api.UserStoreException)

Example 12 with ClaimMapping

use of org.wso2.carbon.identity.application.common.model.xsd.ClaimMapping in project carbon-identity-framework by wso2.

the class MockRealm method init.

@Override
public void init(RealmConfiguration realmConfiguration, Map<String, ClaimMapping> claimMappingMap, Map<String, ProfileConfiguration> map1, int tenantId) throws UserStoreException {
    this.realmConfiguration = realmConfiguration;
    this.tenantId = tenantId;
    DataSource dataSource = MockInitialContextFactory.initializeDatasource(UM_DB_JNDI_NAME, this.getClass(), new String[] { UM_DB_SQL_FILE });
    userStoreManager = new MockUserStoreManager(dataSource);
    ((MockUserStoreManager) this.userStoreManager).setRealmConfiguration(this.realmConfiguration);
    claimManager = new MockClaimManager(claimMappingMap);
    ((MockUserStoreManager) this.userStoreManager).setClaimManager(this.claimManager);
    HybridRoleManager hybridRoleManager = new MockHybridRoleManager(dataSource, tenantId, realmConfiguration, this);
    ((MockUserStoreManager) this.userStoreManager).setHybridRoleManager(hybridRoleManager);
}
Also used : HybridRoleManager(org.wso2.carbon.user.core.hybrid.HybridRoleManager) DataSource(javax.sql.DataSource)

Example 13 with ClaimMapping

use of org.wso2.carbon.identity.application.common.model.xsd.ClaimMapping in project carbon-identity-framework by wso2.

the class IdentityProviderManager method getMappedLocalClaims.

/**
 * Retrieves Identity provider information about a given tenant
 *
 * @param idPName      Unique Name of the IdP to which the given IdP claim URIs need to be mapped
 * @param tenantDomain The tenant domain of whose local claim URIs to be mapped
 * @param idPClaimURIs IdP claim URIs which need to be mapped to tenant's local claim URIs
 * @throws IdentityProviderManagementException Error when getting claim mappings
 */
@Override
public Set<ClaimMapping> getMappedLocalClaims(String idPName, String tenantDomain, List<String> idPClaimURIs) throws IdentityProviderManagementException {
    int tenantId = IdentityTenantUtil.getTenantId(tenantDomain);
    if (StringUtils.isEmpty(idPName)) {
        String msg = "Invalid argument: Identity Provider Name value is empty";
        throw new IdentityProviderManagementException(msg);
    }
    IdentityProvider identityProvider = dao.getIdPByName(null, idPName, tenantId, tenantDomain);
    if (identityProvider == null) {
        identityProvider = new FileBasedIdPMgtDAO().getIdPByName(idPName, tenantDomain);
    }
    if (identityProvider == null) {
        identityProvider = IdPManagementServiceComponent.getFileBasedIdPs().get(IdentityApplicationConstants.DEFAULT_IDP_CONFIG);
    }
    ClaimConfig claimConfiguration = identityProvider.getClaimConfig();
    if (claimConfiguration != null) {
        ClaimMapping[] claimMappings = claimConfiguration.getClaimMappings();
        if (claimMappings != null && claimMappings.length > 0 && idPClaimURIs != null) {
            Set<ClaimMapping> returnSet = new HashSet<ClaimMapping>();
            for (String idpClaim : idPClaimURIs) {
                for (ClaimMapping claimMapping : claimMappings) {
                    if (claimMapping.getRemoteClaim().getClaimUri().equals(idpClaim)) {
                        returnSet.add(claimMapping);
                        break;
                    }
                }
            }
            return returnSet;
        }
    }
    return new HashSet<ClaimMapping>();
}
Also used : FileBasedIdPMgtDAO(org.wso2.carbon.idp.mgt.dao.FileBasedIdPMgtDAO) ClaimMapping(org.wso2.carbon.identity.application.common.model.ClaimMapping) ClaimConfig(org.wso2.carbon.identity.application.common.model.ClaimConfig) IdentityProvider(org.wso2.carbon.identity.application.common.model.IdentityProvider) HashSet(java.util.HashSet)

Example 14 with ClaimMapping

use of org.wso2.carbon.identity.application.common.model.xsd.ClaimMapping in project carbon-identity-framework by wso2.

the class IdPManagementUIUtil method buildClaimConfiguration.

/**
 * @param fedIdp
 * @param paramMap
 * @throws IdentityApplicationManagementException
 */
private static void buildClaimConfiguration(IdentityProvider fedIdp, Map<String, String> paramMap, List<String> idpClaims, ClaimMapping[] currentClaimMapping) throws IdentityApplicationManagementException {
    ClaimConfig claimConfiguration = new ClaimConfig();
    if (idpClaims != null && idpClaims.size() > 0) {
        List<Claim> idPClaimList = new ArrayList<Claim>();
        for (Iterator<String> iterator = idpClaims.iterator(); iterator.hasNext(); ) {
            String claimUri = iterator.next();
            Claim idpClaim = new Claim();
            idpClaim.setClaimUri(claimUri);
            idPClaimList.add(idpClaim);
        }
        claimConfiguration.setIdpClaims(idPClaimList.toArray(new Claim[idPClaimList.size()]));
    }
    claimConfiguration.setUserClaimURI(paramMap.get("user_id_claim_dropdown"));
    claimConfiguration.setRoleClaimURI(paramMap.get("role_claim_dropdown"));
    ClaimConfig claimConfigurationUpdated = claimMappingFromUI(claimConfiguration, paramMap);
    fedIdp.setClaimConfig(claimConfigurationUpdated);
}
Also used : ClaimConfig(org.wso2.carbon.identity.application.common.model.idp.xsd.ClaimConfig) ArrayList(java.util.ArrayList) Claim(org.wso2.carbon.identity.application.common.model.idp.xsd.Claim)

Example 15 with ClaimMapping

use of org.wso2.carbon.identity.application.common.model.xsd.ClaimMapping in project carbon-identity-framework by wso2.

the class IdPManagementDAO method getLocalIdPDefaultClaimValues.

/**
 * @param dbConnection
 * @param idPName
 * @param userClaimUri
 * @param roleClaimUri
 * @param idpId
 * @param tenantId
 * @return
 * @throws SQLException
 */
private ClaimConfig getLocalIdPDefaultClaimValues(Connection dbConnection, String idPName, String userClaimUri, String roleClaimUri, int idpId, int tenantId) throws SQLException {
    PreparedStatement prepStmt = null;
    ResultSet rs = null;
    String sqlStmt;
    ClaimConfig claimConfig = new ClaimConfig();
    try {
        claimConfig.setLocalClaimDialect(true);
        claimConfig.setRoleClaimURI(roleClaimUri);
        claimConfig.setUserClaimURI(userClaimUri);
        sqlStmt = IdPManagementConstants.SQLQueries.GET_LOCAL_IDP_DEFAULT_CLAIM_VALUES_SQL;
        prepStmt = dbConnection.prepareStatement(sqlStmt);
        prepStmt.setInt(1, idpId);
        prepStmt.setInt(2, tenantId);
        List<ClaimMapping> claimMappings = new ArrayList<ClaimMapping>();
        rs = prepStmt.executeQuery();
        while (rs.next()) {
            ClaimMapping claimMapping = new ClaimMapping();
            // empty claim.
            Claim remoteClaim = new Claim();
            Claim localClaim = new Claim();
            localClaim.setClaimUri(rs.getString("CLAIM_URI"));
            claimMapping.setLocalClaim(localClaim);
            claimMapping.setRemoteClaim(remoteClaim);
            claimMapping.setDefaultValue(rs.getString("DEFAULT_VALUE"));
            if ((IdPManagementConstants.IS_TRUE_VALUE).equals(rs.getString("IS_REQUESTED"))) {
                claimMapping.setRequested(true);
            } else if (rs.getString("IS_REQUESTED").equals(IdPManagementConstants.IS_TRUE_VALUE)) {
                claimMapping.setRequested(false);
            }
            claimMappings.add(claimMapping);
        }
        claimConfig.setClaimMappings(claimMappings.toArray(new ClaimMapping[claimMappings.size()]));
        return claimConfig;
    } finally {
        IdentityDatabaseUtil.closeAllConnections(null, rs, prepStmt);
    }
}
Also used : ClaimMapping(org.wso2.carbon.identity.application.common.model.ClaimMapping) ClaimConfig(org.wso2.carbon.identity.application.common.model.ClaimConfig) ResultSet(java.sql.ResultSet) ArrayList(java.util.ArrayList) PreparedStatement(java.sql.PreparedStatement) Claim(org.wso2.carbon.identity.application.common.model.Claim)

Aggregations

ClaimMapping (org.wso2.carbon.identity.application.common.model.ClaimMapping)108 HashMap (java.util.HashMap)60 ArrayList (java.util.ArrayList)52 ClaimConfig (org.wso2.carbon.identity.application.common.model.ClaimConfig)27 Map (java.util.Map)26 ServiceProvider (org.wso2.carbon.identity.application.common.model.ServiceProvider)24 ClaimMapping (org.wso2.carbon.identity.application.common.model.xsd.ClaimMapping)24 ClaimMapping (org.wso2.carbon.user.api.ClaimMapping)24 Claim (org.wso2.carbon.identity.application.common.model.Claim)23 Test (org.testng.annotations.Test)22 Claim (org.wso2.carbon.identity.application.common.model.xsd.Claim)21 LocalClaim (org.wso2.carbon.identity.claim.metadata.mgt.model.LocalClaim)21 AuthenticatedUser (org.wso2.carbon.identity.application.authentication.framework.model.AuthenticatedUser)20 IdentityApplicationManagementException (org.wso2.carbon.identity.application.common.IdentityApplicationManagementException)20 List (java.util.List)17 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)17 UserStoreException (org.wso2.carbon.user.api.UserStoreException)17 Matchers.anyString (org.mockito.Matchers.anyString)16 IdentityProvider (org.wso2.carbon.identity.application.common.model.IdentityProvider)13 ClaimMetadataException (org.wso2.carbon.identity.claim.metadata.mgt.exception.ClaimMetadataException)13