Package com.jverstry.LoginLogout.Authentication

Source Code of com.jverstry.LoginLogout.Authentication.MyAuthenticationProvider

package com.jverstry.LoginLogout.Authentication;

import java.util.ArrayList;
import java.util.List;
import org.springframework.security.authentication.AuthenticationProvider;
import org.springframework.security.authentication.BadCredentialsException;
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.AuthenticationException;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.authority.SimpleGrantedAuthority;

public class MyAuthenticationProvider implements AuthenticationProvider {
 
  private static final List<GrantedAuthority> AUTHORITIES
    = new ArrayList<GrantedAuthority>();

  static {
    AUTHORITIES.add(new SimpleGrantedAuthority("ROLE_USER"));
    AUTHORITIES.add(new SimpleGrantedAuthority("ROLE_ANONYMOUS"));
  }

  @Override
  public Authentication authenticate(Authentication auth)
      throws AuthenticationException {
   
    if (auth.getName().equals(auth.getCredentials())) {
      return new UsernamePasswordAuthenticationToken(auth.getName(),
        auth.getCredentials(), AUTHORITIES);
    }
   
    throw new BadCredentialsException("Bad Credentials");
   
  }

  @Override
  public boolean supports(Class<?> authentication) {
   
    if ( authentication == null ) return false;
    return Authentication.class.isAssignableFrom(authentication);
   
  }
 
}
TOP

Related Classes of com.jverstry.LoginLogout.Authentication.MyAuthenticationProvider

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.