CoopEval.java
package edu.rit.coopeval.appbase;
import edu.rit.coopeval.authentication.beans.User;
import edu.rit.coopeval.authentication.beans.UserType;
import edu.rit.webapps.api.ApplicationBase;
import edu.rit.webapps.security.shibboleth.ShibHeader;
import org.apache.log4j.Logger;
import java.util.List;
import java.util.Properties;
public class CoopEval extends ApplicationBase {
protected static Logger logger = Logger.getLogger(CoopEval.class);
// single instance of class search to be used throughout the application.
private static final CoopEval instance = new CoopEval();
private static Properties properties;
/**
* Creates an instance of ClassSearch
*/
public CoopEval() {
properties = new Properties();
}
/**
* Get the single instance of ClassSearch
*
* @return instance # ClassSearch Instance
*/
public static CoopEval getInstance() {
return instance;
}
/**
* Gets the base url at which this application is hosted
*
* @return baseURL # The base URL for the application
*/
public String getBaseURL() {
return (String) CoopEval.getInstance().getConstant("BASE_URL");
}
/**
* Creates a User from a given shibHeader, and ritAccountType
*
* @param shibHeader
* @param ritEduAccountType
* @return currentUser # An object representing the current User
*/
public User getAuthUser(UserType userType, ShibHeader shibHeader, String ritEduAccountType, String ritEduCampusU, String ritEduCampusG, List<String> departments) {
User currentUser = new User();
try {
logger.info("******** userName: " + shibHeader.getUserName() + " account Type: " + ritEduAccountType);
logger.info("*******ritEduCampuU: " + ritEduCampusU + " ritEduCampusG" + ritEduCampusG);
currentUser.setUserName(shibHeader.getUserName());
currentUser.setShibAccountType(ritEduAccountType);
currentUser.setLastName(shibHeader.getLastName());
currentUser.setFirstName(shibHeader.getFirstName());
currentUser.setUid(shibHeader.getUnivId());
currentUser.setAccountType(userType);
currentUser.setDepartments(departments);
} catch (Exception ex) {
// no user by that name found
currentUser = null;
logger.error(ex);
}
return currentUser;
}
/**
* Creates a User loaded from the properties file from a given mode.
*
* @return currentUser # An object representing the current User
*/
public User getUnAuthUser() {
logger.info("In get UnAuthUser");
User user = new User();
user.setUserName((String) CoopEval.getInstance().getConstant("userName"));
user.setLastName((String) CoopEval.getInstance().getConstant("surName"));
user.setFirstName((String) CoopEval.getInstance().getConstant("givenName"));
user.setShibAccountType((String) CoopEval.getInstance().getConstant("accountType"));
user.setUid((String) CoopEval.getInstance().getConstant("uid"));
// Todo move this code after test:
// user = ApplicationUtil.getInstance().createUser();
//showUser(user);
return user;
}
/**
* Prints out the current User for debugging purposes.
*
* @param user
*/
public void showUser(User user) {
logger.info("----------Showing User--------");
logger.info("userName = " + user.getUserName() + "\nsurName = " + user.getLastName() + "\ngivenName = " + user.getFirstName() + "\naccountType = " + user.getAccountType() + "\nshibAccountType = " + user.getShibAccountType() + "\nid = " + user.getUid());
logger.info("----------Done Showing User--------");
}
public Properties getProperties() {
return properties;
}
}