Search in sources :

Example 1 with SimpleMapBackedSecurityRealm

use of org.wildfly.security.auth.realm.SimpleMapBackedSecurityRealm in project wildfly-core by wildfly.

the class RealmDefinitions method getIdentityRealmDefinition.

static ResourceDefinition getIdentityRealmDefinition() {
    AbstractAddStepHandler add = new TrivialAddHandler<SecurityRealm>(SecurityRealm.class, IDENTITY_REALM_ATTRIBUTES, SECURITY_REALM_RUNTIME_CAPABILITY) {

        @Override
        protected ValueSupplier<SecurityRealm> getValueSupplier(ServiceBuilder<SecurityRealm> serviceBuilder, OperationContext context, ModelNode model) throws OperationFailedException {
            final String identity = IDENTITY.resolveModelAttribute(context, model).asString();
            final String attributeName = ATTRIBUTE_NAME.resolveModelAttribute(context, model).asStringOrNull();
            final List<String> attributeValues = ATTRIBUTE_VALUES.unwrap(context, model);
            return () -> {
                final Map<String, ? extends Collection<String>> attributesMap;
                if (attributeName != null) {
                    attributesMap = Collections.singletonMap(attributeName, Collections.unmodifiableList(attributeValues));
                } else {
                    attributesMap = Collections.emptyMap();
                }
                final Map<String, SimpleRealmEntry> realmMap = Collections.singletonMap(identity, new SimpleRealmEntry(Collections.emptyList(), new MapAttributes(attributesMap)));
                SimpleMapBackedSecurityRealm securityRealm = new SimpleMapBackedSecurityRealm();
                securityRealm.setPasswordMap(realmMap);
                return securityRealm;
            };
        }
    };
    return new TrivialResourceDefinition(ElytronDescriptionConstants.IDENTITY_REALM, add, IDENTITY_REALM_ATTRIBUTES, SECURITY_REALM_RUNTIME_CAPABILITY);
}
Also used : OperationContext(org.jboss.as.controller.OperationContext) SimpleMapBackedSecurityRealm(org.wildfly.security.auth.realm.SimpleMapBackedSecurityRealm) SimpleRealmEntry(org.wildfly.security.auth.realm.SimpleRealmEntry) SimpleMapBackedSecurityRealm(org.wildfly.security.auth.realm.SimpleMapBackedSecurityRealm) SecurityRealm(org.wildfly.security.auth.server.SecurityRealm) ServiceBuilder(org.jboss.msc.service.ServiceBuilder) AbstractAddStepHandler(org.jboss.as.controller.AbstractAddStepHandler) MapAttributes(org.wildfly.security.authz.MapAttributes) Collection(java.util.Collection) ModelNode(org.jboss.dmr.ModelNode) Map(java.util.Map)

Example 2 with SimpleMapBackedSecurityRealm

use of org.wildfly.security.auth.realm.SimpleMapBackedSecurityRealm in project wildfly-core by wildfly.

the class ChannelServer method create.

