All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.formkiq.server.service.UserDetailsAuthenticationProvider Maven / Gradle / Ivy

There is a newer version: 0.6.1
Show newest version
package com.formkiq.server.service;

import java.util.logging.Level;
import java.util.logging.Logger;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.authentication.BadCredentialsException;
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
import org.springframework.security.authentication.dao.AbstractUserDetailsAuthenticationProvider;
import org.springframework.security.core.AuthenticationException;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.stereotype.Component;

import javassist.bytecode.stackmap.TypeData.ClassName;

/**
 * Custom Authentication Provider.
 *
 */
@Component
public class UserDetailsAuthenticationProvider extends
        AbstractUserDetailsAuthenticationProvider {

    /** Logger. */
    private static final Logger LOG = Logger.getLogger(ClassName.class
            .getName());

    /** UserService Instance. */
    @Autowired
    private UserService userservice;

    @Override
    protected void additionalAuthenticationChecks(final UserDetails userDetails,
            final UsernamePasswordAuthenticationToken authentication)
            throws AuthenticationException {
        // no additional authentication checks
    }

    @Override
    protected UserDetails retrieveUser(final String username,
            final UsernamePasswordAuthenticationToken authentication)
            throws AuthenticationException {

        String password = authentication.getCredentials() != null
                ? authentication.getCredentials().toString() : "";

        try {

            UserDetails user = this.userservice.findActiveUser(username,
                    password);

            return user;

        } catch (AuthenticationFailureException ex) {
            LOG.log(Level.FINE,
                    "authentication failure exception: " + ex.getMessage());
            throw new BadCredentialsException("invalid credentials");
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy