blob: f730c722337d2f113fd84ed456f483c9a4ea6524 (
plain) (
tree)
|
|
package org.openslx.imagemaster.session;
import org.apache.log4j.Logger;
import org.openslx.imagemaster.db.DbUser;
import org.openslx.imagemaster.thrift.iface.AuthenticationError;
import org.openslx.imagemaster.thrift.iface.AuthenticationException;
import org.openslx.imagemaster.util.Sha512Crypt;
public class Authenticator
{
private static Logger log = Logger.getLogger( Authenticator.class );
/**
* Authenticate the user against whatever backend... currently MySQL only
* @param username
* @param password
* @return
* @throws AuthenticationException
*/
public static User authenticate( String username, String password ) throws AuthenticationException
{
DbUser user = DbUser.forLogin( username );
if ( user == null || !Sha512Crypt.verifyPassword( password, user.password ) ) {
log.debug( "Login failed: " + username );
throw new AuthenticationException( AuthenticationError.INVALID_CREDENTIALS, "Invalid username or password!" );
}
log.debug( "Login successful: " + username );
return user;
}
//
}
|