Search in sources :

Example 31 with ClaimMapping

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

the class ApplicationManagementServiceImpl method getAllLocalClaimUris.

@Override
public String[] getAllLocalClaimUris(String tenantDomain) throws IdentityApplicationManagementException {
    try {
        startTenantFlow(tenantDomain);
        String claimDialect = ApplicationMgtSystemConfig.getInstance().getClaimDialect();
        List<String> claimUris = new ArrayList<>();
        if (UserCoreConstants.DEFAULT_CARBON_DIALECT.equalsIgnoreCase(claimDialect)) {
            // Local claims are retrieved via ClaimMetadataManagement service for consistency.
            List<LocalClaim> localClaims = ApplicationManagementServiceComponentHolder.getInstance().getClaimMetadataManagementService().getLocalClaims(tenantDomain);
            claimUris = getLocalClaimURIs(localClaims);
        } else {
            ClaimMapping[] claimMappings = CarbonContext.getThreadLocalCarbonContext().getUserRealm().getClaimManager().getAllClaimMappings(claimDialect);
            for (ClaimMapping claimMap : claimMappings) {
                claimUris.add(claimMap.getClaim().getClaimUri());
            }
        }
        String[] allLocalClaimUris = (claimUris.toArray(new String[claimUris.size()]));
        if (ArrayUtils.isNotEmpty(allLocalClaimUris)) {
            Arrays.sort(allLocalClaimUris);
        }
        return allLocalClaimUris;
    } catch (Exception e) {
        String error = "Error while reading system claims" + ". " + e.getMessage();
        throw new IdentityApplicationManagementException(error, e);
    } finally {
        endTenantFlow();
    }
}
Also used : ClaimMapping(org.wso2.carbon.user.api.ClaimMapping) IdentityApplicationManagementException(org.wso2.carbon.identity.application.common.IdentityApplicationManagementException) ArrayList(java.util.ArrayList) LocalClaim(org.wso2.carbon.identity.claim.metadata.mgt.model.LocalClaim) IdentityApplicationManagementClientException(org.wso2.carbon.identity.application.common.IdentityApplicationManagementClientException) TransformerException(javax.xml.transform.TransformerException) RegistryException(org.wso2.carbon.registry.api.RegistryException) IOException(java.io.IOException) IdentityApplicationManagementValidationException(org.wso2.carbon.identity.application.common.IdentityApplicationManagementValidationException) IdentityApplicationManagementException(org.wso2.carbon.identity.application.common.IdentityApplicationManagementException) JAXBException(javax.xml.bind.JAXBException) IdentityApplicationRegistrationFailureException(org.wso2.carbon.identity.application.common.IdentityApplicationRegistrationFailureException) SAXException(org.xml.sax.SAXException) DefaultAuthSeqMgtException(org.wso2.carbon.identity.application.mgt.defaultsequence.DefaultAuthSeqMgtException) UserStoreException(org.wso2.carbon.user.api.UserStoreException) IdentityApplicationManagementServerException(org.wso2.carbon.identity.application.common.IdentityApplicationManagementServerException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException)

Example 32 with ClaimMapping

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

the class ApplicationDAOImpl method getClaimMapping.

/**
 * @param serviceProviderName
 * @param tenantDomain
 * @param localIdpAsKey
 * @return
 * @throws SQLException
 * @throws IdentityApplicationManagementException
 */
private Map<String, String> getClaimMapping(String serviceProviderName, String tenantDomain, boolean localIdpAsKey) throws SQLException, IdentityApplicationManagementException {
    int tenantID = -123;
    if (tenantDomain != null) {
        try {
            tenantID = ApplicationManagementServiceComponentHolder.getInstance().getRealmService().getTenantManager().getTenantId(tenantDomain);
        } catch (UserStoreException e1) {
            throw new IdentityApplicationManagementException("Error while reading application");
        }
    }
    Map<String, String> claimMapping = new HashMap<String, String>();
    if (log.isDebugEnabled()) {
        log.debug("Reading Claim Mappings of Application " + serviceProviderName);
    }
    PreparedStatement getClaimPreStmt = null;
    ResultSet resultSet = null;
    Connection connection = IdentityDatabaseUtil.getDBConnection(false);
    try {
        getClaimPreStmt = connection.prepareStatement(LOAD_CLAIM_MAPPING_BY_APP_NAME);
        // IDP_CLAIM, SP_CLAIM, IS_REQUESTED
        getClaimPreStmt.setString(1, serviceProviderName);
        getClaimPreStmt.setInt(2, tenantID);
        resultSet = getClaimPreStmt.executeQuery();
        while (resultSet.next()) {
            if (localIdpAsKey) {
                claimMapping.put(resultSet.getString(1), resultSet.getString(2));
            } else {
                claimMapping.put(resultSet.getString(2), resultSet.getString(1));
            }
        }
    } finally {
        IdentityApplicationManagementUtil.closeStatement(getClaimPreStmt);
        IdentityApplicationManagementUtil.closeResultSet(resultSet);
        IdentityApplicationManagementUtil.closeConnection(connection);
    }
    return claimMapping;
}
Also used : HashMap(java.util.HashMap) IdentityApplicationManagementException(org.wso2.carbon.identity.application.common.IdentityApplicationManagementException) UserStoreException(org.wso2.carbon.user.api.UserStoreException) ResultSet(java.sql.ResultSet) Connection(java.sql.Connection) PreparedStatement(java.sql.PreparedStatement) NamedPreparedStatement(org.wso2.carbon.database.utils.jdbc.NamedPreparedStatement)

Example 33 with ClaimMapping

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

