Advertisement
Guest User

Untitled

a guest
Jun 20th, 2016
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.77 KB | None | 0 0
  1. @Configuration
  2. @EnableWebSecurity
  3. @EnableGlobalMethodSecurity(securedEnabled = true, prePostEnabled = true, proxyTargetClass = true)
  4. @PropertySource(value = { "classpath:application.properties" })
  5. public class SecurityConfig extends WebSecurityConfigurerAdapter {
  6.  
  7.  
  8. @Autowired
  9. AuthenticationConfiguration authenticationConfiguration;
  10.  
  11. @Configuration
  12. protected static class AuthenticationConfiguration implements
  13. AuthenticationProvider {
  14.  
  15. @Autowired
  16. private UserServices userServices;
  17. @Autowired
  18. LdapServices ldapServices;
  19.  
  20. @Override
  21. public Authentication authenticate(Authentication authentication) throws AuthenticationException {
  22. Set<GrantedAuthority> authorities = new HashSet<GrantedAuthority>();
  23. String name = authentication.getName();
  24. String password = authentication.getCredentials().toString();
  25. boolean isFind = ldapServices.ldapSearch(name, password);
  26. if (isFind){
  27. com.domain.User user = userServices.getByUsersEnabled(name);
  28. if (user!=null)
  29. authorities.add(new SimpleGrantedAuthority("ROLE_"+user.getRole().getRole()));
  30. return new UsernamePasswordAuthenticationToken(name, password, authorities);
  31. }
  32. else return null;
  33. }
  34.  
  35.  
  36. @Override
  37. public boolean supports(Class<?> authentication) {
  38. return authentication.equals(UsernamePasswordAuthenticationToken.class);
  39. }
  40. }
  41.  
  42. @Autowired
  43. @Override
  44. protected void configure(AuthenticationManagerBuilder auth) throws Exception {
  45. auth.authenticationProvider(authenticationConfiguration);
  46. }
  47.  
  48. ...web services authentication
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement