diff options
author | Simon Rettberg | 2016-08-30 18:02:43 +0200 |
---|---|---|
committer | Simon Rettberg | 2016-08-30 18:02:43 +0200 |
commit | f45886abed5f04728561d5c8f97423a8036806fc (patch) | |
tree | 1639d97cb76658925aaf4ddc19b080b8ea273e53 /src/main/java/org/openslx/imagemaster/util | |
parent | (WiP) Global image sync (diff) | |
download | masterserver-f45886abed5f04728561d5c8f97423a8036806fc.tar.gz masterserver-f45886abed5f04728561d5c8f97423a8036806fc.tar.xz masterserver-f45886abed5f04728561d5c8f97423a8036806fc.zip |
Implement global image exchange with satellite servers
Diffstat (limited to 'src/main/java/org/openslx/imagemaster/util')
-rw-r--r-- | src/main/java/org/openslx/imagemaster/util/Sha512Crypt.java | 2 | ||||
-rw-r--r-- | src/main/java/org/openslx/imagemaster/util/UserUtil.java | 62 |
2 files changed, 63 insertions, 1 deletions
diff --git a/src/main/java/org/openslx/imagemaster/util/Sha512Crypt.java b/src/main/java/org/openslx/imagemaster/util/Sha512Crypt.java index bcd4b99..c4a4b61 100644 --- a/src/main/java/org/openslx/imagemaster/util/Sha512Crypt.java +++ b/src/main/java/org/openslx/imagemaster/util/Sha512Crypt.java @@ -416,7 +416,7 @@ public final class Sha512Crypt try { - int srounds = Integer.valueOf(num).intValue(); + Integer.valueOf(num).intValue(); } catch (NumberFormatException ex) { diff --git a/src/main/java/org/openslx/imagemaster/util/UserUtil.java b/src/main/java/org/openslx/imagemaster/util/UserUtil.java new file mode 100644 index 0000000..2e447f3 --- /dev/null +++ b/src/main/java/org/openslx/imagemaster/util/UserUtil.java @@ -0,0 +1,62 @@ +package org.openslx.imagemaster.util; + +import java.sql.SQLException; + +import org.openslx.bwlp.thrift.iface.AuthorizationError; +import org.openslx.bwlp.thrift.iface.Role; +import org.openslx.bwlp.thrift.iface.TAuthorizationException; +import org.openslx.bwlp.thrift.iface.TNotFoundException; +import org.openslx.bwlp.thrift.iface.UserInfo; +import org.openslx.imagemaster.db.mappers.DbUser; + +public class UserUtil +{ + + /** + * Given a list of users, return the first one that isn't anonymous, which means they opted in + * for global image sharing. + */ + public static UserInfo getFirstPublishingUser( UserInfo... user ) + { + if ( user == null ) + return null; + for ( UserInfo u : user ) { + if ( Util.isEmpty( u.userId ) ) + continue; + try { + u = DbUser.getUserInfo( u.userId ); + } catch ( SQLException | TNotFoundException e ) { + continue; + } + if ( !Util.isEmpty( u.eMail ) + && ( !Util.isEmpty( u.firstName ) || !Util.isEmpty( u.lastName ) ) ) { + return u; + } + } + return null; + } + + /** + * Given a list of users, return the first one that isn't anonymous, which means they opted in + * for global image sharing. If none matches, return the dummy user. + */ + public static UserInfo getFirstPublishingUserOrDummy( UserInfo... user ) + { + UserInfo ret = getFirstPublishingUser( user ); + if ( ret != null ) + return ret; + try { + return DbUser.getUserInfo( "dummy" ); + } catch ( TNotFoundException | SQLException e ) { + return null; + } + } + + public static void assertTutor( UserInfo userInfo ) throws TAuthorizationException + { + if ( userInfo == null || userInfo.role != Role.TUTOR ) { + throw new TAuthorizationException( AuthorizationError.NO_PERMISSION, "Permission denied!" ); + } + } + +} |