diff --git a/testsuite/integration/elytron/src/test/java/org/wildfly/test/integration/elytron/realm/AggregateRealmTestCase.java b/testsuite/integration/elytron/src/test/java/org/wildfly/test/integration/elytron/realm/AggregateRealmTestCase.java index 503f49a4c4d6..c3d40a4d7302 100644 --- a/testsuite/integration/elytron/src/test/java/org/wildfly/test/integration/elytron/realm/AggregateRealmTestCase.java +++ b/testsuite/integration/elytron/src/test/java/org/wildfly/test/integration/elytron/realm/AggregateRealmTestCase.java @@ -21,18 +21,18 @@ */ package org.wildfly.test.integration.elytron.realm; -import java.io.File; -import java.io.IOException; +import static javax.servlet.http.HttpServletResponse.SC_FORBIDDEN; +import static javax.servlet.http.HttpServletResponse.SC_OK; +import static javax.servlet.http.HttpServletResponse.SC_UNAUTHORIZED; +import static org.junit.Assert.fail; + import java.net.MalformedURLException; import java.net.URL; import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.Arrays; import java.util.List; -import static javax.servlet.http.HttpServletResponse.SC_FORBIDDEN; -import static javax.servlet.http.HttpServletResponse.SC_OK; -import static javax.servlet.http.HttpServletResponse.SC_UNAUTHORIZED; -import org.apache.commons.io.FileUtils; + import org.apache.http.NameValuePair; import org.apache.http.client.utils.URLEncodedUtils; import org.apache.http.message.BasicNameValuePair; @@ -43,21 +43,20 @@ import org.jboss.arquillian.junit.Arquillian; import org.jboss.arquillian.test.api.ArquillianResource; import org.jboss.as.arquillian.api.ServerSetup; -import org.jboss.as.arquillian.api.ServerSetupTask; -import org.jboss.as.arquillian.container.ManagementClient; -import org.jboss.as.test.integration.management.util.CLIWrapper; import org.jboss.as.test.integration.security.common.Utils; -import static org.jboss.as.test.integration.security.common.Utils.createTemporaryFolder; import org.jboss.as.test.integration.security.common.servlets.RolePrintingServlet; -import org.jboss.as.test.shared.CliUtils; -import static org.jboss.as.test.shared.CliUtils.asAbsolutePath; -import org.jboss.as.test.shared.ServerReload; -import org.jboss.crypto.CryptoUtil; import org.jboss.shrinkwrap.api.ShrinkWrap; import org.jboss.shrinkwrap.api.spec.WebArchive; -import static org.junit.Assert.fail; import org.junit.Test; import org.junit.runner.RunWith; +import org.wildfly.test.security.common.AbstractElytronSetupTask; +import org.wildfly.test.security.common.elytron.AggregateSecurityRealm; +import org.wildfly.test.security.common.elytron.ConfigurableElement; +import org.wildfly.test.security.common.elytron.FileSystemRealm; +import org.wildfly.test.security.common.elytron.PropertiesRealm; +import org.wildfly.test.security.common.elytron.SimpleSecurityDomain; +import org.wildfly.test.security.common.elytron.UserWithAttributeValues; +import org.wildfly.test.undertow.common.UndertowApplicationSecurityDomain; /** * Test case for Elytron Aggregate Realm. @@ -506,176 +505,129 @@ private void assertNotInRole(final String rolePrintResponse, String role) { } } - static class SetupTask implements ServerSetupTask { - - private static final String PREDEFINED_HTTP_SERVER_MECHANISM_FACTORY = "global"; + static class SetupTask extends AbstractElytronSetupTask { private static final String PROPERTIES_REALM_AUTHN_NAME = "elytron-authn-properties-realm"; private static final String PROPERTIES_REALM_AUTHZ_NAME = "elytron-authz-properties-realm"; private static final String FILESYSTEM_REALM_AUTHN_NAME = "elytron-authn-filesystem-realm"; - private static final String USERS_AUTHN_REALM_FILENAME = "users-authn.properties"; - private static final String ROLES_AUTHN_REALM_FILENAME = "roles-authn.properties"; - private static final String USERS_AUTHZ_REALM_FILENAME = "users-authz.properties"; - private static final String ROLES_AUTHZ_REALM_FILENAME = "roles-authz.properties"; - private File usersAuthnRealmFile; - private File rolesAuthnRealmFile; - private File usersAuthzRealmFile; - private File rolesAuthzRealmFile; - private String fsRealmPath; - - private File tempFolder; - - @Override - public void setup(ManagementClient mc, String string) throws Exception { - tempFolder = createTemporaryFolder("ely-" + AggregateRealmTestCase.class.getSimpleName()); - String tempFolderAbsolutePath = tempFolder.getAbsolutePath(); - usersAuthnRealmFile = new File(tempFolderAbsolutePath, USERS_AUTHN_REALM_FILENAME); - rolesAuthnRealmFile = new File(tempFolderAbsolutePath, ROLES_AUTHN_REALM_FILENAME); - usersAuthzRealmFile = new File(tempFolderAbsolutePath, USERS_AUTHZ_REALM_FILENAME); - rolesAuthzRealmFile = new File(tempFolderAbsolutePath, ROLES_AUTHZ_REALM_FILENAME); - fsRealmPath = CliUtils.escapePath(tempFolderAbsolutePath + File.separator + "fs-realm-users"); - createPropertiesFiles(); - try (CLIWrapper cli = new CLIWrapper(true)) { - cli.sendLine(String.format( - "/subsystem=elytron/properties-realm=%s:add(users-properties={path=%s},groups-properties={path=%s})", - PROPERTIES_REALM_AUTHN_NAME, asAbsolutePath(usersAuthnRealmFile), - asAbsolutePath(rolesAuthnRealmFile))); - cli.sendLine(String.format( - "/subsystem=elytron/properties-realm=%s:add(users-properties={path=%s},groups-properties={path=%s})", - PROPERTIES_REALM_AUTHZ_NAME, asAbsolutePath(usersAuthzRealmFile), - asAbsolutePath(rolesAuthzRealmFile))); - cli.sendLine(String.format( - "/subsystem=elytron/filesystem-realm=%s:add(path=%s)", - FILESYSTEM_REALM_AUTHN_NAME, fsRealmPath)); - addUserToFilesystemRealm(cli, USER_WITHOUT_ROLE, CORRECT_PASSWORD); - addUserToFilesystemRealm(cli, USER_WITH_ONE_ROLE, CORRECT_PASSWORD); - addUserToFilesystemRealm(cli, USER_WITH_TWO_ROLES, CORRECT_PASSWORD); - addUserToFilesystemRealm(cli, USER_WITH_DIFFERENT_ROLE_IN_DIFFERENT_REALM, CORRECT_PASSWORD, ROLE_USER); - addUserToFilesystemRealm(cli, USER_ONLY_IN_AUTHORIZATION, CORRECT_PASSWORD); - addAggregateRealmAndRelatedResources(cli, AGGREGATE_REALM_SAME_TYPE_NAME, PROPERTIES_REALM_AUTHN_NAME, - PROPERTIES_REALM_AUTHZ_NAME); - addAggregateRealmAndRelatedResources(cli, AGGREGATE_REALM_DIFFERENT_TYPE_NAME, FILESYSTEM_REALM_AUTHN_NAME, - PROPERTIES_REALM_AUTHZ_NAME); - } - ServerReload.reloadIfRequired(mc.getControllerClient()); - } - @Override - public void tearDown(ManagementClient mc, String string) throws Exception { - try (CLIWrapper cli = new CLIWrapper(true)) { - removeAggregateRealmAndRelatedResources(mc, cli, AGGREGATE_REALM_DIFFERENT_TYPE_NAME); - removeAggregateRealmAndRelatedResources(mc, cli, AGGREGATE_REALM_SAME_TYPE_NAME); - ServerReload.reloadIfRequired(mc.getControllerClient()); - cli.sendLine(String.format("/subsystem=elytron/filesystem-realm=%s:remove()", FILESYSTEM_REALM_AUTHN_NAME)); - cli.sendLine(String.format("/subsystem=elytron/properties-realm=%s:remove()", PROPERTIES_REALM_AUTHZ_NAME)); - cli.sendLine(String.format("/subsystem=elytron/properties-realm=%s:remove()", PROPERTIES_REALM_AUTHN_NAME)); - ServerReload.reloadIfRequired(mc.getControllerClient()); - } finally { - removePropertiesFiles(); - } + protected ConfigurableElement[] getConfigurableElements() { + ArrayList configurableElements = new ArrayList<>(); + configurableElements.add(PropertiesRealm.builder() + .withName(PROPERTIES_REALM_AUTHN_NAME) + .withUser(UserWithAttributeValues.builder() + .withName(USER_WITHOUT_ROLE) + .withPassword(CORRECT_PASSWORD) + .build()) + .withUser(UserWithAttributeValues.builder() + .withName(USER_WITH_ONE_ROLE) + .withPassword(CORRECT_PASSWORD) + .build()) + .withUser(UserWithAttributeValues.builder() + .withName(USER_WITH_TWO_ROLES) + .withPassword(CORRECT_PASSWORD) + .build()) + .withUser(UserWithAttributeValues.builder() + .withName(USER_WITH_DIFFERENT_ROLE_IN_DIFFERENT_REALM) + .withPassword(CORRECT_PASSWORD) + .build()) + .withUser(UserWithAttributeValues.builder() + .withName(USER_WITH_DIFFERENT_ROLE_IN_DIFFERENT_REALM) + .withPassword(CORRECT_PASSWORD) + .withValues(ROLE_USER) + .build()) + .withUser(UserWithAttributeValues.builder() + .withName(USER_ONLY_IN_AUTHORIZATION) + .withPassword(CORRECT_PASSWORD) + .build()) + .build()); + configurableElements.add(PropertiesRealm.builder() + .withName(PROPERTIES_REALM_AUTHZ_NAME) + .withUser(UserWithAttributeValues.builder() + .withName(USER_WITHOUT_ROLE) + .withPassword(AUTHORIZATION_REALM_PASSWORD) + .build()) + .withUser(UserWithAttributeValues.builder() + .withName(USER_WITH_ONE_ROLE) + .withPassword(AUTHORIZATION_REALM_PASSWORD) + .withValues(ROLE_USER) + .build()) + .withUser(UserWithAttributeValues.builder() + .withName(USER_WITH_TWO_ROLES) + .withPassword(AUTHORIZATION_REALM_PASSWORD) + .withValues(ROLE_USER, ROLE_ADMIN) + .build()) + .withUser(UserWithAttributeValues.builder() + .withName(USER_WITH_DIFFERENT_ROLE_IN_DIFFERENT_REALM) + .withPassword(AUTHORIZATION_REALM_PASSWORD) + .withValues(ROLE_ADMIN) + .build()) + .withUser(UserWithAttributeValues.builder() + .withName(USER_ONLY_IN_AUTHORIZATION) + .withValues(ROLE_USER) + .build()) + .build()); + configurableElements.add(FileSystemRealm.builder() + .withName(FILESYSTEM_REALM_AUTHN_NAME) + .withUser(UserWithAttributeValues.builder() + .withName(USER_WITHOUT_ROLE) + .withPassword(CORRECT_PASSWORD) + .build()) + .withUser(UserWithAttributeValues.builder() + .withName(USER_WITH_ONE_ROLE) + .withPassword(CORRECT_PASSWORD) + .build()) + .withUser(UserWithAttributeValues.builder() + .withName(USER_WITH_TWO_ROLES) + .withPassword(CORRECT_PASSWORD) + .build()) + .withUser(UserWithAttributeValues.builder() + .withName(USER_WITH_DIFFERENT_ROLE_IN_DIFFERENT_REALM) + .withPassword(CORRECT_PASSWORD) + .withValues(ROLE_USER) + .build()) + .withUser(UserWithAttributeValues.builder() + .withName(USER_ONLY_IN_AUTHORIZATION) + .withPassword(CORRECT_PASSWORD) + .build()) + .build()); + configurableElements.add(AggregateSecurityRealm.builder(AGGREGATE_REALM_SAME_TYPE_NAME) + .withAuthenticationRealm(PROPERTIES_REALM_AUTHN_NAME) + .withAuthorizationRealm(PROPERTIES_REALM_AUTHZ_NAME) + .build()); + configurableElements.add(SimpleSecurityDomain.builder() + .withName(AGGREGATE_REALM_SAME_TYPE_NAME) + .withDefaultRealm(AGGREGATE_REALM_SAME_TYPE_NAME) + .withPermissionMapper("default-permission-mapper") + .withRealms(SimpleSecurityDomain.SecurityDomainRealm.builder() + .withRealm(AGGREGATE_REALM_SAME_TYPE_NAME) + .withRoleDecoder("groups-to-roles") + .build()) + .build()); + configurableElements.add(AggregateSecurityRealm.builder(AGGREGATE_REALM_DIFFERENT_TYPE_NAME) + .withAuthenticationRealm(FILESYSTEM_REALM_AUTHN_NAME) + .withAuthorizationRealm(PROPERTIES_REALM_AUTHZ_NAME) + .build()); + configurableElements.add(SimpleSecurityDomain.builder() + .withName(AGGREGATE_REALM_DIFFERENT_TYPE_NAME) + .withDefaultRealm(AGGREGATE_REALM_DIFFERENT_TYPE_NAME) + .withPermissionMapper("default-permission-mapper") + .withRealms(SimpleSecurityDomain.SecurityDomainRealm.builder() + .withRealm(AGGREGATE_REALM_DIFFERENT_TYPE_NAME) + .withRoleDecoder("groups-to-roles") + .build()) + .build()); + configurableElements.add(UndertowApplicationSecurityDomain.builder() + .withName(AGGREGATE_REALM_SAME_TYPE_NAME) + .withSecurityDomain(AGGREGATE_REALM_SAME_TYPE_NAME) + .build()); + configurableElements.add(UndertowApplicationSecurityDomain.builder() + .withName(AGGREGATE_REALM_DIFFERENT_TYPE_NAME) + .withSecurityDomain(AGGREGATE_REALM_DIFFERENT_TYPE_NAME) + .build()); + return configurableElements.toArray(new ConfigurableElement[configurableElements.size()]); } - - private void createPropertiesFiles() throws IOException { - createUsersProperties_authnRealm(); - createRolesProperties_authnRealm(); - createUsersProperties_authzRealm(); - createRolesProperties_authzRealm(); - } - - private void createUsersProperties_authnRealm() throws IOException { - StringBuilder sb = new StringBuilder(); - sb.append("#$REALM_NAME=" + PROPERTIES_REALM_AUTHN_NAME + "$\n"); - sb.append(createPropertiesUserWithHashedPassword(USER_WITHOUT_ROLE, CORRECT_PASSWORD, PROPERTIES_REALM_AUTHN_NAME)); - sb.append(createPropertiesUserWithHashedPassword(USER_WITH_ONE_ROLE, CORRECT_PASSWORD, PROPERTIES_REALM_AUTHN_NAME)); - sb.append(createPropertiesUserWithHashedPassword(USER_WITH_TWO_ROLES, CORRECT_PASSWORD, PROPERTIES_REALM_AUTHN_NAME)); - sb.append(createPropertiesUserWithHashedPassword(USER_WITH_DIFFERENT_ROLE_IN_DIFFERENT_REALM, CORRECT_PASSWORD, PROPERTIES_REALM_AUTHN_NAME)); - sb.append(createPropertiesUserWithHashedPassword(USER_ONLY_IN_AUTHORIZATION, CORRECT_PASSWORD, PROPERTIES_REALM_AUTHN_NAME)); - FileUtils.writeStringToFile(usersAuthnRealmFile, sb.toString(), StandardCharsets.UTF_8); - } - - private void createRolesProperties_authnRealm() throws IOException { - StringBuilder sb = new StringBuilder(); - sb.append(USER_WITH_DIFFERENT_ROLE_IN_DIFFERENT_REALM + "=" + ROLE_USER + "\n"); - FileUtils.writeStringToFile(rolesAuthnRealmFile, sb.toString(), StandardCharsets.UTF_8); - } - - private void createUsersProperties_authzRealm() throws IOException { - StringBuilder sb = new StringBuilder(); - sb.append("#$REALM_NAME=" + PROPERTIES_REALM_AUTHZ_NAME + "$\n"); - sb.append(createPropertiesUserWithHashedPassword(USER_WITHOUT_ROLE, AUTHORIZATION_REALM_PASSWORD, PROPERTIES_REALM_AUTHZ_NAME)); - sb.append(createPropertiesUserWithHashedPassword(USER_WITH_ONE_ROLE, AUTHORIZATION_REALM_PASSWORD, PROPERTIES_REALM_AUTHZ_NAME)); - sb.append(createPropertiesUserWithHashedPassword(USER_WITH_TWO_ROLES, AUTHORIZATION_REALM_PASSWORD, PROPERTIES_REALM_AUTHZ_NAME)); - sb.append(createPropertiesUserWithHashedPassword(USER_WITH_DIFFERENT_ROLE_IN_DIFFERENT_REALM, AUTHORIZATION_REALM_PASSWORD, PROPERTIES_REALM_AUTHZ_NAME)); - FileUtils.writeStringToFile(usersAuthzRealmFile, sb.toString(), StandardCharsets.UTF_8); - } - - private void createRolesProperties_authzRealm() throws IOException { - StringBuilder sb = new StringBuilder(); - sb.append(USER_WITH_ONE_ROLE + "=" + ROLE_USER + "\n"); - sb.append(USER_WITH_TWO_ROLES + "=" + ROLE_USER + "," + ROLE_ADMIN + "\n"); - sb.append(USER_WITH_DIFFERENT_ROLE_IN_DIFFERENT_REALM + "=" + ROLE_ADMIN + "\n"); - sb.append(USER_ONLY_IN_AUTHORIZATION + "=" + ROLE_USER + "\n"); - FileUtils.writeStringToFile(rolesAuthzRealmFile, sb.toString(), StandardCharsets.UTF_8); - } - - private String createPropertiesUserWithHashedPassword(String username, String password, String realmName) { - return username + "=" + createHashedPassword(username, password, realmName) + "\n"; - } - - private String createHashedPassword(String username, String password, String realmName) { - String clearTextPassword = username + ":" + realmName + ":" + password; - String hashedPassword = CryptoUtil.createPasswordHash("MD5", "hex", null, null, clearTextPassword); - return hashedPassword; - } - - private void removePropertiesFiles() throws IOException { - FileUtils.deleteQuietly(usersAuthnRealmFile); - FileUtils.deleteQuietly(rolesAuthnRealmFile); - FileUtils.deleteQuietly(usersAuthzRealmFile); - FileUtils.deleteQuietly(rolesAuthzRealmFile); - FileUtils.deleteDirectory(new File(fsRealmPath)); - FileUtils.deleteDirectory(tempFolder); - } - - private void addUserToFilesystemRealm(CLIWrapper cli, String username, String password) throws Exception { - addUserToFilesystemRealm(cli, username, password, null); - } - - private void addUserToFilesystemRealm(CLIWrapper cli, String username, String password, String role) - throws Exception { - cli.sendLine(String.format("/subsystem=elytron/filesystem-realm=%s:add-identity(identity=%s)", - FILESYSTEM_REALM_AUTHN_NAME, username)); - cli.sendLine(String.format("/subsystem=elytron/filesystem-realm=%s:set-password(identity=%s, clear={password=\"%s\"})", - FILESYSTEM_REALM_AUTHN_NAME, username, password)); - if (role != null) { - cli.sendLine(String.format("/subsystem=elytron/filesystem-realm=%s:add-identity-attribute(identity=%s, name=Roles, value=[\"%s\"])", - FILESYSTEM_REALM_AUTHN_NAME, username, role)); - } - } - - private void addAggregateRealmAndRelatedResources(CLIWrapper cli, String name, String authnRealm, String authzRealm) { - cli.sendLine(String.format( - "/subsystem=elytron/aggregate-realm=%s:add(authentication-realm=%s,authorization-realm=%s)", - name, authnRealm, authzRealm)); - cli.sendLine(String.format( - "/subsystem=elytron/security-domain=%1$s:add(realms=[{realm=%1$s,role-decoder=groups-to-roles}],default-realm=%1$s,permission-mapper=default-permission-mapper)", - name)); - cli.sendLine(String.format( - "/subsystem=elytron/http-authentication-factory=%1$s:add(http-server-mechanism-factory=%2$s,security-domain=%1$s," - + "mechanism-configurations=[{mechanism-name=BASIC,mechanism-realm-configurations=[{realm-name=\"Some realm\"}]}])", - name, PREDEFINED_HTTP_SERVER_MECHANISM_FACTORY)); - cli.sendLine(String.format( - "/subsystem=undertow/application-security-domain=%1$s:add(http-authentication-factory=%1$s)", - name)); - } - - private void removeAggregateRealmAndRelatedResources(ManagementClient mc, CLIWrapper cli, String name) throws Exception { - cli.sendLine(String.format("/subsystem=undertow/application-security-domain=%s:remove()", name)); - cli.sendLine(String.format("/subsystem=elytron/http-authentication-factory=%s:remove()", name)); - cli.sendLine(String.format("/subsystem=elytron/security-domain=%s:remove()", name)); - cli.sendLine(String.format("/subsystem=elytron/aggregate-realm=%s:remove()", name)); - } - } + } diff --git a/testsuite/integration/elytron/src/test/java/org/wildfly/test/integration/elytron/ssl/UndertowSslSecurityDomainTestCase.java b/testsuite/integration/elytron/src/test/java/org/wildfly/test/integration/elytron/ssl/UndertowSslSecurityDomainTestCase.java index aa45e9a54453..7c318ceb0a94 100644 --- a/testsuite/integration/elytron/src/test/java/org/wildfly/test/integration/elytron/ssl/UndertowSslSecurityDomainTestCase.java +++ b/testsuite/integration/elytron/src/test/java/org/wildfly/test/integration/elytron/ssl/UndertowSslSecurityDomainTestCase.java @@ -68,7 +68,7 @@ import org.wildfly.test.security.common.elytron.SimpleTrustManager; import org.wildfly.test.security.common.elytron.X500AttributePrincipalDecoder; import org.wildfly.test.security.common.elytron.UndertowSslContext; -import org.wildfly.test.security.common.elytron.UserWithRoles; +import org.wildfly.test.security.common.elytron.UserWithAttributeValues; /** * Smoke tests for certificate based authentication using Elytron server-ssl-context, security domain, @@ -241,7 +241,7 @@ protected ConfigurableElement[] getConfigurableElements() { PropertyFileAuthzBasedDomain.builder().withName(NAME) .withAuthnRealm(NAME) .withPrincipalDecoder(NAME) - .withUser(UserWithRoles.builder().withName("CN=client").withRoles("Role1").build()) + .withUser(UserWithAttributeValues.builder().withName("CN=client").withValues("Role1").build()) .build(), ClientCertUndertowDomainMapper.builder().withName(NAME).withSecurityDomain(NAME).build(), SimpleServerSslContext.builder().withName(NAME) diff --git a/testsuite/integration/web/src/test/java/org/jboss/as/test/integration/web/security/WebSecurityCommon.java b/testsuite/integration/web/src/test/java/org/jboss/as/test/integration/web/security/WebSecurityCommon.java index 00a300cca50a..9f2c3b2a3860 100644 --- a/testsuite/integration/web/src/test/java/org/jboss/as/test/integration/web/security/WebSecurityCommon.java +++ b/testsuite/integration/web/src/test/java/org/jboss/as/test/integration/web/security/WebSecurityCommon.java @@ -31,7 +31,7 @@ import org.apache.commons.io.FileUtils; import org.jboss.logging.Logger; -import org.wildfly.test.security.common.elytron.UserWithRoles; +import org.wildfly.test.security.common.elytron.UserWithAttributeValues; /** * @author Jan Stourac @@ -49,14 +49,14 @@ public static boolean isElytron() { private static final Logger LOGGER = Logger.getLogger(WebSecurityCommon.class); - public static PropertyFiles createPropertiesFiles(List usersWithRoles, String realmName) throws + public static PropertyFiles createPropertiesFiles(List usersWithRoles, String realmName) throws Exception { File tempFolder = createTemporaryFolder("properties-" + realmName); final Properties usersProperties = new Properties(); final Properties rolesProperties = new Properties(); - for (UserWithRoles user : usersWithRoles) { + for (UserWithAttributeValues user : usersWithRoles) { usersProperties.setProperty(user.getName(), user.getPassword()); - rolesProperties.setProperty(user.getName(), String.join(",", user.getRoles())); + rolesProperties.setProperty(user.getName(), String.join(",", user.getValues())); } File usersFile = new File(tempFolder, "users.properties"); writeProperties(usersProperties, usersFile, realmName); diff --git a/testsuite/integration/web/src/test/java/org/jboss/as/test/integration/web/security/WebSimpleRoleMappingSecurityDomainSetup.java b/testsuite/integration/web/src/test/java/org/jboss/as/test/integration/web/security/WebSimpleRoleMappingSecurityDomainSetup.java index ba3c382862a6..4f2c400cf61f 100644 --- a/testsuite/integration/web/src/test/java/org/jboss/as/test/integration/web/security/WebSimpleRoleMappingSecurityDomainSetup.java +++ b/testsuite/integration/web/src/test/java/org/jboss/as/test/integration/web/security/WebSimpleRoleMappingSecurityDomainSetup.java @@ -49,7 +49,7 @@ import org.jboss.as.test.integration.security.common.AbstractSecurityDomainSetup; import org.jboss.dmr.ModelNode; import org.jboss.logging.Logger; -import org.wildfly.test.security.common.elytron.UserWithRoles; +import org.wildfly.test.security.common.elytron.UserWithAttributeValues; /** * @author Stuart Douglas @@ -100,12 +100,12 @@ protected void setLegacySecurityRealmBased(final ManagementClient managementClie steps.add(Util.createAddOperation(address)); // Prepare properties files with users, passwords and roles - List userWithRoles = new ArrayList(); - userWithRoles.add(UserWithRoles.builder().withName(GOOD_USER_NAME).withPassword(GOOD_USER_PASSWORD).withRoles + List userWithRoles = new ArrayList(); + userWithRoles.add(UserWithAttributeValues.builder().withName(GOOD_USER_NAME).withPassword(GOOD_USER_PASSWORD).withValues (GOOD_USER_ROLE).build()); - userWithRoles.add(UserWithRoles.builder().withName(SUPER_USER_NAME).withPassword(SUPER_USER_PASSWORD) - .withRoles(SUPER_USER_ROLE).build()); - userWithRoles.add(UserWithRoles.builder().withName(BAD_GUY_NAME).withPassword(BAD_GUY_PASSWORD).withRoles + userWithRoles.add(UserWithAttributeValues.builder().withName(SUPER_USER_NAME).withPassword(SUPER_USER_PASSWORD) + .withValues(SUPER_USER_ROLE).build()); + userWithRoles.add(UserWithAttributeValues.builder().withName(BAD_GUY_NAME).withPassword(BAD_GUY_PASSWORD).withValues (BAD_GUY_ROLE).build()); WebSecurityCommon.PropertyFiles propFiles = WebSecurityCommon.createPropertiesFiles(userWithRoles, WEB_SECURITY_DOMAIN); diff --git a/testsuite/integration/web/src/test/java/org/jboss/as/test/integration/web/security/WebTestsSecurityDomainSetup.java b/testsuite/integration/web/src/test/java/org/jboss/as/test/integration/web/security/WebTestsSecurityDomainSetup.java index 570e1e373b07..827adf3b5fd6 100644 --- a/testsuite/integration/web/src/test/java/org/jboss/as/test/integration/web/security/WebTestsSecurityDomainSetup.java +++ b/testsuite/integration/web/src/test/java/org/jboss/as/test/integration/web/security/WebTestsSecurityDomainSetup.java @@ -52,7 +52,7 @@ import org.jboss.logging.Logger; import org.wildfly.test.security.common.elytron.PropertyFileBasedDomain; import org.wildfly.test.security.common.elytron.UndertowDomainMapper; -import org.wildfly.test.security.common.elytron.UserWithRoles; +import org.wildfly.test.security.common.elytron.UserWithAttributeValues; /** * @author Stuart Douglas @@ -118,12 +118,12 @@ protected void setLegacySecurityRealmBased(final ManagementClient managementClie address = address.append(Constants.AUTHENTICATION, Constants.CLASSIC); steps.add(Util.createAddOperation(address)); - List userWithRoles = new ArrayList(); - userWithRoles.add(UserWithRoles.builder().withName(GOOD_USER_NAME).withPassword(GOOD_USER_PASSWORD).withRoles + List userWithRoles = new ArrayList(); + userWithRoles.add(UserWithAttributeValues.builder().withName(GOOD_USER_NAME).withPassword(GOOD_USER_PASSWORD).withValues (GOOD_USER_ROLE).build()); - userWithRoles.add(UserWithRoles.builder().withName(SUPER_USER_NAME).withPassword(SUPER_USER_PASSWORD) - .withRoles(SUPER_USER_ROLE).build()); - userWithRoles.add(UserWithRoles.builder().withName(BAD_GUY_NAME).withPassword(BAD_GUY_PASSWORD).withRoles + userWithRoles.add(UserWithAttributeValues.builder().withName(SUPER_USER_NAME).withPassword(SUPER_USER_PASSWORD) + .withValues(SUPER_USER_ROLE).build()); + userWithRoles.add(UserWithAttributeValues.builder().withName(BAD_GUY_NAME).withPassword(BAD_GUY_PASSWORD).withValues (BAD_GUY_ROLE).build()); WebSecurityCommon.PropertyFiles propFiles = WebSecurityCommon.createPropertiesFiles(userWithRoles, WEB_SECURITY_DOMAIN); diff --git a/testsuite/integration/web/src/test/java/org/jboss/as/test/integration/web/security/cert/WebCERTTestsElytronSetup.java b/testsuite/integration/web/src/test/java/org/jboss/as/test/integration/web/security/cert/WebCERTTestsElytronSetup.java index 797d60340d01..7c0171510239 100644 --- a/testsuite/integration/web/src/test/java/org/jboss/as/test/integration/web/security/cert/WebCERTTestsElytronSetup.java +++ b/testsuite/integration/web/src/test/java/org/jboss/as/test/integration/web/security/cert/WebCERTTestsElytronSetup.java @@ -35,7 +35,7 @@ import org.wildfly.test.security.common.elytron.SimpleKeyStore; import org.wildfly.test.security.common.elytron.SimpleServerSslContext; import org.wildfly.test.security.common.elytron.SimpleTrustManager; -import org.wildfly.test.security.common.elytron.UserWithRoles; +import org.wildfly.test.security.common.elytron.UserWithAttributeValues; import org.wildfly.test.security.common.elytron.X500AttributePrincipalDecoder; import org.wildfly.test.security.common.other.SimpleSocketBinding; import org.wildfly.test.undertow.common.elytron.SimpleHttpsListener; @@ -90,8 +90,8 @@ protected ConfigurableElement[] getConfigurableElements() { PropertyFileAuthzBasedDomain.builder().withName(SECURITY_DOMAIN_NAME) .withAuthnRealm(NAME) .withPrincipalDecoder(NAME) - .withUser(UserWithRoles.builder().withName("test client").withRoles("gooduser").build()) - .withUser(UserWithRoles.builder().withName("test client 2").withRoles("superuser").build()) + .withUser(UserWithAttributeValues.builder().withName("test client").withValues("gooduser").build()) + .withUser(UserWithAttributeValues.builder().withName("test client 2").withValues("superuser").build()) .build(), ClientCertUndertowDomainMapper.builder().withName(SECURITY_DOMAIN_NAME).withSecurityDomain (SECURITY_DOMAIN_NAME).build(), diff --git a/testsuite/integration/web/src/test/java/org/jboss/as/test/integration/web/security/digest/WebSecurityDigestSecurityDomainSetup.java b/testsuite/integration/web/src/test/java/org/jboss/as/test/integration/web/security/digest/WebSecurityDigestSecurityDomainSetup.java index ce08903ce3f7..109648becec5 100644 --- a/testsuite/integration/web/src/test/java/org/jboss/as/test/integration/web/security/digest/WebSecurityDigestSecurityDomainSetup.java +++ b/testsuite/integration/web/src/test/java/org/jboss/as/test/integration/web/security/digest/WebSecurityDigestSecurityDomainSetup.java @@ -36,7 +36,7 @@ import org.jboss.as.test.integration.web.security.WebSecurityCommon; import org.wildfly.test.security.common.elytron.PropertyFileBasedDomain; import org.wildfly.test.security.common.elytron.UndertowDomainMapper; -import org.wildfly.test.security.common.elytron.UserWithRoles; +import org.wildfly.test.security.common.elytron.UserWithAttributeValues; /** * Security domain setup for digest tests. This prepare either legacy security-domain or elytron configuration. @@ -96,11 +96,11 @@ private class LegacySecurityDomainsSetup extends AbstractSecurityDomainsServerSe @Override protected SecurityDomain[] getSecurityDomains() throws Exception { - List userWithRoles = new ArrayList(); - userWithRoles.add(UserWithRoles.builder().withName(GOOD_USER_NAME).withPassword(GOOD_USER_PASSWORD) - .withRoles(GOOD_USER_ROLE).build()); - userWithRoles.add(UserWithRoles.builder().withName(SUPER_USER_NAME).withPassword(SUPER_USER_PASSWORD) - .withRoles(SUPER_USER_ROLE).build()); + List userWithRoles = new ArrayList(); + userWithRoles.add(UserWithAttributeValues.builder().withName(GOOD_USER_NAME).withPassword(GOOD_USER_PASSWORD) + .withValues(GOOD_USER_ROLE).build()); + userWithRoles.add(UserWithAttributeValues.builder().withName(SUPER_USER_NAME).withPassword(SUPER_USER_PASSWORD) + .withValues(SUPER_USER_ROLE).build()); WebSecurityCommon.PropertyFiles propFiles = WebSecurityCommon.createPropertiesFiles(userWithRoles, SECURITY_DOMAIN_NAME); diff --git a/testsuite/integration/web/src/test/java/org/jboss/as/test/integration/web/security/jaspi/WebJaspiTestsSecurityDomainSetup.java b/testsuite/integration/web/src/test/java/org/jboss/as/test/integration/web/security/jaspi/WebJaspiTestsSecurityDomainSetup.java index b10bdf273dcf..2e1c0b9e960d 100644 --- a/testsuite/integration/web/src/test/java/org/jboss/as/test/integration/web/security/jaspi/WebJaspiTestsSecurityDomainSetup.java +++ b/testsuite/integration/web/src/test/java/org/jboss/as/test/integration/web/security/jaspi/WebJaspiTestsSecurityDomainSetup.java @@ -50,7 +50,7 @@ import org.jboss.as.test.integration.web.security.WebSecurityCommon; import org.jboss.dmr.ModelNode; import org.jboss.logging.Logger; -import org.wildfly.test.security.common.elytron.UserWithRoles; +import org.wildfly.test.security.common.elytron.UserWithAttributeValues; import org.wildfly.test.undertow.common.TestConstants; /** @@ -106,12 +106,12 @@ private void setupLegacySecurityDomain(ManagementClient managementClient) throws steps.add(loginModuleStack); // Prepare properties files with users, passwords and roles - List userWithRoles = new ArrayList(); - userWithRoles.add(UserWithRoles.builder().withName(GOOD_USER_NAME).withPassword(GOOD_USER_PASSWORD).withRoles + List userWithRoles = new ArrayList(); + userWithRoles.add(UserWithAttributeValues.builder().withName(GOOD_USER_NAME).withPassword(GOOD_USER_PASSWORD).withValues (GOOD_USER_ROLE).build()); - userWithRoles.add(UserWithRoles.builder().withName(SUPER_USER_NAME).withPassword(SUPER_USER_PASSWORD) - .withRoles(SUPER_USER_ROLE).build()); - userWithRoles.add(UserWithRoles.builder().withName(BAD_GUY_NAME).withPassword(BAD_GUY_PASSWORD).withRoles + userWithRoles.add(UserWithAttributeValues.builder().withName(SUPER_USER_NAME).withPassword(SUPER_USER_PASSWORD) + .withValues(SUPER_USER_ROLE).build()); + userWithRoles.add(UserWithAttributeValues.builder().withName(BAD_GUY_NAME).withPassword(BAD_GUY_PASSWORD).withValues (BAD_GUY_ROLE).build()); WebSecurityCommon.PropertyFiles propFiles = WebSecurityCommon.createPropertiesFiles(userWithRoles, WEB_SECURITY_DOMAIN); diff --git a/testsuite/shared/src/main/java/org/wildfly/test/security/common/elytron/AbstractUserRolesCapableElement.java b/testsuite/shared/src/main/java/org/wildfly/test/security/common/elytron/AbstractUserAttributeValuesCapableElement.java similarity index 62% rename from testsuite/shared/src/main/java/org/wildfly/test/security/common/elytron/AbstractUserRolesCapableElement.java rename to testsuite/shared/src/main/java/org/wildfly/test/security/common/elytron/AbstractUserAttributeValuesCapableElement.java index b3ef38622afd..e603225b4fe3 100644 --- a/testsuite/shared/src/main/java/org/wildfly/test/security/common/elytron/AbstractUserRolesCapableElement.java +++ b/testsuite/shared/src/main/java/org/wildfly/test/security/common/elytron/AbstractUserAttributeValuesCapableElement.java @@ -33,25 +33,25 @@ * * @author Josef Cacek */ -public abstract class AbstractUserRolesCapableElement extends AbstractConfigurableElement implements UsersRolesCapableElement { +public abstract class AbstractUserAttributeValuesCapableElement extends AbstractConfigurableElement implements UsersAttributeValuesCapableElement { - private final List usersWithRoles; + private final List usersWithValues; - protected AbstractUserRolesCapableElement(Builder builder) { + protected AbstractUserAttributeValuesCapableElement(Builder builder) { super(builder); - this.usersWithRoles = Collections.unmodifiableList(new ArrayList<>(builder.usersWithRoles)); + this.usersWithValues = Collections.unmodifiableList(new ArrayList<>(builder.usersWithValues)); } @Override - public List getUsersWithRoles() { - return usersWithRoles; + public List getUsersWithAttributeValues() { + return usersWithValues; } /** - * Builder to build {@link AbstractUserRolesCapableElement}. + * Builder to build {@link AbstractUserAttributeValuesCapableElement}. */ public abstract static class Builder> extends AbstractConfigurableElement.Builder { - private List usersWithRoles = new ArrayList<>(); + private List usersWithValues = new ArrayList<>(); protected Builder() { } @@ -59,22 +59,22 @@ protected Builder() { /** * Adds the given user to list of users in the domain. * - * @param userWithRoles not-null {@link UserWithRoles} instance + * @param userWithValues not-null {@link UserWithAttributeValues} instance */ - public final T withUser(UserWithRoles userWithRoles) { - this.usersWithRoles.add(Objects.requireNonNull(userWithRoles, "Provided user must not be null.")); + public final T withUser(UserWithAttributeValues userWithValues) { + this.usersWithValues.add(Objects.requireNonNull(userWithValues, "Provided user must not be null.")); return self(); } /** - * Shortcut method for {@link #withUser(UserWithRoles)} one. + * Shortcut method for {@link #withUser(UserWithAttributeValues)} one. * * @param username must not be null * @param password must not be null - * @param roles roles to be assigned to user (may be null) + * @param values values to be assigned to user (may be null) */ - public final T withUser(String username, String password, String... roles) { - this.usersWithRoles.add(UserWithRoles.builder().withName(username).withPassword(password).withRoles(roles).build()); + public final T withUser(String username, String password, String... values) { + this.usersWithValues.add(UserWithAttributeValues.builder().withName(username).withPassword(password).withValues(values).build()); return self(); } } diff --git a/testsuite/shared/src/main/java/org/wildfly/test/security/common/elytron/AggregateSecurityRealm.java b/testsuite/shared/src/main/java/org/wildfly/test/security/common/elytron/AggregateSecurityRealm.java new file mode 100644 index 000000000000..e2aba301bf07 --- /dev/null +++ b/testsuite/shared/src/main/java/org/wildfly/test/security/common/elytron/AggregateSecurityRealm.java @@ -0,0 +1,107 @@ +/* + * Copyright 2019 Red Hat, Inc. + * + * 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.wildfly.test.security.common.elytron; + +import org.jboss.as.controller.PathAddress; +import org.jboss.as.controller.PathElement; +import org.jboss.as.controller.client.ModelControllerClient; +import org.jboss.as.controller.operations.common.Util; +import org.jboss.as.test.integration.management.util.CLIWrapper; +import org.jboss.as.test.integration.security.common.Utils; +import org.jboss.dmr.ModelNode; + +/** + * A {@link ConfigurableElement} to define an Aggregate SecurityRealm resource. + * + * @author Darran Lofthouse + */ +public class AggregateSecurityRealm implements SecurityRealm { + + private final PathAddress address; + private final String name; + private final String authenticationRealm; + private final String authorizationRealm; + + AggregateSecurityRealm(final String name, final String authenticationRealm, final String authorizationRealm) { + this.name = name; + this.address = PathAddress.pathAddress(PathElement.pathElement("subsystem", "elytron"), PathElement.pathElement("aggregate-realm", name)); + this.authenticationRealm = authenticationRealm; + this.authorizationRealm = authorizationRealm; + } + + @Override + public String getName() { + return name; + } + + public ModelNode getAddOperation() { + ModelNode addOperation = Util.createAddOperation(address); + addOperation.get("authentication-realm").set(authenticationRealm); + if (authorizationRealm != null) { + addOperation.get("authorization-realm").set(authorizationRealm); + } + + return addOperation; + } + + public ModelNode getRemoveOperation() { + return Util.createRemoveOperation(address); + } + + @Override + public void create(ModelControllerClient client, CLIWrapper cli) throws Exception { + Utils.applyUpdate(getAddOperation(), client); + } + + @Override + public void remove(ModelControllerClient client, CLIWrapper cli) throws Exception { + Utils.applyUpdate(getRemoveOperation(), client); + } + + public static Builder builder(final String name) { + return new Builder(name); + } + + public static class Builder { + + private final String name; + private String authenticationRealm; + private String authorizationRealm; + + Builder(final String name) { + this.name = name; + } + + public Builder withAuthenticationRealm(final String authenticationRealm) { + this.authenticationRealm = authenticationRealm; + + return this; + } + + public Builder withAuthorizationRealm(final String authorizationRealm) { + this.authorizationRealm = authorizationRealm; + + return this; + } + + public SecurityRealm build() { + return new AggregateSecurityRealm(name, authenticationRealm, authorizationRealm); + } + + } + +} diff --git a/testsuite/shared/src/main/java/org/wildfly/test/security/common/elytron/FileSystemRealm.java b/testsuite/shared/src/main/java/org/wildfly/test/security/common/elytron/FileSystemRealm.java index 10cf99af0d7e..f30f45efc823 100644 --- a/testsuite/shared/src/main/java/org/wildfly/test/security/common/elytron/FileSystemRealm.java +++ b/testsuite/shared/src/main/java/org/wildfly/test/security/common/elytron/FileSystemRealm.java @@ -29,7 +29,7 @@ * * @author Josef Cacek */ -public class FileSystemRealm extends AbstractUserRolesCapableElement implements SecurityRealm { +public class FileSystemRealm extends AbstractUserAttributeValuesCapableElement implements SecurityRealm { private final Path path; private final Integer level; @@ -55,15 +55,15 @@ private FileSystemRealm(Builder builder) { public void create(CLIWrapper cli) throws Exception { final String levelStr = level == null ? "" : ("level=" + level); cli.sendLine(String.format("/subsystem=elytron/filesystem-realm=%s:add(%s, %s)", name, path.asString(), levelStr)); - for (UserWithRoles user : getUsersWithRoles()) { + for (UserWithAttributeValues user : getUsersWithAttributeValues()) { cli.sendLine(String.format("/subsystem=elytron/filesystem-realm=%s:add-identity(identity=%s)", name, user.getName())); cli.sendLine( String.format("/subsystem=elytron/filesystem-realm=%s:set-password(identity=%s, clear={password=\"%s\"})", name, user.getName(), user.getPassword())); - if (!user.getRoles().isEmpty()) { + if (!user.getValues().isEmpty()) { cli.sendLine(String.format( "/subsystem=elytron/filesystem-realm=%s:add-identity-attribute(identity=%s, name=groups, value=[%s])", name, - user.getName(), String.join(",", user.getRoles()))); + user.getName(), String.join(",", user.getValues()))); } } } @@ -86,7 +86,7 @@ public static Builder builder() { /** * Builder to build {@link FileSystemRealm}. */ - public static final class Builder extends AbstractUserRolesCapableElement.Builder { + public static final class Builder extends AbstractUserAttributeValuesCapableElement.Builder { private Path path; private Integer level; diff --git a/testsuite/shared/src/main/java/org/wildfly/test/security/common/elytron/PropertiesRealm.java b/testsuite/shared/src/main/java/org/wildfly/test/security/common/elytron/PropertiesRealm.java index eb28bb09daf5..f7155be7d736 100644 --- a/testsuite/shared/src/main/java/org/wildfly/test/security/common/elytron/PropertiesRealm.java +++ b/testsuite/shared/src/main/java/org/wildfly/test/security/common/elytron/PropertiesRealm.java @@ -33,7 +33,7 @@ * * @author Josef Cacek */ -public class PropertiesRealm extends AbstractUserRolesCapableElement implements SecurityRealm { +public class PropertiesRealm extends AbstractUserAttributeValuesCapableElement implements SecurityRealm { private static final Logger LOGGER = Logger.getLogger(PropertiesRealm.class); @@ -50,9 +50,9 @@ public void create(CLIWrapper cli) throws Exception { this.tempFolder = createTemporaryFolder("ely-" + name); final Properties usersProperties = new Properties(); final Properties rolesProperties = new Properties(); - for (UserWithRoles user : getUsersWithRoles()) { + for (UserWithAttributeValues user : getUsersWithAttributeValues()) { usersProperties.setProperty(user.getName(), user.getPassword()); - rolesProperties.setProperty(user.getName(), String.join(",", user.getRoles())); + rolesProperties.setProperty(user.getName(), String.join(",", user.getValues())); } File usersFile = writeProperties(usersProperties, "users.properties"); File rolesFile = writeProperties(rolesProperties, "roles.properties"); @@ -94,7 +94,7 @@ private File writeProperties(Properties properties, String fileName) throws IOEx /** * Builder to build {@link PropertiesRealm}. */ - public static final class Builder extends AbstractUserRolesCapableElement.Builder { + public static final class Builder extends AbstractUserAttributeValuesCapableElement.Builder { private String groupsAttribute; private Builder() { diff --git a/testsuite/shared/src/main/java/org/wildfly/test/security/common/elytron/PropertyFileAuthzBasedDomain.java b/testsuite/shared/src/main/java/org/wildfly/test/security/common/elytron/PropertyFileAuthzBasedDomain.java index a1dd75642384..905af6b52e39 100644 --- a/testsuite/shared/src/main/java/org/wildfly/test/security/common/elytron/PropertyFileAuthzBasedDomain.java +++ b/testsuite/shared/src/main/java/org/wildfly/test/security/common/elytron/PropertyFileAuthzBasedDomain.java @@ -50,7 +50,7 @@ * * @author Ondrej Kotek */ -public class PropertyFileAuthzBasedDomain extends AbstractUserRolesCapableElement implements SecurityDomain { +public class PropertyFileAuthzBasedDomain extends AbstractUserAttributeValuesCapableElement implements SecurityDomain { private static final Logger LOGGER = Logger.getLogger(PropertyFileAuthzBasedDomain.class); @@ -74,9 +74,9 @@ public void create(CLIWrapper cli) throws Exception { tempFolder = createTemporaryFolder("ely-" + getName()); final Properties usersProperties = new Properties(); final Properties rolesProperties = new Properties(); - for (UserWithRoles user : getUsersWithRoles()) { + for (UserWithAttributeValues user : getUsersWithAttributeValues()) { usersProperties.setProperty(user.getName(), user.getPassword()); - rolesProperties.setProperty(user.getName(), String.join(",", user.getRoles())); + rolesProperties.setProperty(user.getName(), String.join(",", user.getValues())); } File usersFile = writeProperties(usersProperties, "users.properties"); File rolesFile = writeProperties(rolesProperties, "roles.properties"); @@ -132,7 +132,7 @@ public static Builder builder() { return new Builder(); } - public static final class Builder extends AbstractUserRolesCapableElement.Builder { + public static final class Builder extends AbstractUserAttributeValuesCapableElement.Builder { private String authnRealm; private String principalDecoder; diff --git a/testsuite/shared/src/main/java/org/wildfly/test/security/common/elytron/PropertyFileBasedDomain.java b/testsuite/shared/src/main/java/org/wildfly/test/security/common/elytron/PropertyFileBasedDomain.java index ea808bec5ac0..25299cdf07fd 100644 --- a/testsuite/shared/src/main/java/org/wildfly/test/security/common/elytron/PropertyFileBasedDomain.java +++ b/testsuite/shared/src/main/java/org/wildfly/test/security/common/elytron/PropertyFileBasedDomain.java @@ -48,7 +48,7 @@ * * @author Josef Cacek */ -public class PropertyFileBasedDomain extends AbstractUserRolesCapableElement implements SecurityDomain { +public class PropertyFileBasedDomain extends AbstractUserAttributeValuesCapableElement implements SecurityDomain { private static final Logger LOGGER = Logger.getLogger(PropertyFileBasedDomain.class); @@ -66,9 +66,9 @@ public void create(CLIWrapper cli) throws Exception { tempFolder = createTemporaryFolder("ely-" + getName()); final Properties usersProperties = new Properties(); final Properties rolesProperties = new Properties(); - for (UserWithRoles user : getUsersWithRoles()) { + for (UserWithAttributeValues user : getUsersWithAttributeValues()) { usersProperties.setProperty(user.getName(), user.getPassword()); - rolesProperties.setProperty(user.getName(), String.join(",", user.getRoles())); + rolesProperties.setProperty(user.getName(), String.join(",", user.getValues())); } File usersFile = writeProperties(usersProperties, "users.properties"); File rolesFile = writeProperties(rolesProperties, "roles.properties"); @@ -118,7 +118,7 @@ public static Builder builder() { return new Builder(); } - public static final class Builder extends AbstractUserRolesCapableElement.Builder { + public static final class Builder extends AbstractUserAttributeValuesCapableElement.Builder { private String permMapper; diff --git a/testsuite/shared/src/main/java/org/wildfly/test/security/common/elytron/UserWithRoles.java b/testsuite/shared/src/main/java/org/wildfly/test/security/common/elytron/UserWithAttributeValues.java similarity index 69% rename from testsuite/shared/src/main/java/org/wildfly/test/security/common/elytron/UserWithRoles.java rename to testsuite/shared/src/main/java/org/wildfly/test/security/common/elytron/UserWithAttributeValues.java index 8026e6b4bc0d..5d3e51dfd234 100644 --- a/testsuite/shared/src/main/java/org/wildfly/test/security/common/elytron/UserWithRoles.java +++ b/testsuite/shared/src/main/java/org/wildfly/test/security/common/elytron/UserWithAttributeValues.java @@ -28,20 +28,20 @@ import java.util.Set; /** - * Object which holds user configuration (password, roles). + * Object which holds user configuration (password, values). * * @author Josef Cacek */ -public class UserWithRoles { +public class UserWithAttributeValues { private final String name; private final String password; - private final Set roles; + private final Set values; - private UserWithRoles(Builder builder) { + private UserWithAttributeValues(Builder builder) { this.name = Objects.requireNonNull(builder.name, "Username must be not-null"); this.password = builder.password != null ? builder.password : builder.name; - this.roles = new HashSet<>(builder.roles); + this.values = new HashSet<>(builder.values); } /** @@ -61,12 +61,12 @@ public String getPassword() { /** * Set of roles to be assigned to the user. */ - public Set getRoles() { - return roles; + public Set getValues() { + return values; } /** - * Creates builder to build {@link UserWithRoles}. + * Creates builder to build {@link UserWithAttributeValues}. * * @return created builder */ @@ -75,12 +75,12 @@ public static Builder builder() { } /** - * Builder to build {@link UserWithRoles}. + * Builder to build {@link UserWithAttributeValues}. */ public static final class Builder { private String name; private String password; - private final Set roles = new HashSet<>(); + private final Set values = new HashSet<>(); private Builder() { } @@ -96,21 +96,21 @@ public Builder withPassword(String password) { } /** - * Add given roles to the builder. It doesn't replace existing roles, but it adds given roles to them. + * Add given attribute values to the builder. It doesn't replace existing values, but it adds given valuess to them. */ - public Builder withRoles(Set roles) { - if (roles != null) { - this.roles.addAll(roles); + public Builder withValues(Set values) { + if (values != null) { + this.values.addAll(values); } return this; } /** - * Add given roles to the builder. It doesn't replace existing roles, but it adds given roles to them. + * Add given values to the builder. It doesn't replace existing values, but it adds given value to them. */ - public Builder withRoles(String... roles) { - if (roles != null) { - this.roles.addAll(Arrays.asList(roles)); + public Builder withValues(String... values) { + if (values != null) { + this.values.addAll(Arrays.asList(values)); } return this; } @@ -118,8 +118,8 @@ public Builder withRoles(String... roles) { /** * Clears set of already added roles. */ - public Builder clearRoles() { - this.roles.clear(); + public Builder clearValues() { + this.values.clear(); return this; } @@ -128,8 +128,8 @@ public Builder clearRoles() { * * @return */ - public UserWithRoles build() { - return new UserWithRoles(this); + public UserWithAttributeValues build() { + return new UserWithAttributeValues(this); } } diff --git a/testsuite/shared/src/main/java/org/wildfly/test/security/common/elytron/UsersRolesCapableElement.java b/testsuite/shared/src/main/java/org/wildfly/test/security/common/elytron/UsersAttributeValuesCapableElement.java similarity index 86% rename from testsuite/shared/src/main/java/org/wildfly/test/security/common/elytron/UsersRolesCapableElement.java rename to testsuite/shared/src/main/java/org/wildfly/test/security/common/elytron/UsersAttributeValuesCapableElement.java index 9f9ecba00031..933608fbed73 100644 --- a/testsuite/shared/src/main/java/org/wildfly/test/security/common/elytron/UsersRolesCapableElement.java +++ b/testsuite/shared/src/main/java/org/wildfly/test/security/common/elytron/UsersAttributeValuesCapableElement.java @@ -25,15 +25,15 @@ import java.util.List; /** - * This interface represent configuration element with predefined list of users and their roles. It provides ability to tests + * This interface represent configuration element with predefined list of users and their attribute values. It provides ability to tests * to come up with own user population for the tested scenario. * * @author Josef Cacek */ -public interface UsersRolesCapableElement extends ConfigurableElement { +public interface UsersAttributeValuesCapableElement extends ConfigurableElement { /** * Returns predefined (not {@code null}) list of users and their attributes to be created. */ - List getUsersWithRoles(); + List getUsersWithAttributeValues(); }