本文整理匯總了Java中org.wildfly.security.auth.server.SecurityRealm類的典型用法代碼示例。如果您正苦於以下問題:Java SecurityRealm類的具體用法?Java SecurityRealm怎麽用?Java SecurityRealm使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
SecurityRealm類屬於org.wildfly.security.auth.server包,在下文中一共展示了SecurityRealm類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: performRuntime
import org.wildfly.security.auth.server.SecurityRealm; //導入依賴的package包/類
@Override
protected void performRuntime(OperationContext context, ModelNode operation, ModelNode model)
throws OperationFailedException {
ServiceTarget serviceTarget = context.getServiceTarget();
RuntimeCapability<Void> runtimeCapability = SECURITY_REALM_RUNTIME_CAPABILITY.fromBaseCapability(context.getCurrentAddressValue());
ServiceName realmName = runtimeCapability.getCapabilityServiceName(SecurityRealm.class);
final InjectedValue<KeyStore> keyStore = new InjectedValue<KeyStore>();
TrivialService<SecurityRealm> keyStoreRealmService = new TrivialService<SecurityRealm>(() -> new KeyStoreBackedSecurityRealm(keyStore.getValue()));
ServiceBuilder<SecurityRealm> serviceBuilder = serviceTarget.addService(realmName, keyStoreRealmService);
String keyStoreCapabilityName = RuntimeCapability.buildDynamicCapabilityName(KEY_STORE_CAPABILITY, KEYSTORE.resolveModelAttribute(context, model).asString());
ServiceName keyStoreServiceName = context.getCapabilityServiceName(keyStoreCapabilityName, KeyStore.class);
KEY_STORE_UTIL.addInjection(serviceBuilder, keyStore, keyStoreServiceName);
commonDependencies(serviceBuilder)
.setInitialMode(Mode.ACTIVE)
.install();
}
示例2: get
import org.wildfly.security.auth.server.SecurityRealm; //導入依賴的package包/類
@Override
public SecurityRealm get() throws StartException {
try {
HostnameVerifier verifier = null;
if (hostNameVerificationPolicy != null) {
verifier = HostnameVerificationPolicy.valueOf(hostNameVerificationPolicy).getVerifier();
}
OAuth2IntrospectValidator.Builder builder = OAuth2IntrospectValidator.builder().clientId(clientId).clientSecret(clientSecret)
.tokenIntrospectionUrl(new URL(introspectionUrl))
.useSslContext(sslContextInjector.getOptionalValue())
.useSslHostnameVerifier(verifier);
return TokenSecurityRealm.builder().principalClaimName(principalClaimNode.asString())
.validator(builder.build())
.build();
} catch (MalformedURLException e) {
throw new RuntimeException("Failed to parse token introspection URL.", e);
}
}
示例3: performRuntime
import org.wildfly.security.auth.server.SecurityRealm; //導入依賴的package包/類
@Override
protected void performRuntime(OperationContext context, ModelNode operation, ModelNode model)
throws OperationFailedException {
ServiceTarget serviceTarget = context.getServiceTarget();
RuntimeCapability<Void> runtimeCapability = SECURITY_REALM_RUNTIME_CAPABILITY.fromBaseCapability(context.getCurrentAddressValue());
ServiceName realmName = runtimeCapability.getCapabilityServiceName(SecurityRealm.class);
String authenticationRealm = AUTHENTICATION_REALM.resolveModelAttribute(context, model).asString();
String authorizationRealm = AUTHORIZATION_REALM.resolveModelAttribute(context, model).asString();
final InjectedValue<SecurityRealm> authenticationRealmValue = new InjectedValue<SecurityRealm>();
final InjectedValue<SecurityRealm> authorizationRealmValue = new InjectedValue<SecurityRealm>();
TrivialService<SecurityRealm> aggregateRealmService = new TrivialService<SecurityRealm>( () -> new AggregateSecurityRealm(authenticationRealmValue.getValue(), authorizationRealmValue.getValue()));
ServiceBuilder<SecurityRealm> serviceBuilder = serviceTarget.addService(realmName, aggregateRealmService);
addRealmDependency(context, serviceBuilder, authenticationRealm, authenticationRealmValue);
addRealmDependency(context, serviceBuilder, authorizationRealm, authorizationRealmValue);
commonDependencies(serviceBuilder)
.setInitialMode(Mode.ACTIVE)
.install();
}
示例4: createService
import org.wildfly.security.auth.server.SecurityRealm; //導入依賴的package包/類
private TrivialService<SecurityRealm> createService(String realmName, int maxEntries, long maxAge, InjectedValue<SecurityRealm> injector) {
return new TrivialService<>((TrivialService.ValueSupplier<SecurityRealm>) () -> {
SecurityRealm securityRealm = injector.getValue();
if (securityRealm instanceof CacheableSecurityRealm) {
RealmIdentityCache cache = createRealmIdentityCache(maxEntries, maxAge);
CacheableSecurityRealm cacheableRealm = CacheableSecurityRealm.class.cast(securityRealm);
if (securityRealm instanceof ModifiableSecurityRealm) {
return new CachingModifiableSecurityRealm(cacheableRealm, cache);
}
return new CachingSecurityRealm(cacheableRealm, cache);
}
throw ElytronSubsystemMessages.ROOT_LOGGER.realmDoesNotSupportCache(realmName);
});
}
示例5: performRuntime
import org.wildfly.security.auth.server.SecurityRealm; //導入依賴的package包/類
@Override
protected void performRuntime(OperationContext context, ModelNode operation, ModelNode model) throws OperationFailedException {
ServiceTarget serviceTarget = context.getServiceTarget();
String address = context.getCurrentAddressValue();
ServiceName mainServiceName = MODIFIABLE_SECURITY_REALM_RUNTIME_CAPABILITY.fromBaseCapability(address).getCapabilityServiceName();
ServiceName aliasServiceName = SECURITY_REALM_RUNTIME_CAPABILITY.fromBaseCapability(address).getCapabilityServiceName();
final LdapSecurityRealmBuilder builder = LdapSecurityRealmBuilder.builder();
if (DIRECT_VERIFICATION.resolveModelAttribute(context, model).asBoolean()) {
boolean allowBlankPassword = ALLOW_BLANK_PASSWORD.resolveModelAttribute(context, model).asBoolean();
builder.addDirectEvidenceVerification(allowBlankPassword);
}
TrivialService<SecurityRealm> ldapRealmService = new TrivialService<>(builder::build);
ServiceBuilder<SecurityRealm> serviceBuilder = serviceTarget.addService(mainServiceName, ldapRealmService)
.addAliases(aliasServiceName);
commonDependencies(serviceBuilder);
configureIdentityMapping(context, model, builder);
configureDirContext(context, model, builder, serviceBuilder);
serviceBuilder.setInitialMode(ServiceController.Mode.ACTIVE).install();
}
示例6: testPropertyRealm
import org.wildfly.security.auth.server.SecurityRealm; //導入依賴的package包/類
@Test
public void testPropertyRealm() throws Exception {
KernelServices services = super.createKernelServicesBuilder(new TestEnvironment()).setSubsystemXmlResource("realms-test.xml").build();
if (!services.isSuccessfulBoot()) {
Assert.fail(services.getBootError().toString());
}
ServiceName serviceName = Capabilities.SECURITY_REALM_RUNTIME_CAPABILITY.getCapabilityServiceName("HashedPropertyRealm");
SecurityRealm securityRealm = (SecurityRealm) services.getContainer().getService(serviceName).getValue();
testAbstractPropertyRealm(securityRealm);
ServiceName serviceName2 = Capabilities.SECURITY_REALM_RUNTIME_CAPABILITY.getCapabilityServiceName("ClearPropertyRealm");
SecurityRealm securityRealm2 = (SecurityRealm) services.getContainer().getService(serviceName2).getValue();
testAbstractPropertyRealm(securityRealm2);
RealmIdentity identity1 = securityRealm2.getRealmIdentity(fromName("user1"));
Object[] groups = identity1.getAuthorizationIdentity().getAttributes().get("groupAttr").toArray();
Assert.assertArrayEquals(new Object[]{"firstGroup","secondGroup"}, groups);
}
示例7: testAbstractPropertyRealm
import org.wildfly.security.auth.server.SecurityRealm; //導入依賴的package包/類
private void testAbstractPropertyRealm(SecurityRealm securityRealm) throws Exception {
Assert.assertNotNull(securityRealm);
RealmIdentity identity1 = securityRealm.getRealmIdentity(fromName("user1"));
Assert.assertTrue(identity1.exists());
Assert.assertTrue(identity1.verifyEvidence(new PasswordGuessEvidence("password1".toCharArray())));
Assert.assertFalse(identity1.verifyEvidence(new PasswordGuessEvidence("password2".toCharArray())));
identity1.dispose();
RealmIdentity identity2 = securityRealm.getRealmIdentity(fromName("user2"));
Assert.assertTrue(identity2.exists());
Assert.assertTrue(identity2.verifyEvidence(new PasswordGuessEvidence("password2".toCharArray())));
identity2.dispose();
RealmIdentity identity9 = securityRealm.getRealmIdentity(fromName("user9"));
Assert.assertFalse(identity9.exists());
Assert.assertFalse(identity9.verifyEvidence(new PasswordGuessEvidence("password9".toCharArray())));
identity9.dispose();
}
示例8: installServices
import org.wildfly.security.auth.server.SecurityRealm; //導入依賴的package包/類
public static void installServices(final OperationContext context, final String remotingConnectorName, final String httpConnectorName, final ServiceName endpointName,
final OptionMap connectorPropertiesOptionMap, final String securityRealm, final String saslAuthenticationFactory) {
ServiceTarget serviceTarget = context.getServiceTarget();
final RemotingHttpUpgradeService service = new RemotingHttpUpgradeService(httpConnectorName, endpointName.getSimpleName(), connectorPropertiesOptionMap);
ServiceBuilder<RemotingHttpUpgradeService> serviceBuilder = serviceTarget.addService(UPGRADE_SERVICE_NAME.append(remotingConnectorName), service)
.setInitialMode(ServiceController.Mode.PASSIVE)
.addDependency(HTTP_UPGRADE_REGISTRY.append(httpConnectorName), ChannelUpgradeHandler.class, service.injectedRegistry)
.addDependency(HttpListenerRegistryService.SERVICE_NAME, ListenerRegistry.class, service.listenerRegistry)
.addDependency(endpointName, Endpoint.class, service.injectedEndpoint);
if (securityRealm != null) {
serviceBuilder.addDependency(
org.jboss.as.domain.management.SecurityRealm.ServiceUtil.createServiceName(securityRealm),
org.jboss.as.domain.management.SecurityRealm.class, service.injectedSecurityRealm);
}
if (saslAuthenticationFactory != null) {
serviceBuilder.addDependency(
context.getCapabilityServiceName(SASL_AUTHENTICATION_FACTORY_CAPABILITY, saslAuthenticationFactory, SaslAuthenticationFactory.class),
SaslAuthenticationFactory.class, service.injectedSaslAuthenticationFactory);
}
serviceBuilder.install();
}
示例9: getIdentityRealmDefinition
import org.wildfly.security.auth.server.SecurityRealm; //導入依賴的package包/類
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);
}
示例10: performRuntime
import org.wildfly.security.auth.server.SecurityRealm; //導入依賴的package包/類
@Override
protected void performRuntime(OperationContext context, ModelNode operation, ModelNode model)
throws OperationFailedException {
ServiceTarget serviceTarget = context.getServiceTarget();
RuntimeCapability<Void> runtimeCapability = SECURITY_REALM_RUNTIME_CAPABILITY.fromBaseCapability(context.getCurrentAddressValue());
ServiceName realmName = runtimeCapability.getCapabilityServiceName(SecurityRealm.class);
String cacheableRealm = REALM_NAME.resolveModelAttribute(context, model).asString();
int maxEntries = MAXIMUM_ENTRIES.resolveModelAttribute(context, model).asInt();
long maxAge = MAXIMUM_AGE.resolveModelAttribute(context, model).asInt();
InjectedValue<SecurityRealm> cacheableRealmValue = new InjectedValue<>();
ServiceBuilder<SecurityRealm> serviceBuilder = serviceTarget.addService(realmName, createService(cacheableRealm, maxEntries, maxAge, cacheableRealmValue));
addRealmDependency(context, serviceBuilder, cacheableRealm, cacheableRealmValue);
commonDependencies(serviceBuilder).setInitialMode(Mode.ACTIVE).install();
}
示例11: executeRuntimeStep
import org.wildfly.security.auth.server.SecurityRealm; //導入依賴的package包/類
@Override
protected void executeRuntimeStep(final OperationContext context, final ModelNode operation) throws OperationFailedException {
ServiceRegistry serviceRegistry = context.getServiceRegistry(true);
PathAddress currentAddress = context.getCurrentAddress();
RuntimeCapability<Void> runtimeCapability = SECURITY_REALM_RUNTIME_CAPABILITY.fromBaseCapability(currentAddress.getLastElement().getValue());
ServiceName realmName = runtimeCapability.getCapabilityServiceName();
ServiceController<SecurityRealm> serviceController = getRequiredService(serviceRegistry, realmName, SecurityRealm.class);
CachingSecurityRealm securityRealm = CachingSecurityRealm.class.cast(serviceController.getValue());
securityRealm.removeAllFromCache();
}
示例12: configureDirContext
import org.wildfly.security.auth.server.SecurityRealm; //導入依賴的package包/類
private void configureDirContext(OperationContext context, ModelNode model, LdapSecurityRealmBuilder realmBuilder, ServiceBuilder<SecurityRealm> serviceBuilder) throws OperationFailedException {
String dirContextName = DIR_CONTEXT.resolveModelAttribute(context, model).asStringOrNull();
String runtimeCapability = RuntimeCapability.buildDynamicCapabilityName(DIR_CONTEXT_CAPABILITY, dirContextName);
ServiceName dirContextServiceName = context.getCapabilityServiceName(runtimeCapability, DirContextSupplier.class);
final InjectedValue<DirContextSupplier> dirContextInjector = new InjectedValue<>();
serviceBuilder.addDependency(dirContextServiceName, DirContextSupplier.class, dirContextInjector);
realmBuilder.setDirContextSupplier(() -> {
ExceptionSupplier<DirContext, NamingException> supplier = dirContextInjector.getValue();
return supplier.get();
});
}
示例13: performRuntime
import org.wildfly.security.auth.server.SecurityRealm; //導入依賴的package包/類
@Override
protected void performRuntime(OperationContext context, ModelNode operation, ModelNode model)
throws OperationFailedException {
ServiceTarget serviceTarget = context.getServiceTarget();
RuntimeCapability<Void> runtimeCapability = SECURITY_REALM_RUNTIME_CAPABILITY.fromBaseCapability(context.getCurrentAddressValue());
ServiceName realmName = runtimeCapability.getCapabilityServiceName(SecurityRealm.class);
ModelNode principalQueries = PrincipalQueryAttributes.PRINCIPAL_QUERIES.resolveModelAttribute(context, operation);
final JdbcSecurityRealmBuilder builder = JdbcSecurityRealm.builder();
TrivialService<SecurityRealm> service = new TrivialService<SecurityRealm>(builder::build);
ServiceBuilder<SecurityRealm> serviceBuilder = serviceTarget.addService(realmName, service);
for (ModelNode query : principalQueries.asList()) {
String authenticationQuerySql = PrincipalQueryAttributes.SQL.resolveModelAttribute(context, query).asString();
QueryBuilder queryBuilder = builder.principalQuery(authenticationQuerySql)
.withMapper(resolveAttributeMappers(context, query))
.withMapper(resolveKeyMappers(context, query));
String dataSourceName = PrincipalQueryAttributes.DATA_SOURCE.resolveModelAttribute(context, query).asString();
String capabilityName = Capabilities.DATA_SOURCE_CAPABILITY_NAME + "." + dataSourceName;
ServiceName dataSourceServiceName = context.getCapabilityServiceName(capabilityName, DataSource.class);
serviceBuilder.addDependency(dataSourceServiceName, DataSource.class, new Injector<DataSource>() {
@Override
public void inject(DataSource value) throws InjectionException {
queryBuilder.from(value);
}
@Override
public void uninject() {
// no-op
}
});
}
commonDependencies(serviceBuilder)
.setInitialMode(ServiceController.Mode.ACTIVE)
.install();
}
示例14: testOAuth2Realm
import org.wildfly.security.auth.server.SecurityRealm; //導入依賴的package包/類
@Test
public void testOAuth2Realm() throws Exception {
KernelServices services = super.createKernelServicesBuilder(new TestEnvironment()).setSubsystemXmlResource("realms-test.xml").build();
if (!services.isSuccessfulBoot()) {
Assert.fail(services.getBootError().toString());
}
ServiceName serviceName = Capabilities.SECURITY_REALM_RUNTIME_CAPABILITY.getCapabilityServiceName("OAuth2Realm");
SecurityRealm securityRealm = (SecurityRealm) services.getContainer().getService(serviceName).getValue();
Assert.assertNotNull(securityRealm);
}
示例15: addRealmDependency
import org.wildfly.security.auth.server.SecurityRealm; //導入依賴的package包/類
private void addRealmDependency(OperationContext context, ServiceBuilder<SecurityRealm> serviceBuilder, String realmName, Injector<SecurityRealm> securityRealmInjector) {
String runtimeCapability = RuntimeCapability.buildDynamicCapabilityName(SECURITY_REALM_CAPABILITY, realmName);
ServiceName realmServiceName = context.getCapabilityServiceName(runtimeCapability, SecurityRealm.class);
REALM_SERVICE_UTIL.addInjection(serviceBuilder, securityRealmInjector, realmServiceName);
}