com.formkiq.server.service.UserDetailsAuthenticationProvider Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of formkiq-server Show documentation
Show all versions of formkiq-server Show documentation
Server-side integration for the FormKiQ ios application
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");
}
}
}