bwLehrpool Masterserver
Manages authentication and sharing of virtual machines between participating institutions
JsonUser.java
Go to the documentation of this file.
1 package org.openslx.imagemaster.localrpc;
2 
3 import org.apache.logging.log4j.LogManager;
4 import org.apache.logging.log4j.Logger;
5 import org.openslx.bwlp.thrift.iface.AuthorizationError;
6 import org.openslx.bwlp.thrift.iface.Role;
7 import org.openslx.bwlp.thrift.iface.TAuthorizationException;
8 import org.openslx.bwlp.thrift.iface.UserInfo;
10 
11 public class JsonUser
12 {
13 
14  private static final Logger LOGGER = LogManager.getLogger( JsonUser.class );
15 
16  private String userId = null;
17  private String organizationId = null;
18  private String firstName = null;
19  private String lastName = null;
20  private String mail = null;
21  private String role = null;
22  private String status = null;
23  private String error = null;
24  private int timeoutSeconds = 0;
25 
26  private String accessCode;
27 
28  public UserInfo toUser()
29  {
30  if ( !"ok".equals( status ) )
31  return null;
32  Role role;
33  try {
34  role = Role.valueOf( this.role );
35  } catch ( Exception e ) {
36  LOGGER.warn( "Invalid role: " + this.role );
37  return null;
38  }
39  if ( Util.isEmpty( userId, "userId", LOGGER ) || Util.isEmpty( organizationId, "orgId", LOGGER )
40  || Util.isEmpty( lastName, "lastName", LOGGER ) || Util.isEmpty( mail, "mail", LOGGER ) )
41  return null;
42  UserInfo ui = new UserInfo( userId, firstName, lastName, mail, organizationId );
43  ui.role = role;
44  return ui;
45  }
46 
47  public TAuthorizationException toException()
48  {
49  if ( "ok".equals( status ) )
50  return null;
51  return new TAuthorizationException( AuthorizationError.GENERIC_ERROR, this.error );
52  }
53 
54  public String accessCode()
55  {
56  return this.accessCode;
57  }
58 
59  public int timeoutSeconds()
60  {
61  return this.timeoutSeconds;
62  }
63 
64 }
TAuthorizationException toException()
Definition: JsonUser.java:47
Some utilities to make our lives easier.
Definition: Util.java:18
static boolean isEmpty(String str)
Definition: Util.java:123