blob: 91f3127f941995ce688c1163686ad5e52c4c714a (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
|
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();
}
//
}
|