Skip to content

Commit

Permalink
Add new authenticator property: DefinedBy.
Browse files Browse the repository at this point in the history
  • Loading branch information
Thisara-Welmilla committed Oct 4, 2024
1 parent 8a758da commit 4996186
Show file tree
Hide file tree
Showing 15 changed files with 534 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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) &&
Expand All @@ -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
Expand All @@ -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");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -421,6 +422,14 @@ private void addIdp(IdentityProvider identityProvider, List<Authenticator> 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);
}
Expand Down Expand Up @@ -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));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,11 @@ components:
isEnabled:
type: boolean
example: true
definedBy:
type: string
enum:
- SYSTEM
- USER
type:
type: string
enum:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -238,14 +290,15 @@ 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);
}

@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
Expand All @@ -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");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -224,14 +276,15 @@ 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);
}

@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
Expand All @@ -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");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -704,6 +704,8 @@ private List<AuthenticatorListItem> 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));
Expand All @@ -722,6 +724,7 @@ private List<AuthenticatorListItem> 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));
Expand Down Expand Up @@ -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 {
Expand Down
Loading

0 comments on commit 4996186

Please sign in to comment.