Spring security
the major building blocks of Spring Security that we’ve seen so far are:
SecurityContextHolder, to provide access to theSecurityContext.SecurityContext, to hold theAuthenticationand possibly request-specific security information.Authentication, to represent the principal in a Spring Security-specific manner.GrantedAuthority, to reflect the application-wide permissions granted to a principal.UserDetails, to provide the necessary information to build an Authentication object from your application’s DAOs or other source of security data.UserDetailsService, to create aUserDetailswhen passed in aString-based username (or certificate ID or the like).
What is authentication in Spring Security?
Let’s consider a standard authentication scenario that everyone is familiar with.
- A user is prompted to log in with a username and password.
- The system (successfully) verifies that the password is correct for the username.
- The context information for that user is obtained (their list of roles and so on).
- A security context is established for the user
- The user proceeds, potentially to perform some operation which is potentially protected by an access control mechanism which checks the required permissions for the operation against the current security context information.
The first four items constitute the authentication process so we’ll take a look at how these take place within Spring Security.
- The username and password are obtained and combined into an instance of
UsernamePasswordAuthenticationToken(an instance of theAuthenticationinterface, which we saw earlier). - The token is passed to an instance of
AuthenticationManagerfor validation. - The
AuthenticationManagerreturns a fully populatedAuthenticationinstance on successful authentication. - The security context is established by calling
SecurityContextHolder.getContext().setAuthentication(…), passing in the returned authentication object.
The main interface responsible for making access-control decisions in Spring Security is the AccessDecisionManager. It has a decide method which takes an Authentication object representing the principal requesting access, a "secure object" (see below) and a list of security metadata attributes which apply for the object (such as a list of roles which are required for access to be granted).

浙公网安备 33010602011771号