use of org.akaza.openclinica.bean.login.UserAccountBean in project OpenClinica by OpenClinica.
the class UserPermissionInterceptor method handleRequest.
public boolean handleRequest(MessageContext messageContext, Object endpoint) throws Exception {
ResourceBundleProvider.updateLocale(new Locale("en_US"));
Object principal = SecurityContextHolder.getContext().getAuthentication().getPrincipal();
String username = null;
if (principal instanceof UserDetails) {
username = ((UserDetails) principal).getUsername();
} else {
username = principal.toString();
}
UserAccountDAO userAccountDao = new UserAccountDAO(dataSource);
UserAccountBean userAccountBean = ((UserAccountBean) userAccountDao.findByUserName(username));
Boolean result = userAccountBean.getRunWebservices();
if (!result) {
SoapBody response = ((SoapMessage) messageContext.getResponse()).getSoapBody();
response.addClientOrSenderFault("Authorization is required to execute SOAP web services with this account.Please contact your administrator.", Locale.ENGLISH);
return false;
} else {
return result;
}
}
use of org.akaza.openclinica.bean.login.UserAccountBean in project OpenClinica by OpenClinica.
the class StudySubjectEndpoint method getUserAccount.
/**
* Helper Method to get the user account
*
* @return UserAccountBean
*/
private UserAccountBean getUserAccount() {
Object principal = SecurityContextHolder.getContext().getAuthentication().getPrincipal();
String username = null;
if (principal instanceof UserDetails) {
username = ((UserDetails) principal).getUsername();
} else {
username = principal.toString();
}
UserAccountDAO userAccountDao = new UserAccountDAO(dataSource);
return (UserAccountBean) userAccountDao.findByUserName(username);
}
use of org.akaza.openclinica.bean.login.UserAccountBean in project OpenClinica by OpenClinica.
the class DataEndpoint method getUserAccount.
/**
* Helper Method to get the user account
*
* @return UserAccountBean
*/
private UserAccountBean getUserAccount() {
Object principal = SecurityContextHolder.getContext().getAuthentication().getPrincipal();
String username = null;
if (principal instanceof UserDetails) {
username = ((UserDetails) principal).getUsername();
} else {
username = principal.toString();
}
UserAccountDAO userAccountDao = new UserAccountDAO(dataSource);
return (UserAccountBean) userAccountDao.findByUserName(username);
}
use of org.akaza.openclinica.bean.login.UserAccountBean in project OpenClinica by OpenClinica.
the class EventEndpoint method getUserAccount.
/**
* Helper Method to get the user account
*
* @return UserAccountBean
*/
private UserAccountBean getUserAccount() {
Object principal = SecurityContextHolder.getContext().getAuthentication().getPrincipal();
String username = null;
if (principal instanceof UserDetails) {
username = ((UserDetails) principal).getUsername();
} else {
username = principal.toString();
}
UserAccountDAO userAccountDao = new UserAccountDAO(dataSource);
return (UserAccountBean) userAccountDao.findByUserName(username);
}
use of org.akaza.openclinica.bean.login.UserAccountBean in project OpenClinica by OpenClinica.
the class MainMenuServlet method processRequest.
@Override
public void processRequest() throws Exception {
FormProcessor fp = new FormProcessor(request);
ub.incNumVisitsToMainMenu();
session.setAttribute(USER_BEAN_NAME, ub);
request.setAttribute("iconInfoShown", true);
request.setAttribute("closeInfoShowIcons", false);
if (ub == null || ub.getId() == 0) {
// in case database connection is
// broken
forwardPage(Page.MENU, false);
return;
}
StudyDAO sdao = new StudyDAO(sm.getDataSource());
ArrayList studies = null;
long pwdExpireDay = new Long(SQLInitServlet.getField("passwd_expiration_time")).longValue();
Date lastPwdChangeDate = ub.getPasswdTimestamp();
// a flag tells whether users are required to change pwd upon the first
// time log in or pwd expired
int pwdChangeRequired = new Integer(SQLInitServlet.getField("change_passwd_required")).intValue();
// update last visit date to current date
UserAccountDAO udao = new UserAccountDAO(sm.getDataSource());
UserAccountBean ub1 = (UserAccountBean) udao.findByPK(ub.getId());
ub1.setLastVisitDate(new Date(System.currentTimeMillis()));
// have to actually set the above to a timestamp? tbh
ub1.setOwner(ub1);
ub1.setUpdater(ub1);
udao.update(ub1);
// Use study Id in JSPs
request.setAttribute("studyId", currentStudy.getId());
// Event Definition list and Group Class list for add suybject window.
request.setAttribute("allDefsArray", super.getEventDefinitionsByCurrentStudy());
request.setAttribute("studyGroupClasses", super.getStudyGroupClassesByCurrentStudy());
if (ub.isLdapUser()) {
// "Forge" a password change date for LDAP user
lastPwdChangeDate = new Date();
}
System.out.println("is ub a ldapuser??" + ub.isLdapUser());
//@pgawade 18-Sep-2012: fix for issue #14506 (https://issuetracker.openclinica.com/view.php?id=14506#c58197)
if ((lastPwdChangeDate != null) || ((lastPwdChangeDate == null) && (pwdChangeRequired == 0))) {
// not a new user
if (lastPwdChangeDate != null) {
Calendar cal = Calendar.getInstance();
// compute difference between current date and lastPwdChangeDate
long difference = Math.abs(cal.getTime().getTime() - lastPwdChangeDate.getTime());
long days = difference / (1000 * 60 * 60 * 24);
session.setAttribute("passwordExpired", "no");
if (!ub.isLdapUser() && pwdExpireDay > 0 && days >= pwdExpireDay) {
// password expired, need to be changed
System.out.println("here");
studies = (ArrayList) sdao.findAllByUser(ub.getName());
request.setAttribute("studies", studies);
session.setAttribute("userBean1", ub);
addPageMessage(respage.getString("password_expired"));
// YW 06-25-2007 << add the feature that if password is expired,
// have to go through /ResetPassword page
session.setAttribute("passwordExpired", "yes");
if (pwdChangeRequired == 1) {
request.setAttribute("mustChangePass", "yes");
addPageMessage(respage.getString("your_password_has_expired_must_change"));
} else {
request.setAttribute("mustChangePass", "no");
addPageMessage(respage.getString("password_expired") + " " + respage.getString("if_you_do_not_want_change_leave_blank"));
}
forwardPage(Page.RESET_PASSWORD);
// YW >>
}
}
if (ub.getNumVisitsToMainMenu() <= 1) {
if (ub.getLastVisitDate() != null) {
addPageMessage(respage.getString("welcome") + " " + ub.getFirstName() + " " + ub.getLastName() + ". " + respage.getString("last_logged") + " " + local_df.format(ub.getLastVisitDate()) + ". ");
} else {
addPageMessage(respage.getString("welcome") + " " + ub.getFirstName() + " " + ub.getLastName() + ". ");
}
if (currentStudy.getStatus().isLocked()) {
addPageMessage(respage.getString("current_study_locked"));
} else if (currentStudy.getStatus().isFrozen()) {
addPageMessage(respage.getString("current_study_frozen"));
}
}
////Integer assignedDiscrepancies = getDiscrepancyNoteDAO().countAllItemDataByStudyAndUser(currentStudy, ub);
//Integer assignedDiscrepancies = getDiscrepancyNoteDAO().getViewNotesCountWithFilter(" AND dn.assigned_user_id ="
// + ub.getId() + " AND (dn.resolution_status_id=1 OR dn.resolution_status_id=2 OR dn.resolution_status_id=3)", currentStudy);
//Yufang code added by Jamuna, to optimize the query on MainMenu
Integer assignedDiscrepancies = getDiscrepancyNoteDAO().getViewNotesCountWithFilter(ub.getId(), currentStudy.getId());
request.setAttribute("assignedDiscrepancies", assignedDiscrepancies == null ? 0 : assignedDiscrepancies);
int parentStudyId = currentStudy.getParentStudyId() > 0 ? currentStudy.getParentStudyId() : currentStudy.getId();
StudyParameterValueDAO spvdao = new StudyParameterValueDAO(sm.getDataSource());
StudyParameterValueBean parentSPV = spvdao.findByHandleAndStudy(parentStudyId, "subjectIdGeneration");
currentStudy.getStudyParameterConfig().setSubjectIdGeneration(parentSPV.getValue());
String idSetting = parentSPV.getValue();
if (idSetting.equals("auto editable") || idSetting.equals("auto non-editable")) {
//Shaoyu Su
//int nextLabel = this.getStudySubjectDAO().findTheGreatestLabel() + 1;
//request.setAttribute("label", new Integer(nextLabel).toString());
request.setAttribute("label", resword.getString("id_generated_Save_Add"));
//@pgawade 27-June-2012 fix for issue 13477: set label to "ID will be generated on Save or Add" in case of auto generated subject id
fp.addPresetValue("label", resword.getString("id_generated_Save_Add"));
}
setPresetValues(fp.getPresetValues());
if (currentRole.isInvestigator() || currentRole.isResearchAssistant() || currentRole.isResearchAssistant2()) {
setupListStudySubjectTable();
}
if (currentRole.isMonitor()) {
setupSubjectSDVTable();
} else if (currentRole.isCoordinator() || currentRole.isDirector()) {
if (currentStudy.getStatus().isPending()) {
response.sendRedirect(request.getContextPath() + Page.MANAGE_STUDY_MODULE.getFileName());
return;
}
setupStudySiteStatisticsTable();
setupSubjectEventStatusStatisticsTable();
setupStudySubjectStatusStatisticsTable();
if (currentStudy.getParentStudyId() == 0) {
setupStudyStatisticsTable();
}
}
forwardPage(Page.MENU);
// }
} else {
// a new user's first log in
studies = (ArrayList) sdao.findAllByUser(ub.getName());
request.setAttribute("studies", studies);
session.setAttribute("userBean1", ub);
if (pwdChangeRequired == 1) {
} else {
forwardPage(Page.MENU);
}
}
}
Aggregations