Search in sources :

Example 1 with ClaimMetadataClientException

use of org.wso2.carbon.identity.claim.metadata.mgt.exception.ClaimMetadataClientException 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 2 with ClaimMetadataClientException

use of org.wso2.carbon.identity.claim.metadata.mgt.exception.ClaimMetadataClientException in project carbon-identity-framework by wso2.

the class ClaimMetadataManagementServiceImpl method addExternalClaim.

@Override
public void addExternalClaim(ExternalClaim externalClaim, String tenantDomain) throws ClaimMetadataException {
    if (externalClaim == null || StringUtils.isBlank(externalClaim.getClaimURI())) {
        throw new ClaimMetadataClientException(ERROR_CODE_EMPTY_EXTERNAL_CLAIM_URI);
    }
    if (StringUtils.isBlank(externalClaim.getClaimDialectURI())) {
        throw new ClaimMetadataClientException(ERROR_CODE_EMPTY_EXTERNAL_DIALECT_URI);
    }
    if (StringUtils.isBlank(externalClaim.getMappedLocalClaim())) {
        throw new ClaimMetadataClientException(ERROR_CODE_MAPPED_TO_EMPTY_LOCAL_CLAIM_URI);
    }
    if (ClaimConstants.LOCAL_CLAIM_DIALECT_URI.equalsIgnoreCase(externalClaim.getClaimDialectURI())) {
        throw new ClaimMetadataClientException(ERROR_CODE_INVALID_EXTERNAL_CLAIM_DIALECT);
    }
    ClaimConfig claimConfig = IdentityClaimManagementServiceDataHolder.getInstance().getClaimConfig();
    String claimURIRegex = null;
    if (claimConfig != null) {
        claimURIRegex = claimConfig.getClaimUriRegex(externalClaim.getClaimDialectURI());
    }
    if (claimURIRegex != null && !externalClaim.getClaimURI().matches(claimURIRegex)) {
        throw new ClaimMetadataClientException(ERROR_CODE_INVALID_EXTERNAL_CLAIM_URI);
    }
    // TODO : validate tenant domain?
    int tenantId = IdentityTenantUtil.getTenantId(tenantDomain);
    if (isExistingExternalClaimURI(externalClaim.getClaimDialectURI(), externalClaim.getClaimURI(), tenantId)) {
        throw new ClaimMetadataClientException(ERROR_CODE_EXISTING_EXTERNAL_CLAIM_URI.getCode(), String.format(ERROR_CODE_EXISTING_EXTERNAL_CLAIM_URI.getMessage(), externalClaim.getClaimURI(), externalClaim.getClaimDialectURI()));
    }
    boolean isLocalClaimAlreadyMapped = this.externalClaimDAO.isLocalClaimMappedWithinDialect(externalClaim.getMappedLocalClaim(), externalClaim.getClaimDialectURI(), tenantId);
    if (isLocalClaimAlreadyMapped) {
        throw new ClaimMetadataClientException((ERROR_CODE_EXISTING_LOCAL_CLAIM_MAPPING.getCode()), String.format(ERROR_CODE_EXISTING_LOCAL_CLAIM_MAPPING.getMessage(), externalClaim.getMappedLocalClaim(), externalClaim.getClaimDialectURI()));
    }
    // Add listener
    this.externalClaimDAO.addExternalClaim(externalClaim, tenantId);
    ClaimMetadataEventPublisherProxy.getInstance().publishPostAddExternalClaim(tenantId, externalClaim);
}
Also used : ClaimMetadataClientException(org.wso2.carbon.identity.claim.metadata.mgt.exception.ClaimMetadataClientException) ClaimConfig(org.wso2.carbon.user.core.claim.inmemory.ClaimConfig)

Example 3 with ClaimMetadataClientException

use of org.wso2.carbon.identity.claim.metadata.mgt.exception.ClaimMetadataClientException in project carbon-identity-framework by wso2.

the class ClaimDAO method getClaimId.

public int getClaimId(Connection connection, String claimDialectURI, String claimURI, int tenantId) throws ClaimMetadataException {
    PreparedStatement prepStmt = null;
    ResultSet rs = null;
    int claimId = 0;
    String query = SQLConstants.GET_CLAIM_ID;
    try {
        prepStmt = connection.prepareStatement(query);
        prepStmt.setString(1, claimDialectURI);
        prepStmt.setInt(2, tenantId);
        prepStmt.setString(3, claimURI);
        prepStmt.setInt(4, tenantId);
        rs = prepStmt.executeQuery();
        while (rs.next()) {
            claimId = rs.getInt(SQLConstants.ID_COLUMN);
        }
    } catch (SQLException e) {
        throw new ClaimMetadataException("Error while retrieving ID for claim " + claimURI + " in dialect " + claimDialectURI, e);
    } finally {
        IdentityDatabaseUtil.closeResultSet(rs);
        IdentityDatabaseUtil.closeStatement(prepStmt);
    }
    if (claimId == 0) {
        // TODO : Throw runtime exception?
        throw new ClaimMetadataClientException(ERROR_CODE_MAPPED_TO_INVALID_LOCAL_CLAIM_URI.getCode(), String.format(ERROR_CODE_MAPPED_TO_INVALID_LOCAL_CLAIM_URI.getMessage(), claimURI, claimDialectURI));
    }
    return claimId;
}
Also used : ClaimMetadataClientException(org.wso2.carbon.identity.claim.metadata.mgt.exception.ClaimMetadataClientException) ClaimMetadataException(org.wso2.carbon.identity.claim.metadata.mgt.exception.ClaimMetadataException) SQLException(java.sql.SQLException) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement)

