|
@@ -1,10 +1,11 @@
|
|
|
|
+// from the original documentation
|
|
|
|
|
|
[[authz-arch]]
|
|
[[authz-arch]]
|
|
-== Authorization Architecture
|
|
|
|
|
|
+= Authorization Architecture
|
|
|
|
|
|
|
|
|
|
[[authz-authorities]]
|
|
[[authz-authorities]]
|
|
-=== Authorities
|
|
|
|
|
|
+== Authorities
|
|
As we saw in the <<tech-granted-authority,technical overview>>, all `Authentication` implementations store a list of `GrantedAuthority` objects.
|
|
As we saw in the <<tech-granted-authority,technical overview>>, all `Authentication` implementations store a list of `GrantedAuthority` objects.
|
|
These represent the authorities that have been granted to the principal.
|
|
These represent the authorities that have been granted to the principal.
|
|
the `GrantedAuthority` objects are inserted into the `Authentication` object by the `AuthenticationManager` and are later read by `AccessDecisionManager` s when making authorization decisions.
|
|
the `GrantedAuthority` objects are inserted into the `Authentication` object by the `AuthenticationManager` and are later read by `AccessDecisionManager` s when making authorization decisions.
|
|
@@ -19,7 +20,7 @@ String getAuthority();
|
|
----
|
|
----
|
|
|
|
|
|
This method allows
|
|
This method allows
|
|
- `AccessDecisionManager` s to obtain a precise `String` representation of the `GrantedAuthority`.
|
|
|
|
|
|
+`AccessDecisionManager` s to obtain a precise `String` representation of the `GrantedAuthority`.
|
|
By returning a representation as a `String`, a `GrantedAuthority` can be easily "read" by most `AccessDecisionManager` s.
|
|
By returning a representation as a `String`, a `GrantedAuthority` can be easily "read" by most `AccessDecisionManager` s.
|
|
If a `GrantedAuthority` cannot be precisely represented as a `String`, the `GrantedAuthority` is considered "complex" and `getAuthority()` must return `null`.
|
|
If a `GrantedAuthority` cannot be precisely represented as a `String`, the `GrantedAuthority` is considered "complex" and `getAuthority()` must return `null`.
|
|
|
|
|
|
@@ -33,13 +34,13 @@ All `AuthenticationProvider` s included with the security architecture use `Simp
|
|
|
|
|
|
|
|
|
|
[[authz-pre-invocation]]
|
|
[[authz-pre-invocation]]
|
|
-=== Pre-Invocation Handling
|
|
|
|
|
|
+== Pre-Invocation Handling
|
|
As we've also seen in the <<secure-objects,Technical Overview>> chapter, Spring Security provides interceptors which control access to secure objects such as method invocations or web requests.
|
|
As we've also seen in the <<secure-objects,Technical Overview>> chapter, Spring Security provides interceptors which control access to secure objects such as method invocations or web requests.
|
|
A pre-invocation decision on whether the invocation is allowed to proceed is made by the `AccessDecisionManager`.
|
|
A pre-invocation decision on whether the invocation is allowed to proceed is made by the `AccessDecisionManager`.
|
|
|
|
|
|
|
|
|
|
[[authz-access-decision-manager]]
|
|
[[authz-access-decision-manager]]
|
|
-==== The AccessDecisionManager
|
|
|
|
|
|
+=== The AccessDecisionManager
|
|
The `AccessDecisionManager` is called by the `AbstractSecurityInterceptor` and is responsible for making final access control decisions.
|
|
The `AccessDecisionManager` is called by the `AbstractSecurityInterceptor` and is responsible for making final access control decisions.
|
|
the `AccessDecisionManager` interface contains three methods:
|
|
the `AccessDecisionManager` interface contains three methods:
|
|
|
|
|
|
@@ -63,7 +64,7 @@ The `supports(ConfigAttribute)` method is called by the `AbstractSecurityInterce
|
|
The `supports(Class)` method is called by a security interceptor implementation to ensure the configured `AccessDecisionManager` supports the type of secure object that the security interceptor will present.
|
|
The `supports(Class)` method is called by a security interceptor implementation to ensure the configured `AccessDecisionManager` supports the type of secure object that the security interceptor will present.
|
|
|
|
|
|
[[authz-voting-based]]
|
|
[[authz-voting-based]]
|
|
-==== Voting-Based AccessDecisionManager Implementations
|
|
|
|
|
|
+=== Voting-Based AccessDecisionManager Implementations
|
|
Whilst users can implement their own `AccessDecisionManager` to control all aspects of authorization, Spring Security includes several `AccessDecisionManager` implementations that are based on voting.
|
|
Whilst users can implement their own `AccessDecisionManager` to control all aspects of authorization, Spring Security includes several `AccessDecisionManager` implementations that are based on voting.
|
|
<<authz-access-voting>> illustrates the relevant classes.
|
|
<<authz-access-voting>> illustrates the relevant classes.
|
|
|
|
|
|
@@ -105,7 +106,7 @@ For example, votes from a particular `AccessDecisionVoter` might receive additio
|
|
|
|
|
|
|
|
|
|
[[authz-role-voter]]
|
|
[[authz-role-voter]]
|
|
-===== RoleVoter
|
|
|
|
|
|
+==== RoleVoter
|
|
The most commonly used `AccessDecisionVoter` provided with Spring Security is the simple `RoleVoter`, which treats configuration attributes as simple role names and votes to grant access if the user has been assigned that role.
|
|
The most commonly used `AccessDecisionVoter` provided with Spring Security is the simple `RoleVoter`, which treats configuration attributes as simple role names and votes to grant access if the user has been assigned that role.
|
|
|
|
|
|
It will vote if any `ConfigAttribute` begins with the prefix `ROLE_`.
|
|
It will vote if any `ConfigAttribute` begins with the prefix `ROLE_`.
|
|
@@ -115,7 +116,7 @@ If no `ConfigAttribute` begins with `ROLE_`, the voter will abstain.
|
|
|
|
|
|
|
|
|
|
[[authz-authenticated-voter]]
|
|
[[authz-authenticated-voter]]
|
|
-===== AuthenticatedVoter
|
|
|
|
|
|
+==== AuthenticatedVoter
|
|
Another voter which we've implicitly seen is the `AuthenticatedVoter`, which can be used to differentiate between anonymous, fully-authenticated and remember-me authenticated users.
|
|
Another voter which we've implicitly seen is the `AuthenticatedVoter`, which can be used to differentiate between anonymous, fully-authenticated and remember-me authenticated users.
|
|
Many sites allow certain limited access under remember-me authentication, but require a user to confirm their identity by logging in for full access.
|
|
Many sites allow certain limited access under remember-me authentication, but require a user to confirm their identity by logging in for full access.
|
|
|
|
|
|
@@ -124,14 +125,14 @@ See the Javadoc for this class for more information.
|
|
|
|
|
|
|
|
|
|
[[authz-custom-voter]]
|
|
[[authz-custom-voter]]
|
|
-===== Custom Voters
|
|
|
|
|
|
+==== Custom Voters
|
|
Obviously, you can also implement a custom `AccessDecisionVoter` and you can put just about any access-control logic you want in it.
|
|
Obviously, you can also implement a custom `AccessDecisionVoter` and you can put just about any access-control logic you want in it.
|
|
It might be specific to your application (business-logic related) or it might implement some security administration logic.
|
|
It might be specific to your application (business-logic related) or it might implement some security administration logic.
|
|
For example, you'll find a https://spring.io/blog/2009/01/03/spring-security-customization-part-2-adjusting-secured-session-in-real-time[blog article] on the Spring web site which describes how to use a voter to deny access in real-time to users whose accounts have been suspended.
|
|
For example, you'll find a https://spring.io/blog/2009/01/03/spring-security-customization-part-2-adjusting-secured-session-in-real-time[blog article] on the Spring web site which describes how to use a voter to deny access in real-time to users whose accounts have been suspended.
|
|
|
|
|
|
|
|
|
|
[[authz-after-invocation-handling]]
|
|
[[authz-after-invocation-handling]]
|
|
-=== After Invocation Handling
|
|
|
|
|
|
+== After Invocation Handling
|
|
Whilst the `AccessDecisionManager` is called by the `AbstractSecurityInterceptor` before proceeding with the secure object invocation, some applications need a way of modifying the object actually returned by the secure object invocation.
|
|
Whilst the `AccessDecisionManager` is called by the `AbstractSecurityInterceptor` before proceeding with the secure object invocation, some applications need a way of modifying the object actually returned by the secure object invocation.
|
|
Whilst you could easily implement your own AOP concern to achieve this, Spring Security provides a convenient hook that has several concrete implementations that integrate with its ACL capabilities.
|
|
Whilst you could easily implement your own AOP concern to achieve this, Spring Security provides a convenient hook that has several concrete implementations that integrate with its ACL capabilities.
|
|
|
|
|
|
@@ -153,7 +154,7 @@ This latter (recommended) approach is usually achieved through a `ROLE_USER` or
|
|
|
|
|
|
|
|
|
|
[[authz-hierarchical-roles]]
|
|
[[authz-hierarchical-roles]]
|
|
-=== Hierarchical Roles
|
|
|
|
|
|
+== Hierarchical Roles
|
|
It is a common requirement that a particular role in an application should automatically "include" other roles.
|
|
It is a common requirement that a particular role in an application should automatically "include" other roles.
|
|
For example, in an application which has the concept of an "admin" and a "user" role, you may want an admin to be able to do everything a normal user can.
|
|
For example, in an application which has the concept of an "admin" and a "user" role, you may want an admin to be able to do everything a normal user can.
|
|
To achieve this, you can either make sure that all admin users are also assigned the "user" role.
|
|
To achieve this, you can either make sure that all admin users are also assigned the "user" role.
|