Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @Configuration
- @EnableWebSecurity
- @EnableGlobalMethodSecurity(securedEnabled = true, prePostEnabled = true, proxyTargetClass = true)
- @PropertySource(value = { "classpath:application.properties" })
- public class SecurityConfig extends WebSecurityConfigurerAdapter {
- @Autowired
- AuthenticationConfiguration authenticationConfiguration;
- @Configuration
- protected static class AuthenticationConfiguration implements
- AuthenticationProvider {
- @Autowired
- private UserServices userServices;
- @Autowired
- LdapServices ldapServices;
- @Override
- public Authentication authenticate(Authentication authentication) throws AuthenticationException {
- Set<GrantedAuthority> authorities = new HashSet<GrantedAuthority>();
- String name = authentication.getName();
- String password = authentication.getCredentials().toString();
- boolean isFind = ldapServices.ldapSearch(name, password);
- if (isFind){
- com.domain.User user = userServices.getByUsersEnabled(name);
- if (user!=null)
- authorities.add(new SimpleGrantedAuthority("ROLE_"+user.getRole().getRole()));
- return new UsernamePasswordAuthenticationToken(name, password, authorities);
- }
- else return null;
- }
- @Override
- public boolean supports(Class<?> authentication) {
- return authentication.equals(UsernamePasswordAuthenticationToken.class);
- }
- }
- @Autowired
- @Override
- protected void configure(AuthenticationManagerBuilder auth) throws Exception {
- auth.authenticationProvider(authenticationConfiguration);
- }
- ...web services authentication
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement