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);
}
}
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);
}
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;
}
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);
}
}
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);
}
Aggregations