blob: 91f3127f941995ce688c1163686ad5e52c4c714a (
plain) (
tree)
|
|
package org.openslx.imagemaster.session;
import java.sql.SQLException;
import org.apache.log4j.Logger;
import org.openslx.bwlp.thrift.iface.AuthorizationError;
import org.openslx.bwlp.thrift.iface.TAuthorizationException;
import org.openslx.bwlp.thrift.iface.UserInfo;
import org.openslx.imagemaster.db.mappers.DbUser;
import org.openslx.imagemaster.db.models.LocalUser;
/**
* Authenticates a user against a backend (ldap here)
*/
public class Authenticator
{
private static Logger log = Logger.getLogger( Authenticator.class );
/**
* Authenticate the user against whatever backend
*
* @param username
* @param password
* @return
* @throws TAuthenticationException
*/
public static UserInfo authenticate( String username, String password ) throws TAuthorizationException
{
String login = username;
log.info( "Logging in with: " + login );
LocalUser user;
try {
user = DbUser.forLogin( login, password );
} catch ( SQLException e ) {
user = null;
} // throws exception if credentials are invalid
if ( user == null ) {
log.debug( "Login failed: " + username );
throw new TAuthorizationException( AuthorizationError.GENERIC_ERROR, "Something went wrong." );
}
log.debug( "Login succesful: " + username );
return user.toUserInfo();
}
//
}
|