Skip to content

Commit

Permalink
[WFLY-12179] Update the AggregateRealmTestCase to use ConfigurableEle…
Browse files Browse the repository at this point in the history
…ment definitions.
  • Loading branch information
darranl committed Jun 8, 2019
1 parent 239e4ac commit a67684f
Show file tree
Hide file tree
Showing 16 changed files with 328 additions and 269 deletions.

Large diffs are not rendered by default.

Expand Up @@ -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,
Expand Down Expand Up @@ -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)
Expand Down
Expand Up @@ -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
Expand All @@ -49,14 +49,14 @@ public static boolean isElytron() {
private static final Logger LOGGER = Logger.getLogger(WebSecurityCommon.class);


public static PropertyFiles createPropertiesFiles(List<UserWithRoles> usersWithRoles, String realmName) throws
public static PropertyFiles createPropertiesFiles(List<UserWithAttributeValues> 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);
Expand Down
Expand Up @@ -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
Expand Down Expand Up @@ -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> userWithRoles = new ArrayList<UserWithRoles>();
userWithRoles.add(UserWithRoles.builder().withName(GOOD_USER_NAME).withPassword(GOOD_USER_PASSWORD).withRoles
List<UserWithAttributeValues> userWithRoles = new ArrayList<UserWithAttributeValues>();
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);
Expand Down
Expand Up @@ -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
Expand Down Expand Up @@ -118,12 +118,12 @@ protected void setLegacySecurityRealmBased(final ManagementClient managementClie
address = address.append(Constants.AUTHENTICATION, Constants.CLASSIC);
steps.add(Util.createAddOperation(address));

List<UserWithRoles> userWithRoles = new ArrayList<UserWithRoles>();
userWithRoles.add(UserWithRoles.builder().withName(GOOD_USER_NAME).withPassword(GOOD_USER_PASSWORD).withRoles
List<UserWithAttributeValues> userWithRoles = new ArrayList<UserWithAttributeValues>();
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);
Expand Down
Expand Up @@ -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;
Expand Down Expand Up @@ -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(),
Expand Down
Expand Up @@ -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.
Expand Down Expand Up @@ -96,11 +96,11 @@ private class LegacySecurityDomainsSetup extends AbstractSecurityDomainsServerSe

@Override
protected SecurityDomain[] getSecurityDomains() throws Exception {
List<UserWithRoles> userWithRoles = new ArrayList<UserWithRoles>();
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<UserWithAttributeValues> userWithRoles = new ArrayList<UserWithAttributeValues>();
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);

Expand Down
Expand Up @@ -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;

/**
Expand Down Expand Up @@ -106,12 +106,12 @@ private void setupLegacySecurityDomain(ManagementClient managementClient) throws
steps.add(loginModuleStack);

// Prepare properties files with users, passwords and roles
List<UserWithRoles> userWithRoles = new ArrayList<UserWithRoles>();
userWithRoles.add(UserWithRoles.builder().withName(GOOD_USER_NAME).withPassword(GOOD_USER_PASSWORD).withRoles
List<UserWithAttributeValues> userWithRoles = new ArrayList<UserWithAttributeValues>();
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);

Expand Down
Expand Up @@ -33,48 +33,48 @@
*
* @author Josef Cacek
*/
public abstract class AbstractUserRolesCapableElement extends AbstractConfigurableElement implements UsersRolesCapableElement {
public abstract class AbstractUserAttributeValuesCapableElement extends AbstractConfigurableElement implements UsersAttributeValuesCapableElement {

private final List<UserWithRoles> usersWithRoles;
private final List<UserWithAttributeValues> 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<UserWithRoles> getUsersWithRoles() {
return usersWithRoles;
public List<UserWithAttributeValues> getUsersWithAttributeValues() {
return usersWithValues;
}

/**
* Builder to build {@link AbstractUserRolesCapableElement}.
* Builder to build {@link AbstractUserAttributeValuesCapableElement}.
*/
public abstract static class Builder<T extends Builder<T>> extends AbstractConfigurableElement.Builder<T> {
private List<UserWithRoles> usersWithRoles = new ArrayList<>();
private List<UserWithAttributeValues> usersWithValues = new ArrayList<>();

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();
}
}
Expand Down
@@ -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 <a href="mailto:darran.lofthouse@jboss.com">Darran Lofthouse</a>
*/
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);
}

}

}
Expand Up @@ -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;
Expand All @@ -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())));
}
}
}
Expand All @@ -86,7 +86,7 @@ public static Builder builder() {
/**
* Builder to build {@link FileSystemRealm}.
*/
public static final class Builder extends AbstractUserRolesCapableElement.Builder<Builder> {
public static final class Builder extends AbstractUserAttributeValuesCapableElement.Builder<Builder> {
private Path path;
private Integer level;

Expand Down

0 comments on commit a67684f

Please sign in to comment.