bwLehrpool Masterserver
Manages authentication and sharing of virtual machines between participating institutions
UserUtil.java
Go to the documentation of this file.
1 package org.openslx.imagemaster.util;
2 
3 import java.sql.SQLException;
4 
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.TNotFoundException;
9 import org.openslx.bwlp.thrift.iface.UserInfo;
11 
12 public class UserUtil
13 {
14 
19  public static UserInfo getFirstPublishingUser( UserInfo... user )
20  {
21  if ( user == null )
22  return null;
23  for ( UserInfo u : user ) {
24  if ( Util.isEmpty( u.userId ) )
25  continue;
26  try {
27  u = DbUser.getUserInfo( u.userId );
28  } catch ( SQLException | TNotFoundException e ) {
29  continue;
30  }
31  if ( !Util.isEmpty( u.eMail )
32  && ( !Util.isEmpty( u.firstName ) || !Util.isEmpty( u.lastName ) ) ) {
33  return u;
34  }
35  }
36  return null;
37  }
38 
43  public static UserInfo getFirstPublishingUserOrDummy( UserInfo... user )
44  {
45  UserInfo ret = getFirstPublishingUser( user );
46  if ( ret != null )
47  return ret;
48  try {
49  return DbUser.getUserInfo( "dummy" );
50  } catch ( TNotFoundException | SQLException e ) {
51  return null;
52  }
53  }
54 
55  public static void assertTutor( UserInfo userInfo ) throws TAuthorizationException
56  {
57  if ( userInfo == null || userInfo.role != Role.TUTOR ) {
58  throw new TAuthorizationException( AuthorizationError.NO_PERMISSION, "Permission denied!" );
59  }
60  }
61 
62 }
Represents a user that can login against the masterserver.
Definition: DbUser.java:22
static UserInfo getFirstPublishingUserOrDummy(UserInfo...user)
Given a list of users, return the first one that isn't anonymous, which means they opted in for globa...
Definition: UserUtil.java:43
static UserInfo getUserInfo(final String login)
Definition: DbUser.java:70
static void assertTutor(UserInfo userInfo)
Definition: UserUtil.java:55
static UserInfo getFirstPublishingUser(UserInfo...user)
Given a list of users, return the first one that isn't anonymous, which means they opted in for globa...
Definition: UserUtil.java:19
Some utilities to make our lives easier.
Definition: Util.java:18
static boolean isEmpty(String str)
Definition: Util.java:123