From a2fb35cbeb8bb3d48370cb45c91afe9b195dabd9 Mon Sep 17 00:00:00 2001 From: Thisara-Welmilla Date: Thu, 7 Nov 2024 12:09:52 +0530 Subject: [PATCH] Update APIs to support custom authentication management. --- .../idp/v1/model/AuthenticationType.java | 166 +++++++++++ .../api/server/idp/v1/model/Endpoint.java | 120 ++++++++ .../idp/v1/model/FederatedAuthenticator.java | 26 +- .../FederatedAuthenticatorPUTRequest.java | 26 +- .../FederatedUserDefinedAuthenticator.java | 271 ++++++++++++++++++ ...tedUserDefinedAuthenticatorPUTRequest.java | 162 +++++++++++ .../v1/model/MetaFederatedAuthenticator.java | 26 +- .../v1/core/ServerIdpManagementService.java | 93 +++++- .../src/main/resources/idp.yaml | 36 +++ 9 files changed, 908 insertions(+), 18 deletions(-) create mode 100644 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/AuthenticationType.java create mode 100644 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/Endpoint.java create mode 100644 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/FederatedUserDefinedAuthenticator.java create mode 100644 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/FederatedUserDefinedAuthenticatorPUTRequest.java 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/AuthenticationType.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/AuthenticationType.java new file mode 100644 index 0000000000..1b2660df61 --- /dev/null +++ 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/AuthenticationType.java @@ -0,0 +1,166 @@ +/* + * Copyright (c) 2024, WSO2 LLC. (http://www.wso2.com). + * + * WSO2 LLC. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.wso2.carbon.identity.api.server.idp.v1.model; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonCreator; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import javax.validation.constraints.*; + + +import io.swagger.annotations.*; +import java.util.Objects; +import javax.validation.Valid; +import javax.xml.bind.annotation.*; + +public class AuthenticationType { + + +@XmlType(name="TypeEnum") +@XmlEnum(String.class) +public enum TypeEnum { + + @XmlEnumValue("NONE") NONE(String.valueOf("NONE")), @XmlEnumValue("BEARER") BEARER(String.valueOf("BEARER")), @XmlEnumValue("API_KEY") API_KEY(String.valueOf("API_KEY")), @XmlEnumValue("BASIC") BASIC(String.valueOf("BASIC")); + + + private String value; + + TypeEnum(String v) { + value = v; + } + + public String value() { + return value; + } + + @Override + public String toString() { + return String.valueOf(value); + } + + public static TypeEnum fromValue(String value) { + for (TypeEnum b : TypeEnum.values()) { + if (b.value.equals(value)) { + return b; + } + } + throw new IllegalArgumentException("Unexpected value '" + value + "'"); + } +} + + private TypeEnum type; + private Map properties = new HashMap<>(); + + + /** + **/ + public AuthenticationType type(TypeEnum type) { + + this.type = type; + return this; + } + + @ApiModelProperty(example = "BASIC", required = true, value = "") + @JsonProperty("type") + @Valid + @NotNull(message = "Property type cannot be null.") + + public TypeEnum getType() { + return type; + } + public void setType(TypeEnum type) { + this.type = type; + } + + /** + **/ + public AuthenticationType properties(Map properties) { + + this.properties = properties; + return this; + } + + @ApiModelProperty(example = "{\"username\":\"auth_username\",\"password\":\"auth_password\"}", required = true, value = "") + @JsonProperty("properties") + @Valid + @NotNull(message = "Property properties cannot be null.") + + public Map getProperties() { + return properties; + } + public void setProperties(Map properties) { + this.properties = properties; + } + + + public AuthenticationType putPropertiesItem(String key, Object propertiesItem) { + this.properties.put(key, propertiesItem); + return this; + } + + + + @Override + public boolean equals(java.lang.Object o) { + + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + AuthenticationType authenticationType = (AuthenticationType) o; + return Objects.equals(this.type, authenticationType.type) && + Objects.equals(this.properties, authenticationType.properties); + } + + @Override + public int hashCode() { + return Objects.hash(type, properties); + } + + @Override + public String toString() { + + StringBuilder sb = new StringBuilder(); + sb.append("class AuthenticationType {\n"); + + sb.append(" type: ").append(toIndentedString(type)).append("\n"); + sb.append(" properties: ").append(toIndentedString(properties)).append("\n"); + sb.append("}"); + return sb.toString(); + } + + /** + * Convert the given object to string with each line indented by 4 spaces + * (except the first line). + */ + private String toIndentedString(java.lang.Object o) { + + if (o == null) { + return "null"; + } + return o.toString().replace("\n", "\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/Endpoint.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/Endpoint.java new file mode 100644 index 0000000000..477bb8c8ad --- /dev/null +++ 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/Endpoint.java @@ -0,0 +1,120 @@ +/* + * Copyright (c) 2024, WSO2 LLC. (http://www.wso2.com). + * + * WSO2 LLC. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.wso2.carbon.identity.api.server.idp.v1.model; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonCreator; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import org.wso2.carbon.identity.api.server.idp.v1.model.AuthenticationType; +import javax.validation.constraints.*; + + +import io.swagger.annotations.*; +import java.util.Objects; +import javax.validation.Valid; +import javax.xml.bind.annotation.*; + +public class Endpoint { + + private String uri; + private AuthenticationType authentication; + + /** + **/ + public Endpoint uri(String uri) { + + this.uri = uri; + return this; + } + + @ApiModelProperty(example = "https://abc.com/token", value = "") + @JsonProperty("uri") + @Valid @Pattern(regexp="^https?://.+") + public String getUri() { + return uri; + } + public void setUri(String uri) { + this.uri = uri; + } + + /** + **/ + public Endpoint authentication(AuthenticationType authentication) { + + this.authentication = authentication; + return this; + } + + @ApiModelProperty(value = "") + @JsonProperty("authentication") + @Valid + public AuthenticationType getAuthentication() { + return authentication; + } + public void setAuthentication(AuthenticationType authentication) { + this.authentication = authentication; + } + + + + @Override + public boolean equals(java.lang.Object o) { + + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + Endpoint endpoint = (Endpoint) o; + return Objects.equals(this.uri, endpoint.uri) && + Objects.equals(this.authentication, endpoint.authentication); + } + + @Override + public int hashCode() { + return Objects.hash(uri, authentication); + } + + @Override + public String toString() { + + StringBuilder sb = new StringBuilder(); + sb.append("class Endpoint {\n"); + + sb.append(" uri: ").append(toIndentedString(uri)).append("\n"); + sb.append(" authentication: ").append(toIndentedString(authentication)).append("\n"); + sb.append("}"); + return sb.toString(); + } + + /** + * Convert the given object to string with each line indented by 4 spaces + * (except the first line). + */ + private String toIndentedString(java.lang.Object o) { + + if (o == null) { + return "null"; + } + return o.toString().replace("\n", "\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/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 5996d10619..6ceecbd085 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 @@ -22,6 +22,7 @@ import io.swagger.annotations.ApiModelProperty; import java.util.ArrayList; import java.util.List; +import org.wso2.carbon.identity.api.server.idp.v1.model.Endpoint; import org.wso2.carbon.identity.api.server.idp.v1.model.Property; import javax.validation.constraints.*; @@ -75,6 +76,7 @@ public static DefinedByEnum fromValue(String value) { private List properties = null; + private Endpoint endpoint; /** **/ @@ -220,7 +222,25 @@ public FederatedAuthenticator addPropertiesItem(Property propertiesItem) { return this; } + /** + **/ + public FederatedAuthenticator endpoint(Endpoint endpoint) { + + this.endpoint = endpoint; + return this; + } + @ApiModelProperty(value = "") + @JsonProperty("endpoint") + @Valid + public Endpoint getEndpoint() { + return endpoint; + } + public void setEndpoint(Endpoint endpoint) { + this.endpoint = endpoint; + } + + @Override public boolean equals(java.lang.Object o) { @@ -238,12 +258,13 @@ public boolean equals(java.lang.Object o) { Objects.equals(this.definedBy, federatedAuthenticator.definedBy) && Objects.equals(this.isDefault, federatedAuthenticator.isDefault) && Objects.equals(this.tags, federatedAuthenticator.tags) && - Objects.equals(this.properties, federatedAuthenticator.properties); + Objects.equals(this.properties, federatedAuthenticator.properties) && + Objects.equals(this.endpoint, federatedAuthenticator.endpoint); } @Override public int hashCode() { - return Objects.hash(authenticatorId, name, isEnabled, definedBy, isDefault, tags, properties); + return Objects.hash(authenticatorId, name, isEnabled, definedBy, isDefault, tags, properties, endpoint); } @Override @@ -259,6 +280,7 @@ public String toString() { sb.append(" isDefault: ").append(toIndentedString(isDefault)).append("\n"); sb.append(" tags: ").append(toIndentedString(tags)).append("\n"); sb.append(" properties: ").append(toIndentedString(properties)).append("\n"); + sb.append(" endpoint: ").append(toIndentedString(endpoint)).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/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 685579c64a..db8b737efb 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 @@ -22,6 +22,7 @@ import io.swagger.annotations.ApiModelProperty; import java.util.ArrayList; import java.util.List; +import org.wso2.carbon.identity.api.server.idp.v1.model.Endpoint; import org.wso2.carbon.identity.api.server.idp.v1.model.Property; import javax.validation.constraints.*; @@ -73,6 +74,7 @@ public static DefinedByEnum fromValue(String value) { private DefinedByEnum definedBy; private List properties = null; + private Endpoint endpoint; /** **/ @@ -190,7 +192,25 @@ public FederatedAuthenticatorPUTRequest addPropertiesItem(Property propertiesIte return this; } + /** + **/ + public FederatedAuthenticatorPUTRequest endpoint(Endpoint endpoint) { + + this.endpoint = endpoint; + return this; + } + @ApiModelProperty(value = "") + @JsonProperty("endpoint") + @Valid + public Endpoint getEndpoint() { + return endpoint; + } + public void setEndpoint(Endpoint endpoint) { + this.endpoint = endpoint; + } + + @Override public boolean equals(java.lang.Object o) { @@ -207,12 +227,13 @@ public boolean equals(java.lang.Object o) { Objects.equals(this.isEnabled, federatedAuthenticatorPUTRequest.isEnabled) && Objects.equals(this.isDefault, federatedAuthenticatorPUTRequest.isDefault) && Objects.equals(this.definedBy, federatedAuthenticatorPUTRequest.definedBy) && - Objects.equals(this.properties, federatedAuthenticatorPUTRequest.properties); + Objects.equals(this.properties, federatedAuthenticatorPUTRequest.properties) && + Objects.equals(this.endpoint, federatedAuthenticatorPUTRequest.endpoint); } @Override public int hashCode() { - return Objects.hash(authenticatorId, name, isEnabled, isDefault, definedBy, properties); + return Objects.hash(authenticatorId, name, isEnabled, isDefault, definedBy, properties, endpoint); } @Override @@ -227,6 +248,7 @@ public String toString() { 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(" endpoint: ").append(toIndentedString(endpoint)).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/FederatedUserDefinedAuthenticator.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/FederatedUserDefinedAuthenticator.java new file mode 100644 index 0000000000..465eb5d546 --- /dev/null +++ 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/FederatedUserDefinedAuthenticator.java @@ -0,0 +1,271 @@ +/* + * Copyright (c) 2024, WSO2 LLC. (http://www.wso2.com). + * + * WSO2 LLC. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.wso2.carbon.identity.api.server.idp.v1.model; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonCreator; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import java.util.ArrayList; +import java.util.List; +import org.wso2.carbon.identity.api.server.idp.v1.model.Endpoint; +import javax.validation.constraints.*; + + +import io.swagger.annotations.*; +import java.util.Objects; +import javax.validation.Valid; +import javax.xml.bind.annotation.*; + +public class FederatedUserDefinedAuthenticator { + + private String authenticatorId; + private String name; + private Boolean isEnabled = false; + +@XmlType(name="DefinedByEnum") +@XmlEnum(String.class) +public enum DefinedByEnum { + + @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; + + private Endpoint endpoint; + + /** + **/ + public FederatedUserDefinedAuthenticator authenticatorId(String authenticatorId) { + + this.authenticatorId = authenticatorId; + return this; + } + + @ApiModelProperty(example = "Y3VzdG9tQXV0aGVudGljYXRvcg", required = true, value = "") + @JsonProperty("authenticatorId") + @Valid + @NotNull(message = "Property authenticatorId cannot be null.") + + public String getAuthenticatorId() { + return authenticatorId; + } + public void setAuthenticatorId(String authenticatorId) { + this.authenticatorId = authenticatorId; + } + + /** + **/ + public FederatedUserDefinedAuthenticator name(String name) { + + this.name = name; + return this; + } + + @ApiModelProperty(example = "customAuthenticator", value = "") + @JsonProperty("name") + @Valid + public String getName() { + return name; + } + public void setName(String name) { + this.name = name; + } + + /** + **/ + public FederatedUserDefinedAuthenticator isEnabled(Boolean isEnabled) { + + this.isEnabled = isEnabled; + return this; + } + + @ApiModelProperty(example = "true", value = "") + @JsonProperty("isEnabled") + @Valid + public Boolean getIsEnabled() { + return isEnabled; + } + public void setIsEnabled(Boolean isEnabled) { + this.isEnabled = isEnabled; + } + + /** + **/ + public FederatedUserDefinedAuthenticator 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 FederatedUserDefinedAuthenticator isDefault(Boolean isDefault) { + + this.isDefault = isDefault; + return this; + } + + @ApiModelProperty(value = "") + @JsonProperty("isDefault") + @Valid + public Boolean getIsDefault() { + return isDefault; + } + public void setIsDefault(Boolean isDefault) { + this.isDefault = isDefault; + } + + /** + **/ + public FederatedUserDefinedAuthenticator tags(List tags) { + + this.tags = tags; + return this; + } + + @ApiModelProperty(example = "[\"Custom\"]", value = "") + @JsonProperty("tags") + @Valid + public List getTags() { + return tags; + } + public void setTags(List tags) { + this.tags = tags; + } + + public FederatedUserDefinedAuthenticator addTagsItem(String tagsItem) { + if (this.tags == null) { + this.tags = new ArrayList<>(); + } + this.tags.add(tagsItem); + return this; + } + + /** + **/ + public FederatedUserDefinedAuthenticator endpoint(Endpoint endpoint) { + + this.endpoint = endpoint; + return this; + } + + @ApiModelProperty(value = "") + @JsonProperty("endpoint") + @Valid + public Endpoint getEndpoint() { + return endpoint; + } + public void setEndpoint(Endpoint endpoint) { + this.endpoint = endpoint; + } + + + + @Override + public boolean equals(java.lang.Object o) { + + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + FederatedUserDefinedAuthenticator federatedUserDefinedAuthenticator = (FederatedUserDefinedAuthenticator) o; + return Objects.equals(this.authenticatorId, federatedUserDefinedAuthenticator.authenticatorId) && + Objects.equals(this.name, federatedUserDefinedAuthenticator.name) && + Objects.equals(this.isEnabled, federatedUserDefinedAuthenticator.isEnabled) && + Objects.equals(this.definedBy, federatedUserDefinedAuthenticator.definedBy) && + Objects.equals(this.isDefault, federatedUserDefinedAuthenticator.isDefault) && + Objects.equals(this.tags, federatedUserDefinedAuthenticator.tags) && + Objects.equals(this.endpoint, federatedUserDefinedAuthenticator.endpoint); + } + + @Override + public int hashCode() { + return Objects.hash(authenticatorId, name, isEnabled, definedBy, isDefault, tags, endpoint); + } + + @Override + public String toString() { + + StringBuilder sb = new StringBuilder(); + sb.append("class FederatedUserDefinedAuthenticator {\n"); + + 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(" endpoint: ").append(toIndentedString(endpoint)).append("\n"); + sb.append("}"); + return sb.toString(); + } + + /** + * Convert the given object to string with each line indented by 4 spaces + * (except the first line). + */ + private String toIndentedString(java.lang.Object o) { + + if (o == null) { + return "null"; + } + return o.toString().replace("\n", "\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/FederatedUserDefinedAuthenticatorPUTRequest.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/FederatedUserDefinedAuthenticatorPUTRequest.java new file mode 100644 index 0000000000..5825ae4e4e --- /dev/null +++ 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/FederatedUserDefinedAuthenticatorPUTRequest.java @@ -0,0 +1,162 @@ +/* + * Copyright (c) 2024, WSO2 LLC. (http://www.wso2.com). + * + * WSO2 LLC. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.wso2.carbon.identity.api.server.idp.v1.model; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonCreator; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import org.wso2.carbon.identity.api.server.idp.v1.model.Endpoint; +import javax.validation.constraints.*; + + +import io.swagger.annotations.*; +import java.util.Objects; +import javax.validation.Valid; +import javax.xml.bind.annotation.*; + +public class FederatedUserDefinedAuthenticatorPUTRequest { + + private String authenticatorId; + private Boolean isEnabled = false; + private Boolean isDefault = false; + private Endpoint endpoint; + + /** + **/ + public FederatedUserDefinedAuthenticatorPUTRequest authenticatorId(String authenticatorId) { + + this.authenticatorId = authenticatorId; + return this; + } + + @ApiModelProperty(value = "") + @JsonProperty("authenticatorId") + @Valid + public String getAuthenticatorId() { + return authenticatorId; + } + public void setAuthenticatorId(String authenticatorId) { + this.authenticatorId = authenticatorId; + } + + /** + **/ + public FederatedUserDefinedAuthenticatorPUTRequest isEnabled(Boolean isEnabled) { + + this.isEnabled = isEnabled; + return this; + } + + @ApiModelProperty(example = "true", value = "") + @JsonProperty("isEnabled") + @Valid + public Boolean getIsEnabled() { + return isEnabled; + } + public void setIsEnabled(Boolean isEnabled) { + this.isEnabled = isEnabled; + } + + /** + **/ + public FederatedUserDefinedAuthenticatorPUTRequest isDefault(Boolean isDefault) { + + this.isDefault = isDefault; + return this; + } + + @ApiModelProperty(example = "false", value = "") + @JsonProperty("isDefault") + @Valid + public Boolean getIsDefault() { + return isDefault; + } + public void setIsDefault(Boolean isDefault) { + this.isDefault = isDefault; + } + + /** + **/ + public FederatedUserDefinedAuthenticatorPUTRequest endpoint(Endpoint endpoint) { + + this.endpoint = endpoint; + return this; + } + + @ApiModelProperty(value = "") + @JsonProperty("endpoint") + @Valid + public Endpoint getEndpoint() { + return endpoint; + } + public void setEndpoint(Endpoint endpoint) { + this.endpoint = endpoint; + } + + + + @Override + public boolean equals(java.lang.Object o) { + + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + FederatedUserDefinedAuthenticatorPUTRequest federatedUserDefinedAuthenticatorPUTRequest = (FederatedUserDefinedAuthenticatorPUTRequest) o; + return Objects.equals(this.authenticatorId, federatedUserDefinedAuthenticatorPUTRequest.authenticatorId) && + Objects.equals(this.isEnabled, federatedUserDefinedAuthenticatorPUTRequest.isEnabled) && + Objects.equals(this.isDefault, federatedUserDefinedAuthenticatorPUTRequest.isDefault) && + Objects.equals(this.endpoint, federatedUserDefinedAuthenticatorPUTRequest.endpoint); + } + + @Override + public int hashCode() { + return Objects.hash(authenticatorId, isEnabled, isDefault, endpoint); + } + + @Override + public String toString() { + + StringBuilder sb = new StringBuilder(); + sb.append("class FederatedUserDefinedAuthenticatorPUTRequest {\n"); + + sb.append(" authenticatorId: ").append(toIndentedString(authenticatorId)).append("\n"); + sb.append(" isEnabled: ").append(toIndentedString(isEnabled)).append("\n"); + sb.append(" isDefault: ").append(toIndentedString(isDefault)).append("\n"); + sb.append(" endpoint: ").append(toIndentedString(endpoint)).append("\n"); + sb.append("}"); + return sb.toString(); + } + + /** + * Convert the given object to string with each line indented by 4 spaces + * (except the first line). + */ + private String toIndentedString(java.lang.Object o) { + + if (o == null) { + return "null"; + } + return o.toString().replace("\n", "\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/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 46483c4c83..b3591fdc82 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 @@ -22,6 +22,7 @@ import io.swagger.annotations.ApiModelProperty; import java.util.ArrayList; import java.util.List; +import org.wso2.carbon.identity.api.server.idp.v1.model.Endpoint; import org.wso2.carbon.identity.api.server.idp.v1.model.MetaProperty; import javax.validation.constraints.*; @@ -74,6 +75,7 @@ public static DefinedByEnum fromValue(String value) { private List properties = null; + private Endpoint endpoint; /** **/ @@ -199,7 +201,25 @@ public MetaFederatedAuthenticator addPropertiesItem(MetaProperty propertiesItem) return this; } + /** + **/ + public MetaFederatedAuthenticator endpoint(Endpoint endpoint) { + + this.endpoint = endpoint; + return this; + } + @ApiModelProperty(value = "") + @JsonProperty("endpoint") + @Valid + public Endpoint getEndpoint() { + return endpoint; + } + public void setEndpoint(Endpoint endpoint) { + this.endpoint = endpoint; + } + + @Override public boolean equals(java.lang.Object o) { @@ -216,12 +236,13 @@ public boolean equals(java.lang.Object o) { Objects.equals(this.displayName, metaFederatedAuthenticator.displayName) && Objects.equals(this.definedBy, metaFederatedAuthenticator.definedBy) && Objects.equals(this.tags, metaFederatedAuthenticator.tags) && - Objects.equals(this.properties, metaFederatedAuthenticator.properties); + Objects.equals(this.properties, metaFederatedAuthenticator.properties) && + Objects.equals(this.endpoint, metaFederatedAuthenticator.endpoint); } @Override public int hashCode() { - return Objects.hash(authenticatorId, name, displayName, definedBy, tags, properties); + return Objects.hash(authenticatorId, name, displayName, definedBy, tags, properties, endpoint); } @Override @@ -236,6 +257,7 @@ public String toString() { 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(" endpoint: ").append(toIndentedString(endpoint)).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/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 bac516e2d9..45f99e9052 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 @@ -34,6 +34,8 @@ import org.apache.cxf.jaxrs.ext.search.PrimitiveStatement; import org.apache.cxf.jaxrs.ext.search.SearchCondition; import org.apache.cxf.jaxrs.ext.search.SearchContext; +import org.wso2.carbon.identity.action.management.model.AuthProperty; +import org.wso2.carbon.identity.action.management.model.EndpointConfig; import org.wso2.carbon.identity.api.server.common.ContextLoader; import org.wso2.carbon.identity.api.server.common.FileContent; import org.wso2.carbon.identity.api.server.common.Util; @@ -43,11 +45,13 @@ import org.wso2.carbon.identity.api.server.idp.common.IdentityProviderServiceHolder; import org.wso2.carbon.identity.api.server.idp.v1.model.AssociationRequest; import org.wso2.carbon.identity.api.server.idp.v1.model.AssociationResponse; +import org.wso2.carbon.identity.api.server.idp.v1.model.AuthenticationType; import org.wso2.carbon.identity.api.server.idp.v1.model.Certificate; import org.wso2.carbon.identity.api.server.idp.v1.model.Claim; import org.wso2.carbon.identity.api.server.idp.v1.model.Claims; import org.wso2.carbon.identity.api.server.idp.v1.model.ConnectedApp; import org.wso2.carbon.identity.api.server.idp.v1.model.ConnectedApps; +import org.wso2.carbon.identity.api.server.idp.v1.model.Endpoint; import org.wso2.carbon.identity.api.server.idp.v1.model.FederatedAuthenticator; import org.wso2.carbon.identity.api.server.idp.v1.model.FederatedAuthenticatorListItem; import org.wso2.carbon.identity.api.server.idp.v1.model.FederatedAuthenticatorListResponse; @@ -93,6 +97,8 @@ import org.wso2.carbon.identity.application.common.model.ProvisioningConnectorConfig; 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.model.UserDefinedAuthenticatorEndpointConfig; +import org.wso2.carbon.identity.application.common.model.UserDefinedFederatedAuthenticatorConfig; import org.wso2.carbon.identity.application.common.util.IdentityApplicationConstants; import org.wso2.carbon.identity.base.AuthenticatorPropertyConstants.DefinedByType; import org.wso2.carbon.identity.claim.metadata.mgt.exception.ClaimMetadataException; @@ -2842,17 +2848,30 @@ private FederatedAuthenticatorConfig updateFederatedAuthenticatorConfig(String f FederatedAuthenticatorPUTRequest authenticator) { - FederatedAuthenticatorConfig authConfig = new FederatedAuthenticatorConfig(); String authenticatorName = base64URLDecode(federatedAuthenticatorId); + FederatedAuthenticatorConfig authConfig; + DefinedByType definedByType = null; + if (authenticator.getDefinedBy() != null) { + definedByType = authenticator.getDefinedBy().toString(); + } + definedByType = resolveDefinedByType(authenticatorName, definedByType.toString(), false); + if (definedByType == DefinedByType.SYSTEM) { + authConfig = createSystemDefinedFederatedAuthenticator(authenticator, authenticatorName); + } else { + authConfig = createUserDefinedFederatedAuthenticator(authenticator); + } authConfig.setName(authenticatorName); authConfig.setDisplayName(getDisplayNameOfAuthenticator(authenticatorName)); authConfig.setEnabled(authenticator.getIsEnabled()); - String definedByType = null; - if (authenticator.getDefinedBy() != null) { - definedByType = authenticator.getDefinedBy().toString(); - } - authConfig.setDefinedByType(resolveDefinedByType(authenticatorName, definedByType, false)); + return authConfig; + } + + private FederatedAuthenticatorConfig createSystemDefinedFederatedAuthenticator( + FederatedAuthenticatorPUTRequest authenticator, String authenticatorName) { + + FederatedAuthenticatorConfig authConfig = new FederatedAuthenticatorConfig(); + authConfig.setDefinedByType(DefinedByType.SYSTEM); List authProperties = authenticator.getProperties(); if (IdentityApplicationConstants.Authenticator.SAML2SSO.FED_AUTH_NAME.equals(authenticatorName)) { @@ -2864,9 +2883,26 @@ private FederatedAuthenticatorConfig updateFederatedAuthenticatorConfig(String f } List properties = authProperties.stream().map(propertyToInternal).collect(Collectors.toList()); authConfig.setProperties(properties.toArray(new Property[0])); + return authConfig; } + private UserDefinedFederatedAuthenticatorConfig createUserDefinedFederatedAuthenticator( + FederatedAuthenticatorPUTRequest authenticator) { + + UserDefinedFederatedAuthenticatorConfig userDefinedAuthConfig = new UserDefinedFederatedAuthenticatorConfig(); + userDefinedAuthConfig.setDefinedByType(DefinedByType.USER); + + UserDefinedAuthenticatorEndpointConfig.UserDefinedAuthenticatorEndpointConfigBuilder endpointConfigBuilder = + new UserDefinedAuthenticatorEndpointConfig.UserDefinedAuthenticatorEndpointConfigBuilder(); + endpointConfigBuilder.uri(authenticator.getEndpoint().getUri()); + endpointConfigBuilder.authenticationType(authenticator.getEndpoint().getAuthentication().getType().toString()); + endpointConfigBuilder.authenticationProperties(authenticator.getEndpoint().getAuthentication().getProperties() + .entrySet().stream().collect(Collectors.toMap( + Map.Entry::getKey, entry -> entry.getValue().toString()))); + return userDefinedAuthConfig; + } + private DefinedByType resolveDefinedByType( String authenticatorName, String definedByType, boolean isNewFederatedAuthenticator) { @@ -3046,7 +3082,7 @@ private int getExistingAuthConfigPosition(FederatedAuthenticatorConfig[] fedAuth * @return FederatedAuthenticator. */ private FederatedAuthenticator createFederatedAuthenticator(String authenticatorId, - IdentityProvider identityProvider) { + IdentityProvider identityProvider) throws IdentityProviderManagementServerException { FederatedAuthenticatorConfig[] authConfigs = identityProvider.getFederatedAuthenticatorConfigs(); if (ArrayUtils.isEmpty(authConfigs)) { @@ -3070,8 +3106,6 @@ 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()); @@ -3081,13 +3115,48 @@ private FederatedAuthenticator createFederatedAuthenticator(String authenticator federatedAuthenticator.setTags(Arrays.asList(tags)); } } - List properties = - Arrays.stream(config.getProperties()).map(propertyToExternal).collect(Collectors.toList()); - federatedAuthenticator.setProperties(properties); + + if (DefinedByType.SYSTEM == config.getDefinedByType()) { + federatedAuthenticator.setDefinedBy(FederatedAuthenticator.DefinedByEnum.SYSTEM); + List properties = + Arrays.stream(config.getProperties()).map(propertyToExternal).collect(Collectors.toList()); + federatedAuthenticator.setProperties(properties); + } else { + federatedAuthenticator.setDefinedBy(FederatedAuthenticator.DefinedByEnum.USER); + resolveEndpointConfiguration(federatedAuthenticator, config); + } + } return federatedAuthenticator; } + private void resolveEndpointConfiguration(FederatedAuthenticator authenticator, + FederatedAuthenticatorConfig config) throws IdentityProviderManagementServerException { + + try { + UserDefinedFederatedAuthenticatorConfig userDefinedConfig = + (UserDefinedFederatedAuthenticatorConfig) config; + EndpointConfig endpointConfig = userDefinedConfig.getEndpointConfig().getEndpointConfig(); + + AuthenticationType authenticationType = new AuthenticationType(); + authenticationType.setType(AuthenticationType.TypeEnum.fromValue(endpointConfig + .getAuthentication().getType().toString())); + Map authenticatorProperties = new HashMap<>(); + for (AuthProperty prop: endpointConfig.getAuthentication().getProperties()) { + authenticatorProperties.put(prop.getName(), prop.getValue()); + } + authenticationType.setProperties(authenticatorProperties); + + Endpoint endpoint = new Endpoint(); + endpoint.setAuthentication(authenticationType); + endpoint.setUri(userDefinedConfig.getEndpointConfig().getEndpointConfig().getUri()); + authenticator.setEndpoint(endpoint); + } catch (ClassCastException e) { + throw new IdentityProviderManagementServerException("Error occurred while resolving endpoint " + + "configuration of the authenticator.", e); + } + } + /** * Create external OutboundConnector from Provisioning Config. * 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 9e0df2e09d..53d1d0ee1b 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 @@ -2824,6 +2824,9 @@ components: type: array items: $ref: '#/components/schemas/MetaProperty' + endpoint: + endpoint: + $ref: '#/components/schemas/Endpoint' FederatedAuthenticatorRequest: type: object required: @@ -2877,6 +2880,37 @@ components: type: array items: $ref: '#/components/schemas/Property' + endpoint: + $ref: '#/components/schemas/Endpoint' + Endpoint: + type: object + properties: + uri: + type: string + example: https://abc.com/token + pattern: '^https?://.+' + authentication: + $ref: '#/components/schemas/AuthenticationType' + AuthenticationType: + type: object + required: + - type + - properties + properties: + type: + type: string + enum: + - NONE + - BEARER + - API_KEY + - BASIC + example: BASIC + properties: + type: object + additionalProperties: true + example: + username: "auth_username" + password: "auth_password" FederatedAuthenticatorPUTRequest: type: object properties: @@ -2905,6 +2939,8 @@ components: type: array items: $ref: '#/components/schemas/Property' + endpoint: + $ref: '#/components/schemas/Endpoint' FederatedAuthenticatorListResponse: type: object properties: