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.
-
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.static SecurityDomainforIdentity(SecurityIdentity identity)Get the security domain associated with the given identity.SecurityIdentitygetAnonymousSecurityIdentity()Get the anonymous security identity for this realm.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.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.static ScheduledExecutorServicegetScheduledExecutorService()GetsScheduledExecutorServicefor authentication related scheduled task (like authentication timeout).voidhandleSecurityEvent(SecurityEvent securityEvent)Handle aSecurityEvent.voidregisterWithClassLoader(ClassLoader classLoader)Register thisSecurityDomainwith the specifiedClassLoader.static voidunregisterClassLoader(ClassLoader classLoader)Unregister anySecurityDomainassociated with the specifiedClassLoader.
-
-
-
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
-
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
-
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
-
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
-
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)
-
getScheduledExecutorService
public static ScheduledExecutorService getScheduledExecutorService()
GetsScheduledExecutorServicefor authentication related scheduled task (like authentication timeout).- Returns:
- the executor service
-
-