1 2 3 4 5 6 7 8 9 10 11 12 | @Controller public class UserController { @PostMapping(“/login”) public void login(String name, String password){ matchNameAndPassword(name, password); User user = getUser(name); Authentication auth = new CustomAuthentication(user, password); auth.setAuthenticated(true); SecurityContextHolder.getContext.setAuthentication(auth); } } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | private List<AuthenticationProvider> providers; public Authentication authenticate(Authentication authentication) throws AuthenticationException { ...... for (AuthenticationProvider provider : getProviders()) { if (!provider.supports(toTest)) { continue; } try { result = provider.authenticate(authentication); if (result != null) { copyDetails(authentication, result); break; } } } } |
1 2 3 4 5 | public interface AuthenticationProvider { Authentication authenticate(Authentication authentication) throws AuthenticationException; boolean supports(Class<?> authentication); } |
欢迎光临 电子技术论坛_中国专业的电子工程师学习交流社区-中电网技术论坛 (http://bbs.eccn.com/) | Powered by Discuz! 7.0.0 |