the class CacheBackedApplicationDAO method getAllRequestedClaimsByServiceProvider.

public List<String> getAllRequestedClaimsByServiceProvider(String serviceProviderName, String tenantDomain) throws IdentityApplicationManagementException {
    ServiceProvider applicationFromCache = getApplicationFromCache(serviceProviderName, tenantDomain);
    if (applicationFromCache != null) {
        List<String> requestedLocalClaims = new ArrayList<>();
        ClaimConfig claimConfig = applicationFromCache.getClaimConfig();
        ClaimMapping[] claimMappings = claimConfig.getClaimMappings();
        for (ClaimMapping claimMapping : claimMappings) {
            if (claimMapping.isRequested()) {
                requestedLocalClaims.add(claimMapping.getLocalClaim().getClaimUri());
            }
        }
        return requestedLocalClaims;
    }
    return appDAO.getAllRequestedClaimsByServiceProvider(serviceProviderName, tenantDomain);
}
Also used : ClaimMapping(org.wso2.carbon.identity.application.common.model.ClaimMapping) ClaimConfig(org.wso2.carbon.identity.application.common.model.ClaimConfig) ServiceProvider(org.wso2.carbon.identity.application.common.model.ServiceProvider) ArrayList(java.util.ArrayList)

Example 34 with ClaimMapping

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

the class FileBasedApplicationDAO method getAllRequestedClaimsByServiceProvider.

@Override
public List<String> getAllRequestedClaimsByServiceProvider(String serviceProviderName, String tenantDomain) throws IdentityApplicationManagementException {
    ServiceProvider serviceProvider = ApplicationManagementServiceComponent.getFileBasedSPs().get(serviceProviderName);
    List<String> requestedClaimList = new ArrayList<String>();
    if (serviceProvider == null || serviceProvider.getClaimConfig() == null) {
        return requestedClaimList;
    }
    ClaimMapping[] claimMappings = serviceProvider.getClaimConfig().getClaimMappings();
    if (claimMappings != null && claimMappings.length > 0) {
        for (ClaimMapping mapping : claimMappings) {
            if (mapping.isRequested()) {
                if (mapping.getRemoteClaim() != null && mapping.getRemoteClaim().getClaimUri() != null) {
                    requestedClaimList.add(mapping.getRemoteClaim().getClaimUri());
                } else if (mapping.getLocalClaim() != null && mapping.getLocalClaim().getClaimUri() != null) {
                    requestedClaimList.add(mapping.getLocalClaim().getClaimUri());
                }
            }
        }
    }
    return requestedClaimList;
}
Also used : ClaimMapping(org.wso2.carbon.identity.application.common.model.ClaimMapping) ServiceProvider(org.wso2.carbon.identity.application.common.model.ServiceProvider) ArrayList(java.util.ArrayList)

Example 35 with ClaimMapping

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

the class ClaimMetadataHandler method getMappingsFromOtherDialectToCarbon.

/**
 * @param otherDialectURI
 * @param otherClaimURIs
 * @param tenantDomain
 * @return
 * @throws ClaimMetadataException
 */
public Set<ExternalClaim> getMappingsFromOtherDialectToCarbon(String otherDialectURI, Set<String> otherClaimURIs, String tenantDomain) throws ClaimMetadataException {
    Set<ExternalClaim> returnSet = new HashSet<ExternalClaim>();
    if (otherDialectURI == null) {
        String message = "Invalid argument: \'otherDialectURI\' is \'NULL\'";
        log.error(message);
        throw new ClaimMetadataException(message);
    }
    try {
        ClaimMetadataManagementServiceImpl claimMetadataService = new ClaimMetadataManagementServiceImpl();
        if (otherDialectURI.equals(UserCoreConstants.DEFAULT_CARBON_DIALECT)) {
            List<LocalClaim> localClaims = claimMetadataService.getLocalClaims(tenantDomain);
            if (otherClaimURIs == null || otherClaimURIs.isEmpty()) {
                for (LocalClaim localClaim : localClaims) {
                    ExternalClaim claimMapping = new ExternalClaim(localClaim.getClaimDialectURI(), localClaim.getClaimURI(), localClaim.getClaimURI());
                    returnSet.add(claimMapping);
                }
                return returnSet;
            } else {
                for (LocalClaim localClaim : localClaims) {
                    if (otherClaimURIs.contains(localClaim.getClaimURI())) {
                        ExternalClaim claimMapping = new ExternalClaim(otherDialectURI, localClaim.getClaimURI(), localClaim.getClaimURI());
                        returnSet.add(claimMapping);
                    }
                }
                return returnSet;
            }
        } else {
            List<ExternalClaim> externalClaims = claimMetadataService.getExternalClaims(otherDialectURI, tenantDomain);
            if (otherClaimURIs == null || otherClaimURIs.isEmpty()) {
                returnSet = new HashSet<ExternalClaim>(externalClaims);
            } else {
                for (ExternalClaim externalClaim : externalClaims) {
                    if (otherClaimURIs.contains(externalClaim.getClaimURI())) {
                        returnSet.add(externalClaim);
                    }
                }
            }
            return returnSet;
        }
    } catch (ClaimMetadataException e) {
        throw new ClaimMetadataException(e.getMessage(), e);
    }
}
Also used : ClaimMetadataException(org.wso2.carbon.identity.claim.metadata.mgt.exception.ClaimMetadataException) ExternalClaim(org.wso2.carbon.identity.claim.metadata.mgt.model.ExternalClaim) LocalClaim(org.wso2.carbon.identity.claim.metadata.mgt.model.LocalClaim) HashSet(java.util.HashSet)

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