public static ChannelServer create(final Configuration configuration) throws IOException {
    checkNotNullParam("configuration", configuration);
    configuration.validate();
    // Hack WFCORE-3302/REM3-303 workaround
    if (firstCreate) {
        firstCreate = false;
    } else {
        try {
            // wait in case the previous socket has not closed
            Thread.sleep(100);
        } catch (InterruptedException e) {
            Thread.currentThread().interrupt();
            throw new RuntimeException(e);
        }
    }
    // TODO WFCORE-3302 -- Endpoint.getCurrent() should be ok
    final Endpoint endpoint = Endpoint.builder().setEndpointName(configuration.getEndpointName()).build();
    final NetworkServerProvider networkServerProvider = endpoint.getConnectionProviderInterface(configuration.getUriScheme(), NetworkServerProvider.class);
    final SecurityDomain.Builder domainBuilder = SecurityDomain.builder();
    final SimpleMapBackedSecurityRealm realm = new SimpleMapBackedSecurityRealm();
    realm.setPasswordMap("bob", ClearPassword.createRaw(ClearPassword.ALGORITHM_CLEAR, "pass".toCharArray()));
    domainBuilder.addRealm("default", realm).build();
    domainBuilder.setDefaultRealmName("default");
    domainBuilder.setPermissionMapper((permissionMappable, roles) -> PermissionVerifier.ALL);
    SecurityDomain testDomain = domainBuilder.build();
    SaslAuthenticationFactory saslAuthenticationFactory = SaslAuthenticationFactory.builder().setSecurityDomain(testDomain).setMechanismConfigurationSelector(mechanismInformation -> {
        switch(mechanismInformation.getMechanismName()) {
            case "ANONYMOUS":
            case "PLAIN":
                {
                    return MechanismConfiguration.EMPTY;
                }
            default:
                return null;
        }
    }).setFactory(SaslFactories.getElytronSaslServerFactory()).build();
    AcceptingChannel<StreamConnection> streamServer = networkServerProvider.createServer(configuration.getBindAddress(), OptionMap.EMPTY, saslAuthenticationFactory, null);
    return new ChannelServer(endpoint, streamServer);
}
Also used : SaslAuthenticationFactory(org.wildfly.security.auth.server.SaslAuthenticationFactory) SimpleMapBackedSecurityRealm(org.wildfly.security.auth.realm.SimpleMapBackedSecurityRealm) Endpoint(org.jboss.remoting3.Endpoint) NetworkServerProvider(org.jboss.remoting3.spi.NetworkServerProvider) StreamConnection(org.xnio.StreamConnection) SecurityDomain(org.wildfly.security.auth.server.SecurityDomain)

Example 3 with SimpleMapBackedSecurityRealm

use of org.wildfly.security.auth.realm.SimpleMapBackedSecurityRealm in project wildfly-core by wildfly.

the class JmxFacadeRbacEnabledTestCase method setupDomain.

@BeforeClass
public static void setupDomain() {
    Map<String, SimpleRealmEntry> entries = new HashMap<>(StandardRole.values().length);
    for (StandardRole role : StandardRole.values()) {
        entries.put(roleToUserName(role), new SimpleRealmEntry(Collections.emptyList()));
    }
    SimpleMapBackedSecurityRealm securityRealm = new SimpleMapBackedSecurityRealm();
    securityRealm.setPasswordMap(entries);
    testDomain = SecurityDomain.builder().setDefaultRealmName("Default").addRealm("Default", securityRealm).build().setPermissionMapper((p, r) -> new LoginPermission()).build();
}
Also used : SimpleMapBackedSecurityRealm(org.wildfly.security.auth.realm.SimpleMapBackedSecurityRealm) StandardRole(org.jboss.as.controller.access.rbac.StandardRole) SimpleRealmEntry(org.wildfly.security.auth.realm.SimpleRealmEntry) HashMap(java.util.HashMap) LoginPermission(org.wildfly.security.auth.permission.LoginPermission) BeforeClass(org.junit.BeforeClass)

Example 4 with SimpleMapBackedSecurityRealm

use of org.wildfly.security.auth.realm.SimpleMapBackedSecurityRealm in project wildfly-core by wildfly.

the class JmxRbacTestCase method setupDomain.

@BeforeClass
public static void setupDomain() {
    Map<String, SimpleRealmEntry> entries = new HashMap<>(StandardRole.values().length);
    for (StandardRole role : StandardRole.values()) {
        entries.put(roleToUserName(role), new SimpleRealmEntry(Collections.emptyList()));
    }
    SimpleMapBackedSecurityRealm securityRealm = new SimpleMapBackedSecurityRealm();
    securityRealm.setPasswordMap(entries);
    testDomain = SecurityDomain.builder().setDefaultRealmName("Default").addRealm("Default", securityRealm).build().setPermissionMapper((p, r) -> new LoginPermission()).build();
}
Also used : SimpleMapBackedSecurityRealm(org.wildfly.security.auth.realm.SimpleMapBackedSecurityRealm) StandardRole(org.jboss.as.controller.access.rbac.StandardRole) SimpleRealmEntry(org.wildfly.security.auth.realm.SimpleRealmEntry) HashMap(java.util.HashMap) LoginPermission(org.wildfly.security.auth.permission.LoginPermission) BeforeClass(org.junit.BeforeClass)

Example 5 with SimpleMapBackedSecurityRealm

