Overview  Package   Class  Use  Tree  Deprecated  Index  Help 
PREV CLASS   NEXT CLASS FRAMES    NO FRAMES    All Classes
SUMMARY: NESTED | FIELD | CONSTR | METHOD DETAIL: FIELD | CONSTR | METHOD

org.alfresco.repo.security.authentication
Class AuthenticationUtil
java.lang.Object
  org.alfresco.repo.security.authentication.AuthenticationUtil
All Implemented Interfaces:
org.springframework.beans.factory.InitializingBean

@org.alfresco.api.AlfrescoPublicApi
public class AuthenticationUtil
extends Object
implements org.springframework.beans.factory.InitializingBean
Utility helper methods to change the authenticated context for threads.

Nested Class Summary
static interface
AuthenticationUtil.RunAsWork<Result>
Field Summary
static String
SYSTEM_USER_NAME
Constructor Summary
AuthenticationUtil()
Method Summary
void
afterPropertiesSet()
static void
clearCurrentSecurityContext()
          Remove the current security information
static String
getAdminRoleName()
static String
getAdminUserName()
          Get the name of the default admin user (the admin user created during bootstrap)
static net.sf.acegisecurity.Authentication
getFullAuthentication()
           WARN: Advanced usage only. Get the authentication for that was set by an real authentication.
static String
getFullyAuthenticatedUser()
          Get the fully authenticated user.
static String
getGuestRoleName()
          Get the name of the guest role
static String
getGuestUserName()
          Get the name of the Guest User
static net.sf.acegisecurity.Authentication
getRunAsAuthentication()
          Get the current authentication for application of permissions.
static String
getRunAsUser()
          Get the user that is currently in effect for purposes of authentication.
static String
getSystemUserName()
          Get the name of the system user
static Pair<String>
getUserTenant(String userName)
static boolean
isMtEnabled()
static boolean
isRunAsUserTheSystemUser()
static void
logAuthenticatedUsers()
          Logs the current authenticated users
static void
logNDC(String userNameIn)
static void
popAuthentication()
          Pop the authentication context from a threadlocal stack.
static void
pushAuthentication()
          Push the current authentication context onto a threadlocal stack.
static <R> R
runAs(AuthenticationUtil.RunAsWork<R> runAsWork, String uid)
          Execute a unit of work as a given user.
static <R> R
runAsSystem(AuthenticationUtil.RunAsWork<R> runAsWork)
static net.sf.acegisecurity.Authentication
setAdminUserAsFullyAuthenticatedUser()
          Authenticate as the Admin user.
void
setDefaultAdminUserName(String defaultAdminUserName)
void
setDefaultGuestUserName(String defaultGuestUserName)
static net.sf.acegisecurity.Authentication
setFullAuthentication(net.sf.acegisecurity.Authentication authentication)
          Re-authenticate using a previously-created authentication.
static net.sf.acegisecurity.Authentication
setFullyAuthenticatedUser(String userName)
          Authenticate as the given user.
static void
setMtEnabled(boolean mtEnabled)
static net.sf.acegisecurity.Authentication
setRunAsUser(String userName)
           WARN: Advanced usage only. Switch to the given user for all authenticated operations.
static net.sf.acegisecurity.Authentication
setRunAsUserSystem()
           WARN: Advanced usage only. Set the system user as the currently running user for authentication purposes.
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Field Detail
SYSTEM_USER_NAME
public static final String SYSTEM_USER_NAME
See Also:
Constant Field Values
Constructor Detail
AuthenticationUtil
public AuthenticationUtil()
Method Detail
afterPropertiesSet
public void afterPropertiesSet()
                        throws Exception
Specified by:
afterPropertiesSet in interface org.springframework.beans.factory.InitializingBean
Throws:
Exception

setDefaultAdminUserName
public void setDefaultAdminUserName(String defaultAdminUserName)

setDefaultGuestUserName
public void setDefaultGuestUserName(String defaultGuestUserName)

setMtEnabled
public static void setMtEnabled(boolean mtEnabled)

isMtEnabled
public static boolean isMtEnabled()

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(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(String userName)
WARN: Advanced usage only.
Switch to the given user for all authenticated operations. The original, authenticated user can still be found using getFullyAuthenticatedUser().
Parameters:
userName - the user to run as
Returns:
the new authentication

getRunAsAuthentication
public static net.sf.acegisecurity.Authentication getRunAsAuthentication()
                                                                  throws AuthenticationException
Get the current authentication for application of permissions. This includes the any overlay details set by setRunAsUser(String).
Returns:
Authentication Returns the running authentication
Throws:
AuthenticationException

getFullAuthentication
public static net.sf.acegisecurity.Authentication getFullAuthentication()
                                                                 throws AuthenticationException
WARN: 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 String getRunAsUser()
                           throws AuthenticationException
Get the user that is currently in effect for purposes of authentication. This includes any overlays introduced by runAs.
Returns:
Returns the name of the user
Throws:
AuthenticationException

isRunAsUserTheSystemUser
public static boolean isRunAsUserTheSystemUser()

getFullyAuthenticatedUser
public static String getFullyAuthenticatedUser()
                                        throws AuthenticationException
Get the fully authenticated user. It returns the name of the user that last authenticated and excludes any overlay authentication set by runAs.
Returns:
Returns the name of the authenticated user
Throws:
AuthenticationException

getSystemUserName
public static String getSystemUserName()
Get the name of the system user
Returns:
system user name

getAdminUserName
public static String getAdminUserName()
Get the name of the default admin user (the admin user created during bootstrap)
Returns:
admin user name

getAdminRoleName
public static String getAdminRoleName()

getGuestUserName
public static String getGuestUserName()
Get the name of the Guest User

getGuestRoleName
public static 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,
                          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 do
uid - 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(String userNameIn)

getUserTenant
public static Pair<StringgetUserTenant(String userName)

Overview  Package   Class  Use  Tree  Deprecated  Index  Help 
PREV CLASS   NEXT CLASS FRAMES    NO FRAMES    All Classes
SUMMARY: NESTED | FIELD | CONSTR | METHOD DETAIL: FIELD | CONSTR | METHOD

Copyright © 2005–2017 Alfresco Software. All rights reserved.

Java API documentation generated with DocFlex/Javadoc 1.6.1 using JavadocPro template set.