Class SecurityUtil
- Version:
- $Id: SecurityUtil.java,v 1.6 2013/09/14 16:56:04 paul Exp $
- Author:
- Paul
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic StringReturns the username of the authenticated userstatic booleanstatic booleanisPrivate(org.springframework.security.acls.model.Acl acl) Test whether the given ACL is constraining access to users who are at privileges above "anonymous".static booleanisPublic(org.springframework.security.acls.model.Acl acl) static booleanstatic booleanisShared(org.springframework.security.acls.model.Acl acl) static booleanReturns true if the current user has admin authority.static booleanReturns true if the current caller holds the agent authority.static booleanReturns true if the user is anonymous.static booleanReturns true if the current caller holds the curator authority.static booleanReturns true if the current caller curates: a curator, or an administrator.static booleanReturns true if the user is non-anonymous.static StringresolveActingIdentity(String onBehalfOf) Resolve the identity an action should be recorded against, given an optionalonBehalfOfclaim from the caller.
-
Constructor Details
-
SecurityUtil
public SecurityUtil()
-
-
Method Details
-
getCurrentUsername
Returns the username of the authenticated user -
isOwner
-
isPublic
public static boolean isPublic(org.springframework.security.acls.model.Acl acl) -
isPrivate
public static boolean isPrivate(org.springframework.security.acls.model.Acl acl) Test whether the given ACL is constraining access to users who are at privileges above "anonymous".- Returns:
- true if the permissions indicate 'non-public', false if 'public'.
-
isRunningAsAdmin
public static boolean isRunningAsAdmin() -
isUserAdmin
public static boolean isUserAdmin()Returns true if the current user has admin authority.- Returns:
- true if the current user has admin authority
-
isUserAnonymous
public static boolean isUserAnonymous()Returns true if the user is anonymous. -
isUserLoggedIn
public static boolean isUserLoggedIn()Returns true if the user is non-anonymous. -
isUserCurator
public static boolean isUserCurator()Returns true if the current caller holds the curator authority.🛑 Read the granted authorities directly rather than relying on the role hierarchy that makes an administrator satisfy
hasAuthority('GROUP_CURATOR')in a@PreAuthorizeexpression. That expansion is performed by the access-decision voter, not baked intoAuthentication.getAuthorities(), so a programmatic check sees only what was actually granted. Callers wanting "curator or better" must ask forisUserAdmin()too, which is whyisUserCuratorOrAdmin()exists. -
isUserCuratorOrAdmin
public static boolean isUserCuratorOrAdmin()Returns true if the current caller curates: a curator, or an administrator.- See Also:
-
isUserAgent
public static boolean isUserAgent()Returns true if the current caller holds the agent authority. -
resolveActingIdentity
Resolve the identity an action should be recorded against, given an optionalonBehalfOfclaim from the caller.Curation writes reach Gemma through the curation agent rather than from a curator's browser, so the authenticated principal on those calls is the agent acting for someone else. Recording the principal would attribute every curator's work to the agent — and where the identity is part of a uniqueness key, as it is for a
DRAFT's"draft-{curator}"run id, it does worse than mis-attribute: two curators collapse onto one row and the second write silently overwrites the first.So the acting identity travels on the wire, and the principal only decides whether the caller may claim it. Only an agent or an admin may; for anyone else a claim is refused rather than ignored, because quietly substituting their own name would record a different fact from the one they asked for.
- Parameters:
onBehalfOf- the claimed identity, ornullto act as yourself- Returns:
- the identity to record
- Throws:
org.springframework.security.access.AccessDeniedException- if a caller who is neither agent nor admin claims to be someone elseIllegalStateException- if there is no authenticated caller to fall back to
-