Package cz.cvut.fel.wa2.interior.authentication

Source Code of cz.cvut.fel.wa2.interior.authentication.CustomAuthenticationProvider

package cz.cvut.fel.wa2.interior.authentication;


import cz.cvut.fel.wa2.interior.entity.GaeUser;
import cz.cvut.fel.wa2.interior.service.UserService;
import org.springframework.security.authentication.AuthenticationProvider;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.AuthenticationException;
import org.springframework.security.core.userdetails.User;
import org.springframework.security.web.authentication.preauth.PreAuthenticatedAuthenticationToken;

/**
*
* @author Ondrej Panek
*/
public class CustomAuthenticationProvider implements AuthenticationProvider {

    private UserService userService;

    @Override
    public Authentication authenticate(Authentication authentication) throws AuthenticationException {
        //  System.out.println("AUTHENTICATE");
        User user = (User) authentication.getPrincipal();
       // System.out.println("AUTHENTICATING " + user.getUsername());

        CustomAuthentication gaeAuthentication = new CustomAuthentication(user, authentication.getDetails());

        GaeUser googleUser = userService.findByEmail(user.getUsername());
        if (googleUser == null) {
        //    System.out.println("NOT AUTHENTICATED " + user.getUsername());
            gaeAuthentication.setAuthenticated(false);
        }

        return gaeAuthentication;
    }

    @Override
    public final boolean supports(Class<?> authentication) {
        return PreAuthenticatedAuthenticationToken.class.isAssignableFrom(authentication);
    }

    public void setUserService(UserService userService) {
        this.userService = userService;
    }

}
TOP

Related Classes of cz.cvut.fel.wa2.interior.authentication.CustomAuthenticationProvider

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.