Search in sources :

Example 71 with UserAccountBean

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;
    }
}
Also used : Locale(java.util.Locale) UserDetails(org.springframework.security.core.userdetails.UserDetails) UserAccountBean(org.akaza.openclinica.bean.login.UserAccountBean) SoapBody(org.springframework.ws.soap.SoapBody) UserAccountDAO(org.akaza.openclinica.dao.login.UserAccountDAO) SoapMessage(org.springframework.ws.soap.SoapMessage)

Example 72 with UserAccountBean

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);
}
Also used : UserDetails(org.springframework.security.core.userdetails.UserDetails) UserAccountBean(org.akaza.openclinica.bean.login.UserAccountBean) UserAccountDAO(org.akaza.openclinica.dao.login.UserAccountDAO)

Example 73 with UserAccountBean

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);
}
Also used : UserDetails(org.springframework.security.core.userdetails.UserDetails) UserAccountBean(org.akaza.openclinica.bean.login.UserAccountBean) UserAccountDAO(org.akaza.openclinica.dao.login.UserAccountDAO)

Example 74 with UserAccountBean

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);
}
Also used : UserDetails(org.springframework.security.core.userdetails.UserDetails) UserAccountBean(org.akaza.openclinica.bean.login.UserAccountBean) UserAccountDAO(org.akaza.openclinica.dao.login.UserAccountDAO)

Example 75 with UserAccountBean

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);
        }
    }
}
Also used : FormProcessor(org.akaza.openclinica.control.form.FormProcessor) Calendar(java.util.Calendar) ArrayList(java.util.ArrayList) UserAccountDAO(org.akaza.openclinica.dao.login.UserAccountDAO) Date(java.util.Date) StudyParameterValueBean(org.akaza.openclinica.bean.service.StudyParameterValueBean) UserAccountBean(org.akaza.openclinica.bean.login.UserAccountBean) StudyParameterValueDAO(org.akaza.openclinica.dao.service.StudyParameterValueDAO) StudyDAO(org.akaza.openclinica.dao.managestudy.StudyDAO)

Aggregations

UserAccountBean (org.akaza.openclinica.bean.login.UserAccountBean)152 UserAccountDAO (org.akaza.openclinica.dao.login.UserAccountDAO)64 StudyBean (org.akaza.openclinica.bean.managestudy.StudyBean)56 ArrayList (java.util.ArrayList)52 HashMap (java.util.HashMap)38 StudyDAO (org.akaza.openclinica.dao.managestudy.StudyDAO)36 StudyUserRoleBean (org.akaza.openclinica.bean.login.StudyUserRoleBean)35 Date (java.util.Date)32 FormProcessor (org.akaza.openclinica.control.form.FormProcessor)32 Locale (java.util.Locale)30 StudySubjectBean (org.akaza.openclinica.bean.managestudy.StudySubjectBean)18 Iterator (java.util.Iterator)16 InsufficientPermissionException (org.akaza.openclinica.web.InsufficientPermissionException)16 ResponseEntity (org.springframework.http.ResponseEntity)16 EventCRFBean (org.akaza.openclinica.bean.submit.EventCRFBean)15 Validator (org.akaza.openclinica.control.form.Validator)12 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)12 Role (org.akaza.openclinica.bean.core.Role)11 DiscrepancyNoteBean (org.akaza.openclinica.bean.managestudy.DiscrepancyNoteBean)10 StudyEventBean (org.akaza.openclinica.bean.managestudy.StudyEventBean)10