Skip to content

Commit

Permalink
add system claim property
Browse files Browse the repository at this point in the history
  • Loading branch information
amanda-ariyaratne committed Nov 1, 2024
1 parent b89cc6c commit eda6538
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -134,14 +134,19 @@ public List<LocalClaim> getLocalClaims(int tenantId) throws ClaimMetadataExcepti
List<LocalClaim> localClaimsInSystem = this.systemDefaultClaimMetadataManager.getLocalClaims(tenantId);
List<LocalClaim> localClaimsInDB = this.dbBasedClaimMetadataManager.getLocalClaims(tenantId);

Set<String> claimURIsInDB = localClaimsInDB.stream()
.map(LocalClaim::getClaimURI)
.collect(Collectors.toSet());

List<LocalClaim> allLocalClaims = new ArrayList<>(localClaimsInDB);
localClaimsInSystem.stream()
.filter(localClaim -> !claimURIsInDB.contains(localClaim.getClaimURI()))
.forEach(allLocalClaims::add);
localClaimsInSystem.forEach(systemClaim -> {
Optional<LocalClaim> matchingClaimInDB = allLocalClaims.stream()
.filter(dbClaim -> dbClaim.getClaimURI().equals(systemClaim.getClaimURI()))
.findFirst();

if (matchingClaimInDB.isPresent()) {
matchingClaimInDB.get().setClaimProperty(ClaimConstants.IS_SYSTEM_CLAIM, Boolean.TRUE.toString());
} else {
systemClaim.setClaimProperty(ClaimConstants.IS_SYSTEM_CLAIM, Boolean.TRUE.toString());
allLocalClaims.add(systemClaim);
}
});

return allLocalClaims;
}
Expand All @@ -158,9 +163,17 @@ public Optional<LocalClaim> getLocalClaim(String localClaimURI, int tenantId) th

Optional<LocalClaim> localClaimInDB = this.dbBasedClaimMetadataManager.getLocalClaim(localClaimURI, tenantId);
if (localClaimInDB.isPresent()) {
if (isSystemDefaultLocalClaim(localClaimURI, tenantId)) {
localClaimInDB.get().setClaimProperty(ClaimConstants.IS_SYSTEM_CLAIM, Boolean.TRUE.toString());
}
return localClaimInDB;
}
return this.systemDefaultClaimMetadataManager.getLocalClaim(localClaimURI, tenantId);
Optional<LocalClaim> localClaimInSystem = this.systemDefaultClaimMetadataManager.getLocalClaim(localClaimURI, tenantId);
if (localClaimInSystem.isPresent()) {
localClaimInSystem.get().setClaimProperty(ClaimConstants.IS_SYSTEM_CLAIM, Boolean.TRUE.toString());
return localClaimInSystem;
}
return Optional.empty();
}

