Search in sources :

Example 76 with Claim

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

the class ExternalClaimDAO method addExternalClaim.

public void addExternalClaim(ExternalClaim externalClaim, int tenantId) throws ClaimMetadataException {
    Connection connection = IdentityDatabaseUtil.getDBConnection();
    PreparedStatement prepStmt = null;
    String externalClaimURI = externalClaim.getClaimURI();
    String externalClaimDialectURI = externalClaim.getClaimDialectURI();
    String mappedLocalClaimURI = externalClaim.getMappedLocalClaim();
    try {
        // Start transaction
        connection.setAutoCommit(false);
        // If an invalid local claim is provided an exception will be thrown.
        int localClaimId = getClaimId(connection, ClaimConstants.LOCAL_CLAIM_DIALECT_URI, mappedLocalClaimURI, tenantId);
        int externalClaimId = addClaim(connection, externalClaimDialectURI, externalClaimURI, tenantId);
        // Some JDBC Drivers returns this in the result, some don't
        if (externalClaimId == 0) {
            if (log.isDebugEnabled()) {
                log.debug("JDBC Driver did not return the claimId, executing Select operation");
            }
            externalClaimId = getClaimId(connection, externalClaimDialectURI, externalClaimURI, tenantId);
        // TODO : Handle invalid external claim URI
        }
        // TODO : Handle invalid external claim URI
        addClaimMapping(connection, externalClaimId, localClaimId, tenantId);
        addClaimProperties(connection, externalClaimId, externalClaim.getClaimProperties(), tenantId);
        // End transaction
        connection.commit();
    } catch (SQLException e) {
        rollbackTransaction(connection);
        throw new ClaimMetadataException("Error while adding external claim " + externalClaimURI + " to " + "dialect " + externalClaimDialectURI, e);
    } finally {
        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)

Example 77 with Claim

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

the class ClaimAdminService method addNewClaimMapping.

/**
 * @param
 * @throws ClaimManagementException
 */
public void addNewClaimMapping(ClaimMappingDTO claimMappingDTO) throws ClaimManagementException {
    /*Convert the simple structure of ClaimMapping received, to the complex structure
        of ClaimMapping which is used in the back end. */
    ClaimMapping claimMapping = convertClaimMappingDTOToClaimMapping(claimMappingDTO);
    ClaimManagerHandler handler = ClaimManagerHandler.getInstance();
    ClaimMapping currentMapping = handler.getClaimMapping(claimMapping.getClaim().getClaimUri());
    if (currentMapping != null) {
        throw new ClaimManagementException("Duplicate claim exist in the system. Please pick a different Claim Uri");
    }
    handler.addNewClaimMapping(claimMapping);
}
Also used : ClaimMapping(org.wso2.carbon.user.api.ClaimMapping)

Example 78 with Claim

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

the class ClaimAdminService method convertClaimToClaimDTO.

private ClaimDTO convertClaimToClaimDTO(Claim claim) {
    ClaimDTO claimDTO = new ClaimDTO();
    claimDTO.setClaimUri(claim.getClaimUri());
    claimDTO.setDescription(claim.getDescription());
    claimDTO.setDialectURI(claim.getDialectURI());
    claimDTO.setDisplayOrder(claim.getDisplayOrder());
    claimDTO.setDisplayTag(claim.getDisplayTag());
    claimDTO.setRegEx(claim.getRegEx());
    claimDTO.setRequired(claim.isRequired());
    claimDTO.setSupportedByDefault(claim.isSupportedByDefault());
    claimDTO.setValue(claim.getValue());
    claimDTO.setCheckedAttribute(claim.isCheckedAttribute());
    claimDTO.setReadOnly(claim.isReadOnly());
    return claimDTO;
}
Also used : ClaimDTO(org.wso2.carbon.claim.mgt.dto.ClaimDTO)

Example 79 with Claim

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

the class ExternalClaimDAO method getClaimMapping.

private String getClaimMapping(Connection connection, int externalClaimId, int tenantId) throws ClaimMetadataException {
    String mappedLocalClaimURI = null;
    PreparedStatement prepStmt = null;
    ResultSet rs = null;
    String query = SQLConstants.GET_CLAIM_MAPPING;
    try {
        prepStmt = connection.prepareStatement(query);
        prepStmt.setInt(1, externalClaimId);
        prepStmt.setInt(2, tenantId);
        prepStmt.setInt(3, tenantId);
        rs = prepStmt.executeQuery();
        while (rs.next()) {
            mappedLocalClaimURI = rs.getString(SQLConstants.CLAIM_URI_COLUMN);
        }
    } catch (SQLException e) {
        throw new ClaimMetadataException("Error while retrieving claim mapping", e);
    } finally {
        IdentityDatabaseUtil.closeResultSet(rs);
        IdentityDatabaseUtil.closeStatement(prepStmt);
    }
    if (StringUtils.isBlank(mappedLocalClaimURI)) {
        throw new ClaimMetadataException("Invalid external claim URI. Claim mapping cannot be empty.");
    }
    return mappedLocalClaimURI;
}
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 80 with Claim

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

the class ExternalClaimDAO method isMappedLocalClaim.

public boolean isMappedLocalClaim(String mappedLocalClaimURI, int tenantId) throws ClaimMetadataException {
    boolean isMappedLocalClaim = false;
    Connection connection = IdentityDatabaseUtil.getDBConnection(false);
    PreparedStatement prepStmt = null;
    ResultSet rs = null;
    String query = SQLConstants.IS_CLAIM_MAPPING;
    try {
        prepStmt = connection.prepareStatement(query);
        prepStmt.setString(1, ClaimConstants.LOCAL_CLAIM_DIALECT_URI);
        prepStmt.setInt(2, tenantId);
        prepStmt.setString(3, mappedLocalClaimURI);
        prepStmt.setInt(4, tenantId);
        prepStmt.setInt(5, tenantId);
        rs = prepStmt.executeQuery();
        if (rs.next()) {
            isMappedLocalClaim = true;
        }
    } catch (SQLException e) {
        throw new ClaimMetadataException("Error while checking mapped local claim " + mappedLocalClaimURI, e);
    } finally {
        IdentityDatabaseUtil.closeAllConnections(connection, rs, prepStmt);
    }
    return isMappedLocalClaim;
}
Also used : ClaimMetadataException(org.wso2.carbon.identity.claim.metadata.mgt.exception.ClaimMetadataException) SQLException(java.sql.SQLException) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) 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