bwLehrpool Masterserver
Manages authentication and sharing of virtual machines between participating institutions
Authenticator.java
Go to the documentation of this file.
1 package org.openslx.imagemaster.session;
2 
3 import java.sql.SQLException;
4 
5 import org.apache.logging.log4j.LogManager;
6 import org.apache.logging.log4j.Logger;
7 import org.openslx.bwlp.thrift.iface.AuthorizationError;
8 import org.openslx.bwlp.thrift.iface.InvocationError;
9 import org.openslx.bwlp.thrift.iface.TAuthorizationException;
10 import org.openslx.bwlp.thrift.iface.TInvocationException;
11 import org.openslx.bwlp.thrift.iface.UserInfo;
14 
18 public class Authenticator
19 {
20 
21  private static Logger log = LogManager.getLogger( Authenticator.class );
22 
32  public static UserInfo authenticate( String username, String password ) throws TAuthorizationException, TInvocationException
33  {
34  String login = username;
35 
36  log.info( "Logging in with: " + login );
37 
38  LocalUser user;
39  try {
40  user = DbUser.forUserId( login, password );
41  } catch ( SQLException e ) {
42  throw new TInvocationException( InvocationError.INTERNAL_SERVER_ERROR, "Could not connect to database" );
43  } // throws exception if credentials are invalid
44  if ( user == null ) {
45  log.debug( "Login failed: " + username );
46  throw new TAuthorizationException( AuthorizationError.INVALID_CREDENTIALS, "Invalid Username or password" );
47  }
48  log.debug( "Login succesful: " + username );
49 
50  return user.toUserInfo();
51  }
52  //
53 }
Represents a user that can login against the masterserver.
Definition: DbUser.java:22
static UserInfo authenticate(String username, String password)
Authenticate the user against whatever backend.
static LocalUser forUserId(final String login)
Query database for user with given user id.
Definition: DbUser.java:46
Authenticates a user against a backend (mysql here)