use of org.wildfly.security.auth.realm.SimpleMapBackedSecurityRealm in project wildfly-core by wildfly.

the class ChannelServer method create.

public static ChannelServer create(final Configuration configuration) throws IOException {
    checkNotNullParam("configuration", configuration).validate();
    // Hack WFCORE-3302/REM3-303 workaround
    if (firstCreate) {
        firstCreate = false;
    } else {
        try {
            // wait in case the previous socket has not closed
            Thread.sleep(100);
        } catch (InterruptedException e) {
            Thread.currentThread().interrupt();
            throw new RuntimeException(e);
        }
    }
    // TODO WFCORE-3302 -- Endpoint.getCurrent() should be ok
    final Endpoint endpoint = Endpoint.builder().setEndpointName(configuration.getEndpointName()).build();
    final NetworkServerProvider networkServerProvider = endpoint.getConnectionProviderInterface(configuration.getUriScheme(), NetworkServerProvider.class);
    final SecurityDomain.Builder domainBuilder = SecurityDomain.builder();
    final SimpleMapBackedSecurityRealm realm = new SimpleMapBackedSecurityRealm();
    domainBuilder.addRealm("default", realm).build();
    domainBuilder.setDefaultRealmName("default");
    domainBuilder.setPermissionMapper((permissionMappable, roles) -> PermissionVerifier.ALL);
    SecurityDomain testDomain = domainBuilder.build();
    SaslAuthenticationFactory saslAuthenticationFactory = SaslAuthenticationFactory.builder().setSecurityDomain(testDomain).setMechanismConfigurationSelector(mechanismInformation -> "ANONYMOUS".equals(mechanismInformation.getMechanismName()) ? MechanismConfiguration.EMPTY : null).setFactory(new AnonymousServerFactory()).build();
    System.out.println(configuration.getBindAddress());
    AcceptingChannel<StreamConnection> streamServer = networkServerProvider.createServer(configuration.getBindAddress(), OptionMap.EMPTY, saslAuthenticationFactory, null);
    return new ChannelServer(endpoint, null, streamServer);
}
Also used : SaslAuthenticationFactory(org.wildfly.security.auth.server.SaslAuthenticationFactory) SimpleMapBackedSecurityRealm(org.wildfly.security.auth.realm.SimpleMapBackedSecurityRealm) Endpoint(org.jboss.remoting3.Endpoint) AnonymousServerFactory(org.wildfly.security.sasl.anonymous.AnonymousServerFactory) NetworkServerProvider(org.jboss.remoting3.spi.NetworkServerProvider) StreamConnection(org.xnio.StreamConnection) SecurityDomain(org.wildfly.security.auth.server.SecurityDomain)

Aggregations

SimpleMapBackedSecurityRealm (org.wildfly.security.auth.realm.SimpleMapBackedSecurityRealm)27 SecurityDomain (org.wildfly.security.auth.server.SecurityDomain)16 NetworkServerProvider (org.jboss.remoting3.spi.NetworkServerProvider)13 InetSocketAddress (java.net.InetSocketAddress)12 BeforeClass (org.junit.BeforeClass)12 PasswordFactory (org.wildfly.security.password.PasswordFactory)12 ClearPasswordSpec (org.wildfly.security.password.spec.ClearPasswordSpec)12 SaslServerFactory (javax.security.sasl.SaslServerFactory)11 SaslAuthenticationFactory (org.wildfly.security.auth.server.sasl.SaslAuthenticationFactory)11 ServiceLoaderSaslServerFactory (org.wildfly.security.sasl.util.ServiceLoaderSaslServerFactory)10 SimpleRealmEntry (org.wildfly.security.auth.realm.SimpleRealmEntry)9 HashMap (java.util.HashMap)8 LoginPermission (org.wildfly.security.auth.permission.LoginPermission)6 Endpoint (org.jboss.remoting3.Endpoint)5 Test (org.junit.Test)5 MapAttributes (org.wildfly.security.authz.MapAttributes)5 IOException (java.io.IOException)4 Map (java.util.Map)4 SecurityRealm (org.wildfly.security.auth.server.SecurityRealm)4 ClearPassword (org.wildfly.security.password.interfaces.ClearPassword)4