layout | title | permalink |
---|---|---|
page |
401.16 Reading Notes |
/401-R16/ |
(Cheat Sheet by Michelle Ferreirae)
-
Authentication (or "access control") is a process to verify the identity of a particular user.
- In Spring, the primary imported code blocks used are
AuthenticationManager
:
- In Spring, the primary imported code blocks used are
public interface AuthenticationManager {
Authentication authenticate(Authentication authentication)
throws AuthenticationException;
}
and an implemented ProviderManager
and a series of AuthenticationProvider
instances:
public interface AuthenticationProvider {
Authentication authenticate(Authentication authentication)
throws AuthenticationException;
boolean supports(Class<?> authentication);
}
ProviderManager
s can have children which in turn have their own respective AuthenticationProvider
s.
- The
AuthenticationManagerBuilder
class is used for quickly setting up authentication features, and uses the@Autowired
annotation to buildAuthenticationManager
s.
- As opposed to authentication, Authorization is the degree of access or modification privilages a given user has. Similarly to the Authentication hierarchy, an
AccessDecisionManager
may handle multiple instances ofAccessDecisionVoter
-
Client requests to the application go through multiple filters first (determined by container) before the appropriate servlet.
Filter
s are@Bean
s that have systems of prioritizing their order (by theDEFAULT_ORDER
property).- As the filters within Spring's auth system are not accessible to the container, added filters must be
FilterRegistrationBeans
or else not be made@Bean
s.
- As the filters within Spring's auth system are not accessible to the container, added filters must be
-
Spring Security functions as a single filter in this sequence (as
FilterChainProxy
) but has several layers of sub-filters in alternate alternate chains internally.- By default, there are 11 filters in the
FilterChainProxy
to cover common routes (like/error
or/images/**
) as well as a wildcard route (/**
) for other cases.
- By default, there are 11 filters in the
- Filter chains have request matchers that determine which set of filters will apply (at the exclusion of others). Within a chain,
HttpSecurity
further controls authorization.
- Spring Security can also further control resource access within a code base (
@EnableGlobalMethodSecurity(securedEnables = true)
) by annotating particular methods. The following example is from the Spring guide on authorization:
@Service
public class MyService {
@Secured("ROLE_USER")
public String secure() {
return "Hello Security";
}
}