From d356faec0c21f93ae5c2a33e715780ac168eae5b Mon Sep 17 00:00:00 2001 From: thisarawelmilla Date: Fri, 4 Oct 2024 11:54:24 +0530 Subject: [PATCH 1/5] Add new authenticator property: DefinedBy. --- .../UpdateAuthenticationSequence.java | 8 +++ .../v1/model/Authenticator.java | 56 ++++++++++++++++++- .../ServerAuthenticatorManagementService.java | 10 ++++ .../src/main/resources/authenticators.yaml | 5 ++ .../configs/v1/model/Authenticator.java | 56 ++++++++++++++++++- .../v1/model/AuthenticatorListItem.java | 56 ++++++++++++++++++- .../core/ServerConfigManagementService.java | 4 ++ .../src/main/resources/configs.yaml | 10 ++++ .../idp/v1/model/FederatedAuthenticator.java | 56 ++++++++++++++++++- .../model/FederatedAuthenticatorListItem.java | 56 ++++++++++++++++++- .../FederatedAuthenticatorPUTRequest.java | 56 ++++++++++++++++++- .../v1/model/MetaFederatedAuthenticator.java | 56 ++++++++++++++++++- .../MetaFederatedAuthenticatorListItem.java | 56 ++++++++++++++++++- .../v1/core/ServerIdpManagementService.java | 24 ++++++++ .../src/main/resources/idp.yaml | 25 +++++++++ 15 files changed, 526 insertions(+), 8 deletions(-) diff --git a/components/org.wso2.carbon.identity.api.server.application.management/org.wso2.carbon.identity.api.server.application.management.v1/src/main/java/org/wso2/carbon/identity/api/server/application/management/v1/core/functions/application/UpdateAuthenticationSequence.java b/components/org.wso2.carbon.identity.api.server.application.management/org.wso2.carbon.identity.api.server.application.management.v1/src/main/java/org/wso2/carbon/identity/api/server/application/management/v1/core/functions/application/UpdateAuthenticationSequence.java index 7b62ac766d..4d636df20e 100644 --- a/components/org.wso2.carbon.identity.api.server.application.management/org.wso2.carbon.identity.api.server.application.management.v1/src/main/java/org/wso2/carbon/identity/api/server/application/management/v1/core/functions/application/UpdateAuthenticationSequence.java +++ b/components/org.wso2.carbon.identity.api.server.application.management/org.wso2.carbon.identity.api.server.application.management.v1/src/main/java/org/wso2/carbon/identity/api/server/application/management/v1/core/functions/application/UpdateAuthenticationSequence.java @@ -22,6 +22,7 @@ import org.wso2.carbon.identity.api.server.application.management.v1.core.functions.UpdateFunction; import org.wso2.carbon.identity.api.server.application.management.v1.core.functions.Utils; import org.wso2.carbon.identity.application.authentication.framework.util.FrameworkConstants; +import org.wso2.carbon.identity.application.common.ApplicationAuthenticatorService; import org.wso2.carbon.identity.application.common.model.AuthenticationStep; import org.wso2.carbon.identity.application.common.model.FederatedAuthenticatorConfig; import org.wso2.carbon.identity.application.common.model.IdentityProvider; @@ -31,6 +32,7 @@ import org.wso2.carbon.identity.application.common.model.ServiceProvider; import org.wso2.carbon.identity.application.common.model.script.AuthenticationScriptConfig; import org.wso2.carbon.identity.application.mgt.ApplicationConstants; +import org.wso2.carbon.identity.base.AuthenticatorPropertiesConstant.DefinedByType; import java.util.ArrayList; import java.util.Collections; @@ -160,11 +162,17 @@ private AuthenticationStep buildAuthenticationStep(AuthenticationStepModel stepM LocalAuthenticatorConfig localAuthOption = new LocalAuthenticatorConfig(); localAuthOption.setEnabled(true); localAuthOption.setName(option.getAuthenticator()); + DefinedByType definedByType = ApplicationAuthenticatorService.getInstance() + .getLocalAuthenticatorByName(option.getAuthenticator()).getDefinedByType(); + localAuthOption.setDefinedByType(definedByType); localAuthOptions.add(localAuthOption); } else { FederatedAuthenticatorConfig federatedAuthConfig = new FederatedAuthenticatorConfig(); federatedAuthConfig.setEnabled(true); federatedAuthConfig.setName(option.getAuthenticator()); + DefinedByType definedByType = ApplicationAuthenticatorService.getInstance() + .getFederatedAuthenticatorByName(option.getAuthenticator()).getDefinedByType(); + federatedAuthConfig.setDefinedByType(definedByType); IdentityProvider federatedIdp = new IdentityProvider(); federatedIdp.setIdentityProviderName(option.getIdp()); diff --git a/components/org.wso2.carbon.identity.api.server.authenticators/org.wso2.carbon.identity.api.server.authenticators.v1/src/gen/java/org/wso2/carbon/identity/api/server/authenticators/v1/model/Authenticator.java b/components/org.wso2.carbon.identity.api.server.authenticators/org.wso2.carbon.identity.api.server.authenticators.v1/src/gen/java/org/wso2/carbon/identity/api/server/authenticators/v1/model/Authenticator.java index a79c8f2621..76fd698e31 100644 --- a/components/org.wso2.carbon.identity.api.server.authenticators/org.wso2.carbon.identity.api.server.authenticators.v1/src/gen/java/org/wso2/carbon/identity/api/server/authenticators/v1/model/Authenticator.java +++ b/components/org.wso2.carbon.identity.api.server.authenticators/org.wso2.carbon.identity.api.server.authenticators.v1/src/gen/java/org/wso2/carbon/identity/api/server/authenticators/v1/model/Authenticator.java @@ -37,6 +37,40 @@ public class Authenticator { private String displayName; private Boolean isEnabled; +@XmlType(name="DefinedByEnum") +@XmlEnum(String.class) +public enum DefinedByEnum { + + @XmlEnumValue("SYSTEM") SYSTEM(String.valueOf("SYSTEM")), @XmlEnumValue("USER") USER(String.valueOf("USER")); + + + private String value; + + DefinedByEnum(String v) { + value = v; + } + + public String value() { + return value; + } + + @Override + public String toString() { + return String.valueOf(value); + } + + public static DefinedByEnum fromValue(String value) { + for (DefinedByEnum b : DefinedByEnum.values()) { + if (b.value.equals(value)) { + return b; + } + } + throw new IllegalArgumentException("Unexpected value '" + value + "'"); + } +} + + private DefinedByEnum definedBy; + @XmlType(name="TypeEnum") @XmlEnum(String.class) public enum TypeEnum { @@ -148,6 +182,24 @@ public void setIsEnabled(Boolean isEnabled) { this.isEnabled = isEnabled; } + /** + **/ + public Authenticator definedBy(DefinedByEnum definedBy) { + + this.definedBy = definedBy; + return this; + } + + @ApiModelProperty(value = "") + @JsonProperty("definedBy") + @Valid + public DefinedByEnum getDefinedBy() { + return definedBy; + } + public void setDefinedBy(DefinedByEnum definedBy) { + this.definedBy = definedBy; + } + /** **/ public Authenticator type(TypeEnum type) { @@ -262,6 +314,7 @@ public boolean equals(java.lang.Object o) { Objects.equals(this.name, authenticator.name) && Objects.equals(this.displayName, authenticator.displayName) && Objects.equals(this.isEnabled, authenticator.isEnabled) && + Objects.equals(this.definedBy, authenticator.definedBy) && Objects.equals(this.type, authenticator.type) && Objects.equals(this.image, authenticator.image) && Objects.equals(this.description, authenticator.description) && @@ -271,7 +324,7 @@ public boolean equals(java.lang.Object o) { @Override public int hashCode() { - return Objects.hash(id, name, displayName, isEnabled, type, image, description, tags, self); + return Objects.hash(id, name, displayName, isEnabled, definedBy, type, image, description, tags, self); } @Override @@ -284,6 +337,7 @@ public String toString() { sb.append(" name: ").append(toIndentedString(name)).append("\n"); sb.append(" displayName: ").append(toIndentedString(displayName)).append("\n"); sb.append(" isEnabled: ").append(toIndentedString(isEnabled)).append("\n"); + sb.append(" definedBy: ").append(toIndentedString(definedBy)).append("\n"); sb.append(" type: ").append(toIndentedString(type)).append("\n"); sb.append(" image: ").append(toIndentedString(image)).append("\n"); sb.append(" description: ").append(toIndentedString(description)).append("\n"); diff --git a/components/org.wso2.carbon.identity.api.server.authenticators/org.wso2.carbon.identity.api.server.authenticators.v1/src/main/java/org/wso2/carbon/identity/api/server/authenticators/v1/core/ServerAuthenticatorManagementService.java b/components/org.wso2.carbon.identity.api.server.authenticators/org.wso2.carbon.identity.api.server.authenticators.v1/src/main/java/org/wso2/carbon/identity/api/server/authenticators/v1/core/ServerAuthenticatorManagementService.java index a67a7bf481..68887253ca 100644 --- a/components/org.wso2.carbon.identity.api.server.authenticators/org.wso2.carbon.identity.api.server.authenticators.v1/src/main/java/org/wso2/carbon/identity/api/server/authenticators/v1/core/ServerAuthenticatorManagementService.java +++ b/components/org.wso2.carbon.identity.api.server.authenticators/org.wso2.carbon.identity.api.server.authenticators.v1/src/main/java/org/wso2/carbon/identity/api/server/authenticators/v1/core/ServerAuthenticatorManagementService.java @@ -41,6 +41,7 @@ import org.wso2.carbon.identity.application.common.model.IdentityProvider; import org.wso2.carbon.identity.application.common.model.LocalAuthenticatorConfig; import org.wso2.carbon.identity.application.common.model.RequestPathAuthenticatorConfig; +import org.wso2.carbon.identity.base.AuthenticatorPropertiesConstant.DefinedByType; import org.wso2.carbon.identity.base.IdentityException; import org.wso2.carbon.identity.core.model.ExpressionNode; import org.wso2.carbon.identity.core.model.FilterTreeBuilder; @@ -421,6 +422,14 @@ private void addIdp(IdentityProvider identityProvider, List authe authenticator.setType(Authenticator.TypeEnum.FEDERATED); authenticator.setImage(identityProvider.getImageUrl()); authenticator.setDescription(identityProvider.getIdentityProviderDescription()); + // Only older existing IDP has multiple federated authenticator, + if (identityProvider.getFederatedAuthenticatorConfigs().length == 1) { + DefinedByType definedByType = + identityProvider.getFederatedAuthenticatorConfigs()[0].getDefinedByType(); + authenticator.definedBy(Authenticator.DefinedByEnum.valueOf(definedByType.toString())); + } else { + authenticator.definedBy(Authenticator.DefinedByEnum.SYSTEM); + } if (CollectionUtils.isNotEmpty(configTagsListDistinct)) { authenticator.setTags(configTagsListDistinct); } @@ -512,6 +521,7 @@ private Authenticator addLocalAuthenticator(LocalAuthenticatorConfig config) { authenticator.setDisplayName(config.getDisplayName()); authenticator.setIsEnabled(config.isEnabled()); authenticator.setType(Authenticator.TypeEnum.LOCAL); + authenticator.definedBy(Authenticator.DefinedByEnum.valueOf(config.getDefinedByType().toString())); String[] tags = config.getTags(); if (ArrayUtils.isNotEmpty(tags)) { authenticator.setTags(Arrays.asList(tags)); diff --git a/components/org.wso2.carbon.identity.api.server.authenticators/org.wso2.carbon.identity.api.server.authenticators.v1/src/main/resources/authenticators.yaml b/components/org.wso2.carbon.identity.api.server.authenticators/org.wso2.carbon.identity.api.server.authenticators.v1/src/main/resources/authenticators.yaml index fc489ae816..c91bc6ab54 100644 --- a/components/org.wso2.carbon.identity.api.server.authenticators/org.wso2.carbon.identity.api.server.authenticators.v1/src/main/resources/authenticators.yaml +++ b/components/org.wso2.carbon.identity.api.server.authenticators/org.wso2.carbon.identity.api.server.authenticators.v1/src/main/resources/authenticators.yaml @@ -202,6 +202,11 @@ components: isEnabled: type: boolean example: true + definedBy: + type: string + enum: + - SYSTEM + - USER type: type: string enum: diff --git a/components/org.wso2.carbon.identity.api.server.configs/org.wso2.carbon.identity.api.server.configs.v1/src/gen/java/org/wso2/carbon/identity/api/server/configs/v1/model/Authenticator.java b/components/org.wso2.carbon.identity.api.server.configs/org.wso2.carbon.identity.api.server.configs.v1/src/gen/java/org/wso2/carbon/identity/api/server/configs/v1/model/Authenticator.java index ab982bc225..744e6dbe18 100644 --- a/components/org.wso2.carbon.identity.api.server.configs/org.wso2.carbon.identity.api.server.configs.v1/src/gen/java/org/wso2/carbon/identity/api/server/configs/v1/model/Authenticator.java +++ b/components/org.wso2.carbon.identity.api.server.configs/org.wso2.carbon.identity.api.server.configs.v1/src/gen/java/org/wso2/carbon/identity/api/server/configs/v1/model/Authenticator.java @@ -38,6 +38,40 @@ public class Authenticator { private String displayName; private Boolean isEnabled = true; +@XmlType(name="DefinedByEnum") +@XmlEnum(String.class) +public enum DefinedByEnum { + + @XmlEnumValue("SYSTEM") SYSTEM(String.valueOf("SYSTEM")), @XmlEnumValue("USER") USER(String.valueOf("USER")); + + + private String value; + + DefinedByEnum(String v) { + value = v; + } + + public String value() { + return value; + } + + @Override + public String toString() { + return String.valueOf(value); + } + + public static DefinedByEnum fromValue(String value) { + for (DefinedByEnum b : DefinedByEnum.values()) { + if (b.value.equals(value)) { + return b; + } + } + throw new IllegalArgumentException("Unexpected value '" + value + "'"); + } +} + + private DefinedByEnum definedBy; + @XmlType(name="TypeEnum") @XmlEnum(String.class) public enum TypeEnum { @@ -152,6 +186,24 @@ public void setIsEnabled(Boolean isEnabled) { this.isEnabled = isEnabled; } + /** + **/ + public Authenticator definedBy(DefinedByEnum definedBy) { + + this.definedBy = definedBy; + return this; + } + + @ApiModelProperty(value = "") + @JsonProperty("definedBy") + @Valid + public DefinedByEnum getDefinedBy() { + return definedBy; + } + public void setDefinedBy(DefinedByEnum definedBy) { + this.definedBy = definedBy; + } + /** **/ public Authenticator type(TypeEnum type) { @@ -238,6 +290,7 @@ public boolean equals(java.lang.Object o) { Objects.equals(this.name, authenticator.name) && Objects.equals(this.displayName, authenticator.displayName) && Objects.equals(this.isEnabled, authenticator.isEnabled) && + Objects.equals(this.definedBy, authenticator.definedBy) && Objects.equals(this.type, authenticator.type) && Objects.equals(this.tags, authenticator.tags) && Objects.equals(this.properties, authenticator.properties); @@ -245,7 +298,7 @@ public boolean equals(java.lang.Object o) { @Override public int hashCode() { - return Objects.hash(id, name, displayName, isEnabled, type, tags, properties); + return Objects.hash(id, name, displayName, isEnabled, definedBy, type, tags, properties); } @Override @@ -258,6 +311,7 @@ public String toString() { sb.append(" name: ").append(toIndentedString(name)).append("\n"); sb.append(" displayName: ").append(toIndentedString(displayName)).append("\n"); sb.append(" isEnabled: ").append(toIndentedString(isEnabled)).append("\n"); + sb.append(" definedBy: ").append(toIndentedString(definedBy)).append("\n"); sb.append(" type: ").append(toIndentedString(type)).append("\n"); sb.append(" tags: ").append(toIndentedString(tags)).append("\n"); sb.append(" properties: ").append(toIndentedString(properties)).append("\n"); diff --git a/components/org.wso2.carbon.identity.api.server.configs/org.wso2.carbon.identity.api.server.configs.v1/src/gen/java/org/wso2/carbon/identity/api/server/configs/v1/model/AuthenticatorListItem.java b/components/org.wso2.carbon.identity.api.server.configs/org.wso2.carbon.identity.api.server.configs.v1/src/gen/java/org/wso2/carbon/identity/api/server/configs/v1/model/AuthenticatorListItem.java index 4703973ec6..ba26a797e4 100644 --- a/components/org.wso2.carbon.identity.api.server.configs/org.wso2.carbon.identity.api.server.configs.v1/src/gen/java/org/wso2/carbon/identity/api/server/configs/v1/model/AuthenticatorListItem.java +++ b/components/org.wso2.carbon.identity.api.server.configs/org.wso2.carbon.identity.api.server.configs.v1/src/gen/java/org/wso2/carbon/identity/api/server/configs/v1/model/AuthenticatorListItem.java @@ -37,6 +37,40 @@ public class AuthenticatorListItem { private String displayName; private Boolean isEnabled = true; +@XmlType(name="DefinedByEnum") +@XmlEnum(String.class) +public enum DefinedByEnum { + + @XmlEnumValue("SYSTEM") SYSTEM(String.valueOf("SYSTEM")), @XmlEnumValue("USER") USER(String.valueOf("USER")); + + + private String value; + + DefinedByEnum(String v) { + value = v; + } + + public String value() { + return value; + } + + @Override + public String toString() { + return String.valueOf(value); + } + + public static DefinedByEnum fromValue(String value) { + for (DefinedByEnum b : DefinedByEnum.values()) { + if (b.value.equals(value)) { + return b; + } + } + throw new IllegalArgumentException("Unexpected value '" + value + "'"); + } +} + + private DefinedByEnum definedBy; + @XmlType(name="TypeEnum") @XmlEnum(String.class) public enum TypeEnum { @@ -146,6 +180,24 @@ public void setIsEnabled(Boolean isEnabled) { this.isEnabled = isEnabled; } + /** + **/ + public AuthenticatorListItem definedBy(DefinedByEnum definedBy) { + + this.definedBy = definedBy; + return this; + } + + @ApiModelProperty(value = "") + @JsonProperty("definedBy") + @Valid + public DefinedByEnum getDefinedBy() { + return definedBy; + } + public void setDefinedBy(DefinedByEnum definedBy) { + this.definedBy = definedBy; + } + /** **/ public AuthenticatorListItem type(TypeEnum type) { @@ -224,6 +276,7 @@ public boolean equals(java.lang.Object o) { Objects.equals(this.name, authenticatorListItem.name) && Objects.equals(this.displayName, authenticatorListItem.displayName) && Objects.equals(this.isEnabled, authenticatorListItem.isEnabled) && + Objects.equals(this.definedBy, authenticatorListItem.definedBy) && Objects.equals(this.type, authenticatorListItem.type) && Objects.equals(this.tags, authenticatorListItem.tags) && Objects.equals(this.self, authenticatorListItem.self); @@ -231,7 +284,7 @@ public boolean equals(java.lang.Object o) { @Override public int hashCode() { - return Objects.hash(id, name, displayName, isEnabled, type, tags, self); + return Objects.hash(id, name, displayName, isEnabled, definedBy, type, tags, self); } @Override @@ -244,6 +297,7 @@ public String toString() { sb.append(" name: ").append(toIndentedString(name)).append("\n"); sb.append(" displayName: ").append(toIndentedString(displayName)).append("\n"); sb.append(" isEnabled: ").append(toIndentedString(isEnabled)).append("\n"); + sb.append(" definedBy: ").append(toIndentedString(definedBy)).append("\n"); sb.append(" type: ").append(toIndentedString(type)).append("\n"); sb.append(" tags: ").append(toIndentedString(tags)).append("\n"); sb.append(" self: ").append(toIndentedString(self)).append("\n"); diff --git a/components/org.wso2.carbon.identity.api.server.configs/org.wso2.carbon.identity.api.server.configs.v1/src/main/java/org/wso2/carbon/identity/api/server/configs/v1/core/ServerConfigManagementService.java b/components/org.wso2.carbon.identity.api.server.configs/org.wso2.carbon.identity.api.server.configs.v1/src/main/java/org/wso2/carbon/identity/api/server/configs/v1/core/ServerConfigManagementService.java index 142d5bfe13..023adfee91 100644 --- a/components/org.wso2.carbon.identity.api.server.configs/org.wso2.carbon.identity.api.server.configs.v1/src/main/java/org/wso2/carbon/identity/api/server/configs/v1/core/ServerConfigManagementService.java +++ b/components/org.wso2.carbon.identity.api.server.configs/org.wso2.carbon.identity.api.server.configs.v1/src/main/java/org/wso2/carbon/identity/api/server/configs/v1/core/ServerConfigManagementService.java @@ -704,6 +704,8 @@ private List buildAuthenticatorListResponse( authenticatorListItem.setDisplayName(config.getDisplayName()); authenticatorListItem.setIsEnabled(config.isEnabled()); authenticatorListItem.setType(AuthenticatorListItem.TypeEnum.LOCAL); + authenticatorListItem.setDefinedBy( + AuthenticatorListItem.DefinedByEnum.valueOf(config.getDefinedByType().toString())); String[] tags = config.getTags(); if (ArrayUtils.isNotEmpty(tags)) { authenticatorListItem.setTags(Arrays.asList(tags)); @@ -722,6 +724,7 @@ private List buildAuthenticatorListResponse( authenticatorListItem.setDisplayName(config.getDisplayName()); authenticatorListItem.setIsEnabled(config.isEnabled()); authenticatorListItem.setType(AuthenticatorListItem.TypeEnum.REQUEST_PATH); + authenticatorListItem.setDefinedBy(AuthenticatorListItem.DefinedByEnum.SYSTEM); String[] tags = config.getTags(); if (ArrayUtils.isNotEmpty(tags)) { authenticatorListItem.setTags(Arrays.asList(tags)); @@ -771,6 +774,7 @@ private Authenticator buildAuthenticatorResponse(LocalAuthenticatorConfig config authenticator.setName(config.getName()); authenticator.setDisplayName(config.getDisplayName()); authenticator.setIsEnabled(config.isEnabled()); + authenticator.definedBy(Authenticator.DefinedByEnum.valueOf(config.getDefinedByType().toString())); if (config instanceof RequestPathAuthenticatorConfig) { authenticator.setType(Authenticator.TypeEnum.REQUEST_PATH); } else { diff --git a/components/org.wso2.carbon.identity.api.server.configs/org.wso2.carbon.identity.api.server.configs.v1/src/main/resources/configs.yaml b/components/org.wso2.carbon.identity.api.server.configs/org.wso2.carbon.identity.api.server.configs.v1/src/main/resources/configs.yaml index a7226d6ec9..fa508a56ff 100644 --- a/components/org.wso2.carbon.identity.api.server.configs/org.wso2.carbon.identity.api.server.configs.v1/src/main/resources/configs.yaml +++ b/components/org.wso2.carbon.identity.api.server.configs/org.wso2.carbon.identity.api.server.configs.v1/src/main/resources/configs.yaml @@ -1187,6 +1187,11 @@ components: type: boolean default: true example: true + definedBy: + type: string + enum: + - SYSTEM + - USER type: type: string enum: @@ -1217,6 +1222,11 @@ components: isEnabled: type: boolean default: true + definedBy: + type: string + enum: + - SYSTEM + - USER type: type: string enum: diff --git a/components/org.wso2.carbon.identity.api.server.idp/org.wso2.carbon.identity.api.server.idp.v1/src/gen/java/org/wso2/carbon/identity/api/server/idp/v1/model/FederatedAuthenticator.java b/components/org.wso2.carbon.identity.api.server.idp/org.wso2.carbon.identity.api.server.idp.v1/src/gen/java/org/wso2/carbon/identity/api/server/idp/v1/model/FederatedAuthenticator.java index 84373ee10c..5996d10619 100644 --- a/components/org.wso2.carbon.identity.api.server.idp/org.wso2.carbon.identity.api.server.idp.v1/src/gen/java/org/wso2/carbon/identity/api/server/idp/v1/model/FederatedAuthenticator.java +++ b/components/org.wso2.carbon.identity.api.server.idp/org.wso2.carbon.identity.api.server.idp.v1/src/gen/java/org/wso2/carbon/identity/api/server/idp/v1/model/FederatedAuthenticator.java @@ -36,6 +36,40 @@ public class FederatedAuthenticator { private String authenticatorId; private String name; private Boolean isEnabled = false; + +@XmlType(name="DefinedByEnum") +@XmlEnum(String.class) +public enum DefinedByEnum { + + @XmlEnumValue("SYSTEM") SYSTEM(String.valueOf("SYSTEM")), @XmlEnumValue("USER") USER(String.valueOf("USER")); + + + private String value; + + DefinedByEnum(String v) { + value = v; + } + + public String value() { + return value; + } + + @Override + public String toString() { + return String.valueOf(value); + } + + public static DefinedByEnum fromValue(String value) { + for (DefinedByEnum b : DefinedByEnum.values()) { + if (b.value.equals(value)) { + return b; + } + } + throw new IllegalArgumentException("Unexpected value '" + value + "'"); + } +} + + private DefinedByEnum definedBy; private Boolean isDefault = false; private List tags = null; @@ -98,6 +132,24 @@ public void setIsEnabled(Boolean isEnabled) { this.isEnabled = isEnabled; } + /** + **/ + public FederatedAuthenticator definedBy(DefinedByEnum definedBy) { + + this.definedBy = definedBy; + return this; + } + + @ApiModelProperty(value = "") + @JsonProperty("definedBy") + @Valid + public DefinedByEnum getDefinedBy() { + return definedBy; + } + public void setDefinedBy(DefinedByEnum definedBy) { + this.definedBy = definedBy; + } + /** **/ public FederatedAuthenticator isDefault(Boolean isDefault) { @@ -183,6 +235,7 @@ public boolean equals(java.lang.Object o) { return Objects.equals(this.authenticatorId, federatedAuthenticator.authenticatorId) && Objects.equals(this.name, federatedAuthenticator.name) && Objects.equals(this.isEnabled, federatedAuthenticator.isEnabled) && + Objects.equals(this.definedBy, federatedAuthenticator.definedBy) && Objects.equals(this.isDefault, federatedAuthenticator.isDefault) && Objects.equals(this.tags, federatedAuthenticator.tags) && Objects.equals(this.properties, federatedAuthenticator.properties); @@ -190,7 +243,7 @@ public boolean equals(java.lang.Object o) { @Override public int hashCode() { - return Objects.hash(authenticatorId, name, isEnabled, isDefault, tags, properties); + return Objects.hash(authenticatorId, name, isEnabled, definedBy, isDefault, tags, properties); } @Override @@ -202,6 +255,7 @@ public String toString() { sb.append(" authenticatorId: ").append(toIndentedString(authenticatorId)).append("\n"); sb.append(" name: ").append(toIndentedString(name)).append("\n"); sb.append(" isEnabled: ").append(toIndentedString(isEnabled)).append("\n"); + sb.append(" definedBy: ").append(toIndentedString(definedBy)).append("\n"); sb.append(" isDefault: ").append(toIndentedString(isDefault)).append("\n"); sb.append(" tags: ").append(toIndentedString(tags)).append("\n"); sb.append(" properties: ").append(toIndentedString(properties)).append("\n"); diff --git a/components/org.wso2.carbon.identity.api.server.idp/org.wso2.carbon.identity.api.server.idp.v1/src/gen/java/org/wso2/carbon/identity/api/server/idp/v1/model/FederatedAuthenticatorListItem.java b/components/org.wso2.carbon.identity.api.server.idp/org.wso2.carbon.identity.api.server.idp.v1/src/gen/java/org/wso2/carbon/identity/api/server/idp/v1/model/FederatedAuthenticatorListItem.java index 1c479915aa..ea7d4d2a13 100644 --- a/components/org.wso2.carbon.identity.api.server.idp/org.wso2.carbon.identity.api.server.idp.v1/src/gen/java/org/wso2/carbon/identity/api/server/idp/v1/model/FederatedAuthenticatorListItem.java +++ b/components/org.wso2.carbon.identity.api.server.idp/org.wso2.carbon.identity.api.server.idp.v1/src/gen/java/org/wso2/carbon/identity/api/server/idp/v1/model/FederatedAuthenticatorListItem.java @@ -35,6 +35,40 @@ public class FederatedAuthenticatorListItem { private String authenticatorId; private String name; private Boolean isEnabled = false; + +@XmlType(name="DefinedByEnum") +@XmlEnum(String.class) +public enum DefinedByEnum { + + @XmlEnumValue("SYSTEM") SYSTEM(String.valueOf("SYSTEM")), @XmlEnumValue("USER") USER(String.valueOf("USER")); + + + private String value; + + DefinedByEnum(String v) { + value = v; + } + + public String value() { + return value; + } + + @Override + public String toString() { + return String.valueOf(value); + } + + public static DefinedByEnum fromValue(String value) { + for (DefinedByEnum b : DefinedByEnum.values()) { + if (b.value.equals(value)) { + return b; + } + } + throw new IllegalArgumentException("Unexpected value '" + value + "'"); + } +} + + private DefinedByEnum definedBy; private List tags = null; private String self; @@ -93,6 +127,24 @@ public void setIsEnabled(Boolean isEnabled) { this.isEnabled = isEnabled; } + /** + **/ + public FederatedAuthenticatorListItem definedBy(DefinedByEnum definedBy) { + + this.definedBy = definedBy; + return this; + } + + @ApiModelProperty(value = "") + @JsonProperty("definedBy") + @Valid + public DefinedByEnum getDefinedBy() { + return definedBy; + } + public void setDefinedBy(DefinedByEnum definedBy) { + this.definedBy = definedBy; + } + /** **/ public FederatedAuthenticatorListItem tags(List tags) { @@ -152,13 +204,14 @@ public boolean equals(java.lang.Object o) { return Objects.equals(this.authenticatorId, federatedAuthenticatorListItem.authenticatorId) && Objects.equals(this.name, federatedAuthenticatorListItem.name) && Objects.equals(this.isEnabled, federatedAuthenticatorListItem.isEnabled) && + Objects.equals(this.definedBy, federatedAuthenticatorListItem.definedBy) && Objects.equals(this.tags, federatedAuthenticatorListItem.tags) && Objects.equals(this.self, federatedAuthenticatorListItem.self); } @Override public int hashCode() { - return Objects.hash(authenticatorId, name, isEnabled, tags, self); + return Objects.hash(authenticatorId, name, isEnabled, definedBy, tags, self); } @Override @@ -170,6 +223,7 @@ public String toString() { sb.append(" authenticatorId: ").append(toIndentedString(authenticatorId)).append("\n"); sb.append(" name: ").append(toIndentedString(name)).append("\n"); sb.append(" isEnabled: ").append(toIndentedString(isEnabled)).append("\n"); + sb.append(" definedBy: ").append(toIndentedString(definedBy)).append("\n"); sb.append(" tags: ").append(toIndentedString(tags)).append("\n"); sb.append(" self: ").append(toIndentedString(self)).append("\n"); sb.append("}"); diff --git a/components/org.wso2.carbon.identity.api.server.idp/org.wso2.carbon.identity.api.server.idp.v1/src/gen/java/org/wso2/carbon/identity/api/server/idp/v1/model/FederatedAuthenticatorPUTRequest.java b/components/org.wso2.carbon.identity.api.server.idp/org.wso2.carbon.identity.api.server.idp.v1/src/gen/java/org/wso2/carbon/identity/api/server/idp/v1/model/FederatedAuthenticatorPUTRequest.java index 0ec1edc32b..685579c64a 100644 --- a/components/org.wso2.carbon.identity.api.server.idp/org.wso2.carbon.identity.api.server.idp.v1/src/gen/java/org/wso2/carbon/identity/api/server/idp/v1/model/FederatedAuthenticatorPUTRequest.java +++ b/components/org.wso2.carbon.identity.api.server.idp/org.wso2.carbon.identity.api.server.idp.v1/src/gen/java/org/wso2/carbon/identity/api/server/idp/v1/model/FederatedAuthenticatorPUTRequest.java @@ -37,6 +37,40 @@ public class FederatedAuthenticatorPUTRequest { private String name; private Boolean isEnabled = false; private Boolean isDefault = false; + +@XmlType(name="DefinedByEnum") +@XmlEnum(String.class) +public enum DefinedByEnum { + + @XmlEnumValue("SYSTEM") SYSTEM(String.valueOf("SYSTEM")), @XmlEnumValue("USER") USER(String.valueOf("USER")); + + + private String value; + + DefinedByEnum(String v) { + value = v; + } + + public String value() { + return value; + } + + @Override + public String toString() { + return String.valueOf(value); + } + + public static DefinedByEnum fromValue(String value) { + for (DefinedByEnum b : DefinedByEnum.values()) { + if (b.value.equals(value)) { + return b; + } + } + throw new IllegalArgumentException("Unexpected value '" + value + "'"); + } +} + + private DefinedByEnum definedBy; private List properties = null; @@ -112,6 +146,24 @@ public void setIsDefault(Boolean isDefault) { this.isDefault = isDefault; } + /** + **/ + public FederatedAuthenticatorPUTRequest definedBy(DefinedByEnum definedBy) { + + this.definedBy = definedBy; + return this; + } + + @ApiModelProperty(value = "") + @JsonProperty("definedBy") + @Valid + public DefinedByEnum getDefinedBy() { + return definedBy; + } + public void setDefinedBy(DefinedByEnum definedBy) { + this.definedBy = definedBy; + } + /** **/ public FederatedAuthenticatorPUTRequest properties(List properties) { @@ -154,12 +206,13 @@ public boolean equals(java.lang.Object o) { Objects.equals(this.name, federatedAuthenticatorPUTRequest.name) && Objects.equals(this.isEnabled, federatedAuthenticatorPUTRequest.isEnabled) && Objects.equals(this.isDefault, federatedAuthenticatorPUTRequest.isDefault) && + Objects.equals(this.definedBy, federatedAuthenticatorPUTRequest.definedBy) && Objects.equals(this.properties, federatedAuthenticatorPUTRequest.properties); } @Override public int hashCode() { - return Objects.hash(authenticatorId, name, isEnabled, isDefault, properties); + return Objects.hash(authenticatorId, name, isEnabled, isDefault, definedBy, properties); } @Override @@ -172,6 +225,7 @@ public String toString() { sb.append(" name: ").append(toIndentedString(name)).append("\n"); sb.append(" isEnabled: ").append(toIndentedString(isEnabled)).append("\n"); sb.append(" isDefault: ").append(toIndentedString(isDefault)).append("\n"); + sb.append(" definedBy: ").append(toIndentedString(definedBy)).append("\n"); sb.append(" properties: ").append(toIndentedString(properties)).append("\n"); sb.append("}"); return sb.toString(); diff --git a/components/org.wso2.carbon.identity.api.server.idp/org.wso2.carbon.identity.api.server.idp.v1/src/gen/java/org/wso2/carbon/identity/api/server/idp/v1/model/MetaFederatedAuthenticator.java b/components/org.wso2.carbon.identity.api.server.idp/org.wso2.carbon.identity.api.server.idp.v1/src/gen/java/org/wso2/carbon/identity/api/server/idp/v1/model/MetaFederatedAuthenticator.java index d85f7cc9af..46483c4c83 100644 --- a/components/org.wso2.carbon.identity.api.server.idp/org.wso2.carbon.identity.api.server.idp.v1/src/gen/java/org/wso2/carbon/identity/api/server/idp/v1/model/MetaFederatedAuthenticator.java +++ b/components/org.wso2.carbon.identity.api.server.idp/org.wso2.carbon.identity.api.server.idp.v1/src/gen/java/org/wso2/carbon/identity/api/server/idp/v1/model/MetaFederatedAuthenticator.java @@ -36,6 +36,40 @@ public class MetaFederatedAuthenticator { private String authenticatorId; private String name; private String displayName; + +@XmlType(name="DefinedByEnum") +@XmlEnum(String.class) +public enum DefinedByEnum { + + @XmlEnumValue("SYSTEM") SYSTEM(String.valueOf("SYSTEM")), @XmlEnumValue("USER") USER(String.valueOf("USER")); + + + private String value; + + DefinedByEnum(String v) { + value = v; + } + + public String value() { + return value; + } + + @Override + public String toString() { + return String.valueOf(value); + } + + public static DefinedByEnum fromValue(String value) { + for (DefinedByEnum b : DefinedByEnum.values()) { + if (b.value.equals(value)) { + return b; + } + } + throw new IllegalArgumentException("Unexpected value '" + value + "'"); + } +} + + private DefinedByEnum definedBy; private List tags = null; private List properties = null; @@ -95,6 +129,24 @@ public void setDisplayName(String displayName) { this.displayName = displayName; } + /** + **/ + public MetaFederatedAuthenticator definedBy(DefinedByEnum definedBy) { + + this.definedBy = definedBy; + return this; + } + + @ApiModelProperty(value = "") + @JsonProperty("definedBy") + @Valid + public DefinedByEnum getDefinedBy() { + return definedBy; + } + public void setDefinedBy(DefinedByEnum definedBy) { + this.definedBy = definedBy; + } + /** **/ public MetaFederatedAuthenticator tags(List tags) { @@ -162,13 +214,14 @@ public boolean equals(java.lang.Object o) { return Objects.equals(this.authenticatorId, metaFederatedAuthenticator.authenticatorId) && Objects.equals(this.name, metaFederatedAuthenticator.name) && Objects.equals(this.displayName, metaFederatedAuthenticator.displayName) && + Objects.equals(this.definedBy, metaFederatedAuthenticator.definedBy) && Objects.equals(this.tags, metaFederatedAuthenticator.tags) && Objects.equals(this.properties, metaFederatedAuthenticator.properties); } @Override public int hashCode() { - return Objects.hash(authenticatorId, name, displayName, tags, properties); + return Objects.hash(authenticatorId, name, displayName, definedBy, tags, properties); } @Override @@ -180,6 +233,7 @@ public String toString() { sb.append(" authenticatorId: ").append(toIndentedString(authenticatorId)).append("\n"); sb.append(" name: ").append(toIndentedString(name)).append("\n"); sb.append(" displayName: ").append(toIndentedString(displayName)).append("\n"); + sb.append(" definedBy: ").append(toIndentedString(definedBy)).append("\n"); sb.append(" tags: ").append(toIndentedString(tags)).append("\n"); sb.append(" properties: ").append(toIndentedString(properties)).append("\n"); sb.append("}"); diff --git a/components/org.wso2.carbon.identity.api.server.idp/org.wso2.carbon.identity.api.server.idp.v1/src/gen/java/org/wso2/carbon/identity/api/server/idp/v1/model/MetaFederatedAuthenticatorListItem.java b/components/org.wso2.carbon.identity.api.server.idp/org.wso2.carbon.identity.api.server.idp.v1/src/gen/java/org/wso2/carbon/identity/api/server/idp/v1/model/MetaFederatedAuthenticatorListItem.java index b7ef4c326a..7def0a4289 100644 --- a/components/org.wso2.carbon.identity.api.server.idp/org.wso2.carbon.identity.api.server.idp.v1/src/gen/java/org/wso2/carbon/identity/api/server/idp/v1/model/MetaFederatedAuthenticatorListItem.java +++ b/components/org.wso2.carbon.identity.api.server.idp/org.wso2.carbon.identity.api.server.idp.v1/src/gen/java/org/wso2/carbon/identity/api/server/idp/v1/model/MetaFederatedAuthenticatorListItem.java @@ -34,6 +34,40 @@ public class MetaFederatedAuthenticatorListItem { private String authenticatorId; private String name; + +@XmlType(name="DefinedByEnum") +@XmlEnum(String.class) +public enum DefinedByEnum { + + @XmlEnumValue("SYSTEM") SYSTEM(String.valueOf("SYSTEM")), @XmlEnumValue("USER") USER(String.valueOf("USER")); + + + private String value; + + DefinedByEnum(String v) { + value = v; + } + + public String value() { + return value; + } + + @Override + public String toString() { + return String.valueOf(value); + } + + public static DefinedByEnum fromValue(String value) { + for (DefinedByEnum b : DefinedByEnum.values()) { + if (b.value.equals(value)) { + return b; + } + } + throw new IllegalArgumentException("Unexpected value '" + value + "'"); + } +} + + private DefinedByEnum definedBy; private List tags = null; private String self; @@ -74,6 +108,24 @@ public void setName(String name) { this.name = name; } + /** + **/ + public MetaFederatedAuthenticatorListItem definedBy(DefinedByEnum definedBy) { + + this.definedBy = definedBy; + return this; + } + + @ApiModelProperty(value = "") + @JsonProperty("definedBy") + @Valid + public DefinedByEnum getDefinedBy() { + return definedBy; + } + public void setDefinedBy(DefinedByEnum definedBy) { + this.definedBy = definedBy; + } + /** **/ public MetaFederatedAuthenticatorListItem tags(List tags) { @@ -132,13 +184,14 @@ public boolean equals(java.lang.Object o) { MetaFederatedAuthenticatorListItem metaFederatedAuthenticatorListItem = (MetaFederatedAuthenticatorListItem) o; return Objects.equals(this.authenticatorId, metaFederatedAuthenticatorListItem.authenticatorId) && Objects.equals(this.name, metaFederatedAuthenticatorListItem.name) && + Objects.equals(this.definedBy, metaFederatedAuthenticatorListItem.definedBy) && Objects.equals(this.tags, metaFederatedAuthenticatorListItem.tags) && Objects.equals(this.self, metaFederatedAuthenticatorListItem.self); } @Override public int hashCode() { - return Objects.hash(authenticatorId, name, tags, self); + return Objects.hash(authenticatorId, name, definedBy, tags, self); } @Override @@ -149,6 +202,7 @@ public String toString() { sb.append(" authenticatorId: ").append(toIndentedString(authenticatorId)).append("\n"); sb.append(" name: ").append(toIndentedString(name)).append("\n"); + sb.append(" definedBy: ").append(toIndentedString(definedBy)).append("\n"); sb.append(" tags: ").append(toIndentedString(tags)).append("\n"); sb.append(" self: ").append(toIndentedString(self)).append("\n"); sb.append("}"); diff --git a/components/org.wso2.carbon.identity.api.server.idp/org.wso2.carbon.identity.api.server.idp.v1/src/main/java/org/wso2/carbon/identity/api/server/idp/v1/core/ServerIdpManagementService.java b/components/org.wso2.carbon.identity.api.server.idp/org.wso2.carbon.identity.api.server.idp.v1/src/main/java/org/wso2/carbon/identity/api/server/idp/v1/core/ServerIdpManagementService.java index da4f38f5c9..282fc34c9d 100644 --- a/components/org.wso2.carbon.identity.api.server.idp/org.wso2.carbon.identity.api.server.idp.v1/src/main/java/org/wso2/carbon/identity/api/server/idp/v1/core/ServerIdpManagementService.java +++ b/components/org.wso2.carbon.identity.api.server.idp/org.wso2.carbon.identity.api.server.idp.v1/src/main/java/org/wso2/carbon/identity/api/server/idp/v1/core/ServerIdpManagementService.java @@ -94,6 +94,7 @@ import org.wso2.carbon.identity.application.common.model.RoleMapping; import org.wso2.carbon.identity.application.common.model.SubProperty; import org.wso2.carbon.identity.application.common.util.IdentityApplicationConstants; +import org.wso2.carbon.identity.base.AuthenticatorPropertiesConstant.DefinedByType; import org.wso2.carbon.identity.claim.metadata.mgt.exception.ClaimMetadataException; import org.wso2.carbon.identity.claim.metadata.mgt.model.LocalClaim; import org.wso2.carbon.identity.configuration.mgt.core.model.ResourceSearchBean; @@ -1771,6 +1772,16 @@ private void updateFederatedAuthenticatorConfig(IdentityProvider idp, FederatedA authConfig.setName(base64URLDecode(authenticator.getAuthenticatorId())); authConfig.setDisplayName(getDisplayNameOfAuthenticator(authConfig.getName())); authConfig.setEnabled(authenticator.getIsEnabled()); + /* Resolve definedBy type: If there is authenticator by same name and its type is system: SYSTEM. + If not: USER. */ + FederatedAuthenticatorConfig authenticatorConfig = ApplicationAuthenticatorService.getInstance() + .getFederatedAuthenticatorByName(authenticator.getAuthenticatorId()); + if (authenticatorConfig != null && + DefinedByType.SYSTEM.equals(authenticatorConfig.getDefinedByType())) { + authConfig.setDefinedByType(DefinedByType.SYSTEM); + } else { + authConfig.setDefinedByType(DefinedByType.USER); + } List authProperties = authenticator.getProperties(); if (IdentityApplicationConstants.Authenticator.SAML2SSO.FED_AUTH_NAME.equals(authConfig.getName())) { @@ -2456,6 +2467,8 @@ private FederatedAuthenticatorListResponse createFederatedAuthenticatorResponse( fedAuthListItem.setAuthenticatorId(base64URLEncode(fedAuthConfig.getName())); fedAuthListItem.setName(fedAuthConfig.getName()); fedAuthListItem.setIsEnabled(fedAuthConfig.isEnabled()); + fedAuthListItem.setDefinedBy(FederatedAuthenticatorListItem.DefinedByEnum.valueOf( + fedAuthConfig.getDefinedByType().toString())); FederatedAuthenticatorConfig federatedAuthenticatorConfig = ApplicationAuthenticatorService.getInstance().getFederatedAuthenticatorByName( fedAuthConfig.getName()); @@ -2838,6 +2851,15 @@ private FederatedAuthenticatorConfig createFederatedAuthenticatorConfig(String f authConfig.setName(authenticatorName); authConfig.setDisplayName(getDisplayNameOfAuthenticator(authenticatorName)); authConfig.setEnabled(authenticator.getIsEnabled()); + // Resolve definedBy type: If there is authenticator by same name and its type is system: SYSTEM. If not: USER. + FederatedAuthenticatorConfig authenticatorConfig = ApplicationAuthenticatorService.getInstance() + .getFederatedAuthenticatorByName(authenticatorName); + if (authenticatorConfig != null && + DefinedByType.SYSTEM.equals(authenticatorConfig.getDefinedByType())) { + authConfig.setDefinedByType(DefinedByType.SYSTEM); + } else { + authConfig.setDefinedByType(DefinedByType.USER); + } List authProperties = authenticator.getProperties(); if (IdentityApplicationConstants.Authenticator.SAML2SSO.FED_AUTH_NAME.equals(authenticatorName)) { validateSamlMetadata(authProperties); @@ -3030,6 +3052,8 @@ private FederatedAuthenticator createFederatedAuthenticator(String authenticator federatedAuthenticator.setName(config.getName()); federatedAuthenticator.setIsEnabled(config.isEnabled()); federatedAuthenticator.setIsDefault(isDefaultAuthenticator); + federatedAuthenticator.setDefinedBy(FederatedAuthenticator.DefinedByEnum.valueOf( + config.getDefinedByType().toString())); FederatedAuthenticatorConfig federatedAuthenticatorConfig = ApplicationAuthenticatorService.getInstance().getFederatedAuthenticatorByName( config.getName()); diff --git a/components/org.wso2.carbon.identity.api.server.idp/org.wso2.carbon.identity.api.server.idp.v1/src/main/resources/idp.yaml b/components/org.wso2.carbon.identity.api.server.idp/org.wso2.carbon.identity.api.server.idp.v1/src/main/resources/idp.yaml index 8fee505e59..9e0df2e09d 100644 --- a/components/org.wso2.carbon.identity.api.server.idp/org.wso2.carbon.identity.api.server.idp.v1/src/main/resources/idp.yaml +++ b/components/org.wso2.carbon.identity.api.server.idp/org.wso2.carbon.identity.api.server.idp.v1/src/main/resources/idp.yaml @@ -2783,6 +2783,11 @@ components: name: type: string example: SAML2Authenticator + definedBy: + type: string + enum: + - SYSTEM + - USER tags: type: array items: @@ -2804,6 +2809,11 @@ components: displayName: type: string example: 'SAML2 Web SSO Configuration' + definedBy: + type: string + enum: + - SYSTEM + - USER tags: type: array items: @@ -2849,6 +2859,11 @@ components: type: boolean default: false example: true + definedBy: + type: string + enum: + - SYSTEM + - USER isDefault: type: boolean default: false @@ -2881,6 +2896,11 @@ components: type: boolean default: false example: false + definedBy: + type: string + enum: + - SYSTEM + - USER properties: type: array items: @@ -2908,6 +2928,11 @@ components: type: boolean default: false example: true + definedBy: + type: string + enum: + - SYSTEM + - USER tags: type: array items: From bcfc49ef1634783fceef2c9a01c5896e5b873f01 Mon Sep 17 00:00:00 2001 From: thisarawelmilla Date: Mon, 7 Oct 2024 20:56:37 +0530 Subject: [PATCH 2/5] Addressed comments --- .../UpdateAuthenticationSequence.java | 2 +- .../ServerAuthenticatorManagementService.java | 2 +- .../v1/core/ServerIdpManagementService.java | 35 ++++++++----------- 3 files changed, 17 insertions(+), 22 deletions(-) diff --git a/components/org.wso2.carbon.identity.api.server.application.management/org.wso2.carbon.identity.api.server.application.management.v1/src/main/java/org/wso2/carbon/identity/api/server/application/management/v1/core/functions/application/UpdateAuthenticationSequence.java b/components/org.wso2.carbon.identity.api.server.application.management/org.wso2.carbon.identity.api.server.application.management.v1/src/main/java/org/wso2/carbon/identity/api/server/application/management/v1/core/functions/application/UpdateAuthenticationSequence.java index 4d636df20e..bd76572d87 100644 --- a/components/org.wso2.carbon.identity.api.server.application.management/org.wso2.carbon.identity.api.server.application.management.v1/src/main/java/org/wso2/carbon/identity/api/server/application/management/v1/core/functions/application/UpdateAuthenticationSequence.java +++ b/components/org.wso2.carbon.identity.api.server.application.management/org.wso2.carbon.identity.api.server.application.management.v1/src/main/java/org/wso2/carbon/identity/api/server/application/management/v1/core/functions/application/UpdateAuthenticationSequence.java @@ -32,7 +32,7 @@ import org.wso2.carbon.identity.application.common.model.ServiceProvider; import org.wso2.carbon.identity.application.common.model.script.AuthenticationScriptConfig; import org.wso2.carbon.identity.application.mgt.ApplicationConstants; -import org.wso2.carbon.identity.base.AuthenticatorPropertiesConstant.DefinedByType; +import org.wso2.carbon.identity.base.AuthenticatorPropertyConstants.DefinedByType; import java.util.ArrayList; import java.util.Collections; diff --git a/components/org.wso2.carbon.identity.api.server.authenticators/org.wso2.carbon.identity.api.server.authenticators.v1/src/main/java/org/wso2/carbon/identity/api/server/authenticators/v1/core/ServerAuthenticatorManagementService.java b/components/org.wso2.carbon.identity.api.server.authenticators/org.wso2.carbon.identity.api.server.authenticators.v1/src/main/java/org/wso2/carbon/identity/api/server/authenticators/v1/core/ServerAuthenticatorManagementService.java index 68887253ca..88f1c6a64b 100644 --- a/components/org.wso2.carbon.identity.api.server.authenticators/org.wso2.carbon.identity.api.server.authenticators.v1/src/main/java/org/wso2/carbon/identity/api/server/authenticators/v1/core/ServerAuthenticatorManagementService.java +++ b/components/org.wso2.carbon.identity.api.server.authenticators/org.wso2.carbon.identity.api.server.authenticators.v1/src/main/java/org/wso2/carbon/identity/api/server/authenticators/v1/core/ServerAuthenticatorManagementService.java @@ -41,7 +41,7 @@ import org.wso2.carbon.identity.application.common.model.IdentityProvider; import org.wso2.carbon.identity.application.common.model.LocalAuthenticatorConfig; import org.wso2.carbon.identity.application.common.model.RequestPathAuthenticatorConfig; -import org.wso2.carbon.identity.base.AuthenticatorPropertiesConstant.DefinedByType; +import org.wso2.carbon.identity.base.AuthenticatorPropertyConstants.DefinedByType; import org.wso2.carbon.identity.base.IdentityException; import org.wso2.carbon.identity.core.model.ExpressionNode; import org.wso2.carbon.identity.core.model.FilterTreeBuilder; diff --git a/components/org.wso2.carbon.identity.api.server.idp/org.wso2.carbon.identity.api.server.idp.v1/src/main/java/org/wso2/carbon/identity/api/server/idp/v1/core/ServerIdpManagementService.java b/components/org.wso2.carbon.identity.api.server.idp/org.wso2.carbon.identity.api.server.idp.v1/src/main/java/org/wso2/carbon/identity/api/server/idp/v1/core/ServerIdpManagementService.java index 282fc34c9d..c512eaebbd 100644 --- a/components/org.wso2.carbon.identity.api.server.idp/org.wso2.carbon.identity.api.server.idp.v1/src/main/java/org/wso2/carbon/identity/api/server/idp/v1/core/ServerIdpManagementService.java +++ b/components/org.wso2.carbon.identity.api.server.idp/org.wso2.carbon.identity.api.server.idp.v1/src/main/java/org/wso2/carbon/identity/api/server/idp/v1/core/ServerIdpManagementService.java @@ -94,7 +94,7 @@ import org.wso2.carbon.identity.application.common.model.RoleMapping; import org.wso2.carbon.identity.application.common.model.SubProperty; import org.wso2.carbon.identity.application.common.util.IdentityApplicationConstants; -import org.wso2.carbon.identity.base.AuthenticatorPropertiesConstant.DefinedByType; +import org.wso2.carbon.identity.base.AuthenticatorPropertyConstants.DefinedByType; import org.wso2.carbon.identity.claim.metadata.mgt.exception.ClaimMetadataException; import org.wso2.carbon.identity.claim.metadata.mgt.model.LocalClaim; import org.wso2.carbon.identity.configuration.mgt.core.model.ResourceSearchBean; @@ -1772,16 +1772,7 @@ private void updateFederatedAuthenticatorConfig(IdentityProvider idp, FederatedA authConfig.setName(base64URLDecode(authenticator.getAuthenticatorId())); authConfig.setDisplayName(getDisplayNameOfAuthenticator(authConfig.getName())); authConfig.setEnabled(authenticator.getIsEnabled()); - /* Resolve definedBy type: If there is authenticator by same name and its type is system: SYSTEM. - If not: USER. */ - FederatedAuthenticatorConfig authenticatorConfig = ApplicationAuthenticatorService.getInstance() - .getFederatedAuthenticatorByName(authenticator.getAuthenticatorId()); - if (authenticatorConfig != null && - DefinedByType.SYSTEM.equals(authenticatorConfig.getDefinedByType())) { - authConfig.setDefinedByType(DefinedByType.SYSTEM); - } else { - authConfig.setDefinedByType(DefinedByType.USER); - } + authConfig.setDefinedByType(resolveDefinedByType(authConfig.getName())); List authProperties = authenticator.getProperties(); if (IdentityApplicationConstants.Authenticator.SAML2SSO.FED_AUTH_NAME.equals(authConfig.getName())) { @@ -2851,15 +2842,7 @@ private FederatedAuthenticatorConfig createFederatedAuthenticatorConfig(String f authConfig.setName(authenticatorName); authConfig.setDisplayName(getDisplayNameOfAuthenticator(authenticatorName)); authConfig.setEnabled(authenticator.getIsEnabled()); - // Resolve definedBy type: If there is authenticator by same name and its type is system: SYSTEM. If not: USER. - FederatedAuthenticatorConfig authenticatorConfig = ApplicationAuthenticatorService.getInstance() - .getFederatedAuthenticatorByName(authenticatorName); - if (authenticatorConfig != null && - DefinedByType.SYSTEM.equals(authenticatorConfig.getDefinedByType())) { - authConfig.setDefinedByType(DefinedByType.SYSTEM); - } else { - authConfig.setDefinedByType(DefinedByType.USER); - } + authConfig.setDefinedByType(resolveDefinedByType(authenticatorName)); List authProperties = authenticator.getProperties(); if (IdentityApplicationConstants.Authenticator.SAML2SSO.FED_AUTH_NAME.equals(authenticatorName)) { validateSamlMetadata(authProperties); @@ -2873,6 +2856,18 @@ private FederatedAuthenticatorConfig createFederatedAuthenticatorConfig(String f return authConfig; } + private DefinedByType resolveDefinedByType(String authenticatorName) { + + // Resolve definedBy type: If there is authenticator by same name and its type is system: SYSTEM. If not: USER. + FederatedAuthenticatorConfig authenticatorConfig = ApplicationAuthenticatorService.getInstance() + .getFederatedAuthenticatorByName(authenticatorName); + if (authenticatorConfig != null && + DefinedByType.SYSTEM.equals(authenticatorConfig.getDefinedByType())) { + return DefinedByType.SYSTEM; + } + return DefinedByType.USER; + } + /** * Verify if scopes have not been set in both Scopes field and Additional Query Parameters field * From 6883465231abca3cb29f7af007caa49d4247aea6 Mon Sep 17 00:00:00 2001 From: thisarawelmilla Date: Fri, 11 Oct 2024 16:30:08 +0530 Subject: [PATCH 3/5] Addressed comments --- .../ServerAuthenticatorManagementService.java | 7 +++- .../v1/core/ServerIdpManagementService.java | 40 ++++++++++++------- 2 files changed, 32 insertions(+), 15 deletions(-) diff --git a/components/org.wso2.carbon.identity.api.server.authenticators/org.wso2.carbon.identity.api.server.authenticators.v1/src/main/java/org/wso2/carbon/identity/api/server/authenticators/v1/core/ServerAuthenticatorManagementService.java b/components/org.wso2.carbon.identity.api.server.authenticators/org.wso2.carbon.identity.api.server.authenticators.v1/src/main/java/org/wso2/carbon/identity/api/server/authenticators/v1/core/ServerAuthenticatorManagementService.java index 88f1c6a64b..c888cfafdc 100644 --- a/components/org.wso2.carbon.identity.api.server.authenticators/org.wso2.carbon.identity.api.server.authenticators.v1/src/main/java/org/wso2/carbon/identity/api/server/authenticators/v1/core/ServerAuthenticatorManagementService.java +++ b/components/org.wso2.carbon.identity.api.server.authenticators/org.wso2.carbon.identity.api.server.authenticators.v1/src/main/java/org/wso2/carbon/identity/api/server/authenticators/v1/core/ServerAuthenticatorManagementService.java @@ -422,7 +422,11 @@ private void addIdp(IdentityProvider identityProvider, List authe authenticator.setType(Authenticator.TypeEnum.FEDERATED); authenticator.setImage(identityProvider.getImageUrl()); authenticator.setDescription(identityProvider.getIdentityProviderDescription()); - // Only older existing IDP has multiple federated authenticator, + + /* For the /authenticators APIs, per IDP have an item in the response payload, not per federated authenticator + within the IDP. If an IDP has more than one federated authenticator, it is considered as an existing older + authenticator and should always be classified as a SYSTEM type. Otherwise, it can be classified as either + SYSTEM or USER, depending on the 'definedBy' type of the federated authenticator. */ if (identityProvider.getFederatedAuthenticatorConfigs().length == 1) { DefinedByType definedByType = identityProvider.getFederatedAuthenticatorConfigs()[0].getDefinedByType(); @@ -430,6 +434,7 @@ private void addIdp(IdentityProvider identityProvider, List authe } else { authenticator.definedBy(Authenticator.DefinedByEnum.SYSTEM); } + if (CollectionUtils.isNotEmpty(configTagsListDistinct)) { authenticator.setTags(configTagsListDistinct); } diff --git a/components/org.wso2.carbon.identity.api.server.idp/org.wso2.carbon.identity.api.server.idp.v1/src/main/java/org/wso2/carbon/identity/api/server/idp/v1/core/ServerIdpManagementService.java b/components/org.wso2.carbon.identity.api.server.idp/org.wso2.carbon.identity.api.server.idp.v1/src/main/java/org/wso2/carbon/identity/api/server/idp/v1/core/ServerIdpManagementService.java index c512eaebbd..b1610138a7 100644 --- a/components/org.wso2.carbon.identity.api.server.idp/org.wso2.carbon.identity.api.server.idp.v1/src/main/java/org/wso2/carbon/identity/api/server/idp/v1/core/ServerIdpManagementService.java +++ b/components/org.wso2.carbon.identity.api.server.idp/org.wso2.carbon.identity.api.server.idp.v1/src/main/java/org/wso2/carbon/identity/api/server/idp/v1/core/ServerIdpManagementService.java @@ -674,8 +674,7 @@ public FederatedAuthenticatorListResponse updateFederatedAuthenticators(String i // Need to create a clone, since modifying the fields of the original object, will modify the cached // IDP object. IdentityProvider idpToUpdate = createIdPClone(idp); - updateFederatedAuthenticatorConfig(idpToUpdate, authenticatorRequest); - + updateFederatedAuthenticatorConfig(idpToUpdate, authenticatorRequest, false); IdentityProvider updatedIdp = IdentityProviderServiceHolder.getIdentityProviderManager() .updateIdPByResourceId( idpId, idpToUpdate, ContextLoader.getTenantDomainFromContext()); @@ -684,7 +683,6 @@ public FederatedAuthenticatorListResponse updateFederatedAuthenticators(String i throw handleIdPException(e, Constants.ErrorMessage.ERROR_CODE_ERROR_UPDATING_IDP, StringUtils.EMPTY); } } - /** * Update federated authenticator of and IDP. * @@ -709,7 +707,7 @@ public FederatedAuthenticator updateFederatedAuthenticator(String idpId, String IdentityProvider idpToUpdate = createIdPClone(idp); // Create new FederatedAuthenticatorConfig to store the federated authenticator information. - FederatedAuthenticatorConfig authConfig = createFederatedAuthenticatorConfig(federatedAuthenticatorId, + FederatedAuthenticatorConfig authConfig = updateFederatedAuthenticatorConfig(federatedAuthenticatorId, authenticator); FederatedAuthenticatorConfig[] fedAuthConfigs = createFederatedAuthenticatorArrayClone (federatedAuthenticatorId, idp.getFederatedAuthenticatorConfigs()); @@ -1760,7 +1758,7 @@ private MetaOutboundConnector createMetaOutboundConnector(ProvisioningConnectorC } private void updateFederatedAuthenticatorConfig(IdentityProvider idp, FederatedAuthenticatorRequest - federatedAuthenticatorRequest) { + federatedAuthenticatorRequest, boolean isNewFederatedAuthenticator) { if (federatedAuthenticatorRequest != null) { List federatedAuthenticators = federatedAuthenticatorRequest.getAuthenticators(); @@ -1772,7 +1770,8 @@ private void updateFederatedAuthenticatorConfig(IdentityProvider idp, FederatedA authConfig.setName(base64URLDecode(authenticator.getAuthenticatorId())); authConfig.setDisplayName(getDisplayNameOfAuthenticator(authConfig.getName())); authConfig.setEnabled(authenticator.getIsEnabled()); - authConfig.setDefinedByType(resolveDefinedByType(authConfig.getName())); + authConfig.setDefinedByType(resolveDefinedByType(authConfig.getName(), + authenticator.getDefinedBy().toString(), isNewFederatedAuthenticator)); List authProperties = authenticator.getProperties(); if (IdentityApplicationConstants.Authenticator.SAML2SSO.FED_AUTH_NAME.equals(authConfig.getName())) { @@ -2112,7 +2111,7 @@ private IdentityProvider createIDP(IdentityProviderPOSTRequest identityProviderP } idp.setFederationHub(identityProviderPOSTRequest.getIsFederationHub()); - updateFederatedAuthenticatorConfig(idp, identityProviderPOSTRequest.getFederatedAuthenticators()); + updateFederatedAuthenticatorConfig(idp, identityProviderPOSTRequest.getFederatedAuthenticators(), true); if (identityProviderPOSTRequest.getProvisioning() != null) { updateOutboundConnectorConfig(idp, identityProviderPOSTRequest.getProvisioning().getOutboundConnectors()); updateJIT(idp, identityProviderPOSTRequest.getProvisioning().getJit()); @@ -2833,7 +2832,7 @@ private ProvisioningConnectorConfig createProvisioningConnectorConfig(String out * @param authenticator Internal federated authenticator config. * @return Federated authenticator config of the specified ID. */ - private FederatedAuthenticatorConfig createFederatedAuthenticatorConfig(String federatedAuthenticatorId, + private FederatedAuthenticatorConfig updateFederatedAuthenticatorConfig(String federatedAuthenticatorId, FederatedAuthenticatorPUTRequest authenticator) { @@ -2842,7 +2841,8 @@ private FederatedAuthenticatorConfig createFederatedAuthenticatorConfig(String f authConfig.setName(authenticatorName); authConfig.setDisplayName(getDisplayNameOfAuthenticator(authenticatorName)); authConfig.setEnabled(authenticator.getIsEnabled()); - authConfig.setDefinedByType(resolveDefinedByType(authenticatorName)); + authConfig.setDefinedByType(resolveDefinedByType(authenticatorName, + authenticator.getDefinedBy().toString(), false)); List authProperties = authenticator.getProperties(); if (IdentityApplicationConstants.Authenticator.SAML2SSO.FED_AUTH_NAME.equals(authenticatorName)) { validateSamlMetadata(authProperties); @@ -2856,14 +2856,26 @@ private FederatedAuthenticatorConfig createFederatedAuthenticatorConfig(String f return authConfig; } - private DefinedByType resolveDefinedByType(String authenticatorName) { + private DefinedByType resolveDefinedByType( + String authenticatorName, String definedByType, boolean isNewFederatedAuthenticator) { - // Resolve definedBy type: If there is authenticator by same name and its type is system: SYSTEM. If not: USER. + /* For new federated authenticators: + If 'definedByType' is not null, use the value provided in the request payload. If not, default to SYSTEM. */ + if (isNewFederatedAuthenticator) { + if (definedByType != null) { + return DefinedByType.valueOf(definedByType); + } else { + return DefinedByType.SYSTEM; + } + } + /* For existing federated authenticators, disregard any value provided in the request payload. + Instead, resolve and retrieve the 'definedBy' type of the corresponding existing authenticator. + If the authenticator config is present in the ApplicationAuthenticatorService list, return its type, + if not return USER. */ FederatedAuthenticatorConfig authenticatorConfig = ApplicationAuthenticatorService.getInstance() .getFederatedAuthenticatorByName(authenticatorName); - if (authenticatorConfig != null && - DefinedByType.SYSTEM.equals(authenticatorConfig.getDefinedByType())) { - return DefinedByType.SYSTEM; + if (authenticatorConfig != null) { + return DefinedByType.valueOf(authenticatorConfig.getDefinedByType().toString()); } return DefinedByType.USER; } From 2797f393f061c65cd33c8d383aa4b2e98ca08ed8 Mon Sep 17 00:00:00 2001 From: thisarawelmilla Date: Fri, 18 Oct 2024 10:23:57 +0530 Subject: [PATCH 4/5] Bump carbon.identity.framework.version. --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index bbe2397226..bacae97a94 100644 --- a/pom.xml +++ b/pom.xml @@ -803,7 +803,7 @@ 1.4 1.2.4 1.10.6 - 7.5.0 + 7.5.71 3.0.5 1.12.0 **/gen/**/* From 17f7a54dedc82241ef30eceab3157c526bb9a168 Mon Sep 17 00:00:00 2001 From: thisarawelmilla Date: Fri, 18 Oct 2024 23:04:04 +0530 Subject: [PATCH 5/5] Fix null pointer exception. --- .../idp/v1/core/ServerIdpManagementService.java | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/components/org.wso2.carbon.identity.api.server.idp/org.wso2.carbon.identity.api.server.idp.v1/src/main/java/org/wso2/carbon/identity/api/server/idp/v1/core/ServerIdpManagementService.java b/components/org.wso2.carbon.identity.api.server.idp/org.wso2.carbon.identity.api.server.idp.v1/src/main/java/org/wso2/carbon/identity/api/server/idp/v1/core/ServerIdpManagementService.java index b1610138a7..bac516e2d9 100644 --- a/components/org.wso2.carbon.identity.api.server.idp/org.wso2.carbon.identity.api.server.idp.v1/src/main/java/org/wso2/carbon/identity/api/server/idp/v1/core/ServerIdpManagementService.java +++ b/components/org.wso2.carbon.identity.api.server.idp/org.wso2.carbon.identity.api.server.idp.v1/src/main/java/org/wso2/carbon/identity/api/server/idp/v1/core/ServerIdpManagementService.java @@ -1770,8 +1770,14 @@ private void updateFederatedAuthenticatorConfig(IdentityProvider idp, FederatedA authConfig.setName(base64URLDecode(authenticator.getAuthenticatorId())); authConfig.setDisplayName(getDisplayNameOfAuthenticator(authConfig.getName())); authConfig.setEnabled(authenticator.getIsEnabled()); + + String definedByType = null; + if (authenticator.getDefinedBy() != null) { + definedByType = authenticator.getDefinedBy().toString(); + } authConfig.setDefinedByType(resolveDefinedByType(authConfig.getName(), - authenticator.getDefinedBy().toString(), isNewFederatedAuthenticator)); + definedByType, isNewFederatedAuthenticator)); + List authProperties = authenticator.getProperties(); if (IdentityApplicationConstants.Authenticator.SAML2SSO.FED_AUTH_NAME.equals(authConfig.getName())) { @@ -2841,8 +2847,13 @@ private FederatedAuthenticatorConfig updateFederatedAuthenticatorConfig(String f authConfig.setName(authenticatorName); authConfig.setDisplayName(getDisplayNameOfAuthenticator(authenticatorName)); authConfig.setEnabled(authenticator.getIsEnabled()); - authConfig.setDefinedByType(resolveDefinedByType(authenticatorName, - authenticator.getDefinedBy().toString(), false)); + + String definedByType = null; + if (authenticator.getDefinedBy() != null) { + definedByType = authenticator.getDefinedBy().toString(); + } + authConfig.setDefinedByType(resolveDefinedByType(authenticatorName, definedByType, false)); + List authProperties = authenticator.getProperties(); if (IdentityApplicationConstants.Authenticator.SAML2SSO.FED_AUTH_NAME.equals(authenticatorName)) { validateSamlMetadata(authProperties);