Example 4 with ClaimMetadataClientException

use of org.wso2.carbon.identity.claim.metadata.mgt.exception.ClaimMetadataClientException in project carbon-identity-framework by wso2.

the class ClaimMetadataManagementAdminService method addLocalClaim.

@SuppressWarnings("unused")
public void addLocalClaim(LocalClaimDTO localClaim) throws ClaimMetadataException {
    try {
        LocalClaim claim = ClaimMetadataUtils.convertLocalClaimDTOToLocalClaim(localClaim);
        String tenantDomain = CarbonContext.getThreadLocalCarbonContext().getTenantDomain();
        IdentityClaimManagementServiceDataHolder.getInstance().getClaimManagementService().addLocalClaim(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) LocalClaim(org.wso2.carbon.identity.claim.metadata.mgt.model.LocalClaim)

Example 5 with ClaimMetadataClientException

use of org.wso2.carbon.identity.claim.metadata.mgt.exception.ClaimMetadataClientException in project carbon-identity-framework by wso2.

the class ClaimMetadataManagementServiceImpl method updateLocalClaim.

@Override
public void updateLocalClaim(LocalClaim localClaim, String tenantDomain) throws ClaimMetadataException {
    if (localClaim == null || StringUtils.isBlank(localClaim.getClaimURI())) {
        throw new ClaimMetadataClientException(ERROR_CODE_EMPTY_LOCAL_CLAIM_URI);
    } else if (localClaim.getMappedAttributes().isEmpty()) {
        throw new ClaimMetadataClientException(ERROR_CODE_EMPTY_MAPPED_ATTRIBUTES_IN_LOCAL_CLAIM.getCode(), String.format(ERROR_CODE_EMPTY_MAPPED_ATTRIBUTES_IN_LOCAL_CLAIM.getMessage(), localClaim.getClaimDialectURI(), localClaim.getClaimURI()));
    }
    validateClaimProperties(localClaim.getClaimProperties());
    // TODO : validate claim URI already exists?
    // TODO : validate tenant domain?
    int tenantId = IdentityTenantUtil.getTenantId(tenantDomain);
    ClaimMetadataEventPublisherProxy.getInstance().publishPreUpdateLocalClaim(tenantId, localClaim);
    this.localClaimDAO.updateLocalClaim(localClaim, tenantId);
    ClaimMetadataEventPublisherProxy.getInstance().publishPostUpdateLocalClaim(tenantId, localClaim);
}
Also used : ClaimMetadataClientException(org.wso2.carbon.identity.claim.metadata.mgt.exception.ClaimMetadataClientException)

Aggregations

ClaimMetadataClientException (org.wso2.carbon.identity.claim.metadata.mgt.exception.ClaimMetadataClientException)8 ClaimMetadataException (org.wso2.carbon.identity.claim.metadata.mgt.exception.ClaimMetadataException)3 PreparedStatement (java.sql.PreparedStatement)1 ResultSet (java.sql.ResultSet)1 SQLException (java.sql.SQLException)1 Response (javax.ws.rs.core.Response)1 APIError (org.wso2.carbon.identity.api.server.common.error.APIError)1 ErrorResponse (org.wso2.carbon.identity.api.server.common.error.ErrorResponse)1 ConnectionEstablishedResponse (org.wso2.carbon.identity.api.server.userstore.v1.model.ConnectionEstablishedResponse)1 UserStoreAttributeMappingResponse (org.wso2.carbon.identity.api.server.userstore.v1.model.UserStoreAttributeMappingResponse)1 UserStoreListResponse (org.wso2.carbon.identity.api.server.userstore.v1.model.UserStoreListResponse)1 UserStoreResponse (org.wso2.carbon.identity.api.server.userstore.v1.model.UserStoreResponse)1 ClaimMetadataMgtListener (org.wso2.carbon.identity.claim.metadata.mgt.listener.ClaimMetadataMgtListener)1 ExternalClaim (org.wso2.carbon.identity.claim.metadata.mgt.model.ExternalClaim)1 LocalClaim (org.wso2.carbon.identity.claim.metadata.mgt.model.LocalClaim)1 ClaimConfig (org.wso2.carbon.user.core.claim.inmemory.ClaimConfig)1