Package org.wildfly.security.auth.server
Class SecurityDomain
- java.lang.Object
-
- org.wildfly.security.auth.server.SecurityDomain
-
public final class SecurityDomain extends Object
A security domain. Security domains encapsulate a set of security policies.- Author:
- David M. Lloyd, Darran Lofthouse
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
SecurityDomain.Builder
A builder for creating new security domains.static class
SecurityDomain.RealmBuilder
A builder for a realm within a security domain.private static class
SecurityDomain.ScheduledExecutorServiceProvider
-
Field Summary
-
Constructor Summary
Constructors Constructor Description SecurityDomain(SecurityDomain.Builder builder, LinkedHashMap<String,RealmInfo> realmMap)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description SecurityIdentity
authenticate(String name, Evidence evidence)
Perform an authentication based onEvidence
for the specified identity name.SecurityIdentity
authenticate(Principal principal, Evidence evidence)
SecurityIdentity
authenticate(Evidence evidence)
Perform an authentication based onEvidence
alone.static SecurityDomain.Builder
builder()
Create a new security domain builder.SecurityIdentity
createAdHocIdentity(String name)
Create an empty ad-hoc identity.SecurityIdentity
createAdHocIdentity(Principal principal)
Create an empty ad-hoc identity.ServerAuthenticationContext
createNewAuthenticationContext()
Create a new authentication context for this security domain which can be used to carry out a single authentication operation.ServerAuthenticationContext
createNewAuthenticationContext(MechanismConfigurationSelector mechanismConfigurationSelector)
Create a new authentication context for this security domain which can be used to carry out a single authentication operation.(package private) ServerAuthenticationContext
createNewAuthenticationContext(SecurityIdentity capturedIdentity, MechanismConfigurationSelector mechanismConfigurationSelector)
static SecurityDomain
forIdentity(SecurityIdentity identity)
Get the security domain associated with the given identity.(package private) Supplier<SecurityIdentity>
getAndSetCurrentSecurityIdentity(Supplier<SecurityIdentity> newIdentity)
SecurityIdentity
getAnonymousSecurityIdentity()
Get the anonymous security identity for this realm.(package private) Map<String,RoleMapper>
getCategoryRoleMappers()
SupportLevel
getCredentialAcquireSupport(Class<? extends Credential> credentialType)
Determine whether a credential of the given type and algorithm is definitely obtainable, possibly obtainable (for some identities), or definitely not obtainable.SupportLevel
getCredentialAcquireSupport(Class<? extends Credential> credentialType, String algorithmName)
Determine whether a credential of the given type and algorithm is definitely obtainable, possibly obtainable (for some identities), or definitely not obtainable.SupportLevel
getCredentialAcquireSupport(Class<? extends Credential> credentialType, String algorithmName, AlgorithmParameterSpec parameterSpec)
Determine whether a credential of the given type and algorithm is definitely obtainable, possibly obtainable (for some identities), or definitely not obtainable.static SecurityDomain
getCurrent()
Get theSecurityDomain
associated with the context class loader of the calling Thread ornull
if one is not associated.SecurityIdentity
getCurrentSecurityIdentity()
Get the current security identity for this domain.(package private) String
getDefaultRealmName()
(package private) Function<Evidence,Principal>
getEvidenceDecoder()
SupportLevel
getEvidenceVerifySupport(Class<? extends Evidence> evidenceType)
Determine whether a given type of evidence is definitely verifiable, possibly verifiable (for some identities), or definitely not verifiable.SupportLevel
getEvidenceVerifySupport(Class<? extends Evidence> evidenceType, String algorithmName)
Determine whether a given type of evidence is definitely verifiable, possibly verifiable (for some identities), or definitely not verifiable.RealmIdentity
getIdentity(String name)
Look up aRealmIdentity
by name by wrapping the name in aNamePrincipal
and callinggetIdentity(Principal)
.RealmIdentity
getIdentity(Principal principal)
Look up aRealmIdentity
by principal.ModifiableRealmIdentity
getIdentityForUpdate(Principal principal)
Look up aModifiableRealmIdentity
by principal.org.wildfly.common.function.ExceptionFunction<Principal,ModifiableRealmIdentity,RealmUnavailableException>
getIdentityLookupForUpdateFunction()
Get a function which can be used to look up principals for update without a security manager permission check.org.wildfly.common.function.ExceptionFunction<Principal,RealmIdentity,RealmUnavailableException>
getIdentityLookupFunction()
Get a function which can be used to look up principals without a security manager permission check.(package private) <I,R extends SecurityRealm>
IgetIdentityPrivileged(Principal principal, Class<R> realmType, org.wildfly.common.function.ExceptionBiFunction<R,Principal,I,RealmUnavailableException> fn, Supplier<I> nonExistent, Supplier<I> anonymous)
(package private) Function<Principal,Principal>
getPostRealmRewriter()
(package private) Function<Principal,Principal>
getPreRealmRewriter()
(package private) SecurityRealm
getRealm(String realmName)
(package private) RealmInfo
getRealmInfo(String realmName)
(package private) Collection<RealmInfo>
getRealmInfos()
(package private) RealmMapper
getRealmMapper()
(package private) RoleDecoder
getRoleDecoder()
(package private) RoleMapper
getRoleMapper()
static ScheduledExecutorService
getScheduledExecutorService()
GetsScheduledExecutorService
for authentication related scheduled task (like authentication timeout).private SupportLevel
getSupportLevel(Function<SecurityRealm,SupportLevel> getSupportLevel)
void
handleSecurityEvent(SecurityEvent securityEvent)
Handle aSecurityEvent
.(package private) PermissionVerifier
mapPermissions(SecurityIdentity securityIdentity)
(package private) String
mapRealmName(Principal principal, Evidence evidence)
(package private) Roles
mapRoles(SecurityIdentity securityIdentity)
private SupportLevel
minMax(SupportLevel min, SupportLevel max)
void
registerWithClassLoader(ClassLoader classLoader)
Register thisSecurityDomain
with the specifiedClassLoader
.(package private) static void
safeHandleSecurityEvent(SecurityDomain domain, SecurityEvent event)
(package private) void
setCurrentSecurityIdentity(Supplier<SecurityIdentity> newIdentity)
(package private) SecurityIdentity
transform(SecurityIdentity securityIdentity)
(package private) boolean
trustsDomain(SecurityDomain domain)
static void
unregisterClassLoader(ClassLoader classLoader)
Unregister anySecurityDomain
associated with the specifiedClassLoader
.
-
-
-
Field Detail
-
CLASS_LOADER_DOMAIN_MAP
private static final ConcurrentHashMap<ClassLoader,SecurityDomain> CLASS_LOADER_DOMAIN_MAP
-
EMPTY_REALM_INFO
private static final RealmInfo EMPTY_REALM_INFO
-
AUTHENTICATE
static final ElytronPermission AUTHENTICATE
-
CREATE_SECURITY_DOMAIN
static final ElytronPermission CREATE_SECURITY_DOMAIN
-
REGISTER_SECURITY_DOMAIN
static final ElytronPermission REGISTER_SECURITY_DOMAIN
-
GET_SECURITY_DOMAIN
static final ElytronPermission GET_SECURITY_DOMAIN
-
UNREGISTER_SECURITY_DOMAIN
static final ElytronPermission UNREGISTER_SECURITY_DOMAIN
-
CREATE_AUTH_CONTEXT
static final ElytronPermission CREATE_AUTH_CONTEXT
-
GET_IDENTITY
static final ElytronPermission GET_IDENTITY
-
GET_IDENTITY_FOR_UPDATE
static final ElytronPermission GET_IDENTITY_FOR_UPDATE
-
CREATE_AD_HOC_IDENTITY
static final ElytronPermission CREATE_AD_HOC_IDENTITY
-
HANDLE_SECURITY_EVENT
static final ElytronPermission HANDLE_SECURITY_EVENT
-
defaultRealmName
private final String defaultRealmName
-
realmMapper
private final RealmMapper realmMapper
-
currentSecurityIdentity
private final ThreadLocal<Supplier<SecurityIdentity>> currentSecurityIdentity
-
roleMapper
private final RoleMapper roleMapper
-
anonymousIdentity
private final SecurityIdentity anonymousIdentity
-
permissionMapper
private final PermissionMapper permissionMapper
-
categoryRoleMappers
private final Map<String,RoleMapper> categoryRoleMappers
-
securityIdentityTransformer
private final UnaryOperator<SecurityIdentity> securityIdentityTransformer
-
trustedSecurityDomain
private final Predicate<SecurityDomain> trustedSecurityDomain
-
securityEventListener
private final Consumer<SecurityEvent> securityEventListener
-
roleDecoder
private final RoleDecoder roleDecoder
-
-
Constructor Detail
-
SecurityDomain
SecurityDomain(SecurityDomain.Builder builder, LinkedHashMap<String,RealmInfo> realmMap)
-
-
Method Detail
-
registerWithClassLoader
public void registerWithClassLoader(ClassLoader classLoader)
Register thisSecurityDomain
with the specifiedClassLoader
. Registration with enabled security manager requiresregisterSecurityDomain
ElytronPermission
.- Parameters:
classLoader
- the nonnull
ClassLoader
to associate thisSecurityDomain
with.- Throws:
IllegalStateException
- If aSecurityDomain
is already associated with the specifiedClassLoader
.
-
getCurrent
public static SecurityDomain getCurrent()
Get theSecurityDomain
associated with the context class loader of the calling Thread ornull
if one is not associated. Obtaining security domain with enabled security manager requiresgetSecurityDomain
ElytronPermission
.- Returns:
- the
SecurityDomain
associated with the context class loader of the calling Thread ornull
if one is not associated.
-
forIdentity
public static SecurityDomain forIdentity(SecurityIdentity identity)
Get the security domain associated with the given identity. Obtaining security domain with enabled security manager requiresgetSecurityDomain
ElytronPermission
.- Parameters:
identity
- the security identity (must not benull
)- Returns:
- the identity's security domain (not
null
)
-
unregisterClassLoader
public static void unregisterClassLoader(ClassLoader classLoader)
Unregister anySecurityDomain
associated with the specifiedClassLoader
. Unregistration with enabled security manager requiresunregisterSecurityDomain
ElytronPermission
.- Parameters:
classLoader
- the nonnull
ClassLoader
to clear anySecurityDomain
association.
-
builder
public static SecurityDomain.Builder builder()
Create a new security domain builder.- Returns:
- the builder
-
createNewAuthenticationContext
public ServerAuthenticationContext createNewAuthenticationContext()
Create a new authentication context for this security domain which can be used to carry out a single authentication operation. Calling with enabled security manager requirescreateServerAuthenticationContext
ElytronPermission
.- Returns:
- the new authentication context
-
createNewAuthenticationContext
public ServerAuthenticationContext createNewAuthenticationContext(MechanismConfigurationSelector mechanismConfigurationSelector)
Create a new authentication context for this security domain which can be used to carry out a single authentication operation. Calling with enabled security manager requirescreateServerAuthenticationContext
ElytronPermission
.- Parameters:
mechanismConfigurationSelector
- the selector to use to obtain the mechanism configuration- Returns:
- the new authentication context
-
createNewAuthenticationContext
ServerAuthenticationContext createNewAuthenticationContext(SecurityIdentity capturedIdentity, MechanismConfigurationSelector mechanismConfigurationSelector)
-
authenticate
public SecurityIdentity authenticate(Evidence evidence) throws RealmUnavailableException, SecurityException
Perform an authentication based onEvidence
alone. Note: It is the caller's responsibility to destroy any evidence passed into this method.- Parameters:
evidence
- theEvidence
to use for authentication.- Returns:
- the authenticated identity.
- Throws:
RealmUnavailableException
- if the requiresSecurityRealm
is not available.SecurityException
- if authentication fails.
-
authenticate
public SecurityIdentity authenticate(String name, Evidence evidence) throws RealmUnavailableException, SecurityException
Perform an authentication based onEvidence
for the specified identity name. Note: It is the caller's responsibility to destroy any evidence passed into this method.- Parameters:
name
- the name of the identity to authenticate ornull
if the identity is to be derived from the evidence.evidence
- theEvidence
to use for authentication.- Returns:
- the authenticated identity.
- Throws:
RealmUnavailableException
- if the requiresSecurityRealm
is not available.SecurityException
- if authentication fails.
-
authenticate
public SecurityIdentity authenticate(Principal principal, Evidence evidence) throws RealmUnavailableException, SecurityException
Perform an authentication based onEvidence
for the specified identityPrincipal
. Note: It is the caller's responsibility to destroy any evidence passed into this method. Calling with enabled security manager requiresauthenticate
ElytronPermission
.- Parameters:
principal
- the principal of the identity to authenticate ornull
if the identity is to be derived from the evidence.evidence
- theEvidence
to use for authentication.- Returns:
- the authenticated identity.
- Throws:
RealmUnavailableException
- if the requiresSecurityRealm
is not available.SecurityException
- if authentication fails.
-
getIdentity
public RealmIdentity getIdentity(String name) throws RealmUnavailableException
Look up aRealmIdentity
by name by wrapping the name in aNamePrincipal
and callinggetIdentity(Principal)
. The returned identity must be disposed.- Parameters:
name
- the name to map (must not benull
)- Returns:
- the identity for the name (not
null
, may be non-existent) - Throws:
RealmUnavailableException
- if the realm is not able to perform the mappingIllegalArgumentException
- if the name is not validSecurityException
- if the caller is not authorized to perform the operation
-
getIdentity
public RealmIdentity getIdentity(Principal principal) throws RealmUnavailableException, IllegalArgumentException
Look up aRealmIdentity
by principal. The returned identity must be disposed. Calling with enabled security manager requiresgetIdentity
ElytronPermission
.- Parameters:
principal
- the principal to map (must not benull
)- Returns:
- the identity for the name (not
null
, may be non-existent) - Throws:
IllegalArgumentException
- if the principal could not be successfully decoded to a nameRealmUnavailableException
- if the realm is not able to perform the mappingSecurityException
- if the caller is not authorized to perform the operation
-
getIdentityForUpdate
public ModifiableRealmIdentity getIdentityForUpdate(Principal principal) throws RealmUnavailableException, IllegalArgumentException
Look up aModifiableRealmIdentity
by principal. The returned identity must be disposed. Calling with enabled security manager requiresgetIdentityForUpdate
ElytronPermission
.- Parameters:
principal
- the principal to map (must not benull
)- Returns:
- the identity for the name (not
null
, may be non-existent) - Throws:
IllegalArgumentException
- if the principal could not be successfully decoded to a nameRealmUnavailableException
- if the realm is not able to perform the mappingSecurityException
- if the caller is not authorized to perform the operation
-
getIdentityLookupFunction
public org.wildfly.common.function.ExceptionFunction<Principal,RealmIdentity,RealmUnavailableException> getIdentityLookupFunction()
Get a function which can be used to look up principals without a security manager permission check. All returned identities must be disposed. Calling with enabled security manager requiresgetIdentity
ElytronPermission
.- Returns:
- the lookup function (not
null
) - Throws:
SecurityException
- if the caller is not authorized to perform the operation
-
getIdentityLookupForUpdateFunction
public org.wildfly.common.function.ExceptionFunction<Principal,ModifiableRealmIdentity,RealmUnavailableException> getIdentityLookupForUpdateFunction()
Get a function which can be used to look up principals for update without a security manager permission check. All returned identities must be disposed. Calling with enabled security manager requiresgetIdentityForUpdate
ElytronPermission
.- Returns:
- the lookup function (not
null
) - Throws:
SecurityException
- if the caller is not authorized to perform the operation
-
getIdentityPrivileged
<I,R extends SecurityRealm> I getIdentityPrivileged(Principal principal, Class<R> realmType, org.wildfly.common.function.ExceptionBiFunction<R,Principal,I,RealmUnavailableException> fn, Supplier<I> nonExistent, Supplier<I> anonymous) throws RealmUnavailableException
- Throws:
RealmUnavailableException
-
getRealm
SecurityRealm getRealm(String realmName)
-
getRealmInfos
Collection<RealmInfo> getRealmInfos()
-
getCredentialAcquireSupport
public SupportLevel getCredentialAcquireSupport(Class<? extends Credential> credentialType, String algorithmName, AlgorithmParameterSpec parameterSpec)
Determine whether a credential of the given type and algorithm is definitely obtainable, possibly obtainable (for some identities), or definitely not obtainable. Credential isSupportLevel.SUPPORTED
, if it is supported by all realms of the domain. Credential isSupportLevel.POSSIBLY_SUPPORTED
if it is supported or possibly supported by at least one realm of the domain. Otherwise it isSupportLevel.UNSUPPORTED
.- Parameters:
credentialType
- the exact credential type (must not benull
)algorithmName
- the algorithm name, ornull
if any algorithm is acceptable or the credential type does not support algorithm namesparameterSpec
- the algorithm parameters to match, ornull
if any parameters are acceptable or the credential type does not support algorithm parameters- Returns:
- the level of support for this credential
-
getCredentialAcquireSupport
public SupportLevel getCredentialAcquireSupport(Class<? extends Credential> credentialType, String algorithmName)
Determine whether a credential of the given type and algorithm is definitely obtainable, possibly obtainable (for some identities), or definitely not obtainable. Credential isSupportLevel.SUPPORTED
, if it is supported by all realms of the domain. Credential isSupportLevel.POSSIBLY_SUPPORTED
if it is supported or possibly supported by at least one realm of the domain. Otherwise it isSupportLevel.UNSUPPORTED
.- Parameters:
credentialType
- the exact credential type (must not benull
)algorithmName
- the algorithm name, ornull
if any algorithm is acceptable or the credential type does not support algorithm names- Returns:
- the level of support for this credential
-
getCredentialAcquireSupport
public SupportLevel getCredentialAcquireSupport(Class<? extends Credential> credentialType)
Determine whether a credential of the given type and algorithm is definitely obtainable, possibly obtainable (for some identities), or definitely not obtainable. Credential isSupportLevel.SUPPORTED
, if it is supported by all realms of the domain. Credential isSupportLevel.POSSIBLY_SUPPORTED
if it is supported or possibly supported by at least one realm of the domain. Otherwise it isSupportLevel.UNSUPPORTED
.- Parameters:
credentialType
- the exact credential type (must not benull
)- Returns:
- the level of support for this credential
-
getEvidenceVerifySupport
public SupportLevel getEvidenceVerifySupport(Class<? extends Evidence> evidenceType, String algorithmName)
Determine whether a given type of evidence is definitely verifiable, possibly verifiable (for some identities), or definitely not verifiable. Evidence isSupportLevel.SUPPORTED
, if it is supported by all realms of the domain. Evidence isSupportLevel.POSSIBLY_SUPPORTED
if it is supported or possibly supported by at least one realm of the domain. Otherwise it isSupportLevel.UNSUPPORTED
.- Parameters:
evidenceType
- the type of evidence to be verified (must not benull
)algorithmName
- the algorithm name, ornull
if any algorithm is acceptable or the evidence type does not support algorithm names- Returns:
- the level of support for this evidence type
-
getEvidenceVerifySupport
public SupportLevel getEvidenceVerifySupport(Class<? extends Evidence> evidenceType)
Determine whether a given type of evidence is definitely verifiable, possibly verifiable (for some identities), or definitely not verifiable. Evidence isSupportLevel.SUPPORTED
, if it is supported by all realms of the domain. Evidence isSupportLevel.POSSIBLY_SUPPORTED
if it is supported or possibly supported by at least one realm of the domain. Otherwise it isSupportLevel.UNSUPPORTED
.- Parameters:
evidenceType
- the type of evidence to be verified (must not benull
)- Returns:
- the level of support for this evidence type
-
getSupportLevel
private SupportLevel getSupportLevel(Function<SecurityRealm,SupportLevel> getSupportLevel)
-
minMax
private SupportLevel minMax(SupportLevel min, SupportLevel max)
-
getCurrentSecurityIdentity
public SecurityIdentity getCurrentSecurityIdentity()
Get the current security identity for this domain. Code can be executed with given identity usingSecurityIdentity.runAs*
methods.- Returns:
- the current security identity for this domain (not
null
)
-
getAnonymousSecurityIdentity
public SecurityIdentity getAnonymousSecurityIdentity()
Get the anonymous security identity for this realm.- Returns:
- the anonymous security identity for this realm (not
null
)
-
createAdHocIdentity
public SecurityIdentity createAdHocIdentity(String name)
Create an empty ad-hoc identity. The identity will have no authorization information and no credentials associated with it.- Parameters:
name
- the identity name (must not benull
)- Returns:
- the ad-hoc identity
-
createAdHocIdentity
public SecurityIdentity createAdHocIdentity(Principal principal)
Create an empty ad-hoc identity. The identity will have no authorization information and no credentials associated with it. Calling with enabled security manager requirescreateAdHocIdentity
ElytronPermission
.- Parameters:
principal
- the identity principal (must not benull
)- Returns:
- the ad-hoc identity
-
getAndSetCurrentSecurityIdentity
Supplier<SecurityIdentity> getAndSetCurrentSecurityIdentity(Supplier<SecurityIdentity> newIdentity)
-
setCurrentSecurityIdentity
void setCurrentSecurityIdentity(Supplier<SecurityIdentity> newIdentity)
-
mapRoles
Roles mapRoles(SecurityIdentity securityIdentity)
-
mapPermissions
PermissionVerifier mapPermissions(SecurityIdentity securityIdentity)
-
getDefaultRealmName
String getDefaultRealmName()
-
getRealmMapper
RealmMapper getRealmMapper()
-
getRoleMapper
RoleMapper getRoleMapper()
-
getCategoryRoleMappers
Map<String,RoleMapper> getCategoryRoleMappers()
-
transform
SecurityIdentity transform(SecurityIdentity securityIdentity)
-
trustsDomain
boolean trustsDomain(SecurityDomain domain)
-
handleSecurityEvent
public void handleSecurityEvent(SecurityEvent securityEvent)
Handle aSecurityEvent
. Calling with enabled security manager requireshandleSecurityEvent
ElytronPermission
.- Parameters:
securityEvent
-SecurityEvent
to be handled- See Also:
SecurityDomain.Builder.setSecurityEventListener(Consumer)
-
safeHandleSecurityEvent
static void safeHandleSecurityEvent(SecurityDomain domain, SecurityEvent event)
-
getRoleDecoder
RoleDecoder getRoleDecoder()
-
getScheduledExecutorService
public static ScheduledExecutorService getScheduledExecutorService()
GetsScheduledExecutorService
for authentication related scheduled task (like authentication timeout).- Returns:
- the executor service
-
-