From e9d73d63088aad2ad7f4a88884dcd86ffaf10905 Mon Sep 17 00:00:00 2001 From: Thisara-Welmilla Date: Thu, 12 Dec 2024 10:50:08 +0530 Subject: [PATCH 1/2] Add integration tests for user defined local authenticator mgt. --- .../v1/AuthenticatorFailureTest.java | 322 ++++++++++++++++ .../v1/AuthenticatorSuccessTest.java | 115 +++++- .../management/v1/AuthenticatorTestBase.java | 38 ++ .../v1/model/AuthenticationType.java | 166 ++++++++ .../management/v1/model/Authenticator.java | 362 ++++++++++++++++++ .../management/v1/model/Endpoint.java | 120 ++++++ ...UserDefinedLocalAuthenticatorCreation.java | 290 ++++++++++++++ .../UserDefinedLocalAuthenticatorUpdate.java | 192 ++++++++++ .../UserDefinedLocalAuthenticatorPayload.java | 104 +++++ .../src/test/resources/testng.xml | 1 + 10 files changed, 1708 insertions(+), 2 deletions(-) create mode 100644 modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/authenticator/management/v1/AuthenticatorFailureTest.java create mode 100644 modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/authenticator/management/v1/model/AuthenticationType.java create mode 100644 modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/authenticator/management/v1/model/Authenticator.java create mode 100644 modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/authenticator/management/v1/model/Endpoint.java create mode 100644 modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/authenticator/management/v1/model/UserDefinedLocalAuthenticatorCreation.java create mode 100644 modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/authenticator/management/v1/model/UserDefinedLocalAuthenticatorUpdate.java create mode 100644 modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/authenticator/management/v1/util/UserDefinedLocalAuthenticatorPayload.java diff --git a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/authenticator/management/v1/AuthenticatorFailureTest.java b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/authenticator/management/v1/AuthenticatorFailureTest.java new file mode 100644 index 0000000000..5c98f49c3b --- /dev/null +++ b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/authenticator/management/v1/AuthenticatorFailureTest.java @@ -0,0 +1,322 @@ +/* + * 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.identity.integration.test.rest.api.server.authenticator.management.v1; + +import com.fasterxml.jackson.core.JsonProcessingException; +import io.restassured.RestAssured; +import io.restassured.response.Response; +import org.apache.commons.lang.StringUtils; +import org.apache.http.HttpStatus; +import org.json.JSONException; +import org.testng.annotations.AfterClass; +import org.testng.annotations.AfterMethod; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.BeforeMethod; +import org.testng.annotations.DataProvider; +import org.testng.annotations.Factory; +import org.testng.annotations.Test; +import org.wso2.carbon.automation.engine.context.TestUserMode; +import org.wso2.carbon.identity.api.server.authenticators.v1.model.AuthenticationType; +import org.wso2.carbon.identity.api.server.authenticators.v1.model.UserDefinedLocalAuthenticatorCreation; +import org.wso2.carbon.identity.api.server.authenticators.v1.model.UserDefinedLocalAuthenticatorUpdate; +import org.wso2.carbon.identity.application.common.model.UserDefinedLocalAuthenticatorConfig; +import org.wso2.carbon.identity.base.AuthenticatorPropertyConstants; +import org.wso2.identity.integration.test.rest.api.server.authenticator.management.v1.util.UserDefinedLocalAuthenticatorPayload; + +import java.io.IOException; + +import static org.hamcrest.CoreMatchers.equalTo; + +/** + * Test authenticator failure scenarios. + */ +public class AuthenticatorFailureTest extends AuthenticatorTestBase { + + private UserDefinedLocalAuthenticatorConfig testAuthenticatorConfig; + private UserDefinedLocalAuthenticatorCreation creationPayload; + private UserDefinedLocalAuthenticatorUpdate updatePayload; + + @Factory(dataProvider = "restAPIUserConfigProvider") + public AuthenticatorFailureTest(TestUserMode userMode) throws Exception { + + super.init(userMode); + this.context = isServer; + this.authenticatingUserName = context.getContextTenant().getTenantAdmin().getUserName(); + this.authenticatingCredential = context.getContextTenant().getTenantAdmin().getPassword(); + this.tenant = context.getContextTenant().getDomain(); + } + + @BeforeClass(alwaysRun = true) + public void init() throws IOException, JSONException { + + super.testInit(API_VERSION, swaggerDefinition, tenant); + testAuthenticatorConfig = createBaseUserDefinedLocalAuthenticator( + AuthenticatorPropertyConstants.AuthenticationType.IDENTIFICATION); + addUserDefinedAuthenticatorToIS(); + + } + + @AfterClass(alwaysRun = true) + public void testConclude() { + + super.conclude(); + getResponseOfDelete(AUTHENTICATOR_CUSTOM_API_BASE_PATH + PATH_SEPARATOR + customIdPId); + } + + @BeforeMethod(alwaysRun = true) + public void testInit() { + + RestAssured.basePath = basePath; + creationPayload = UserDefinedLocalAuthenticatorPayload + .getBasedUserDefinedLocalAuthenticatorCreation(testAuthenticatorConfig); + updatePayload = UserDefinedLocalAuthenticatorPayload + .getBasedUserDefinedLocalAuthenticatorUpdate(testAuthenticatorConfig); + } + + @AfterMethod(alwaysRun = true) + public void testFinish() { + + RestAssured.basePath = StringUtils.EMPTY; + } + + @DataProvider(name = "restAPIUserConfigProvider") + public static Object[][] restAPIUserConfigProvider() { + + return new Object[][]{ + {TestUserMode.SUPER_TENANT_ADMIN}, + {TestUserMode.TENANT_ADMIN} + }; + } + + @Test(priority = 1) + public void createUserDefinedLocalAuthenticatorInvalidName() throws JsonProcessingException { + + creationPayload.setName("invalid@name"); + String body = UserDefinedLocalAuthenticatorPayload.convertToJasonPayload(creationPayload); + Response response = getResponseOfPost(AUTHENTICATOR_CUSTOM_API_BASE_PATH, body); + response.then() + .log().ifValidationFails() + .assertThat() + .statusCode(HttpStatus.SC_BAD_REQUEST) + .body("code", equalTo("AUT-60004")) + .body("message", equalTo("Authenticator name is invalid.")) + .body("description", equalTo("The provided authenticator name invalid@name is not in the " + + "expected format ^[a-zA-Z0-9][a-zA-Z0-9-_]*$.")); + } + + @Test(priority = 2) + public void createUserDefinedLocalAuthenticatorMissingEndpointProperty() throws JsonProcessingException { + + creationPayload.getEndpoint().getAuthentication().getProperties().remove("username"); + String body = UserDefinedLocalAuthenticatorPayload.convertToJasonPayload(creationPayload); + Response response = getResponseOfPost(AUTHENTICATOR_CUSTOM_API_BASE_PATH, body); + response.then() + .log().ifValidationFails() + .assertThat() + .statusCode(HttpStatus.SC_BAD_REQUEST) + .body("code", equalTo("AUT-60003")) + .body("message", equalTo("Invalid endpoint configuration provided.")) + .body("description", equalTo("The property username must be provided as an authentication " + + "property for the BASIC authentication type.")); + } + + @Test(priority = 3) + public void createUserDefinedLocalAuthenticatorEmptyDisplayName() throws JsonProcessingException { + + creationPayload.setDisplayName(""); + String body = UserDefinedLocalAuthenticatorPayload.convertToJasonPayload(creationPayload); + Response response = getResponseOfPost(AUTHENTICATOR_CUSTOM_API_BASE_PATH, body); + response.then() + .log().ifValidationFails() + .assertThat() + .statusCode(HttpStatus.SC_BAD_REQUEST) + .body("code", equalTo("AUT-60004")) + .body("message", equalTo("Invalid empty or blank value.")) + .body("description", equalTo("Value for displayName should not be empty or blank.")); + } + + @Test(priority = 4) + public void createUserDefinedLocalAuthenticatorInvalidEndpointUri() throws JsonProcessingException { + + creationPayload.getEndpoint().setUri("htt://test.com"); + String body = UserDefinedLocalAuthenticatorPayload.convertToJasonPayload(creationPayload); + Response response = getResponseOfPostNoFilter(AUTHENTICATOR_CUSTOM_API_BASE_PATH, body); + response.then() + .log().ifValidationFails() + .assertThat() + .statusCode(HttpStatus.SC_BAD_REQUEST) + .body("code", equalTo("UE-10000")) + .body("message", equalTo("Invalid Request")) + .body("description", equalTo("must match \"^https?://.+\"")); + } + + @Test(priority = 5) + public void createUserDefinedLocalAuthenticatorEmptyEndpointProperty() throws JsonProcessingException { + + creationPayload.getEndpoint().getAuthentication().getProperties().put("username", ""); + String body = UserDefinedLocalAuthenticatorPayload.convertToJasonPayload(creationPayload); + Response response = getResponseOfPost(AUTHENTICATOR_CUSTOM_API_BASE_PATH, body); + response.then() + .log().ifValidationFails() + .assertThat() + .statusCode(HttpStatus.SC_BAD_REQUEST) + .body("code", equalTo("AUT-60003")) + .body("message", equalTo("Invalid endpoint configuration provided.")) + .body("description", equalTo("The Property username cannot be blank.")); + } + + @Test(priority = 6) + public void createUserDefinedLocalAuthenticatorInvalidEndpointAuthenticationType() throws JsonProcessingException { + + String body = UserDefinedLocalAuthenticatorPayload.convertToJasonPayload(creationPayload); + body = StringUtils.replace(body, AuthenticatorPropertyConstants.AuthenticationType.IDENTIFICATION.toString(), + "InvalidAuthenticationType."); + Response response = getResponseOfPostNoFilter(AUTHENTICATOR_CUSTOM_API_BASE_PATH, body); + response.then() + .log().ifValidationFails() + .assertThat() + .statusCode(HttpStatus.SC_BAD_REQUEST) + .body("code", equalTo("UE-10000")) + .body("message", equalTo("Invalid Request.")) + .body("description", equalTo("Provided request body content is not in the expected format.")); + } + + @Test(priority = 7) + public void createUserDefinedLocalAuthenticatorInvalidAuthenticationType() throws JsonProcessingException { + + String body = UserDefinedLocalAuthenticatorPayload.convertToJasonPayload(creationPayload); + body = StringUtils.replace(body, AuthenticationType.TypeEnum.BASIC.toString(), "InvalidType."); + Response response = getResponseOfPostNoFilter(AUTHENTICATOR_CUSTOM_API_BASE_PATH, body); + response.then() + .log().ifValidationFails() + .assertThat() + .statusCode(HttpStatus.SC_BAD_REQUEST) + .body("code", equalTo("UE-10000")) + .body("message", equalTo("Invalid Request.")) + .body("description", equalTo("Provided request body content is not in the expected format.")); + } + + @Test(priority = 8) + public void updateNonExistingUserDefinedLocalAuthenticator() throws JsonProcessingException { + + String body = UserDefinedLocalAuthenticatorPayload.convertToJasonPayload(updatePayload); + Response response = getResponseOfPutWithNoFilter(AUTHENTICATOR_CUSTOM_API_BASE_PATH + PATH_SEPARATOR + + customIdPId, body); + response.then() + .log().ifValidationFails() + .assertThat() + .statusCode(HttpStatus.SC_NOT_FOUND); + } + + + @Test(priority = 9) + public void createUserDefinedLocalAuthenticatorWithExistingAuthenticatorName() throws JsonProcessingException { + + String body = UserDefinedLocalAuthenticatorPayload.convertToJasonPayload(creationPayload); + Response response = getResponseOfPost(AUTHENTICATOR_CUSTOM_API_BASE_PATH, body); + response.then() + .log().ifValidationFails() + .assertThat() + .statusCode(HttpStatus.SC_CREATED); + + Response responseForDuplication = getResponseOfPost(AUTHENTICATOR_CUSTOM_API_BASE_PATH, body); + responseForDuplication.then() + .log().ifValidationFails() + .assertThat() + .statusCode(HttpStatus.SC_BAD_REQUEST) + .body("code", equalTo("AUT-60003")) + .body("message", equalTo("The authenticator already exists.")) + .body("description", equalTo("The authenticator already exists for the given name:" + + " customAuthenticator.")); + } + + @Test(priority = 10) + public void updateUserDefinedLocalAuthenticatorMissingEndpointProperty() throws JsonProcessingException { + + updatePayload.getEndpoint().getAuthentication().getProperties().remove("username"); + String body = UserDefinedLocalAuthenticatorPayload.convertToJasonPayload(updatePayload); + Response response = getResponseOfPutWithNoFilter(AUTHENTICATOR_CUSTOM_API_BASE_PATH + PATH_SEPARATOR + + customIdPId, body); + response.then() + .log().ifValidationFails() + .assertThat() + .statusCode(HttpStatus.SC_BAD_REQUEST) + .body("code", equalTo("AUT-60003")) + .body("message", equalTo("Invalid endpoint configuration provided.")) + .body("description", equalTo("The property username must be provided as an authentication " + + "property for the BASIC authentication type.")); + } + + @Test(priority = 11) + public void updateUserDefinedLocalAuthenticatorEmptyDisplayName() throws JsonProcessingException { + + updatePayload.setDisplayName(""); + String body = UserDefinedLocalAuthenticatorPayload.convertToJasonPayload(updatePayload); + Response response = getResponseOfPutWithNoFilter(AUTHENTICATOR_CUSTOM_API_BASE_PATH + PATH_SEPARATOR + + customIdPId, body); + response.then() + .log().ifValidationFails() + .assertThat() + .statusCode(HttpStatus.SC_BAD_REQUEST) + .body("code", equalTo("AUT-60004")) + .body("message", equalTo("Invalid empty or blank value.")) + .body("description", equalTo("Value for displayName should not be empty or blank.")); + } + + @Test(priority = 12) + public void updateUserDefinedLocalAuthenticatorInvalidEndpointUri() throws JsonProcessingException { + + updatePayload.getEndpoint().setUri("htt://test.com"); + String body = UserDefinedLocalAuthenticatorPayload.convertToJasonPayload(updatePayload); + Response response = getResponseOfPutWithNoFilter(AUTHENTICATOR_CUSTOM_API_BASE_PATH + PATH_SEPARATOR + + customIdPId, body); + response.then() + .log().ifValidationFails() + .assertThat() + .statusCode(HttpStatus.SC_BAD_REQUEST) + .body("code", equalTo("UE-10000")) + .body("message", equalTo("Invalid Request")) + .body("description", equalTo("must match \"^https?://.+\"")); + } + + @Test(priority = 13) + public void updateUserDefinedLocalAuthenticatorInvalidEndpointAuthenticationType() throws JsonProcessingException { + + String body = UserDefinedLocalAuthenticatorPayload.convertToJasonPayload(updatePayload); + body = StringUtils.replace(body, AuthenticationType.TypeEnum.BASIC.toString(), "InvalidType."); + Response response = getResponseOfPutWithNoFilter(AUTHENTICATOR_CUSTOM_API_BASE_PATH + PATH_SEPARATOR + + customIdPId, body); + response.then() + .log().ifValidationFails() + .assertThat() + .statusCode(HttpStatus.SC_BAD_REQUEST) + .body("code", equalTo("UE-10000")) + .body("message", equalTo("Invalid Request.")) + .body("description", equalTo("Provided request body content is not in the expected format.")); + } + + private void addUserDefinedAuthenticatorToIS() throws JsonProcessingException { + + creationPayload = UserDefinedLocalAuthenticatorPayload + .getBasedUserDefinedLocalAuthenticatorCreation(testAuthenticatorConfig); + String body = UserDefinedLocalAuthenticatorPayload.convertToJasonPayload(creationPayload); + getResponseOfPost(AUTHENTICATOR_CUSTOM_API_BASE_PATH, body); + } +} diff --git a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/authenticator/management/v1/AuthenticatorSuccessTest.java b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/authenticator/management/v1/AuthenticatorSuccessTest.java index b2eeb6f7e3..f06582739f 100644 --- a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/authenticator/management/v1/AuthenticatorSuccessTest.java +++ b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/authenticator/management/v1/AuthenticatorSuccessTest.java @@ -18,10 +18,13 @@ package org.wso2.identity.integration.test.rest.api.server.authenticator.management.v1; +import com.fasterxml.jackson.core.JsonProcessingException; import io.restassured.RestAssured; import io.restassured.response.Response; import org.apache.commons.lang.StringUtils; +import org.apache.http.HttpHeaders; import org.apache.http.HttpStatus; +import org.checkerframework.checker.units.qual.A; import org.json.JSONException; import org.json.JSONObject; import org.json.JSONArray; @@ -34,14 +37,25 @@ import org.testng.annotations.Factory; import org.testng.annotations.Test; import org.wso2.carbon.automation.engine.context.TestUserMode; +import org.wso2.carbon.identity.api.server.authenticators.v1.model.UserDefinedLocalAuthenticatorCreation; +import org.wso2.carbon.identity.api.server.authenticators.v1.model.UserDefinedLocalAuthenticatorUpdate; +import org.wso2.carbon.identity.application.common.model.UserDefinedLocalAuthenticatorConfig; +import org.wso2.carbon.identity.base.AuthenticatorPropertyConstants; +import org.wso2.identity.integration.test.rest.api.server.authenticator.management.v1.util.UserDefinedLocalAuthenticatorPayload; import java.io.IOException; +import static org.hamcrest.CoreMatchers.equalTo; +import static org.hamcrest.core.IsNull.notNullValue; + /** * Tests for happy paths of the authentication Management REST API. */ -public class AuthenticatorSuccessTest extends AuthenticatorTestBase{ +public class AuthenticatorSuccessTest extends AuthenticatorTestBase { + private UserDefinedLocalAuthenticatorConfig testAuthenticatorConfig; + private UserDefinedLocalAuthenticatorCreation creationPayload; + private UserDefinedLocalAuthenticatorUpdate updatePayload; @Factory(dataProvider = "restAPIUserConfigProvider") public AuthenticatorSuccessTest(TestUserMode userMode) throws Exception { @@ -54,9 +68,11 @@ public AuthenticatorSuccessTest(TestUserMode userMode) throws Exception { } @BeforeClass(alwaysRun = true) - public void init() throws IOException { + public void init() throws IOException, JSONException { super.testInit(API_VERSION, swaggerDefinition, tenant); + testAuthenticatorConfig = createBaseUserDefinedLocalAuthenticator( + AuthenticatorPropertyConstants.AuthenticationType.IDENTIFICATION); } @AfterClass(alwaysRun = true) @@ -69,6 +85,10 @@ public void testConclude() { public void testInit() { RestAssured.basePath = basePath; + creationPayload = UserDefinedLocalAuthenticatorPayload + .getBasedUserDefinedLocalAuthenticatorCreation(testAuthenticatorConfig); + updatePayload = UserDefinedLocalAuthenticatorPayload + .getBasedUserDefinedLocalAuthenticatorUpdate(testAuthenticatorConfig); } @AfterMethod(alwaysRun = true) @@ -106,5 +126,96 @@ public void getAuthenticators() throws JSONException { } } + @Test(dependsOnMethods = {"getAuthenticators"}) + public void testCreateUserDefinedLocalAuthenticator() throws JsonProcessingException { + + String body = UserDefinedLocalAuthenticatorPayload.convertToJasonPayload(creationPayload); + Response response = getResponseOfPost(AUTHENTICATOR_CUSTOM_API_BASE_PATH, body); + response.then() + .log().ifValidationFails() + .assertThat() + .statusCode(HttpStatus.SC_CREATED) + .header(HttpHeaders.LOCATION, notNullValue()) + .body("id", equalTo(customIdPId)) + .body("name", equalTo(AUTHENTICATOR_NAME)) + .body("displayName", equalTo(AUTHENTICATOR_DISPLAY_NAME)) + .body("type", equalTo("LOCAL")) + .body("definedBy", equalTo("USER")) + .body("isEnabled", equalTo(true)) + .body("self", equalTo(getTenantedRelativePath( + AUTHENTICATOR_CONFIG_API_BASE_PATH + customIdPId, tenant))); + } + + @Test(dependsOnMethods = {"testCreateUserDefinedLocalAuthenticator"}) + public void getUserDefinedLocalAuthenticators() throws JSONException { + + Response response = getResponseOfGet(AUTHENTICATOR_API_BASE_PATH); + response.then() + .log().ifValidationFails() + .assertThat() + .statusCode(HttpStatus.SC_OK); + + boolean isUserDefinedAuthenticatorFound = false; + JSONArray jsonArray = new JSONArray(response.body().asString()); + for (int i = 0; i < jsonArray.length(); i++) { + JSONObject authenticator = jsonArray.getJSONObject(i); + if ("USER".equals(authenticator.getString("definedBy"))) { + isUserDefinedAuthenticatorFound = true; + Assert.assertEquals(authenticator.getString("id"), customIdPId); + Assert.assertEquals(authenticator.getString("name"), AUTHENTICATOR_NAME); + Assert.assertEquals(authenticator.getString("displayName"), AUTHENTICATOR_DISPLAY_NAME); + Assert.assertEquals(authenticator.getString("type"), "LOCAL"); + Assert.assertTrue(authenticator.getBoolean("isEnabled")); + Assert.assertEquals(authenticator.getString("self"), + getTenantedRelativePath(AUTHENTICATOR_CONFIG_API_BASE_PATH + customIdPId, tenant)); + } + } + Assert.assertTrue(isUserDefinedAuthenticatorFound); + } + + @Test(dependsOnMethods = {"testCreateUserDefinedLocalAuthenticator"}) + public void testUpdateUserDefinedLocalAuthenticator() throws JsonProcessingException { + + updatePayload.displayName(AUTHENTICATOR_DISPLAY_NAME + UPDATE_VALUE_POSTFIX); + updatePayload.isEnabled(false); + updatePayload.getEndpoint().uri(AUTHENTICATOR_ENDPOINT_URI + UPDATE_VALUE_POSTFIX); + String body = UserDefinedLocalAuthenticatorPayload.convertToJasonPayload(updatePayload); + Response response = getResponseOfPutWithNoFilter(AUTHENTICATOR_CUSTOM_API_BASE_PATH + PATH_SEPARATOR + + customIdPId, body); + response.then() + .log().ifValidationFails() + .assertThat() + .statusCode(HttpStatus.SC_OK) + .body("id", equalTo(customIdPId)) + .body("name", equalTo(AUTHENTICATOR_NAME)) + .body("displayName", equalTo(AUTHENTICATOR_DISPLAY_NAME + UPDATE_VALUE_POSTFIX)) + .body("type", equalTo("LOCAL")) + .body("definedBy", equalTo("USER")) + .body("isEnabled", equalTo(false)) + .body("self", equalTo(getTenantedRelativePath( + AUTHENTICATOR_CONFIG_API_BASE_PATH + customIdPId, tenant))); + } + + @Test(dependsOnMethods = {"testUpdateUserDefinedLocalAuthenticator"}) + public void testDeleteUserDefinedLocalAuthenticator() throws JsonProcessingException { + + Response response = getResponseOfDelete(AUTHENTICATOR_CUSTOM_API_BASE_PATH + PATH_SEPARATOR + + customIdPId); + response.then() + .log().ifValidationFails() + .assertThat() + .statusCode(HttpStatus.SC_NO_CONTENT); + } + + @Test(dependsOnMethods = {"testUpdateUserDefinedLocalAuthenticator"}) + public void testDeleteNonExistingUserDefinedLocalAuthenticator() throws JsonProcessingException { + + Response response = getResponseOfDelete(AUTHENTICATOR_CUSTOM_API_BASE_PATH + PATH_SEPARATOR + + customIdPId); + response.then() + .log().ifValidationFails() + .assertThat() + .statusCode(HttpStatus.SC_NO_CONTENT); + } } diff --git a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/authenticator/management/v1/AuthenticatorTestBase.java b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/authenticator/management/v1/AuthenticatorTestBase.java index 677455d1ed..4503f72501 100644 --- a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/authenticator/management/v1/AuthenticatorTestBase.java +++ b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/authenticator/management/v1/AuthenticatorTestBase.java @@ -24,9 +24,16 @@ import org.testng.annotations.AfterClass; import org.testng.annotations.AfterMethod; import org.testng.annotations.BeforeMethod; +import org.wso2.carbon.identity.api.server.authenticators.v1.model.AuthenticationType; +import org.wso2.carbon.identity.application.common.model.UserDefinedAuthenticatorEndpointConfig; +import org.wso2.carbon.identity.application.common.model.UserDefinedLocalAuthenticatorConfig; +import org.wso2.carbon.identity.base.AuthenticatorPropertyConstants; import org.wso2.identity.integration.test.rest.api.server.common.RESTAPIServerTestBase; import java.io.IOException; +import java.nio.charset.StandardCharsets; +import java.util.Base64; +import java.util.HashMap; public class AuthenticatorTestBase extends RESTAPIServerTestBase { @@ -35,6 +42,16 @@ public class AuthenticatorTestBase extends RESTAPIServerTestBase { protected static final String API_PACKAGE_NAME = "org.wso2.carbon.identity.api.server.authenticators.v1"; protected static final String AUTHENTICATOR_API_BASE_PATH = "/authenticators"; + protected static final String AUTHENTICATOR_CUSTOM_API_BASE_PATH = "/authenticators/custom"; + protected static final String AUTHENTICATOR_CONFIG_API_BASE_PATH = "/api/server/v1/configs/authenticators/"; + protected static final String PATH_SEPARATOR = "/"; + + protected final String AUTHENTICATOR_NAME = "customAuthenticator"; + protected final String AUTHENTICATOR_DISPLAY_NAME = "ABC custom authenticator"; + protected final String AUTHENTICATOR_ENDPOINT_URI = "https://test.com/authenticate"; + protected final String customIdPId = Base64.getUrlEncoder().withoutPadding().encodeToString( + AUTHENTICATOR_NAME.getBytes(StandardCharsets.UTF_8)); + protected final String UPDATE_VALUE_POSTFIX = "Updated"; protected static String swaggerDefinition; @@ -64,4 +81,25 @@ public void testFinish() { RestAssured.basePath = StringUtils.EMPTY; } + + protected UserDefinedLocalAuthenticatorConfig createBaseUserDefinedLocalAuthenticator( + AuthenticatorPropertyConstants.AuthenticationType type) { + + UserDefinedLocalAuthenticatorConfig config = new UserDefinedLocalAuthenticatorConfig(type); + config.setName(AUTHENTICATOR_NAME); + config.setDisplayName(AUTHENTICATOR_DISPLAY_NAME); + config.setEnabled(true); + + UserDefinedAuthenticatorEndpointConfig.UserDefinedAuthenticatorEndpointConfigBuilder endpointConfig = + new UserDefinedAuthenticatorEndpointConfig.UserDefinedAuthenticatorEndpointConfigBuilder(); + endpointConfig.uri(AUTHENTICATOR_ENDPOINT_URI); + endpointConfig.authenticationType(String.valueOf(AuthenticationType.TypeEnum.BASIC)); + endpointConfig.authenticationProperties(new HashMap() {{ + put("username", "adminUsername"); + put("password", "adminPassword"); + }}); + config.setEndpointConfig(endpointConfig.build()); + + return config; + } } diff --git a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/authenticator/management/v1/model/AuthenticationType.java b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/authenticator/management/v1/model/AuthenticationType.java new file mode 100644 index 0000000000..b3df1de0ed --- /dev/null +++ b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/authenticator/management/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.authenticators.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/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/authenticator/management/v1/model/Authenticator.java b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/authenticator/management/v1/model/Authenticator.java new file mode 100644 index 0000000000..76fd698e31 --- /dev/null +++ b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/authenticator/management/v1/model/Authenticator.java @@ -0,0 +1,362 @@ +/* +* Copyright (c) 2021, WSO2 LLC. (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. +*/ + +package org.wso2.carbon.identity.api.server.authenticators.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 javax.validation.constraints.*; + + +import io.swagger.annotations.*; +import java.util.Objects; +import javax.validation.Valid; +import javax.xml.bind.annotation.*; + +public class Authenticator { + + private String id; + private String name; + 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 { + + @XmlEnumValue("LOCAL") LOCAL(String.valueOf("LOCAL")), @XmlEnumValue("FEDERATED") FEDERATED(String.valueOf("FEDERATED")); + + + 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 String image; + private String description; + private List tags = null; + + private String self; + + /** + **/ + public Authenticator id(String id) { + + this.id = id; + return this; + } + + @ApiModelProperty(example = "QmFzaWNBdXRoZW50aWNhdG9y", value = "") + @JsonProperty("id") + @Valid + public String getId() { + return id; + } + public void setId(String id) { + this.id = id; + } + + /** + **/ + public Authenticator name(String name) { + + this.name = name; + return this; + } + + @ApiModelProperty(example = "BasicAuthenticator", value = "") + @JsonProperty("name") + @Valid + public String getName() { + return name; + } + public void setName(String name) { + this.name = name; + } + + /** + **/ + public Authenticator displayName(String displayName) { + + this.displayName = displayName; + return this; + } + + @ApiModelProperty(example = "basic", value = "") + @JsonProperty("displayName") + @Valid + public String getDisplayName() { + return displayName; + } + public void setDisplayName(String displayName) { + this.displayName = displayName; + } + + /** + **/ + public Authenticator 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 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) { + + this.type = type; + return this; + } + + @ApiModelProperty(value = "") + @JsonProperty("type") + @Valid + public TypeEnum getType() { + return type; + } + public void setType(TypeEnum type) { + this.type = type; + } + + /** + **/ + public Authenticator image(String image) { + + this.image = image; + return this; + } + + @ApiModelProperty(example = "basic-authenticator-logo-url", value = "") + @JsonProperty("image") + @Valid + public String getImage() { + return image; + } + public void setImage(String image) { + this.image = image; + } + + /** + **/ + public Authenticator description(String description) { + + this.description = description; + return this; + } + + @ApiModelProperty(example = "The basic authenticator.", value = "") + @JsonProperty("description") + @Valid + public String getDescription() { + return description; + } + public void setDescription(String description) { + this.description = description; + } + + /** + **/ + public Authenticator tags(List tags) { + + this.tags = tags; + return this; + } + + @ApiModelProperty(example = "[\"2FA\",\"MFA\"]", value = "") + @JsonProperty("tags") + @Valid + public List getTags() { + return tags; + } + public void setTags(List tags) { + this.tags = tags; + } + + public Authenticator addTagsItem(String tagsItem) { + if (this.tags == null) { + this.tags = new ArrayList<>(); + } + this.tags.add(tagsItem); + return this; + } + + /** + **/ + public Authenticator self(String self) { + + this.self = self; + return this; + } + + @ApiModelProperty(example = "/t/carbon.super/api/server/v1/configs/authenticators/eDUwOUNlcnRpZmljYXRlQXV0aGVudGljYXRvcg", value = "") + @JsonProperty("self") + @Valid + public String getSelf() { + return self; + } + public void setSelf(String self) { + this.self = self; + } + + + + @Override + public boolean equals(java.lang.Object o) { + + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + Authenticator authenticator = (Authenticator) o; + return Objects.equals(this.id, authenticator.id) && + 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) && + Objects.equals(this.tags, authenticator.tags) && + Objects.equals(this.self, authenticator.self); + } + + @Override + public int hashCode() { + return Objects.hash(id, name, displayName, isEnabled, definedBy, type, image, description, tags, self); + } + + @Override + public String toString() { + + StringBuilder sb = new StringBuilder(); + sb.append("class Authenticator {\n"); + + sb.append(" id: ").append(toIndentedString(id)).append("\n"); + 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"); + sb.append(" tags: ").append(toIndentedString(tags)).append("\n"); + sb.append(" self: ").append(toIndentedString(self)).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/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/authenticator/management/v1/model/Endpoint.java b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/authenticator/management/v1/model/Endpoint.java new file mode 100644 index 0000000000..fbf614fe71 --- /dev/null +++ b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/authenticator/management/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.authenticators.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.authenticators.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/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/authenticator/management/v1/model/UserDefinedLocalAuthenticatorCreation.java b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/authenticator/management/v1/model/UserDefinedLocalAuthenticatorCreation.java new file mode 100644 index 0000000000..5f41aecca3 --- /dev/null +++ b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/authenticator/management/v1/model/UserDefinedLocalAuthenticatorCreation.java @@ -0,0 +1,290 @@ +/* + * 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.authenticators.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.authenticators.v1.model.Endpoint; +import javax.validation.constraints.*; + +/** + * This represents the configuration for creating the user defined local authenticator. + **/ + +import io.swagger.annotations.*; +import java.util.Objects; +import javax.validation.Valid; +import javax.xml.bind.annotation.*; +@ApiModel(description = "This represents the configuration for creating the user defined local authenticator.") +public class UserDefinedLocalAuthenticatorCreation { + + private String name; + private String id; + private String displayName; + private Boolean isEnabled; + +@XmlType(name="AuthenticationTypeEnum") +@XmlEnum(String.class) +public enum AuthenticationTypeEnum { + + @XmlEnumValue("IDENTIFICATION") IDENTIFICATION(String.valueOf("IDENTIFICATION")), @XmlEnumValue("VERIFICATION") VERIFICATION(String.valueOf("VERIFICATION")); + + + private String value; + + AuthenticationTypeEnum(String v) { + value = v; + } + + public String value() { + return value; + } + + @Override + public String toString() { + return String.valueOf(value); + } + + public static AuthenticationTypeEnum fromValue(String value) { + for (AuthenticationTypeEnum b : AuthenticationTypeEnum.values()) { + if (b.value.equals(value)) { + return b; + } + } + throw new IllegalArgumentException("Unexpected value '" + value + "'"); + } +} + + private AuthenticationTypeEnum authenticationType; + private String image; + private String description; + private Endpoint endpoint; + + /** + **/ + public UserDefinedLocalAuthenticatorCreation name(String name) { + + this.name = name; + return this; + } + + @ApiModelProperty(example = "CustomAuthenticator", required = true, value = "") + @JsonProperty("name") + @Valid + @NotNull(message = "Property name cannot be null.") + + public String getName() { + return name; + } + public void setName(String name) { + this.name = name; + } + + /** + **/ + public UserDefinedLocalAuthenticatorCreation id(String id) { + + this.id = id; + return this; + } + + @ApiModelProperty(example = "Q3VzdG9tQXV0aGVudGljYXRvcg==", value = "") + @JsonProperty("id") + @Valid + public String getId() { + return id; + } + public void setId(String id) { + this.id = id; + } + + /** + **/ + public UserDefinedLocalAuthenticatorCreation displayName(String displayName) { + + this.displayName = displayName; + return this; + } + + @ApiModelProperty(example = "Custom auth", required = true, value = "") + @JsonProperty("displayName") + @Valid + @NotNull(message = "Property displayName cannot be null.") + + public String getDisplayName() { + return displayName; + } + public void setDisplayName(String displayName) { + this.displayName = displayName; + } + + /** + **/ + public UserDefinedLocalAuthenticatorCreation isEnabled(Boolean isEnabled) { + + this.isEnabled = isEnabled; + return this; + } + + @ApiModelProperty(example = "true", required = true, value = "") + @JsonProperty("isEnabled") + @Valid + @NotNull(message = "Property isEnabled cannot be null.") + + public Boolean getIsEnabled() { + return isEnabled; + } + public void setIsEnabled(Boolean isEnabled) { + this.isEnabled = isEnabled; + } + + /** + **/ + public UserDefinedLocalAuthenticatorCreation authenticationType(AuthenticationTypeEnum authenticationType) { + + this.authenticationType = authenticationType; + return this; + } + + @ApiModelProperty(value = "") + @JsonProperty("authenticationType") + @Valid + public AuthenticationTypeEnum getAuthenticationType() { + return authenticationType; + } + public void setAuthenticationType(AuthenticationTypeEnum authenticationType) { + this.authenticationType = authenticationType; + } + + /** + **/ + public UserDefinedLocalAuthenticatorCreation image(String image) { + + this.image = image; + return this; + } + + @ApiModelProperty(example = "https://custom-authenticator-logo-url", value = "") + @JsonProperty("image") + @Valid + public String getImage() { + return image; + } + public void setImage(String image) { + this.image = image; + } + + /** + **/ + public UserDefinedLocalAuthenticatorCreation description(String description) { + + this.description = description; + return this; + } + + @ApiModelProperty(example = "The user defined custom local authenticator.", value = "") + @JsonProperty("description") + @Valid + public String getDescription() { + return description; + } + public void setDescription(String description) { + this.description = description; + } + + /** + **/ + public UserDefinedLocalAuthenticatorCreation endpoint(Endpoint endpoint) { + + this.endpoint = endpoint; + return this; + } + + @ApiModelProperty(required = true, value = "") + @JsonProperty("endpoint") + @Valid + @NotNull(message = "Property endpoint cannot be null.") + + 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; + } + UserDefinedLocalAuthenticatorCreation userDefinedLocalAuthenticatorCreation = (UserDefinedLocalAuthenticatorCreation) o; + return Objects.equals(this.name, userDefinedLocalAuthenticatorCreation.name) && + Objects.equals(this.id, userDefinedLocalAuthenticatorCreation.id) && + Objects.equals(this.displayName, userDefinedLocalAuthenticatorCreation.displayName) && + Objects.equals(this.isEnabled, userDefinedLocalAuthenticatorCreation.isEnabled) && + Objects.equals(this.authenticationType, userDefinedLocalAuthenticatorCreation.authenticationType) && + Objects.equals(this.image, userDefinedLocalAuthenticatorCreation.image) && + Objects.equals(this.description, userDefinedLocalAuthenticatorCreation.description) && + Objects.equals(this.endpoint, userDefinedLocalAuthenticatorCreation.endpoint); + } + + @Override + public int hashCode() { + return Objects.hash(name, id, displayName, isEnabled, authenticationType, image, description, endpoint); + } + + @Override + public String toString() { + + StringBuilder sb = new StringBuilder(); + sb.append("class UserDefinedLocalAuthenticatorCreation {\n"); + + sb.append(" name: ").append(toIndentedString(name)).append("\n"); + sb.append(" id: ").append(toIndentedString(id)).append("\n"); + sb.append(" displayName: ").append(toIndentedString(displayName)).append("\n"); + sb.append(" isEnabled: ").append(toIndentedString(isEnabled)).append("\n"); + sb.append(" authenticationType: ").append(toIndentedString(authenticationType)).append("\n"); + sb.append(" image: ").append(toIndentedString(image)).append("\n"); + sb.append(" description: ").append(toIndentedString(description)).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/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/authenticator/management/v1/model/UserDefinedLocalAuthenticatorUpdate.java b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/authenticator/management/v1/model/UserDefinedLocalAuthenticatorUpdate.java new file mode 100644 index 0000000000..d31ff73267 --- /dev/null +++ b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/authenticator/management/v1/model/UserDefinedLocalAuthenticatorUpdate.java @@ -0,0 +1,192 @@ +/* + * 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.authenticators.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.authenticators.v1.model.Endpoint; +import javax.validation.constraints.*; + +/** + * TThis represents the configuration for updating user defined local authenticator. + **/ + +import io.swagger.annotations.*; +import java.util.Objects; +import javax.validation.Valid; +import javax.xml.bind.annotation.*; +@ApiModel(description = "TThis represents the configuration for updating user defined local authenticator.") +public class UserDefinedLocalAuthenticatorUpdate { + + private String displayName; + private Boolean isEnabled; + private String image; + private String description; + private Endpoint endpoint; + + /** + **/ + public UserDefinedLocalAuthenticatorUpdate displayName(String displayName) { + + this.displayName = displayName; + return this; + } + + @ApiModelProperty(example = "Custom auth", required = true, value = "") + @JsonProperty("displayName") + @Valid + @NotNull(message = "Property displayName cannot be null.") + + public String getDisplayName() { + return displayName; + } + public void setDisplayName(String displayName) { + this.displayName = displayName; + } + + /** + **/ + public UserDefinedLocalAuthenticatorUpdate isEnabled(Boolean isEnabled) { + + this.isEnabled = isEnabled; + return this; + } + + @ApiModelProperty(example = "true", required = true, value = "") + @JsonProperty("isEnabled") + @Valid + @NotNull(message = "Property isEnabled cannot be null.") + + public Boolean getIsEnabled() { + return isEnabled; + } + public void setIsEnabled(Boolean isEnabled) { + this.isEnabled = isEnabled; + } + + /** + **/ + public UserDefinedLocalAuthenticatorUpdate image(String image) { + + this.image = image; + return this; + } + + @ApiModelProperty(example = "https://custom-authenticator-logo-url", value = "") + @JsonProperty("image") + @Valid + public String getImage() { + return image; + } + public void setImage(String image) { + this.image = image; + } + + /** + **/ + public UserDefinedLocalAuthenticatorUpdate description(String description) { + + this.description = description; + return this; + } + + @ApiModelProperty(example = "The user defined custom local authenticator.", value = "") + @JsonProperty("description") + @Valid + public String getDescription() { + return description; + } + public void setDescription(String description) { + this.description = description; + } + + /** + **/ + public UserDefinedLocalAuthenticatorUpdate endpoint(Endpoint endpoint) { + + this.endpoint = endpoint; + return this; + } + + @ApiModelProperty(required = true, value = "") + @JsonProperty("endpoint") + @Valid + @NotNull(message = "Property endpoint cannot be null.") + + 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; + } + UserDefinedLocalAuthenticatorUpdate userDefinedLocalAuthenticatorUpdate = (UserDefinedLocalAuthenticatorUpdate) o; + return Objects.equals(this.displayName, userDefinedLocalAuthenticatorUpdate.displayName) && + Objects.equals(this.isEnabled, userDefinedLocalAuthenticatorUpdate.isEnabled) && + Objects.equals(this.image, userDefinedLocalAuthenticatorUpdate.image) && + Objects.equals(this.description, userDefinedLocalAuthenticatorUpdate.description) && + Objects.equals(this.endpoint, userDefinedLocalAuthenticatorUpdate.endpoint); + } + + @Override + public int hashCode() { + return Objects.hash(displayName, isEnabled, image, description, endpoint); + } + + @Override + public String toString() { + + StringBuilder sb = new StringBuilder(); + sb.append("class UserDefinedLocalAuthenticatorUpdate {\n"); + + sb.append(" displayName: ").append(toIndentedString(displayName)).append("\n"); + sb.append(" isEnabled: ").append(toIndentedString(isEnabled)).append("\n"); + sb.append(" image: ").append(toIndentedString(image)).append("\n"); + sb.append(" description: ").append(toIndentedString(description)).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/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/authenticator/management/v1/util/UserDefinedLocalAuthenticatorPayload.java b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/authenticator/management/v1/util/UserDefinedLocalAuthenticatorPayload.java new file mode 100644 index 0000000000..3578901b75 --- /dev/null +++ b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/authenticator/management/v1/util/UserDefinedLocalAuthenticatorPayload.java @@ -0,0 +1,104 @@ +/* + * 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.identity.integration.test.rest.api.server.authenticator.management.v1.util; + +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import org.wso2.carbon.identity.action.management.model.AuthProperty; +import org.wso2.carbon.identity.api.server.authenticators.v1.model.AuthenticationType; +import org.wso2.carbon.identity.api.server.authenticators.v1.model.UserDefinedLocalAuthenticatorCreation; +import org.wso2.carbon.identity.api.server.authenticators.v1.model.Endpoint; +import org.wso2.carbon.identity.api.server.authenticators.v1.model.UserDefinedLocalAuthenticatorUpdate; +import org.wso2.carbon.identity.application.common.model.UserDefinedAuthenticatorEndpointConfig; +import org.wso2.carbon.identity.application.common.model.UserDefinedLocalAuthenticatorConfig; + +import java.util.Map; +import java.util.stream.Collectors; + +/** + * The util class to create a user defined local authenticator payload for APIs. + */ +public class UserDefinedLocalAuthenticatorPayload { + + /** + * Convert the object to a JSON payload. + * + * @param ob Object to be converted to a JSON payload. + * @return JSON payload. + * @throws JsonProcessingException If any error occurred while converting the object to a JSON payload. + */ + public static String convertToJasonPayload(Object ob) throws JsonProcessingException { + + ObjectMapper objectMapper = new ObjectMapper(); + objectMapper.setSerializationInclusion(JsonInclude.Include.NON_NULL); + return objectMapper.writeValueAsString(ob); + } + + /** + * Create a UserDefinedLocalAuthenticatorCreation object. + * + * @param config UserDefinedLocalAuthenticatorConfig object. + * @return UserDefinedLocalAuthenticatorCreation object. + */ + public static UserDefinedLocalAuthenticatorCreation getBasedUserDefinedLocalAuthenticatorCreation( + UserDefinedLocalAuthenticatorConfig config) { + + UserDefinedLocalAuthenticatorCreation configForCreation = new UserDefinedLocalAuthenticatorCreation(); + configForCreation.setName(config.getName()); + configForCreation.setDisplayName(config.getDisplayName()); + configForCreation.setIsEnabled(config.isEnabled()); + configForCreation.setAuthenticationType(UserDefinedLocalAuthenticatorCreation.AuthenticationTypeEnum.valueOf( + config.getAuthenticationType().toString())); + configForCreation.setEndpoint(convertToEndpoint(config.getEndpointConfig())); + return configForCreation; + } + + /** + * Create a UserDefinedLocalAuthenticatorUpdate object. + * + * @param config UserDefinedLocalAuthenticatorConfig object. + * @return UserDefinedLocalAuthenticatorUpdate object. + */ + public static UserDefinedLocalAuthenticatorUpdate getBasedUserDefinedLocalAuthenticatorUpdate( + UserDefinedLocalAuthenticatorConfig config) { + + UserDefinedLocalAuthenticatorUpdate configForUpdate = new UserDefinedLocalAuthenticatorUpdate(); + configForUpdate.setDisplayName(config.getDisplayName()); + configForUpdate.setIsEnabled(config.isEnabled()); + configForUpdate.setEndpoint(convertToEndpoint(config.getEndpointConfig())); + return configForUpdate; + } + + private static Endpoint convertToEndpoint(UserDefinedAuthenticatorEndpointConfig endpointConfig) { + + Endpoint endpoint = new Endpoint(); + endpoint.setUri(endpointConfig.getEndpointConfig().getUri()); + AuthenticationType authenticationConfig = new AuthenticationType(); + authenticationConfig.setType(AuthenticationType.TypeEnum.valueOf(endpointConfig.getEndpointConfig() + .getAuthentication().getType().toString())); + Map propertyMap = endpointConfig.getEndpointConfig().getAuthentication().getProperties().stream() + .collect(Collectors.toMap(AuthProperty::getName, AuthProperty::getValue)); + authenticationConfig.setProperties(propertyMap); + authenticationConfig.setProperties(propertyMap); + endpoint.setAuthentication(authenticationConfig); + return endpoint; + } +} diff --git a/modules/integration/tests-integration/tests-backend/src/test/resources/testng.xml b/modules/integration/tests-integration/tests-backend/src/test/resources/testng.xml index 630b531007..4e300a81b5 100644 --- a/modules/integration/tests-integration/tests-backend/src/test/resources/testng.xml +++ b/modules/integration/tests-integration/tests-backend/src/test/resources/testng.xml @@ -240,6 +240,7 @@ + From db3bc51ab775e510daeaef7da2a4e28a0fcb1a5f Mon Sep 17 00:00:00 2001 From: Thisara-Welmilla Date: Tue, 17 Dec 2024 10:34:30 +0530 Subject: [PATCH 2/2] Address comments. --- .../authenticator/management/v1/AuthenticatorFailureTest.java | 1 - 1 file changed, 1 deletion(-) diff --git a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/authenticator/management/v1/AuthenticatorFailureTest.java b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/authenticator/management/v1/AuthenticatorFailureTest.java index 5c98f49c3b..66ea21f790 100644 --- a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/authenticator/management/v1/AuthenticatorFailureTest.java +++ b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/authenticator/management/v1/AuthenticatorFailureTest.java @@ -70,7 +70,6 @@ public void init() throws IOException, JSONException { testAuthenticatorConfig = createBaseUserDefinedLocalAuthenticator( AuthenticatorPropertyConstants.AuthenticationType.IDENTIFICATION); addUserDefinedAuthenticatorToIS(); - } @AfterClass(alwaysRun = true)