Search in sources :

Example 66 with Claim

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

the class ClaimMetadataManagementAdminService method addExternalClaim.

@SuppressWarnings("unused")
public void addExternalClaim(ExternalClaimDTO externalClaim) throws ClaimMetadataException {
    try {
        ExternalClaim claim = ClaimMetadataUtils.convertExternalClaimDTOToExternalClaim(externalClaim);
        String tenantDomain = CarbonContext.getThreadLocalCarbonContext().getTenantDomain();
        IdentityClaimManagementServiceDataHolder.getInstance().getClaimManagementService().addExternalClaim(claim, tenantDomain);
    } catch (ClaimMetadataClientException e) {
        if (log.isDebugEnabled()) {
            log.debug(e.getMessage(), e);
        }
        throw new ClaimMetadataException(e.getMessage(), e);
    } catch (Throwable e) {
        log.error(e.getMessage(), e);
        throw new ClaimMetadataException(e.getMessage(), e);
    }
}
Also used : ClaimMetadataClientException(org.wso2.carbon.identity.claim.metadata.mgt.exception.ClaimMetadataClientException) ClaimMetadataException(org.wso2.carbon.identity.claim.metadata.mgt.exception.ClaimMetadataException) ExternalClaim(org.wso2.carbon.identity.claim.metadata.mgt.model.ExternalClaim)

Example 67 with Claim

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

the class CacheBackedExternalClaimDAO method removeExternalClaimCache.

/**
 * Remove mapped external claims at post removing claim dialect.
 *
 * @param externalClaimDialectURI External claim dialect uri
 * @param tenantId                Tenant Id
 */
public void removeExternalClaimCache(String externalClaimDialectURI, int tenantId) {
    ExternalClaimCacheKey cacheKey = new ExternalClaimCacheKey(externalClaimDialectURI);
    externalClaimCache.clearCacheEntry(cacheKey, tenantId);
}
Also used : ExternalClaimCacheKey(org.wso2.carbon.identity.claim.metadata.mgt.cache.ExternalClaimCacheKey)

Example 68 with Claim

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

the class CacheBackedExternalClaimDAO method getExternalClaims.

public List<ExternalClaim> getExternalClaims(String externalDialectURI, int tenantId) throws ClaimMetadataException {
    ExternalClaimCacheKey cacheKey = new ExternalClaimCacheKey(externalDialectURI);
    List<ExternalClaim> externalClaimList = externalClaimCache.getValueFromCache(cacheKey, tenantId);
    if (externalClaimList == null) {
        if (log.isDebugEnabled()) {
            log.debug("Cache miss for external claim list for dialect: " + externalDialectURI + " in tenant: " + tenantId);
        }
        externalClaimList = externalClaimDAO.getExternalClaims(externalDialectURI, tenantId);
        externalClaimCache.addToCache(cacheKey, new ArrayList<>(externalClaimList), tenantId);
    } else {
        if (log.isDebugEnabled()) {
            log.debug("Cache hit for external claim list for dialect: " + externalDialectURI + " in tenant: " + tenantId);
        }
    }
    return externalClaimList;
}
Also used : ExternalClaimCacheKey(org.wso2.carbon.identity.claim.metadata.mgt.cache.ExternalClaimCacheKey) ExternalClaim(org.wso2.carbon.identity.claim.metadata.mgt.model.ExternalClaim)

Example 69 with Claim

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

the class ClaimDAO method addClaim.

public int addClaim(Connection connection, String claimDialectURI, String claimURI, int tenantId) throws ClaimMetadataException {
    PreparedStatement prepStmt = null;
    ResultSet rs = null;
    int claimId = 0;
    String query = SQLConstants.ADD_CLAIM;
    try {
        String dbProductName = connection.getMetaData().getDatabaseProductName();
        prepStmt = connection.prepareStatement(query, new String[] { DBUtils.getConvertedAutoGeneratedColumnName(dbProductName, SQLConstants.ID_COLUMN) });
        prepStmt.setString(1, claimDialectURI);
        prepStmt.setInt(2, tenantId);
        prepStmt.setString(3, claimURI);
        prepStmt.setInt(4, tenantId);
        prepStmt.executeUpdate();
        rs = prepStmt.getGeneratedKeys();
        if (rs.next()) {
            claimId = rs.getInt(1);
        }
    } catch (SQLException e) {
        throw new ClaimMetadataException("Error while adding claim " + claimURI + " to dialect " + claimDialectURI, e);
    } finally {
        IdentityDatabaseUtil.closeResultSet(rs);
        IdentityDatabaseUtil.closeStatement(prepStmt);
    }
    return claimId;
}
Also used : ClaimMetadataException(org.wso2.carbon.identity.claim.metadata.mgt.exception.ClaimMetadataException) SQLException(java.sql.SQLException) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement)

Example 70 with Claim

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

the class ClaimDAO method removeClaim.

public void removeClaim(String claimDialectURI, String localClaimURI, int tenantId) throws ClaimMetadataException {
    Connection connection = IdentityDatabaseUtil.getDBConnection();
    PreparedStatement prepStmt = null;
    String query = SQLConstants.REMOVE_CLAIM;
    try {
        prepStmt = connection.prepareStatement(query);
        prepStmt.setString(1, claimDialectURI);
        prepStmt.setInt(2, tenantId);
        prepStmt.setString(3, localClaimURI);
        prepStmt.setInt(4, tenantId);
        prepStmt.executeUpdate();
        IdentityDatabaseUtil.commitTransaction(connection);
    } catch (SQLException e) {
        IdentityDatabaseUtil.rollbackTransaction(connection);
        throw new ClaimMetadataException("Error while deleting claim " + localClaimURI + " from dialect" + claimDialectURI, e);
    } finally {
        IdentityDatabaseUtil.closeStatement(prepStmt);
        IdentityDatabaseUtil.closeConnection(connection);
    }
}
Also used : ClaimMetadataException(org.wso2.carbon.identity.claim.metadata.mgt.exception.ClaimMetadataException) SQLException(java.sql.SQLException) Connection(java.sql.Connection) PreparedStatement(java.sql.PreparedStatement)

Aggregations

HashMap (java.util.HashMap)112 ArrayList (java.util.ArrayList)90 ClaimMapping (org.wso2.carbon.identity.application.common.model.ClaimMapping)67 UserStoreException (org.wso2.carbon.user.api.UserStoreException)66 Test (org.testng.annotations.Test)63 ClaimMetadataException (org.wso2.carbon.identity.claim.metadata.mgt.exception.ClaimMetadataException)55 Map (java.util.Map)50 PreparedStatement (java.sql.PreparedStatement)48 SQLException (java.sql.SQLException)43 LocalClaim (org.wso2.carbon.identity.claim.metadata.mgt.model.LocalClaim)34 RealmService (org.wso2.carbon.user.core.service.RealmService)30 UserRealm (org.wso2.carbon.user.core.UserRealm)29 UserStoreManager (org.wso2.carbon.user.core.UserStoreManager)29 Claim (org.wso2.carbon.user.api.Claim)28 UserStoreException (org.wso2.carbon.user.core.UserStoreException)28 ResultSet (java.sql.ResultSet)27 ClaimConfig (org.wso2.carbon.identity.application.common.model.ClaimConfig)26 Connection (java.sql.Connection)25 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)24 AuthenticatedUser (org.wso2.carbon.identity.application.authentication.framework.model.AuthenticatedUser)24