Package org.beangle.security.monitor.auth.provider.dao

Source Code of org.beangle.security.monitor.auth.provider.dao.DaoAuthenticationProvider

package org.beangle.security.monitor.auth.provider.dao;

import org.beangle.security.User;
import org.beangle.security.monitor.Authentication;
import org.beangle.security.monitor.AuthenticationException;
import org.beangle.security.monitor.BadCredentialsException;
import org.beangle.security.monitor.auth.provider.AbstractAuthenticationProvider;
import org.beangle.security.monitor.auth.provider.UserNamePasswordAuthentication;
import org.beangle.security.monitor.auth.provider.encoding.PasswordEncoder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class DaoAuthenticationProvider extends AbstractAuthenticationProvider {

  private final Logger logger = LoggerFactory.getLogger(DaoAuthenticationProvider.class);
  private PasswordEncoder passwordEncoder;

  public Authentication authenticate(Authentication auth) throws AuthenticationException {
    logger.debug("Authentication using {}", getClass());
    User user = attachToUser(auth);
    if (!passwordEncoder.isPasswordValid(user.getPassword(), (String) auth.getCredentials())) {
      throw new BadCredentialsException(Authentication.ERROR_PASSWORD);
    }
    return auth;
  }

  public boolean supports(Class<?> authTokenType) {
    return (UserNamePasswordAuthentication.class.isAssignableFrom(authTokenType));
  }

  public void setPasswordEncoder(PasswordEncoder passwordEncoder) {
    this.passwordEncoder = passwordEncoder;
  }

  public String toString() {
    return getClass().getName();
  }

}
TOP

Related Classes of org.beangle.security.monitor.auth.provider.dao.DaoAuthenticationProvider

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.