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