public final class SecurityHelper extends Object
UserDetails
. This details contain the email, locale and id for further usage.Modifier and Type | Method and Description |
---|---|
static User |
assertCurrentKenmeiUser()
Deprecated.
this method should not be used since it returns the user entity which can be an
uninitialized hibernate proxy. Use
assertCurrentUserId() instead and
pass the returned userId together with an appropriate Converter (which is in most
cases not the IdentityConverter!) to UserManagement.getUserById. |
static UserDetails |
assertCurrentUser()
Checks if there is a user logged in.
|
static UserDetails |
assertCurrentUser(Long userId)
Gets the current logged in user and checks if the given id is matching.
|
static Long |
assertCurrentUserId()
Get the current user id.
|
static UserDetails |
assertCurrentUserIsClientManager()
Checks if there is a user logged in and the user is client manager.
|
static boolean |
assertCurrentUserOrPublicUser()
Checks if there is a user logged in with user role of user or public user.
|
static void |
assertCurrentUserRole(UserRole role)
Asserts that the current user has the given role
|
static UserDetails |
getCurrentUser()
Get the current user which is set in the acegi security context.
|
static String |
getCurrentUserAlias()
Get the alias of the current user, or null if no user is logged in
|
static Long |
getCurrentUserId()
Get the current user id, or null if no user is logged in
|
static boolean |
hasRole(UserRole role)
Checks that the current user has the given role
|
static boolean |
isClientManager() |
static boolean |
isCurrentUserId(Long userId)
check if the current user id matches the given id
|
static boolean |
isCurrentUserOrPublicUser()
Checks if there is a user logged in with user role of user or public user.
|
static boolean |
isInternalSystem() |
static boolean |
isPublicUser()
Checks the security context if the authenticated user is in role of the public user.
|
@Deprecated public static User assertCurrentKenmeiUser()
assertCurrentUserId()
instead and
pass the returned userId together with an appropriate Converter (which is in most
cases not the IdentityConverter!) to UserManagement.getUserById.public static UserDetails assertCurrentUser()
public static UserDetails assertCurrentUser(Long userId)
userId
- The user id to assert for the current userpublic static Long assertCurrentUserId()
public static UserDetails assertCurrentUserIsClientManager()
Note: this method should usually not be used because it throws the wrong exception!
Especially in service layer an AuthorizationException
should be thrown which has no
spring dependency and is checked and thus allows better handling.
public static boolean assertCurrentUserOrPublicUser()
public static void assertCurrentUserRole(UserRole role) throws AuthorizationException
role
- the role to checkAuthorizationException
- in case the user does not has the rolepublic static UserDetails getCurrentUser()
UserDetails
of the current user or null if no user is logged inpublic static String getCurrentUserAlias()
public static Long getCurrentUserId()
public static boolean hasRole(UserRole role)
role
- the role to checkpublic static boolean isClientManager()
public static boolean isCurrentUserId(Long userId)
userId
- the user id to checkpublic static boolean isCurrentUserOrPublicUser()
public static boolean isInternalSystem()
public static boolean isPublicUser()
Copyright © 2019 Communote team. All rights reserved.