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);
}
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);
}
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();
}
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();
}
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);
}
Aggregations