use of org.akaza.openclinica.bean.login.UserAccountBean in project OpenClinica by OpenClinica.
the class OpenClinicaSecurityContextLogoutHandler method auditLogout.
void auditLogout(String username) {
ResourceBundleProvider.updateLocale(new Locale("en_US"));
UserAccountBean userAccount = (UserAccountBean) getUserAccountDao().findByUserName(username);
AuditUserLoginBean auditUserLogin = new AuditUserLoginBean();
auditUserLogin.setUserName(username);
auditUserLogin.setLoginStatus(LoginStatus.SUCCESSFUL_LOGOUT);
auditUserLogin.setLoginAttemptDate(new Date());
auditUserLogin.setUserAccountId(userAccount != null ? userAccount.getId() : null);
getAuditUserLoginDao().saveOrUpdate(auditUserLogin);
}
use of org.akaza.openclinica.bean.login.UserAccountBean in project OpenClinica by OpenClinica.
the class OpenClinicaSessionRegistryImpl method auditLogout.
void auditLogout(String username) {
ResourceBundleProvider.updateLocale(new Locale("en_US"));
UserAccountBean userAccount = (UserAccountBean) getUserAccountDao().findByUserName(username);
AuditUserLoginBean auditUserLogin = new AuditUserLoginBean();
auditUserLogin.setUserName(username);
auditUserLogin.setLoginStatus(LoginStatus.SUCCESSFUL_LOGOUT);
auditUserLogin.setLoginAttemptDate(new Date());
auditUserLogin.setUserAccountId(userAccount != null ? userAccount.getId() : null);
getAuditUserLoginDao().saveOrUpdate(auditUserLogin);
}
use of org.akaza.openclinica.bean.login.UserAccountBean in project OpenClinica by OpenClinica.
the class SetUpUserInterceptor method preHandle.
@Override
public boolean preHandle(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Object o) throws Exception {
Locale locale = ResourceBundleProvider.localeMap.get(Thread.currentThread());
if (locale == null) {
ResourceBundleProvider.updateLocale(httpServletRequest.getLocale());
}
//Set up the user account bean: check the Session first
HttpSession currentSession = httpServletRequest.getSession();
UserAccountBean userBean = (UserAccountBean) currentSession.getAttribute("userBean");
String userName = "";
boolean userBeanIsInvalid;
UserAccountDAO userAccountDAO = new UserAccountDAO(dataSource);
if (userBean == null) {
userName = httpServletRequest.getRemoteUser();
userBeanIsInvalid = "".equalsIgnoreCase(userName);
if (!userBeanIsInvalid) {
userBean = (UserAccountBean) userAccountDAO.findByUserName(userName);
userBeanIsInvalid = (userBean == null);
if (!userBeanIsInvalid) {
currentSession.setAttribute(USER_BEAN_NAME, userBean);
}
}
}
//The user bean could still be null at this point
if (userBean == null) {
userBean = new UserAccountBean();
userBean.setName("unknown");
currentSession.setAttribute(USER_BEAN_NAME, userBean);
}
userBean = userBean.getId() > 0 ? (UserAccountBean) userAccountDAO.findByPK(userBean.getId()) : userBean;
SetUpStudyRole setupStudy = new SetUpStudyRole(dataSource);
setupStudy.setUp(currentSession, userBean);
return true;
}
use of org.akaza.openclinica.bean.login.UserAccountBean in project OpenClinica by OpenClinica.
the class SubmitDataServletTest method test_SubmitDataServlet_MayViewData.
// Scenario
// Data Entry Person (site) can access Subject
public void test_SubmitDataServlet_MayViewData() {
UserAccountBean ub = new UserAccountBean();
//StudyUserRoleBean currentRole = new StudyUserRoleBean();
//currentRole.setRole(Role.COORDINATOR);
StudyUserRoleBean studyUserRoleBeanMock = mock(StudyUserRoleBean.class);
// Positive Testing
when(studyUserRoleBeanMock.getRole()).thenReturn(Role.RESEARCHASSISTANT);
boolean result1 = SubmitDataServlet.mayViewData(ub, studyUserRoleBeanMock);
assertEquals(true, result1);
// Positive Testing
when(studyUserRoleBeanMock.getRole()).thenReturn(Role.RESEARCHASSISTANT2);
boolean result2 = SubmitDataServlet.mayViewData(ub, studyUserRoleBeanMock);
assertEquals(true, result2);
// Negative Testing
when(studyUserRoleBeanMock.getRole()).thenReturn(Role.ADMIN);
boolean result3 = SubmitDataServlet.mayViewData(ub, studyUserRoleBeanMock);
assertEquals(false, result3);
// Negative Testing
when(studyUserRoleBeanMock.getRole()).thenReturn(Role.INVALID);
boolean result4 = SubmitDataServlet.mayViewData(ub, studyUserRoleBeanMock);
assertEquals(false, result4);
}
use of org.akaza.openclinica.bean.login.UserAccountBean in project OpenClinica by OpenClinica.
the class SubmitDataServletTest method test_SubmitDataServlet_MaySubmitData.
// Scenario
// Data Entry Person (site) can access Notes & Discrepancies
public void test_SubmitDataServlet_MaySubmitData() {
UserAccountBean ub = new UserAccountBean();
//StudyUserRoleBean currentRole = new StudyUserRoleBean();
//currentRole.setRole(Role.COORDINATOR);
StudyUserRoleBean studyUserRoleBeanMock = mock(StudyUserRoleBean.class);
// Positive Testing
when(studyUserRoleBeanMock.getRole()).thenReturn(Role.RESEARCHASSISTANT);
boolean result1 = SubmitDataServlet.maySubmitData(ub, studyUserRoleBeanMock);
assertEquals(true, result1);
// Positive Testing
when(studyUserRoleBeanMock.getRole()).thenReturn(Role.RESEARCHASSISTANT2);
boolean result2 = SubmitDataServlet.maySubmitData(ub, studyUserRoleBeanMock);
assertEquals(true, result2);
// Negative Testing
when(studyUserRoleBeanMock.getRole()).thenReturn(Role.ADMIN);
boolean result3 = SubmitDataServlet.maySubmitData(ub, studyUserRoleBeanMock);
assertEquals(false, result3);
// Negative Testing
when(studyUserRoleBeanMock.getRole()).thenReturn(Role.INVALID);
boolean result4 = SubmitDataServlet.maySubmitData(ub, studyUserRoleBeanMock);
assertEquals(false, result4);
}
Aggregations