Class AuthenticationUtil
- java.lang.Object
-
- org.alfresco.repo.security.authentication.AuthenticationUtil
-
- All Implemented Interfaces:
org.springframework.beans.factory.InitializingBean
@AlfrescoPublicApi public class AuthenticationUtil extends java.lang.Object implements org.springframework.beans.factory.InitializingBeanUtility helper methods to change the authenticated context for threads.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interfaceAuthenticationUtil.RunAsWork<Result>
-
Field Summary
Fields Modifier and Type Field Description static java.lang.StringSYSTEM_USER_NAME
-
Constructor Summary
Constructors Constructor Description AuthenticationUtil()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidafterPropertiesSet()static voidclearCurrentSecurityContext()Remove the current security informationstatic java.lang.StringgetAdminRoleName()static java.lang.StringgetAdminUserName()Get the name of the default admin user (the admin user created during bootstrap)static net.sf.acegisecurity.AuthenticationgetFullAuthentication()WARN: Advanced usage only.
Get the authentication for that was set by an real authentication.static java.lang.StringgetFullyAuthenticatedUser()Get the fully authenticated user.static java.lang.StringgetGuestRoleName()Get the name of the guest rolestatic java.lang.StringgetGuestUserName()Get the name of the Guest Userstatic java.lang.StringgetMaskedUsername(net.sf.acegisecurity.Authentication authentication)static net.sf.acegisecurity.AuthenticationgetRunAsAuthentication()Get the current authentication for application of permissions.static java.lang.StringgetRunAsUser()Get the user that is currently in effect for purposes of authentication.static java.lang.StringgetSystemUserName()Get the name of the system userstatic org.alfresco.util.Pair<java.lang.String,java.lang.String>getUserTenant(java.lang.String userName)static booleanisMtEnabled()static booleanisRunAsUserTheSystemUser()static voidlogAuthenticatedUsers()Logs the current authenticated usersstatic voidlogNDC(java.lang.String userNameIn)static java.lang.StringmaskUsername(java.lang.String userName)static voidpopAuthentication()Pop the authentication context from a threadlocal stack.static voidpushAuthentication()Push the current authentication context onto a threadlocal stack.static <R> RrunAs(AuthenticationUtil.RunAsWork<R> runAsWork, java.lang.String uid)Execute a unit of work as a given user.static <R> RrunAsSystem(AuthenticationUtil.RunAsWork<R> runAsWork)static net.sf.acegisecurity.AuthenticationsetAdminUserAsFullyAuthenticatedUser()Authenticate as the Admin user.voidsetDefaultAdminUserName(java.lang.String defaultAdminUserName)voidsetDefaultGuestUserName(java.lang.String defaultGuestUserName)static net.sf.acegisecurity.AuthenticationsetFullAuthentication(net.sf.acegisecurity.Authentication authentication)Re-authenticate using a previously-created authentication.static net.sf.acegisecurity.AuthenticationsetFullyAuthenticatedUser(java.lang.String userName)Authenticate as the given user.static voidsetMtEnabled(boolean mtEnabled)static net.sf.acegisecurity.AuthenticationsetRunAsUser(java.lang.String userName)WARN: Advanced usage only.
Switch to the given user for all authenticated operations.static net.sf.acegisecurity.AuthenticationsetRunAsUserSystem()WARN: Advanced usage only.
Set the system user as the currently running user for authentication purposes.
-
-
-
Field Detail
-
SYSTEM_USER_NAME
public static final java.lang.String SYSTEM_USER_NAME
- See Also:
- Constant Field Values
-
-
Method Detail
-
afterPropertiesSet
public void afterPropertiesSet() throws java.lang.Exception- Specified by:
afterPropertiesSetin interfaceorg.springframework.beans.factory.InitializingBean- Throws:
java.lang.Exception
-
setDefaultAdminUserName
public void setDefaultAdminUserName(java.lang.String defaultAdminUserName)
-
setDefaultGuestUserName
public void setDefaultGuestUserName(java.lang.String defaultGuestUserName)
-
setMtEnabled
public static void setMtEnabled(boolean mtEnabled)
-
isMtEnabled
public static boolean isMtEnabled()
-
maskUsername
public static java.lang.String maskUsername(java.lang.String userName)
-
getMaskedUsername
public static java.lang.String getMaskedUsername(net.sf.acegisecurity.Authentication authentication)
-
setAdminUserAsFullyAuthenticatedUser
public static net.sf.acegisecurity.Authentication setAdminUserAsFullyAuthenticatedUser()
Authenticate as the Admin user. The Admin user will be authenticated and all operations with be run in the context of this Admin user.- Returns:
- the authentication token
-
setFullyAuthenticatedUser
public static net.sf.acegisecurity.Authentication setFullyAuthenticatedUser(java.lang.String userName)
Authenticate as the given user. The user will be authenticated and all operations with be run in the context of this user.- Parameters:
userName- the user name- Returns:
- the authentication token
-
setFullAuthentication
public static net.sf.acegisecurity.Authentication setFullAuthentication(net.sf.acegisecurity.Authentication authentication)
Re-authenticate using a previously-created authentication.
-
setRunAsUserSystem
public static net.sf.acegisecurity.Authentication setRunAsUserSystem()
WARN: Advanced usage only.
Set the system user as the currently running user for authentication purposes.- Returns:
- Authentication
- See Also:
setRunAsUser(String)
-
setRunAsUser
public static net.sf.acegisecurity.Authentication setRunAsUser(java.lang.String userName)
WARN: Advanced usage only.
Switch to the given user for all authenticated operations. The original, authenticated user can still be found usinggetFullyAuthenticatedUser().- Parameters:
userName- the user to run as- Returns:
- the new authentication
-
getRunAsAuthentication
public static net.sf.acegisecurity.Authentication getRunAsAuthentication() throws AuthenticationExceptionGet the current authentication for application of permissions. This includes the any overlay details set bysetRunAsUser(String).- Returns:
- Authentication Returns the running authentication
- Throws:
AuthenticationException
-
getFullAuthentication
public static net.sf.acegisecurity.Authentication getFullAuthentication() throws AuthenticationExceptionWARN: Advanced usage only.
Get the authentication for that was set by an real authentication.- Returns:
- Authentication Returns the real authentication
- Throws:
AuthenticationException
-
getRunAsUser
public static java.lang.String getRunAsUser() throws AuthenticationExceptionGet the user that is currently in effect for purposes of authentication. This includes any overlays introduced byrunAs.- Returns:
- Returns the name of the user
- Throws:
AuthenticationException
-
isRunAsUserTheSystemUser
public static boolean isRunAsUserTheSystemUser()
-
getFullyAuthenticatedUser
public static java.lang.String getFullyAuthenticatedUser() throws AuthenticationExceptionGet the fully authenticated user. It returns the name of the user that last authenticated and excludes any overlay authentication set byrunAs.- Returns:
- Returns the name of the authenticated user
- Throws:
AuthenticationException
-
getSystemUserName
public static java.lang.String getSystemUserName()
Get the name of the system user- Returns:
- system user name
-
getAdminUserName
public static java.lang.String getAdminUserName()
Get the name of the default admin user (the admin user created during bootstrap)- Returns:
- admin user name
-
getAdminRoleName
public static java.lang.String getAdminRoleName()
-
getGuestUserName
public static java.lang.String getGuestUserName()
Get the name of the Guest User
-
getGuestRoleName
public static java.lang.String getGuestRoleName()
Get the name of the guest role
-
clearCurrentSecurityContext
public static void clearCurrentSecurityContext()
Remove the current security information
-
runAs
public static <R> R runAs(AuthenticationUtil.RunAsWork<R> runAsWork, java.lang.String uid)
Execute a unit of work as a given user. The thread's authenticated user will be returned to its normal state after the call.- Parameters:
runAsWork- the unit of work to douid- the user ID- Returns:
- Returns the work's return value
-
runAsSystem
public static <R> R runAsSystem(AuthenticationUtil.RunAsWork<R> runAsWork)
-
pushAuthentication
public static void pushAuthentication()
Push the current authentication context onto a threadlocal stack.
-
popAuthentication
public static void popAuthentication()
Pop the authentication context from a threadlocal stack.
-
logAuthenticatedUsers
public static void logAuthenticatedUsers()
Logs the current authenticated users
-
logNDC
public static void logNDC(java.lang.String userNameIn)
-
getUserTenant
public static org.alfresco.util.Pair<java.lang.String,java.lang.String> getUserTenant(java.lang.String userName)
-
-