Skip to content

Commit

Permalink
Merge pull request #521 from Yasasr1/update-assert-subject-sp-config
Browse files Browse the repository at this point in the history
Introduce mappedLocalSubjectMandatory service provider configuration
  • Loading branch information
Yasasr1 authored Nov 6, 2023
2 parents 4eba6ec + 9787ea0 commit ab53239
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,9 @@ public enum ErrorMessage {
INVALID_POLICY_TYPE_FOR_API_RESOURCE("60512", "Invalid policy type provided for the API " +
"resource.", "API resource with id: %s doesn't allow the provided policy type: %s."),

ERROR_ASSERT_LOCAL_SUBJECT_IDENTIFIER_DISABLED("60513",
"Invalid configuration.",
"'useMappedLocalSubject' cannot be disabled when 'mappedLocalSubjectMandatory' is enabled."),
// Server Errors.
ERROR_RETRIEVING_SAML_METADATA("65001",
"Error occurred while retrieving SAML Metadata.",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ public class SubjectConfig {
private Boolean includeUserDomain;
private Boolean includeTenantDomain;
private Boolean useMappedLocalSubject;
private Boolean mappedLocalSubjectMandatory;

/**
**/
Expand Down Expand Up @@ -110,6 +111,24 @@ public void setUseMappedLocalSubject(Boolean useMappedLocalSubject) {
this.useMappedLocalSubject = useMappedLocalSubject;
}

/**
**/
public SubjectConfig mappedLocalSubjectMandatory(Boolean mappedLocalSubjectMandatory) {

this.mappedLocalSubjectMandatory = mappedLocalSubjectMandatory;
return this;
}

@ApiModelProperty(example = "false", value = "")
@JsonProperty("mappedLocalSubjectMandatory")
@Valid
public Boolean getMappedLocalSubjectMandatory() {
return mappedLocalSubjectMandatory;
}
public void setMappedLocalSubjectMandatory(Boolean mappedLocalSubjectMandatory) {
this.mappedLocalSubjectMandatory = mappedLocalSubjectMandatory;
}



@Override
Expand All @@ -125,12 +144,13 @@ public boolean equals(java.lang.Object o) {
return Objects.equals(this.claim, subjectConfig.claim) &&
Objects.equals(this.includeUserDomain, subjectConfig.includeUserDomain) &&
Objects.equals(this.includeTenantDomain, subjectConfig.includeTenantDomain) &&
Objects.equals(this.useMappedLocalSubject, subjectConfig.useMappedLocalSubject);
Objects.equals(this.useMappedLocalSubject, subjectConfig.useMappedLocalSubject) &&
Objects.equals(this.mappedLocalSubjectMandatory, subjectConfig.mappedLocalSubjectMandatory);
}

@Override
public int hashCode() {
return Objects.hash(claim, includeUserDomain, includeTenantDomain, useMappedLocalSubject);
return Objects.hash(claim, includeUserDomain, includeTenantDomain, useMappedLocalSubject, mappedLocalSubjectMandatory);
}

@Override
Expand All @@ -143,6 +163,7 @@ public String toString() {
sb.append(" includeUserDomain: ").append(toIndentedString(includeUserDomain)).append("\n");
sb.append(" includeTenantDomain: ").append(toIndentedString(includeTenantDomain)).append("\n");
sb.append(" useMappedLocalSubject: ").append(toIndentedString(useMappedLocalSubject)).append("\n");
sb.append(" mappedLocalSubjectMandatory: ").append(toIndentedString(mappedLocalSubjectMandatory)).append("\n");
sb.append("}");
return sb.toString();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,7 @@ private SubjectConfig buildSubjectClaimConfig(ServiceProvider application) {

if (application.getClaimConfig() != null) {
subjectConfig.useMappedLocalSubject(application.getClaimConfig().isAlwaysSendMappedLocalSubjectId());
subjectConfig.mappedLocalSubjectMandatory(application.getClaimConfig().isMappedLocalSubjectMandatory());
}

LocalAndOutboundAuthenticationConfig localAndOutboundAuthConfig =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@
import java.util.Optional;
import java.util.stream.Collectors;

import static org.wso2.carbon.identity.api.server.application.management.common.ApplicationManagementConstants.ErrorMessage.ERROR_ASSERT_LOCAL_SUBJECT_IDENTIFIER_DISABLED;
import static org.wso2.carbon.identity.api.server.application.management.v1.core.functions.Utils.buildBadRequestError;
import static org.wso2.carbon.identity.api.server.application.management.v1.core.functions.Utils.setIfNotNull;

/**
Expand Down Expand Up @@ -131,6 +133,12 @@ private void updateSubjectClaimConfigs(SubjectConfig subjectApiModel, ServicePro

if (subjectApiModel != null) {

if (Boolean.TRUE.equals(subjectApiModel.getMappedLocalSubjectMandatory()) &&
Boolean.FALSE.equals(subjectApiModel.getUseMappedLocalSubject())) {
throw buildBadRequestError(ERROR_ASSERT_LOCAL_SUBJECT_IDENTIFIER_DISABLED.getCode(),
ERROR_ASSERT_LOCAL_SUBJECT_IDENTIFIER_DISABLED.getDescription());
}

LocalAndOutboundAuthenticationConfig authConfig = getLocalAndOutboundConfig(application);
if (subjectApiModel.getClaim() != null) {
setIfNotNull(subjectApiModel.getClaim().getUri(), authConfig::setSubjectClaimUri);
Expand All @@ -142,6 +150,7 @@ private void updateSubjectClaimConfigs(SubjectConfig subjectApiModel, ServicePro

ClaimConfig claimConfig = getClaimConfig(application);
setIfNotNull(subjectApiModel.getUseMappedLocalSubject(), claimConfig::setAlwaysSendMappedLocalSubjectId);
setIfNotNull(subjectApiModel.getMappedLocalSubjectMandatory(), claimConfig::setMappedLocalSubjectMandatory);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2934,6 +2934,9 @@ components:
useMappedLocalSubject:
type: boolean
example: false
mappedLocalSubjectMandatory:
type: boolean
example: false
RoleConfig:
type: object
properties:
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -760,7 +760,7 @@
<maven.buildnumber.plugin.version>1.4</maven.buildnumber.plugin.version>
<org.apache.felix.annotations.version>1.2.4</org.apache.felix.annotations.version>
<identity.governance.version>1.8.62</identity.governance.version>
<carbon.identity.framework.version>5.25.430</carbon.identity.framework.version>
<carbon.identity.framework.version>5.25.481</carbon.identity.framework.version>
<maven.findbugsplugin.version>3.0.5</maven.findbugsplugin.version>
<identity.workflow.impl.bps.version>5.2.0</identity.workflow.impl.bps.version>
<maven.checkstyleplugin.excludes>**/gen/**/*</maven.checkstyleplugin.excludes>
Expand Down

0 comments on commit ab53239

Please sign in to comment.