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 classSecurityDomain.BuilderA builder for creating new security domains.static classSecurityDomain.RealmBuilderA builder for a realm within a security domain.private static classSecurityDomain.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 SecurityIdentityauthenticate(String name, Evidence evidence)Perform an authentication based onEvidencefor the specified identity name.SecurityIdentityauthenticate(Principal principal, Evidence evidence)SecurityIdentityauthenticate(Evidence evidence)Perform an authentication based onEvidencealone.static SecurityDomain.Builderbuilder()Create a new security domain builder.SecurityIdentitycreateAdHocIdentity(String name)Create an empty ad-hoc identity.SecurityIdentitycreateAdHocIdentity(Principal principal)Create an empty ad-hoc identity.ServerAuthenticationContextcreateNewAuthenticationContext()Create a new authentication context for this security domain which can be used to carry out a single authentication operation.ServerAuthenticationContextcreateNewAuthenticationContext(MechanismConfigurationSelector mechanismConfigurationSelector)Create a new authentication context for this security domain which can be used to carry out a single authentication operation.(package private) ServerAuthenticationContextcreateNewAuthenticationContext(SecurityIdentity capturedIdentity, MechanismConfigurationSelector mechanismConfigurationSelector)static SecurityDomainforIdentity(SecurityIdentity identity)Get the security domain associated with the given identity.(package private) Supplier<SecurityIdentity>getAndSetCurrentSecurityIdentity(Supplier<SecurityIdentity> newIdentity)SecurityIdentitygetAnonymousSecurityIdentity()Get the anonymous security identity for this realm.(package private) Map<String,RoleMapper>getCategoryRoleMappers()SupportLevelgetCredentialAcquireSupport(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.SupportLevelgetCredentialAcquireSupport(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.SupportLevelgetCredentialAcquireSupport(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 SecurityDomaingetCurrent()Get theSecurityDomainassociated with the context class loader of the calling Thread ornullif one is not associated.SecurityIdentitygetCurrentSecurityIdentity()Get the current security identity for this domain.(package private) StringgetDefaultRealmName()(package private) Function<Evidence,Principal>getEvidenceDecoder()SupportLevelgetEvidenceVerifySupport(Class<? extends Evidence> evidenceType)Determine whether a given type of evidence is definitely verifiable, possibly verifiable (for some identities), or definitely not verifiable.SupportLevelgetEvidenceVerifySupport(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.RealmIdentitygetIdentity(String name)Look up aRealmIdentityby name by wrapping the name in aNamePrincipaland callinggetIdentity(Principal).RealmIdentitygetIdentity(Principal principal)Look up aRealmIdentityby principal.ModifiableRealmIdentitygetIdentityForUpdate(Principal principal)Look up aModifiableRealmIdentityby 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) SecurityRealmgetRealm(String realmName)(package private) RealmInfogetRealmInfo(String realmName)(package private) Collection<RealmInfo>getRealmInfos()(package private) RealmMappergetRealmMapper()(package private) RoleDecodergetRoleDecoder()(package private) RoleMappergetRoleMapper()static ScheduledExecutorServicegetScheduledExecutorService()GetsScheduledExecutorServicefor authentication related scheduled task (like authentication timeout).private SupportLevelgetSupportLevel(Function<SecurityRealm,SupportLevel> getSupportLevel)voidhandleSecurityEvent(SecurityEvent securityEvent)Handle aSecurityEvent.(package private) PermissionVerifiermapPermissions(SecurityIdentity securityIdentity)(package private) StringmapRealmName(Principal principal, Evidence evidence)(package private) RolesmapRoles(SecurityIdentity securityIdentity)private SupportLevelminMax(SupportLevel min, SupportLevel max)voidregisterWithClassLoader(ClassLoader classLoader)Register thisSecurityDomainwith the specifiedClassLoader.(package private) static voidsafeHandleSecurityEvent(SecurityDomain domain, SecurityEvent event)(package private) voidsetCurrentSecurityIdentity(Supplier<SecurityIdentity> newIdentity)(package private) SecurityIdentitytransform(SecurityIdentity securityIdentity)(package private) booleantrustsDomain(SecurityDomain domain)static voidunregisterClassLoader(ClassLoader classLoader)Unregister anySecurityDomainassociated 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 thisSecurityDomainwith the specifiedClassLoader. Registration with enabled security manager requiresregisterSecurityDomainElytronPermission.- Parameters:
classLoader- the nonnullClassLoaderto associate thisSecurityDomainwith.- Throws:
IllegalStateException- If aSecurityDomainis already associated with the specifiedClassLoader.
-
getCurrent
public static SecurityDomain getCurrent()
Get theSecurityDomainassociated with the context class loader of the calling Thread ornullif one is not associated. Obtaining security domain with enabled security manager requiresgetSecurityDomainElytronPermission.- Returns:
- the
SecurityDomainassociated with the context class loader of the calling Thread ornullif 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 requiresgetSecurityDomainElytronPermission.- Parameters:
identity- the security identity (must not benull)- Returns:
- the identity's security domain (not
null)
-
unregisterClassLoader
public static void unregisterClassLoader(ClassLoader classLoader)
Unregister anySecurityDomainassociated with the specifiedClassLoader. Unregistration with enabled security manager requiresunregisterSecurityDomainElytronPermission.- Parameters:
classLoader- the nonnullClassLoaderto clear anySecurityDomainassociation.
-
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 requirescreateServerAuthenticationContextElytronPermission.- 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 requirescreateServerAuthenticationContextElytronPermission.- 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 onEvidencealone. Note: It is the caller's responsibility to destroy any evidence passed into this method.- Parameters:
evidence- theEvidenceto use for authentication.- Returns:
- the authenticated identity.
- Throws:
RealmUnavailableException- if the requiresSecurityRealmis not available.SecurityException- if authentication fails.
-
authenticate
public SecurityIdentity authenticate(String name, Evidence evidence) throws RealmUnavailableException, SecurityException
Perform an authentication based onEvidencefor 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 ornullif the identity is to be derived from the evidence.evidence- theEvidenceto use for authentication.- Returns:
- the authenticated identity.
- Throws:
RealmUnavailableException- if the requiresSecurityRealmis not available.SecurityException- if authentication fails.
-
authenticate
public SecurityIdentity authenticate(Principal principal, Evidence evidence) throws RealmUnavailableException, SecurityException
Perform an authentication based onEvidencefor the specified identityPrincipal. Note: It is the caller's responsibility to destroy any evidence passed into this method. Calling with enabled security manager requiresauthenticateElytronPermission.- Parameters:
principal- the principal of the identity to authenticate ornullif the identity is to be derived from the evidence.evidence- theEvidenceto use for authentication.- Returns:
- the authenticated identity.
- Throws:
RealmUnavailableException- if the requiresSecurityRealmis not available.SecurityException- if authentication fails.
-
getIdentity
public RealmIdentity getIdentity(String name) throws RealmUnavailableException
Look up aRealmIdentityby name by wrapping the name in aNamePrincipaland 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 aRealmIdentityby principal. The returned identity must be disposed. Calling with enabled security manager requiresgetIdentityElytronPermission.- 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 aModifiableRealmIdentityby principal. The returned identity must be disposed. Calling with enabled security manager requiresgetIdentityForUpdateElytronPermission.- 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 requiresgetIdentityElytronPermission.- 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 requiresgetIdentityForUpdateElytronPermission.- 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_SUPPORTEDif 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, ornullif any algorithm is acceptable or the credential type does not support algorithm namesparameterSpec- the algorithm parameters to match, ornullif 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_SUPPORTEDif 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, ornullif 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_SUPPORTEDif 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_SUPPORTEDif 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, ornullif 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_SUPPORTEDif 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 requirescreateAdHocIdentityElytronPermission.- 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 requireshandleSecurityEventElytronPermission.- Parameters:
securityEvent-SecurityEventto be handled- See Also:
SecurityDomain.Builder.setSecurityEventListener(Consumer)
-
safeHandleSecurityEvent
static void safeHandleSecurityEvent(SecurityDomain domain, SecurityEvent event)
-
getRoleDecoder
RoleDecoder getRoleDecoder()
-
getScheduledExecutorService
public static ScheduledExecutorService getScheduledExecutorService()
GetsScheduledExecutorServicefor authentication related scheduled task (like authentication timeout).- Returns:
- the executor service
-
-