Class AuthorizationSupport
java.lang.Object
net.solarnetwork.central.security.AuthorizationSupport
- Direct Known Subclasses:
UserMetadataSecurityAspect
Helper class for authorization needs, e.g. aspect implementations.
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionGet aSecurityPolicyfor the active user, if available.Get theSolarNodeOwnershipDao.org.springframework.util.PathMatcherGet the path matcher to use.<T> TpolicyEnforcerCheck(T domainObject) Enforce a security policy on a domain object andSecurityPolicyMetadataType#Nodemetadata type.<T> TpolicyEnforcerCheck(T domainObject, SecurityPolicyMetadataType metadataType) Enforce a security policy on a domain object or collection of domain objects.protected voidrequireNodeReadAccess(Long nodeId) Require the active user have "read" access to a given node ID.voidrequireNodeReadAccess(Long nodeId, org.slf4j.Logger log) Require the active user have "read" access to a given node ID.protected voidrequireNodeWriteAccess(Long nodeId) Require the active user have "write" access to a given node ID.voidrequireNodeWriteAccess(Long nodeId, org.slf4j.Logger log) Require the active user have "write" access to a given node ID.protected voidrequireUserReadAccess(Long userId) Require the active user have "read" access to a given user ID.voidrequireUserReadAccess(Long userId, org.slf4j.Logger log) Require the active user have "read" access to a given user ID.protected voidrequireUserWriteAccess(Long userId) Require the active user have "write" access to a given user ID.voidrequireUserWriteAccess(Long userId, org.slf4j.Logger log) Require the active user have "write" access to a given user ID.voidsetPathMatcher(org.springframework.util.PathMatcher pathMatcher) Set the path matcher to use.
-
Field Details
-
log
protected final org.slf4j.Logger log
-
-
Constructor Details
-
AuthorizationSupport
Constructor.- Parameters:
userNodeDao- the UserNodeDao to use- Throws:
IllegalArgumentException- if any argumnet is null
-
-
Method Details
-
getNodeOwnershipDao
Get theSolarNodeOwnershipDao.- Returns:
- The
SolarNodeOwnershipDao.
-
requireNodeWriteAccess
Require the active user have "write" access to a given node ID. If the active user is not authorized, aAuthorizationExceptionwill be thrown.- Parameters:
nodeId- the node ID to check- Throws:
AuthorizationException- if the authorization check fails
-
requireNodeWriteAccess
Require the active user have "write" access to a given node ID. If the active user is not authorized, aAuthorizationExceptionwill be thrown.- Parameters:
nodeId- the node ID to checklog- the logger to use- Throws:
AuthorizationException- if the authorization check fails- Since:
- 1.1
-
requireNodeReadAccess
Require the active user have "read" access to a given node ID. If the active user is not authorized, aAuthorizationExceptionwill be thrown.- Parameters:
nodeId- the node ID to check- Throws:
AuthorizationException- if the authorization check fails
-
requireNodeReadAccess
Require the active user have "read" access to a given node ID. If the active user is not authorized, aAuthorizationExceptionwill be thrown.- Parameters:
nodeId- the node ID to checklog- the logger to use- Throws:
AuthorizationException- if the authorization check fails- Since:
- 1.1
-
requireUserWriteAccess
Require the active user have "write" access to a given user ID. If the active user is not authorized, aAuthorizationExceptionwill be thrown.- Parameters:
userId- the user ID to check- Throws:
AuthorizationException- if the authorization check fails
-
requireUserWriteAccess
Require the active user have "write" access to a given user ID. If the active user is not authorized, aAuthorizationExceptionwill be thrown.- Parameters:
userId- the user ID to checklog- the logger to use- Throws:
AuthorizationException- if the authorization check fails- Since:
- 1.1
-
getActiveSecurityPolicy
Get aSecurityPolicyfor the active user, if available.- Returns:
- The active user's policy, or
null.
-
requireUserReadAccess
Require the active user have "read" access to a given user ID. If the active user is not authorized, aAuthorizationExceptionwill be thrown.- Parameters:
userId- the user ID to check- Throws:
AuthorizationException- if the authorization check fails
-
requireUserReadAccess
Require the active user have "read" access to a given user ID. If the active user is not authorized, aAuthorizationExceptionwill be thrown.- Parameters:
userId- the user ID to checklog- the logger to use- Throws:
AuthorizationException- if the authorization check fails- Since:
- 1.1
-
policyEnforcerCheck
public <T> T policyEnforcerCheck(T domainObject) Enforce a security policy on a domain object andSecurityPolicyMetadataType#Nodemetadata type.- Type Parameters:
T- the domain object type- Parameters:
domainObject- The domain object to enforce the active policy on.- Returns:
- The domain object to use.
- Throws:
AuthorizationException- If the policy check fails.
-
policyEnforcerCheck
Enforce a security policy on a domain object or collection of domain objects. TheFilterResultsAPI is supported, as isList.- Type Parameters:
T- the domain object type- Parameters:
domainObject- The domain object to enforce the active policy on.metadataType- The metadata type to enforce the active policy on.- Returns:
- The domain object to use.
- Throws:
AuthorizationException- If the policy check fails.
-
getPathMatcher
public org.springframework.util.PathMatcher getPathMatcher()Get the path matcher to use.- Returns:
- the path matcher
-
setPathMatcher
public void setPathMatcher(org.springframework.util.PathMatcher pathMatcher) Set the path matcher to use.- Parameters:
pathMatcher- the matcher to use
-