From c78219195f5f67367843fdb0ebe1d1ab1a646422 Mon Sep 17 00:00:00 2001 From: Lakshan Date: Fri, 18 Aug 2023 18:56:02 +0530 Subject: [PATCH 1/5] Update swagger and add new api endpoint --- .../governance/v1/IdentityGovernanceApi.java | 54 ++++-- .../v1/IdentityGovernanceApiService.java | 33 ++-- .../governance/v1/model/ConnectorReq.java | 137 ++++++++++++++ .../v1/model/MultipleConnectorsPatchReq.java | 170 ++++++++++++++++++ .../IdentityGovernanceApiServiceImpl.java | 26 ++- .../main/resources/identity-governance.yaml | 65 +++++++ 6 files changed, 449 insertions(+), 36 deletions(-) create mode 100644 components/org.wso2.carbon.identity.api.server.identity.governance/org.wso2.carbon.identity.api.server.identity.governance.v1/src/gen/java/org/wso2/carbon/identity/api/server/identity/governance/v1/model/ConnectorReq.java create mode 100644 components/org.wso2.carbon.identity.api.server.identity.governance/org.wso2.carbon.identity.api.server.identity.governance.v1/src/gen/java/org/wso2/carbon/identity/api/server/identity/governance/v1/model/MultipleConnectorsPatchReq.java diff --git a/components/org.wso2.carbon.identity.api.server.identity.governance/org.wso2.carbon.identity.api.server.identity.governance.v1/src/gen/java/org/wso2/carbon/identity/api/server/identity/governance/v1/IdentityGovernanceApi.java b/components/org.wso2.carbon.identity.api.server.identity.governance/org.wso2.carbon.identity.api.server.identity.governance.v1/src/gen/java/org/wso2/carbon/identity/api/server/identity/governance/v1/IdentityGovernanceApi.java index bd3df87be2..1bad872daa 100644 --- a/components/org.wso2.carbon.identity.api.server.identity.governance/org.wso2.carbon.identity.api.server.identity.governance.v1/src/gen/java/org/wso2/carbon/identity/api/server/identity/governance/v1/IdentityGovernanceApi.java +++ b/components/org.wso2.carbon.identity.api.server.identity.governance/org.wso2.carbon.identity.api.server.identity.governance.v1/src/gen/java/org/wso2/carbon/identity/api/server/identity/governance/v1/IdentityGovernanceApi.java @@ -1,18 +1,20 @@ /* -* Copyright (c) 2019, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. -* -* Licensed 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. -*/ + * Copyright (c) 2023, 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.identity.governance.v1; @@ -23,6 +25,7 @@ import org.wso2.carbon.identity.api.server.identity.governance.v1.model.ConnectorsPatchReq; import org.wso2.carbon.identity.api.server.identity.governance.v1.model.Error; import java.util.List; +import org.wso2.carbon.identity.api.server.identity.governance.v1.model.MultipleConnectorsPatchReq; import org.wso2.carbon.identity.api.server.identity.governance.v1.model.PreferenceResp; import org.wso2.carbon.identity.api.server.identity.governance.v1.model.PreferenceSearchAttribute; import org.wso2.carbon.identity.api.server.identity.governance.v1.IdentityGovernanceApiService; @@ -176,4 +179,27 @@ public Response patchConnector(@ApiParam(value = "Id of the connector category." return delegate.patchConnector(categoryId, connectorId, connectorsPatchReq ); } + @Valid + @PATCH + @Path("/{category-id}/connectors") + @Consumes({ "application/json" }) + @Produces({ "*/*" }) + @ApiOperation(value = "Patch governance connectors of a category.", notes = "Patch governance connectors of a category.
Permission required:
* /permission/admin/manage/identity/idpmgt/update
Scope required:
* internal_idp_update ", response = Void.class, authorizations = { + @Authorization(value = "BasicAuth"), + @Authorization(value = "OAuth2", scopes = { + + }) + }, tags={ "Management" }) + @ApiResponses(value = { + @ApiResponse(code = 200, message = "OK.", response = Void.class), + @ApiResponse(code = 400, message = "Bad Request.", response = Error.class), + @ApiResponse(code = 401, message = "Unauthorized.", response = Void.class), + @ApiResponse(code = 404, message = "Not Found.", response = Error.class), + @ApiResponse(code = 500, message = "Internal Server Error.", response = Error.class) + }) + public Response patchConnectorsOfCategory(@ApiParam(value = "Id of the connector category.",required=true) @PathParam("category-id") String categoryId, @ApiParam(value = "Governance connectors and properties to update" ,required=true) @Valid MultipleConnectorsPatchReq multipleConnectorsPatchReq) { + + return delegate.patchConnectorsOfCategory(categoryId, multipleConnectorsPatchReq ); + } + } diff --git a/components/org.wso2.carbon.identity.api.server.identity.governance/org.wso2.carbon.identity.api.server.identity.governance.v1/src/gen/java/org/wso2/carbon/identity/api/server/identity/governance/v1/IdentityGovernanceApiService.java b/components/org.wso2.carbon.identity.api.server.identity.governance/org.wso2.carbon.identity.api.server.identity.governance.v1/src/gen/java/org/wso2/carbon/identity/api/server/identity/governance/v1/IdentityGovernanceApiService.java index 8ff0cf3d07..f98a6173e4 100644 --- a/components/org.wso2.carbon.identity.api.server.identity.governance/org.wso2.carbon.identity.api.server.identity.governance.v1/src/gen/java/org/wso2/carbon/identity/api/server/identity/governance/v1/IdentityGovernanceApiService.java +++ b/components/org.wso2.carbon.identity.api.server.identity.governance/org.wso2.carbon.identity.api.server.identity.governance.v1/src/gen/java/org/wso2/carbon/identity/api/server/identity/governance/v1/IdentityGovernanceApiService.java @@ -1,23 +1,26 @@ /* -* Copyright (c) 2019, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. -* -* Licensed 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. -*/ + * Copyright (c) 2023, 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.identity.governance.v1; import org.wso2.carbon.identity.api.server.identity.governance.v1.model.ConnectorsPatchReq; import org.wso2.carbon.identity.api.server.identity.governance.v1.model.PreferenceSearchAttribute; +import org.wso2.carbon.identity.api.server.identity.governance.v1.model.MultipleConnectorsPatchReq; import java.util.List; @@ -37,4 +40,6 @@ public interface IdentityGovernanceApiService { public Response getPreferenceByPost(List preferenceSearchAttribute); public Response patchConnector(String categoryId, String connectorId, ConnectorsPatchReq connectorsPatchReq); + + public Response patchConnectorsOfCategory(String categoryId, MultipleConnectorsPatchReq multipleConnectorsPatchReq); } diff --git a/components/org.wso2.carbon.identity.api.server.identity.governance/org.wso2.carbon.identity.api.server.identity.governance.v1/src/gen/java/org/wso2/carbon/identity/api/server/identity/governance/v1/model/ConnectorReq.java b/components/org.wso2.carbon.identity.api.server.identity.governance/org.wso2.carbon.identity.api.server.identity.governance.v1/src/gen/java/org/wso2/carbon/identity/api/server/identity/governance/v1/model/ConnectorReq.java new file mode 100644 index 0000000000..31ce3fc4a1 --- /dev/null +++ b/components/org.wso2.carbon.identity.api.server.identity.governance/org.wso2.carbon.identity.api.server.identity.governance.v1/src/gen/java/org/wso2/carbon/identity/api/server/identity/governance/v1/model/ConnectorReq.java @@ -0,0 +1,137 @@ +/* + * Copyright (c) 2023, 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.identity.governance.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.identity.governance.v1.model.PropertyReq; +import javax.validation.constraints.*; + +/** + * Governance connector to patch + **/ + +import io.swagger.annotations.*; +import java.util.Objects; +import javax.validation.Valid; +import javax.xml.bind.annotation.*; +@ApiModel(description = "Governance connector to patch") +public class ConnectorReq { + + private String id; + private List properties = new ArrayList<>(); + + + /** + * Connector id. + **/ + public ConnectorReq id(String id) { + + this.id = id; + return this; + } + + @ApiModelProperty(example = "c3VzcGVuc2lvbi5ub3RpZmljYXRpb24", required = true, value = "Connector id.") + @JsonProperty("id") + @Valid + @NotNull(message = "Property id cannot be null.") + + public String getId() { + return id; + } + public void setId(String id) { + this.id = id; + } + + /** + * Governance connector properties to patch. + **/ + public ConnectorReq properties(List properties) { + + this.properties = properties; + return this; + } + + @ApiModelProperty(required = true, value = "Governance connector properties to patch.") + @JsonProperty("properties") + @Valid + @NotNull(message = "Property properties cannot be null.") + + public List getProperties() { + return properties; + } + public void setProperties(List properties) { + this.properties = properties; + } + + public ConnectorReq addPropertiesItem(PropertyReq propertiesItem) { + this.properties.add(propertiesItem); + return this; + } + + + + @Override + public boolean equals(java.lang.Object o) { + + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + ConnectorReq connectorReq = (ConnectorReq) o; + return Objects.equals(this.id, connectorReq.id) && + Objects.equals(this.properties, connectorReq.properties); + } + + @Override + public int hashCode() { + return Objects.hash(id, properties); + } + + @Override + public String toString() { + + StringBuilder sb = new StringBuilder(); + sb.append("class ConnectorReq {\n"); + + sb.append(" id: ").append(toIndentedString(id)).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.identity.governance/org.wso2.carbon.identity.api.server.identity.governance.v1/src/gen/java/org/wso2/carbon/identity/api/server/identity/governance/v1/model/MultipleConnectorsPatchReq.java b/components/org.wso2.carbon.identity.api.server.identity.governance/org.wso2.carbon.identity.api.server.identity.governance.v1/src/gen/java/org/wso2/carbon/identity/api/server/identity/governance/v1/model/MultipleConnectorsPatchReq.java new file mode 100644 index 0000000000..20d7d60e8b --- /dev/null +++ b/components/org.wso2.carbon.identity.api.server.identity.governance/org.wso2.carbon.identity.api.server.identity.governance.v1/src/gen/java/org/wso2/carbon/identity/api/server/identity/governance/v1/model/MultipleConnectorsPatchReq.java @@ -0,0 +1,170 @@ +/* + * Copyright (c) 2023, 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.identity.governance.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.identity.governance.v1.model.ConnectorReq; +import javax.validation.constraints.*; + +/** + * Multiple governance connectors properties patch request. + **/ + +import io.swagger.annotations.*; +import java.util.Objects; +import javax.validation.Valid; +import javax.xml.bind.annotation.*; +@ApiModel(description = "Multiple governance connectors properties patch request.") +public class MultipleConnectorsPatchReq { + + +@XmlType(name="OperationEnum") +@XmlEnum(String.class) +public enum OperationEnum { + + @XmlEnumValue("UPDATE") UPDATE(String.valueOf("UPDATE")); + + + private String value; + + OperationEnum(String v) { + value = v; + } + + public String value() { + return value; + } + + @Override + public String toString() { + return String.valueOf(value); + } + + public static OperationEnum fromValue(String value) { + for (OperationEnum b : OperationEnum.values()) { + if (b.value.equals(value)) { + return b; + } + } + throw new IllegalArgumentException("Unexpected value '" + value + "'"); + } +} + + private OperationEnum operation; + private List connectors = new ArrayList<>(); + + + /** + * Governance connector properties patch operation. + **/ + public MultipleConnectorsPatchReq operation(OperationEnum operation) { + + this.operation = operation; + return this; + } + + @ApiModelProperty(example = "UPDATE", required = true, value = "Governance connector properties patch operation.") + @JsonProperty("operation") + @Valid + @NotNull(message = "Property operation cannot be null.") + + public OperationEnum getOperation() { + return operation; + } + public void setOperation(OperationEnum operation) { + this.operation = operation; + } + + /** + * Governance connectors to patch + **/ + public MultipleConnectorsPatchReq connectors(List connectors) { + + this.connectors = connectors; + return this; + } + + @ApiModelProperty(required = true, value = "Governance connectors to patch") + @JsonProperty("connectors") + @Valid + @NotNull(message = "Property connectors cannot be null.") + + public List getConnectors() { + return connectors; + } + public void setConnectors(List connectors) { + this.connectors = connectors; + } + + public MultipleConnectorsPatchReq addConnectorsItem(ConnectorReq connectorsItem) { + this.connectors.add(connectorsItem); + return this; + } + + + + @Override + public boolean equals(java.lang.Object o) { + + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + MultipleConnectorsPatchReq multipleConnectorsPatchReq = (MultipleConnectorsPatchReq) o; + return Objects.equals(this.operation, multipleConnectorsPatchReq.operation) && + Objects.equals(this.connectors, multipleConnectorsPatchReq.connectors); + } + + @Override + public int hashCode() { + return Objects.hash(operation, connectors); + } + + @Override + public String toString() { + + StringBuilder sb = new StringBuilder(); + sb.append("class MultipleConnectorsPatchReq {\n"); + + sb.append(" operation: ").append(toIndentedString(operation)).append("\n"); + sb.append(" connectors: ").append(toIndentedString(connectors)).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.identity.governance/org.wso2.carbon.identity.api.server.identity.governance.v1/src/main/java/org/wso2/carbon/identity/api/server/identity/governance/v1/impl/IdentityGovernanceApiServiceImpl.java b/components/org.wso2.carbon.identity.api.server.identity.governance/org.wso2.carbon.identity.api.server.identity.governance.v1/src/main/java/org/wso2/carbon/identity/api/server/identity/governance/v1/impl/IdentityGovernanceApiServiceImpl.java index 74fbae8546..8f4bd03a1c 100644 --- a/components/org.wso2.carbon.identity.api.server.identity.governance/org.wso2.carbon.identity.api.server.identity.governance.v1/src/main/java/org/wso2/carbon/identity/api/server/identity/governance/v1/impl/IdentityGovernanceApiServiceImpl.java +++ b/components/org.wso2.carbon.identity.api.server.identity.governance/org.wso2.carbon.identity.api.server.identity.governance.v1/src/main/java/org/wso2/carbon/identity/api/server/identity/governance/v1/impl/IdentityGovernanceApiServiceImpl.java @@ -1,17 +1,19 @@ /* - * Copyright (c) 2019, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * Copyright (c) 2023, WSO2 LLC. (http://www.wso2.com). * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. + * 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. + * 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.identity.governance.v1.impl; @@ -20,6 +22,7 @@ import org.wso2.carbon.identity.api.server.identity.governance.v1.IdentityGovernanceApiService; import org.wso2.carbon.identity.api.server.identity.governance.v1.core.ServerIdentityGovernanceService; import org.wso2.carbon.identity.api.server.identity.governance.v1.model.ConnectorsPatchReq; +import org.wso2.carbon.identity.api.server.identity.governance.v1.model.MultipleConnectorsPatchReq; import org.wso2.carbon.identity.api.server.identity.governance.v1.model.PreferenceSearchAttribute; import java.util.List; @@ -65,6 +68,13 @@ public Response patchConnector(String categoryId, String connectorId, Connectors return Response.ok().build(); } + @Override + public Response patchConnectorsOfCategory(String categoryId, MultipleConnectorsPatchReq multipleConnectorsPatchReq) { + + // TODO: do some magic! + return Response.ok().entity("magic!").build(); + } + @Override public Response getPreferenceByPost(List preferenceSearchAttribute) { diff --git a/components/org.wso2.carbon.identity.api.server.identity.governance/org.wso2.carbon.identity.api.server.identity.governance.v1/src/main/resources/identity-governance.yaml b/components/org.wso2.carbon.identity.api.server.identity.governance/org.wso2.carbon.identity.api.server.identity.governance.v1/src/main/resources/identity-governance.yaml index a03f1a34b0..a4db1aa9a5 100644 --- a/components/org.wso2.carbon.identity.api.server.identity.governance/org.wso2.carbon.identity.api.server.identity.governance.v1/src/main/resources/identity-governance.yaml +++ b/components/org.wso2.carbon.identity.api.server.identity.governance/org.wso2.carbon.identity.api.server.identity.governance.v1/src/main/resources/identity-governance.yaml @@ -108,6 +108,37 @@ paths: $ref: '#/components/responses/NotFound' '500': $ref: '#/components/responses/ServerError' + patch: + tags: + - Management + summary: Patch governance connectors of a category. + operationId: patchConnectorsOfCategory + description: | + Patch governance connectors of a category.
+ Permission required:
+ * /permission/admin/manage/identity/idpmgt/update
+ Scope required:
+ * internal_idp_update + parameters: + - $ref: '#/components/parameters/categoryIdPathParam' + responses: + '200': + $ref: '#/components/responses/OK' + '400': + $ref: '#/components/responses/InvalidInput' + '401': + $ref: '#/components/responses/Unauthorized' + '404': + $ref: '#/components/responses/NotFound' + '500': + $ref: '#/components/responses/ServerError' + requestBody: + content: + application/json: + schema: + $ref: '#/components/schemas/MultipleConnectorsPatchReq' + description: Governance connectors and properties to update + required: true '/identity-governance/{category-id}/connectors/{connector-id}': get: tags: @@ -748,6 +779,40 @@ components: description: Governance connector properties to patch. items: $ref: '#/components/schemas/PropertyReq' + MultipleConnectorsPatchReq: + type: object + description: Multiple governance connectors properties patch request. + required: + - operation + - connectors + properties: + operation: + type: string + description: Governance connector properties patch operation. + enum: + - UPDATE + example: UPDATE + connectors: + type: array + description: Governance connectors to patch + items: + $ref: '#/components/schemas/ConnectorReq' + ConnectorReq: + type: object + description: Governance connector to patch + required: + - id + - properties + properties: + id: + type: string + description: Connector id. + example: c3VzcGVuc2lvbi5ub3RpZmljYXRpb24 + properties: + type: array + description: Governance connector properties to patch. + items: + $ref: '#/components/schemas/PropertyReq' PropertyReq: type: object description: Governance connector property to patch. From 9c31920ca5df7dcf45f20420bdb6a06e98fbb409 Mon Sep 17 00:00:00 2001 From: Lakshan Date: Mon, 21 Aug 2023 15:06:08 +0530 Subject: [PATCH 2/5] Add functionality to update multiple governance connector properties through one PATCH request --- .../core/ServerIdentityGovernanceService.java | 69 ++++++++++++++++--- .../IdentityGovernanceApiServiceImpl.java | 7 +- 2 files changed, 65 insertions(+), 11 deletions(-) diff --git a/components/org.wso2.carbon.identity.api.server.identity.governance/org.wso2.carbon.identity.api.server.identity.governance.v1/src/main/java/org/wso2/carbon/identity/api/server/identity/governance/v1/core/ServerIdentityGovernanceService.java b/components/org.wso2.carbon.identity.api.server.identity.governance/org.wso2.carbon.identity.api.server.identity.governance.v1/src/main/java/org/wso2/carbon/identity/api/server/identity/governance/v1/core/ServerIdentityGovernanceService.java index fc7be0dd39..7b9ebfc060 100644 --- a/components/org.wso2.carbon.identity.api.server.identity.governance/org.wso2.carbon.identity.api.server.identity.governance.v1/src/main/java/org/wso2/carbon/identity/api/server/identity/governance/v1/core/ServerIdentityGovernanceService.java +++ b/components/org.wso2.carbon.identity.api.server.identity.governance/org.wso2.carbon.identity.api.server.identity.governance.v1/src/main/java/org/wso2/carbon/identity/api/server/identity/governance/v1/core/ServerIdentityGovernanceService.java @@ -1,17 +1,19 @@ /* - * Copyright (c) 2019 , WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * Copyright (c) 2023, WSO2 LLC. (http://www.wso2.com). * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. + * 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. + * 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.identity.governance.v1.core; @@ -27,9 +29,11 @@ import org.wso2.carbon.identity.api.server.identity.governance.v1.model.CategoriesRes; import org.wso2.carbon.identity.api.server.identity.governance.v1.model.CategoryConnectorsRes; import org.wso2.carbon.identity.api.server.identity.governance.v1.model.CategoryRes; +import org.wso2.carbon.identity.api.server.identity.governance.v1.model.ConnectorReq; import org.wso2.carbon.identity.api.server.identity.governance.v1.model.ConnectorRes; import org.wso2.carbon.identity.api.server.identity.governance.v1.model.ConnectorsPatchReq; import org.wso2.carbon.identity.api.server.identity.governance.v1.model.MetaRes; +import org.wso2.carbon.identity.api.server.identity.governance.v1.model.MultipleConnectorsPatchReq; import org.wso2.carbon.identity.api.server.identity.governance.v1.model.PreferenceResp; import org.wso2.carbon.identity.api.server.identity.governance.v1.model.PreferenceSearchAttribute; import org.wso2.carbon.identity.api.server.identity.governance.v1.model.PropertyReq; @@ -302,6 +306,55 @@ public void updateGovernanceConnectorProperty(String categoryId, String connecto } } + /** + * + * Update multiple governance connector properties. + * + * @param categoryId Governance connector category id. + * @param multipleConnectorsPatchReq Governance connectors and properties to update. + */ + public void updateGovernanceConnectorProperties(String categoryId, + MultipleConnectorsPatchReq multipleConnectorsPatchReq) { + + try { + IdentityGovernanceService identityGovernanceService = GovernanceDataHolder.getIdentityGovernanceService(); + String tenantDomain = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantDomain(); + + // Check whether the category ID is accurate. + CategoryRes category = getGovernanceConnectorCategory(categoryId); + if (category == null) { + throw handleNotFoundError(categoryId, GovernanceConstants.ErrorMessage.ERROR_CODE_CATEGORY_NOT_FOUND); + } + + Map configurationDetails = new HashMap<>(); + + // Loop through each connector in the request and add the properties to be updated to a hashmap. + for (ConnectorReq connectorReq : multipleConnectorsPatchReq.getConnectors()) { + String connectorId = connectorReq.getId(); + + // Check whether the connector ID is accurate. + ConnectorRes connector = getGovernanceConnector(categoryId, connectorId); + if (connector == null) { + throw handleNotFoundError(connectorId, + GovernanceConstants.ErrorMessage.ERROR_CODE_CONNECTOR_NOT_FOUND); + } + + // Add properties of the connector to be updated to the configurationDetails hashmap. + for (PropertyReq propertyReqDTO : connectorReq.getProperties()) { + configurationDetails.put(propertyReqDTO.getName(), propertyReqDTO.getValue()); + } + } + + identityGovernanceService.updateConfiguration(tenantDomain, configurationDetails); + + } catch (IdentityGovernanceException e) { + GovernanceConstants.ErrorMessage errorEnum = + GovernanceConstants.ErrorMessage.ERROR_CODE_ERROR_UPDATING_CONNECTOR_PROPERTY; + Response.Status status = Response.Status.INTERNAL_SERVER_ERROR; + throw handleException(e, errorEnum, status); + } + } + private APIError handleException(Exception e, GovernanceConstants.ErrorMessage errorEnum, Response.Status status, String... data) { diff --git a/components/org.wso2.carbon.identity.api.server.identity.governance/org.wso2.carbon.identity.api.server.identity.governance.v1/src/main/java/org/wso2/carbon/identity/api/server/identity/governance/v1/impl/IdentityGovernanceApiServiceImpl.java b/components/org.wso2.carbon.identity.api.server.identity.governance/org.wso2.carbon.identity.api.server.identity.governance.v1/src/main/java/org/wso2/carbon/identity/api/server/identity/governance/v1/impl/IdentityGovernanceApiServiceImpl.java index 8f4bd03a1c..02fb36a8c3 100644 --- a/components/org.wso2.carbon.identity.api.server.identity.governance/org.wso2.carbon.identity.api.server.identity.governance.v1/src/main/java/org/wso2/carbon/identity/api/server/identity/governance/v1/impl/IdentityGovernanceApiServiceImpl.java +++ b/components/org.wso2.carbon.identity.api.server.identity.governance/org.wso2.carbon.identity.api.server.identity.governance.v1/src/main/java/org/wso2/carbon/identity/api/server/identity/governance/v1/impl/IdentityGovernanceApiServiceImpl.java @@ -69,10 +69,11 @@ public Response patchConnector(String categoryId, String connectorId, Connectors } @Override - public Response patchConnectorsOfCategory(String categoryId, MultipleConnectorsPatchReq multipleConnectorsPatchReq) { + public Response patchConnectorsOfCategory(String categoryId, + MultipleConnectorsPatchReq multipleConnectorsPatchReq) { - // TODO: do some magic! - return Response.ok().entity("magic!").build(); + identityGovernanceService.updateGovernanceConnectorProperties(categoryId, multipleConnectorsPatchReq); + return Response.ok().build(); } @Override From 7188336f74627b5252de735fa58e6b9d75116a44 Mon Sep 17 00:00:00 2001 From: Lakshan Date: Tue, 22 Aug 2023 07:36:53 +0530 Subject: [PATCH 3/5] Improve error handling in getGovernanceConnector --- .../governance/common/GovernanceConstants.java | 4 +++- .../core/ServerIdentityGovernanceService.java | 17 ++++++++++++++--- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/components/org.wso2.carbon.identity.api.server.identity.governance/org.wso2.carbon.identity.api.server.identity.governance.common/src/main/java/org/wso2/carbon/identity/api/server/identity/governance/common/GovernanceConstants.java b/components/org.wso2.carbon.identity.api.server.identity.governance/org.wso2.carbon.identity.api.server.identity.governance.common/src/main/java/org/wso2/carbon/identity/api/server/identity/governance/common/GovernanceConstants.java index 8cfc8f10fa..240b93cb25 100644 --- a/components/org.wso2.carbon.identity.api.server.identity.governance/org.wso2.carbon.identity.api.server.identity.governance.common/src/main/java/org/wso2/carbon/identity/api/server/identity/governance/common/GovernanceConstants.java +++ b/components/org.wso2.carbon.identity.api.server.identity.governance/org.wso2.carbon.identity.api.server.identity.governance.common/src/main/java/org/wso2/carbon/identity/api/server/identity/governance/common/GovernanceConstants.java @@ -67,7 +67,9 @@ public enum ErrorMessage { ERROR_CODE_INCORRECT_CONNECTOR_NAME("50011", "Invalid connector name", "Unable to find a connector with the name %s."), ERROR_CODE_UNSUPPORTED_PROPERTY_NAME("50012", "Unsupported property is requested.", - "The property %s is not supported by this API."); + "The property %s is not supported by this API."), + ERROR_CODE_CONNECTOR_CATEGORY_MISMATCH("50013", "Connector category mismatch.", + "The connector %s is not found in the category %s."); private final String code; private final String message; diff --git a/components/org.wso2.carbon.identity.api.server.identity.governance/org.wso2.carbon.identity.api.server.identity.governance.v1/src/main/java/org/wso2/carbon/identity/api/server/identity/governance/v1/core/ServerIdentityGovernanceService.java b/components/org.wso2.carbon.identity.api.server.identity.governance/org.wso2.carbon.identity.api.server.identity.governance.v1/src/main/java/org/wso2/carbon/identity/api/server/identity/governance/v1/core/ServerIdentityGovernanceService.java index 7b9ebfc060..b037ce895c 100644 --- a/components/org.wso2.carbon.identity.api.server.identity.governance/org.wso2.carbon.identity.api.server.identity.governance.v1/src/main/java/org/wso2/carbon/identity/api/server/identity/governance/v1/core/ServerIdentityGovernanceService.java +++ b/components/org.wso2.carbon.identity.api.server.identity.governance/org.wso2.carbon.identity.api.server.identity.governance.v1/src/main/java/org/wso2/carbon/identity/api/server/identity/governance/v1/core/ServerIdentityGovernanceService.java @@ -163,7 +163,8 @@ public ConnectorRes getGovernanceConnector(String categoryId, String connectorId .withoutPadding() .encodeToString(connectorConfig.getCategory().getBytes(StandardCharsets.UTF_8)); if (!categoryId.equals(categoryIdFound)) { - throw handleNotFoundError(connectorId, GovernanceConstants.ErrorMessage.ERROR_CODE_CONNECTOR_NOT_FOUND); + throw handleMismatchError(connectorId, categoryId, + GovernanceConstants.ErrorMessage.ERROR_CODE_CONNECTOR_CATEGORY_MISMATCH); } return buildConnectorResDTO(connectorConfig); @@ -320,7 +321,7 @@ public void updateGovernanceConnectorProperties(String categoryId, IdentityGovernanceService identityGovernanceService = GovernanceDataHolder.getIdentityGovernanceService(); String tenantDomain = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantDomain(); - // Check whether the category ID is accurate. + // Check whether the category ID exists. CategoryRes category = getGovernanceConnectorCategory(categoryId); if (category == null) { throw handleNotFoundError(categoryId, GovernanceConstants.ErrorMessage.ERROR_CODE_CATEGORY_NOT_FOUND); @@ -332,7 +333,7 @@ public void updateGovernanceConnectorProperties(String categoryId, for (ConnectorReq connectorReq : multipleConnectorsPatchReq.getConnectors()) { String connectorId = connectorReq.getId(); - // Check whether the connector ID is accurate. + // Check whether the connector ID exists. ConnectorRes connector = getGovernanceConnector(categoryId, connectorId); if (connector == null) { throw handleNotFoundError(connectorId, @@ -508,4 +509,14 @@ private APIError handleNotFoundError(String resourceId, return new APIError(status, errorResponse); } + + private APIError handleMismatchError(String connectorId, String categoryId, + GovernanceConstants.ErrorMessage errorMessage) { + + Response.Status status = Response.Status.NOT_FOUND; + ErrorResponse errorResponse = + getErrorBuilder(errorMessage, connectorId, categoryId).build(LOG, errorMessage.getDescription()); + + return new APIError(status, errorResponse); + } } From c84f0250fc15a2e1f154e6a0506bd9aa25f94d91 Mon Sep 17 00:00:00 2001 From: Lakshan Date: Thu, 24 Aug 2023 16:14:15 +0530 Subject: [PATCH 4/5] License header year reverted back to original --- .../server/identity/governance/v1/IdentityGovernanceApi.java | 2 +- .../identity/governance/v1/IdentityGovernanceApiService.java | 2 +- .../governance/v1/core/ServerIdentityGovernanceService.java | 2 +- .../governance/v1/impl/IdentityGovernanceApiServiceImpl.java | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/components/org.wso2.carbon.identity.api.server.identity.governance/org.wso2.carbon.identity.api.server.identity.governance.v1/src/gen/java/org/wso2/carbon/identity/api/server/identity/governance/v1/IdentityGovernanceApi.java b/components/org.wso2.carbon.identity.api.server.identity.governance/org.wso2.carbon.identity.api.server.identity.governance.v1/src/gen/java/org/wso2/carbon/identity/api/server/identity/governance/v1/IdentityGovernanceApi.java index 1bad872daa..b4f5b05af4 100644 --- a/components/org.wso2.carbon.identity.api.server.identity.governance/org.wso2.carbon.identity.api.server.identity.governance.v1/src/gen/java/org/wso2/carbon/identity/api/server/identity/governance/v1/IdentityGovernanceApi.java +++ b/components/org.wso2.carbon.identity.api.server.identity.governance/org.wso2.carbon.identity.api.server.identity.governance.v1/src/gen/java/org/wso2/carbon/identity/api/server/identity/governance/v1/IdentityGovernanceApi.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023, WSO2 LLC. (http://www.wso2.com). + * Copyright (c) 2019, 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 diff --git a/components/org.wso2.carbon.identity.api.server.identity.governance/org.wso2.carbon.identity.api.server.identity.governance.v1/src/gen/java/org/wso2/carbon/identity/api/server/identity/governance/v1/IdentityGovernanceApiService.java b/components/org.wso2.carbon.identity.api.server.identity.governance/org.wso2.carbon.identity.api.server.identity.governance.v1/src/gen/java/org/wso2/carbon/identity/api/server/identity/governance/v1/IdentityGovernanceApiService.java index f98a6173e4..7bad8730bc 100644 --- a/components/org.wso2.carbon.identity.api.server.identity.governance/org.wso2.carbon.identity.api.server.identity.governance.v1/src/gen/java/org/wso2/carbon/identity/api/server/identity/governance/v1/IdentityGovernanceApiService.java +++ b/components/org.wso2.carbon.identity.api.server.identity.governance/org.wso2.carbon.identity.api.server.identity.governance.v1/src/gen/java/org/wso2/carbon/identity/api/server/identity/governance/v1/IdentityGovernanceApiService.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023, WSO2 LLC. (http://www.wso2.com). + * Copyright (c) 2019, 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 diff --git a/components/org.wso2.carbon.identity.api.server.identity.governance/org.wso2.carbon.identity.api.server.identity.governance.v1/src/main/java/org/wso2/carbon/identity/api/server/identity/governance/v1/core/ServerIdentityGovernanceService.java b/components/org.wso2.carbon.identity.api.server.identity.governance/org.wso2.carbon.identity.api.server.identity.governance.v1/src/main/java/org/wso2/carbon/identity/api/server/identity/governance/v1/core/ServerIdentityGovernanceService.java index b037ce895c..a43056b79b 100644 --- a/components/org.wso2.carbon.identity.api.server.identity.governance/org.wso2.carbon.identity.api.server.identity.governance.v1/src/main/java/org/wso2/carbon/identity/api/server/identity/governance/v1/core/ServerIdentityGovernanceService.java +++ b/components/org.wso2.carbon.identity.api.server.identity.governance/org.wso2.carbon.identity.api.server.identity.governance.v1/src/main/java/org/wso2/carbon/identity/api/server/identity/governance/v1/core/ServerIdentityGovernanceService.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023, WSO2 LLC. (http://www.wso2.com). + * Copyright (c) 2019, 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 diff --git a/components/org.wso2.carbon.identity.api.server.identity.governance/org.wso2.carbon.identity.api.server.identity.governance.v1/src/main/java/org/wso2/carbon/identity/api/server/identity/governance/v1/impl/IdentityGovernanceApiServiceImpl.java b/components/org.wso2.carbon.identity.api.server.identity.governance/org.wso2.carbon.identity.api.server.identity.governance.v1/src/main/java/org/wso2/carbon/identity/api/server/identity/governance/v1/impl/IdentityGovernanceApiServiceImpl.java index 02fb36a8c3..dd85e5de13 100644 --- a/components/org.wso2.carbon.identity.api.server.identity.governance/org.wso2.carbon.identity.api.server.identity.governance.v1/src/main/java/org/wso2/carbon/identity/api/server/identity/governance/v1/impl/IdentityGovernanceApiServiceImpl.java +++ b/components/org.wso2.carbon.identity.api.server.identity.governance/org.wso2.carbon.identity.api.server.identity.governance.v1/src/main/java/org/wso2/carbon/identity/api/server/identity/governance/v1/impl/IdentityGovernanceApiServiceImpl.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023, WSO2 LLC. (http://www.wso2.com). + * Copyright (c) 2019, 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 From 995d219602e22add5eafa13ef6b468b98894c84a Mon Sep 17 00:00:00 2001 From: Lakshan Date: Mon, 28 Aug 2023 10:19:40 +0530 Subject: [PATCH 5/5] Removing handleMismatchError --- .../governance/common/GovernanceConstants.java | 4 +--- .../v1/core/ServerIdentityGovernanceService.java | 13 +------------ 2 files changed, 2 insertions(+), 15 deletions(-) diff --git a/components/org.wso2.carbon.identity.api.server.identity.governance/org.wso2.carbon.identity.api.server.identity.governance.common/src/main/java/org/wso2/carbon/identity/api/server/identity/governance/common/GovernanceConstants.java b/components/org.wso2.carbon.identity.api.server.identity.governance/org.wso2.carbon.identity.api.server.identity.governance.common/src/main/java/org/wso2/carbon/identity/api/server/identity/governance/common/GovernanceConstants.java index 240b93cb25..8cfc8f10fa 100644 --- a/components/org.wso2.carbon.identity.api.server.identity.governance/org.wso2.carbon.identity.api.server.identity.governance.common/src/main/java/org/wso2/carbon/identity/api/server/identity/governance/common/GovernanceConstants.java +++ b/components/org.wso2.carbon.identity.api.server.identity.governance/org.wso2.carbon.identity.api.server.identity.governance.common/src/main/java/org/wso2/carbon/identity/api/server/identity/governance/common/GovernanceConstants.java @@ -67,9 +67,7 @@ public enum ErrorMessage { ERROR_CODE_INCORRECT_CONNECTOR_NAME("50011", "Invalid connector name", "Unable to find a connector with the name %s."), ERROR_CODE_UNSUPPORTED_PROPERTY_NAME("50012", "Unsupported property is requested.", - "The property %s is not supported by this API."), - ERROR_CODE_CONNECTOR_CATEGORY_MISMATCH("50013", "Connector category mismatch.", - "The connector %s is not found in the category %s."); + "The property %s is not supported by this API."); private final String code; private final String message; diff --git a/components/org.wso2.carbon.identity.api.server.identity.governance/org.wso2.carbon.identity.api.server.identity.governance.v1/src/main/java/org/wso2/carbon/identity/api/server/identity/governance/v1/core/ServerIdentityGovernanceService.java b/components/org.wso2.carbon.identity.api.server.identity.governance/org.wso2.carbon.identity.api.server.identity.governance.v1/src/main/java/org/wso2/carbon/identity/api/server/identity/governance/v1/core/ServerIdentityGovernanceService.java index a43056b79b..6787ef2fa8 100644 --- a/components/org.wso2.carbon.identity.api.server.identity.governance/org.wso2.carbon.identity.api.server.identity.governance.v1/src/main/java/org/wso2/carbon/identity/api/server/identity/governance/v1/core/ServerIdentityGovernanceService.java +++ b/components/org.wso2.carbon.identity.api.server.identity.governance/org.wso2.carbon.identity.api.server.identity.governance.v1/src/main/java/org/wso2/carbon/identity/api/server/identity/governance/v1/core/ServerIdentityGovernanceService.java @@ -163,8 +163,7 @@ public ConnectorRes getGovernanceConnector(String categoryId, String connectorId .withoutPadding() .encodeToString(connectorConfig.getCategory().getBytes(StandardCharsets.UTF_8)); if (!categoryId.equals(categoryIdFound)) { - throw handleMismatchError(connectorId, categoryId, - GovernanceConstants.ErrorMessage.ERROR_CODE_CONNECTOR_CATEGORY_MISMATCH); + throw handleNotFoundError(connectorId, GovernanceConstants.ErrorMessage.ERROR_CODE_CONNECTOR_NOT_FOUND); } return buildConnectorResDTO(connectorConfig); @@ -509,14 +508,4 @@ private APIError handleNotFoundError(String resourceId, return new APIError(status, errorResponse); } - - private APIError handleMismatchError(String connectorId, String categoryId, - GovernanceConstants.ErrorMessage errorMessage) { - - Response.Status status = Response.Status.NOT_FOUND; - ErrorResponse errorResponse = - getErrorBuilder(errorMessage, connectorId, categoryId).build(LOG, errorMessage.getDescription()); - - return new APIError(status, errorResponse); - } }