SHARE
TWEET

Untitled

a guest Feb 4th, 2016 101 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. @Component
  2. public class CustomAuthenticationProvider implements AuthenticationProvider {
  3. private static final Logger logger = LoggerFactory.getLogger(CustomAuthenticationProvider.class);
  4.  
  5. @Override
  6. public Authentication authenticate(Authentication auth) throws AuthenticationException {
  7.     String userName = auth.getName().trim();
  8.     String password = auth.getCredentials().toString().trim();
  9.     String companyName ;
  10.  
  11.  
  12.     if (userName.equals("admin") && password.equals("123456")) {
  13.         List<GrantedAuthority> grantedAuths = new ArrayList<>();
  14.         grantedAuths.add(new SimpleGrantedAuthority("ROLE_ADMIN"));
  15.         Authentication upat = new UsernamePasswordAuthenticationToken(userName, password, grantedAuths);
  16.         logger.info("{}:{}",userName,grantedAuths);
  17.         return upat;
  18.  
  19.     } else {
  20.         return null;
  21.     }
  22. }
  23.  
  24. @Override
  25. public boolean supports(Class<?> auth) {
  26.     return (UsernamePasswordAuthenticationToken.class.isAssignableFrom(auth));
  27. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top