blob: 0ff7cf7619d9cf0ff17c00a7af7e075e2e9ce35b (
plain) (
tree)
|
|
package org.openslx.dozmod.thrift;
import org.apache.log4j.Logger;
import org.apache.thrift.TException;
import org.openslx.bwlp.thrift.iface.ImagePermissions;
import org.openslx.bwlp.thrift.iface.LecturePermissions;
import org.openslx.bwlp.thrift.iface.SatelliteConfig;
import org.openslx.bwlp.thrift.iface.UserInfo;
import org.openslx.bwlp.thrift.iface.WhoamiInfo;
import org.openslx.thrifthelper.ThriftManager;
public class Session {
private static final Logger LOGGER = Logger.getLogger(Session.class);
private static String firstName = null;
private static String lastName = null;
private static String eMail = null;
private static String userId = null;
private static String organizationId = null;
private static String satelliteToken = null;
private static String masterToken = null;
private static String satelliteAddress = null;
public static void initialize(WhoamiInfo whoami, String satAddress, String satToken, String masToken) {
UserInfo ui = whoami.getUser();
if (userId != null && !userId.equals(ui.userId))
throw new IllegalArgumentException("Cannot set new session data with different user id");
if (satelliteAddress != null && !satelliteAddress.equals(satAddress))
throw new IllegalArgumentException("Cannot set new session data with different satellite address");
firstName = ui.firstName;
lastName = ui.lastName;
eMail = ui.eMail;
userId = ui.userId;
organizationId = ui.organizationId;
masterToken = masToken;
satelliteToken = satToken;
satelliteAddress = satAddress;
}
/**
* @return the first name
*/
public static String getFirstName() {
return firstName;
}
/**
* @return the last name
*/
public static String getLastName() {
return lastName;
}
/**
* @return the eMail
*/
public static String getEMail() {
return eMail;
}
/**
* @return the user id
*/
public static String getUserId() {
return userId;
}
/**
* @return the organization id
*/
public static String getOrganizationId() {
return organizationId;
}
/**
* @return the satellite token
*/
public static String getSatelliteToken() {
return satelliteToken;
}
/**
* @return the master token
*/
public static String getMasterToken() {
return masterToken;
}
/**
* @return the satelliteAddress
*/
public static String getSatelliteAddress() {
return satelliteAddress;
}
private static SatelliteConfig satConf = null;
/**
* Query the satellite server for its configuration and default values.
*
* @return
*/
public static SatelliteConfig getSatelliteConfig() {
synchronized (SatelliteConfig.class) {
if (satConf != null)
return satConf;
try {
satConf = ThriftManager.getSatClient().getConfiguration();
return satConf;
} catch (TException e) {
LOGGER.warn("Could not get satellite configuration, falling back to builtin defaults", e);
SatelliteConfig satConfig = new SatelliteConfig();
satConfig.setDefaultImagePermissions(new ImagePermissions(true, true, false, false));
satConfig.setDefaultLecturePermissions(new LecturePermissions(false, false));
satConfig.setMaxImageValidityDays(200);
satConfig.setMaxLectureValidityDays(100);
satConfig.setPageSize(200);
return satConfig;
}
}
}
}
|