/**
Expand All @@ -172,6 +185,7 @@ public Optional<LocalClaim> getLocalClaim(String localClaimURI, int tenantId) th
*/
public void addLocalClaim(LocalClaim localClaim, int tenantId) throws ClaimMetadataException {

localClaim.getClaimProperties().remove(ClaimConstants.IS_SYSTEM_CLAIM);
if (!isClaimDialectInDB(ClaimConstants.LOCAL_CLAIM_DIALECT_URI, tenantId)) {
addSystemDefaultDialectToDB(ClaimConstants.LOCAL_CLAIM_DIALECT_URI, tenantId);
}
Expand All @@ -187,6 +201,7 @@ public void addLocalClaim(LocalClaim localClaim, int tenantId) throws ClaimMetad
*/
public void updateLocalClaim(LocalClaim localClaim, int tenantId) throws ClaimMetadataException {

localClaim.getClaimProperties().remove(ClaimConstants.IS_SYSTEM_CLAIM);
if (isLocalClaimInDB(localClaim.getClaimURI(), tenantId)) {
this.dbBasedClaimMetadataManager.updateLocalClaim(localClaim, tenantId);
} else {
Expand Down Expand Up @@ -264,9 +279,11 @@ public List<ExternalClaim> getExternalClaims(String externalClaimDialectURI, int
for (ExternalClaim externalClaimInSystem : externalClaimsInSystem) {
ExternalClaim matchingClaimInDB = externalClaimsInDBMap.get(externalClaimInSystem.getClaimURI());
if (matchingClaimInDB != null) {
matchingClaimInDB.setClaimProperty(ClaimConstants.IS_SYSTEM_CLAIM, Boolean.TRUE.toString());
allExternalClaims.add(matchingClaimInDB);
externalClaimsInDBMap.remove(externalClaimInSystem.getClaimURI());
} else {
externalClaimInSystem.setClaimProperty(ClaimConstants.IS_SYSTEM_CLAIM, Boolean.TRUE.toString());
allExternalClaims.add(externalClaimInSystem);
}
}
Expand All @@ -289,9 +306,18 @@ public Optional<ExternalClaim> getExternalClaim(String externalClaimDialectURI,
Optional<ExternalClaim> externalClaim = this.dbBasedClaimMetadataManager.getExternalClaim(
externalClaimDialectURI, claimURI, tenantId);
if (externalClaim.isPresent()) {
if (isSystemDefaultExternalClaim(externalClaimDialectURI, claimURI, tenantId)) {
externalClaim.get().setClaimProperty(ClaimConstants.IS_SYSTEM_CLAIM, Boolean.TRUE.toString());
}
return externalClaim;
}
return this.systemDefaultClaimMetadataManager.getExternalClaim(externalClaimDialectURI, claimURI, tenantId);
Optional<ExternalClaim> externalClaimInSystem = this.systemDefaultClaimMetadataManager.getExternalClaim(
externalClaimDialectURI, claimURI, tenantId);
if (externalClaimInSystem.isPresent()) {
externalClaimInSystem.get().setClaimProperty(ClaimConstants.IS_SYSTEM_CLAIM, Boolean.TRUE.toString());
return externalClaimInSystem;
}
return Optional.empty();
}

/**
Expand All @@ -304,6 +330,7 @@ public Optional<ExternalClaim> getExternalClaim(String externalClaimDialectURI,
public void addExternalClaim(ExternalClaim externalClaim, int tenantId)
throws ClaimMetadataException {

externalClaim.getClaimProperties().remove(ClaimConstants.IS_SYSTEM_CLAIM);
if (!isClaimDialectInDB(externalClaim.getClaimDialectURI(), tenantId)) {
addSystemDefaultDialectToDB(externalClaim.getClaimDialectURI(), tenantId);
}
Expand All @@ -323,6 +350,7 @@ public void addExternalClaim(ExternalClaim externalClaim, int tenantId)
public void updateExternalClaim(ExternalClaim externalClaim, int tenantId)
throws ClaimMetadataException {

externalClaim.getClaimProperties().remove(ClaimConstants.IS_SYSTEM_CLAIM);
if (isExternalClaimInDB(externalClaim.getClaimURI(), externalClaim.getClaimDialectURI(), tenantId)) {
this.dbBasedClaimMetadataManager.updateExternalClaim(externalClaim, tenantId);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ public class ClaimConstants {
public static final String MAPPED_LOCAL_CLAIM_PROPERTY = "MappedLocalClaim";
public static final String MIN_LENGTH = "minLength";
public static final String MAX_LENGTH = "maxLength";
public static final String IS_SYSTEM_CLAIM = "isSystemClaim";

/**
* Enum for error messages.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -347,8 +347,7 @@ public static ClaimMapping convertExternalClaimToClaimMapping(ExternalClaim exte
claim = createLocalClaim(claimKey, claimMapping,
filterClaimProperties(claimConfig.getPropertyHolderMap().get(claimKey)));
} else {
claim = createExternalClaim(claimKey, filterClaimProperties(claimConfig.getPropertyHolderMap()
.get(claimKey)));
claim = createExternalClaim(claimKey, claimConfig.getPropertyHolderMap().get(claimKey));
}
claims.computeIfAbsent(claimDialectURI, k -> new ArrayList<>()).add(claim);
}
Expand All @@ -361,6 +360,7 @@ public static Map<String, String> filterClaimProperties(Map<String, String> clai
claimProperties.remove(ClaimConstants.DIALECT_PROPERTY);
claimProperties.remove(ClaimConstants.CLAIM_URI_PROPERTY);
claimProperties.remove(ClaimConstants.ATTRIBUTE_ID_PROPERTY);
claimProperties.remove(ClaimConstants.IS_SYSTEM_CLAIM);

claimProperties.putIfAbsent(ClaimConstants.DISPLAY_NAME_PROPERTY, "0");
claimProperties.computeIfPresent(ClaimConstants.SUPPORTED_BY_DEFAULT_PROPERTY,
Expand Down

0 comments on commit eda6538

Please sign in to comment.