Example usage for org.apache.shiro SecurityUtils getSubject

List of usage examples for org.apache.shiro SecurityUtils getSubject

Introduction

In this page you can find the example usage for org.apache.shiro SecurityUtils getSubject.

Prototype

public static Subject getSubject() 

Source Link

Document

Returns the currently accessible Subject available to the calling code depending on runtime environment.

Usage

From source file:au.org.theark.web.menu.LimsTabProviderImpl.java

License:Open Source License

@Override
public boolean isVisible() {
    Long sessionStudyId = (Long) SecurityUtils.getSubject().getSession()
            .getAttribute(au.org.theark.core.Constants.STUDY_CONTEXT_ID);
    return sessionStudyId != null;
}

From source file:au.org.theark.web.menu.MainTabProviderImpl.java

License:Open Source License

public ITab createTab(final String tabName) {
    //Global Search Tab created in HomePage.java to move to end of tabs.
    if (tabName.equalsIgnoreCase(au.org.theark.core.Constants.ARK_MODULE_STUDY)
            || tabName.equalsIgnoreCase(au.org.theark.core.Constants.ARK_MODULE_GLOBAL_SEARCH)) {
        return new ArkMainTab(new Model<String>(tabName)) {
            /**/*from w ww . ja  v a  2  s .  co  m*/
             * 
             */
            private static final long serialVersionUID = -8671910074409249398L;

            @Override
            public Panel getPanel(String pid) {
                return panelToReturn(pid, tabName);
            }

            public boolean isAccessible() {
                // Study tab is always accessible
                return true;
            }

            public boolean isVisible() {
                // Study tab is always visible
                return true;
            }
        };
    } else {
        return new ArkMainTab(new Model<String>(tabName)) {
            /**
             * 
             */
            private static final long serialVersionUID = -6838973454398478802L;

            @Override
            public Panel getPanel(String pid) {
                return panelToReturn(pid, tabName);
            }

            public boolean isAccessible() {
                // Only accessible when study in session (repainted on Study selection)
                Long sessionStudyId = (Long) SecurityUtils.getSubject().getSession()
                        .getAttribute(au.org.theark.core.Constants.STUDY_CONTEXT_ID);
                if (sessionStudyId == null) {
                    this.getPanel(au.org.theark.core.Constants.ARK_MODULE_SUBJECT)
                            .error(au.org.theark.core.Constants.NO_STUDY_IN_CONTEXT_MESSAGE);
                    return false;
                } else
                    return true;
            }

            public boolean isVisible() {
                // Only visible when study in session (repainted on Study selection)
                Long sessionStudyId = (Long) SecurityUtils.getSubject().getSession()
                        .getAttribute(au.org.theark.core.Constants.STUDY_CONTEXT_ID);
                if (sessionStudyId == null) {
                    return false;
                } else
                    return true;
            }
        };
    }
}

From source file:au.org.theark.web.menu.ReportSubMenuTab.java

License:Open Source License

public void buildTabs() {
    List<ITab> moduleSubTabsList = new ArrayList<ITab>();
    List<MenuModule> moduleTabs = new ArrayList<MenuModule>();

    // This way we can get the menus from the back-end. We should source this data from a table in the backend and wrap it up in a class like this
    MenuModule menuModule = new MenuModule();
    menuModule.setModuleName(Constants.REPORT_DETAIL); //these are functions and not so much "modules" as they are referened in the ark system
    menuModule.setResourceKey(Constants.TAB_MODULE_REPORT_DETAIL);
    moduleTabs.add(menuModule);//from w  w w  .j  av a  2 s  . c om

    MenuModule advancedMenuModule = new MenuModule();
    advancedMenuModule.setModuleName(Constants.DATA_EXTRACTION); //these are functions and not so much "modules" as they are referened in the ark system
    advancedMenuModule.setResourceKey(Constants.TAB_MODULE_DATA_EXTRACTION);
    moduleTabs.add(advancedMenuModule);

    for (final MenuModule moduleName : moduleTabs) {
        moduleSubTabsList.add(new AbstractTab(new Model<String>(moduleName.getModuleName())) {

            private static final long serialVersionUID = -7414890128705025350L;

            public boolean isVisible() {
                // Data extraction tab requires study in context
                if (moduleName.getModuleName().equalsIgnoreCase(Constants.DATA_EXTRACTION)) {
                    Long studySessionId = (Long) SecurityUtils.getSubject().getSession()
                            .getAttribute(au.org.theark.core.Constants.STUDY_CONTEXT_ID);
                    return studySessionId != null;
                }
                // Reports tab always shown
                return true;
            }

            @Override
            public Panel getPanel(String panelId) {
                Panel panelToReturn = null;// Set up a common tab that will be accessible for all users

                if (moduleName.getModuleName().equalsIgnoreCase(Constants.REPORT_DETAIL)) {
                    ReportContainerPanel reportContainerPanel = new ReportContainerPanel(panelId);
                    reportContainerPanel.initialisePanel();
                    panelToReturn = reportContainerPanel;
                } else if (moduleName.getModuleName().equalsIgnoreCase(Constants.DATA_EXTRACTION)) {
                    //
                    //                  if (securityManager.hasRole(currentUser.getPrincipals(), au.org.theark.core.security.RoleConstants.ARK_ROLE_SUPER_ADMINISTATOR) )
                    //                        {
                    //                     //do i need this?
                    //                        }
                    processAuthorizationCache(au.org.theark.core.Constants.ARK_MODULE_REPORTING,
                            iArkCommonService.getArkFunctionByName(
                                    au.org.theark.core.Constants.FUNCTION_KEY_VALUE_DATA_EXTRACTION));

                    DataExtractionContainerPanel dataExtractionContainerPanel = new DataExtractionContainerPanel(
                            panelId);
                    //dataExtractionContainerPanel.initialiseSearchPanel();   THESE ARE PROTECTED...BUT DO I REALLY NEED TO DO THEM NOW ANYWAY?
                    panelToReturn = dataExtractionContainerPanel;
                }

                return panelToReturn;
            };
        });
    }

    ArkAjaxTabbedPanel moduleTabbedPanel = new ArkAjaxTabbedPanel(Constants.REPORT_SUBMENU, moduleSubTabsList);
    add(moduleTabbedPanel);
}

From source file:au.org.theark.web.menu.StudySubMenuTab.java

License:Open Source License

/**
 * Build the list of tabs that represent the sub-menus
 *//*from w w w  .j a va2s.  com*/
public void buildTabs() {
    ArkModule arkModule = iArkCommonService.getArkModuleByName(Constants.ARK_MODULE_STUDY);
    List<ArkFunction> arkFunctionList = iArkCommonService.getModuleFunction(arkModule);// Gets a list of ArkFunctions for the given Module

    /*
     * Iterate each ArkFunction render the Tabs.When something is clicked it uses the arkFunction and calls processAuthorizationCache to clear
     * principals of the user and loads the new set of principals.(permissions)
     */
    for (final ArkFunction arkFunction : arkFunctionList) {
        moduleSubTabsList
                .add(new AbstractTab(new StringResourceModel(arkFunction.getResourceKey(), this, null)) {
                    /**
                     * 
                     */
                    private static final long serialVersionUID = -8421399480756599074L;

                    @Override
                    public Panel getPanel(String panelId) {
                        Panel panelToReturn = null;// Set up a common tab that will be accessible for all users

                        // Clear authorisation cache
                        processAuthorizationCache(au.org.theark.core.Constants.ARK_MODULE_STUDY, arkFunction);

                        if (arkFunction.getName()
                                .equalsIgnoreCase(au.org.theark.core.Constants.FUNCTION_KEY_VALUE_STUDY)) {
                            panelToReturn = new StudyContainerPanel(panelId, studyNameMarkup, studyLogoMarkup,
                                    arkContextMarkup, mainTabProvider.getModuleTabbedPanel());
                        } else if (arkFunction.getName().equalsIgnoreCase(
                                au.org.theark.core.Constants.FUNCTION_KEY_VALUE_STUDY_COMPONENT)) {
                            panelToReturn = new StudyComponentContainerPanel(panelId);
                        } else if (arkFunction.getName()
                                .equalsIgnoreCase(au.org.theark.core.Constants.FUNCTION_KEY_VALUE_USER)) {
                            panelToReturn = new UserContainerPanel(panelId);
                        }
                        //Added on 2015-06-22 Categorize  the custom field.
                        //Changed the Constant value from "Subject" to "Study" on 2015-08-17.        
                        else if (arkFunction.getName().equalsIgnoreCase(
                                au.org.theark.core.Constants.FUNCTION_KEY_VALUE_SUBJECT_CUSTOM_FIELD_CATEGORY)) {
                            panelToReturn = new CustomFieldCategoryContainerPanel(panelId, true,
                                    iArkCommonService.getArkFunctionByName(
                                            au.org.theark.core.Constants.FUNCTION_KEY_VALUE_SUBJECT_CUSTOM_FIELD_CATEGORY));

                        } else if (arkFunction.getName().equalsIgnoreCase(
                                au.org.theark.core.Constants.FUNCTION_KEY_VALUE_SUBJECT_CUSTOM_FIELD)) {
                            panelToReturn = new CustomFieldContainerPanel(panelId, true,
                                    iArkCommonService.getArkFunctionByName(
                                            au.org.theark.core.Constants.FUNCTION_KEY_VALUE_SUBJECT_CUSTOM_FIELD));
                        } else if (arkFunction.getName().equalsIgnoreCase(
                                au.org.theark.core.Constants.FUNCTION_KEY_VALUE_SUBJECT_CUSTOM_FIELD_UPLOAD)) {
                            panelToReturn = new CustomFieldUploadContainerPanel(panelId,
                                    iArkCommonService.getArkFunctionByName(
                                            au.org.theark.core.Constants.FUNCTION_KEY_VALUE_SUBJECT_CUSTOM_FIELD_UPLOAD));
                        } else if (arkFunction.getName().equalsIgnoreCase(
                                au.org.theark.core.Constants.FUNCTION_KEY_VALUE_STUDY_STUDY_DATA_UPLOAD)) {
                            panelToReturn = new SubjectUploadContainerPanel(panelId, arkFunction);
                        } else if (arkFunction.getName()
                                .equalsIgnoreCase(au.org.theark.core.Constants.FUNCTION_KEY_VALUE_CALENDAR)) {
                            panelToReturn = new CalendarContainerPanel(panelId);
                        } else if (arkFunction.getName()
                                .equalsIgnoreCase(Constants.FUNCTION_KEY_VALUE_SETTING)) {
                            panelToReturn = new SettingsContainerPanel(panelId, StudySpecificSetting.class);
                        }
                        return panelToReturn;
                    }

                    @Override
                    public boolean isVisible() {
                        if (arkFunction.getName()
                                .equalsIgnoreCase(au.org.theark.core.Constants.FUNCTION_KEY_VALUE_STUDY)) {
                            // Study function always visible
                            return true;
                        } else {
                            // Other functions require study in context 
                            Long sessionStudyId = (Long) SecurityUtils.getSubject().getSession()
                                    .getAttribute(au.org.theark.core.Constants.STUDY_CONTEXT_ID);
                            // Subject Upload only visible to parent studies 
                            if (arkFunction.getName()
                                    .equalsIgnoreCase(au.org.theark.core.Constants.FUNCTION_KEY_VALUE_USER)) {
                                processAuthorizationCache(au.org.theark.core.Constants.ARK_MODULE_STUDY,
                                        arkFunction);
                                SecurityManager securityManager = ThreadContext.getSecurityManager();
                                Subject currentUser = SecurityUtils.getSubject();
                                // In Demo mode ON only a Super Administrator can see the Manage user tab 
                                //Refer ARK-1846
                                if (Constants.YES
                                        .equalsIgnoreCase(iArkCommonService.getDemoMode().getPropertyValue())) {
                                    return ArkPermissionHelper.hasEditPermission(securityManager, currentUser)
                                            && sessionStudyId != null
                                            && securityManager.hasRole(currentUser.getPrincipals(),
                                                    au.org.theark.core.security.RoleConstants.ARK_ROLE_SUPER_ADMINISTATOR);
                                } else {
                                    return ArkPermissionHelper.hasEditPermission(securityManager, currentUser)
                                            && sessionStudyId != null;
                                }
                            }
                            return sessionStudyId != null;
                        }
                    }
                });
    }

    ArkAjaxTabbedPanel moduleTabbedPanel = new ArkAjaxTabbedPanel(Constants.MENU_STUDY_SUBMENU,
            moduleSubTabsList, arkContextMarkup);
    add(moduleTabbedPanel);
}

From source file:au.org.theark.web.pages.home.BasePage.java

License:Open Source License

@SuppressWarnings("unchecked")
public BasePage() {
    currentUser = SecurityUtils.getSubject();

    if (currentUser.getPrincipal() != null) {
        ContextImage studyLogoImage = new ContextImage("studyLogoImage",
                new Model<String>("images/" + Constants.NO_STUDY_LOGO_IMAGE));

        principal = (String) currentUser.getPrincipal();
        userNameLbl = new Label("loggedInUser", new Model<String>(principal));
        studyNameLbl = new Label("studyNameLabel", new Model<String>(" "));

        // Markup for Study name
        studyNameMarkup = new WebMarkupContainer("studyNameMarkupContainer");
        studyNameMarkup.add(studyNameLbl);
        studyNameMarkup.setOutputMarkupPlaceholderTag(true);

        // Markup for Study Logo
        studyLogoMarkup = new WebMarkupContainer("studyLogoMarkupContainer");
        studyLogoMarkup.add(studyLogoImage);
        studyLogoMarkup.setOutputMarkupPlaceholderTag(true);

        // Add images
        add(studyNameMarkup);/*from ww  w  . ja v a  2s  .  c  om*/
        add(studyLogoMarkup);
        productImage = iArkCommonService.getProductImage();
        hostedByImage = iArkCommonService.getHostedByImage();
        add(productImage);
        add(hostedByImage);

        ArkBusyAjaxLink myDetailLink = new ArkBusyAjaxLink("myDetailLink") {

            /**
             * 
             */
            private static final long serialVersionUID = 422053857225833627L;

            @Override
            public void onClick(AjaxRequestTarget target) {
                showModalWindow(target);
            }
        };

        myDetailLink.add(userNameLbl);
        add(myDetailLink);
        modalWindow = new MyDetailModalWindow("modalWindow") {
            /**
             * 
             */
            private static final long serialVersionUID = -1351016643735035753L;

            @Override
            protected void onCloseModalWindow(AjaxRequestTarget target) {
                // target.addComponent(BasePage.this);
            }
        };
        add(modalWindow);

        ajaxLogoutLink = new ArkBusyAjaxLink("ajaxLogoutLink") {
            /**
             * 
             */
            private static final long serialVersionUID = 422053857225833627L;

            @Override
            public void onClick(AjaxRequestTarget target) {
                currentUser = SecurityUtils.getSubject();
                principal = (String) currentUser.getPrincipal();
                log.info("\n -- " + principal + " has logged out. ----");
                currentUser.logout();

                Session.get().invalidateNow(); // invalidate the wicket session
                setResponsePage(LoginPage.class);
            }
        };
        add(ajaxLogoutLink);
    } else {
        setResponsePage(LoginPage.class);
    }
}

From source file:au.org.theark.web.pages.home.HomePage.java

License:Open Source License

/**
 * Constructor that is invoked when page is invoked without a session.
 * //from w w  w . j  ava  2  s  .  c o m
 * @param parameters
 *           Page parameters
 */
public HomePage(final PageParameters parameters) {
    Subject currentUser = SecurityUtils.getSubject();

    if (currentUser.getPrincipal() != null) {
        buildContextPanel();
        buildModuleTabs();
    } else {
        setResponsePage(LoginPage.class);
    }

    // Applet used for barcode printing
    PrintAppletPanel printAppletPanel = new PrintAppletPanel("printAppletPanel", "zebra");
    printAppletPanel.add(new AttributeModifier("class", "floatLeft"));
    this.add(printAppletPanel);
}

From source file:au.org.theark.web.pages.home.HomePage.java

License:Open Source License

public void onBeforeRender() {

    super.onBeforeRender();

    Long studyIdInSession = (Long) SecurityUtils.getSubject().getSession()
            .getAttribute(au.org.theark.core.Constants.STUDY_CONTEXT_ID);

    Study study = null;// ww w  .  j  a va 2 s  . c o  m
    if (studyIdInSession != null) {
        study = iArkCommonService.getStudy(studyIdInSession);
    }

    if (study != null) {
        ContextHelper contextHelper = new ContextHelper();
        contextHelper.setStudyContextLabel(study.getName(), this.arkContextPanelMarkup);
        Long sessionPersonId = (Long) SecurityUtils.getSubject().getSession()
                .getAttribute(au.org.theark.core.Constants.PERSON_CONTEXT_ID);
        String sessionPersonType = (String) SecurityUtils.getSubject().getSession()
                .getAttribute(au.org.theark.core.Constants.PERSON_TYPE);
        if (sessionPersonId != null && sessionPersonType != null
                && sessionPersonType.equals(au.org.theark.core.Constants.PERSON_CONTEXT_TYPE_SUBJECT)) {

            try {
                //todo:  are we are getting just to catch an exception and log an error????
                studyService.getPerson(sessionPersonId);
                LinkSubjectStudy lss = iArkCommonService.getSubject(sessionPersonId, study);
                contextHelper.setSubjectContextLabel(lss.getSubjectUID(), this.arkContextPanelMarkup);
                contextHelper.setSubjectNameContextLabel(lss.getPerson().getFullName(),
                        this.arkContextPanelMarkup);
            } catch (EntityNotFoundException e) {
                log.error(e.getMessage());
            } catch (ArkSystemException e) {
                log.error(e.getMessage());
            }
        }
    }

}

From source file:au.org.theark.web.pages.home.HomePage.java

License:Open Source License

/**
 * Build the list of main tabs/modules based on the current logged in user
 *///from   ww w  .  j  a  v a2  s .co  m
@Override
protected void buildModuleTabs() {
    List<ITab> moduleTabsList = new ArrayList<ITab>(0);
    List<ArkModule> arkModuleList = new ArrayList<ArkModule>(0);
    Subject currentUser = SecurityUtils.getSubject();
    String ldapUserName = currentUser.getPrincipal().toString();

    MainTabProviderImpl studyMainTabProvider = null;

    try {
        ArkUser arkUser = iArkCommonService.getArkUser(ldapUserName);
        arkModuleList = iArkCommonService.getArkModuleListByArkUser(arkUser);

        for (ArkModule arkModule : arkModuleList) {
            //log.info("arkModule: " + arkModule.getName());
            if (arkModule.getName().equalsIgnoreCase(au.org.theark.core.Constants.ARK_MODULE_STUDY)) {
                // Study
                studyMainTabProvider = new MainTabProviderImpl(arkModule.getName());
                // Pass in the Study logo mark up, to allow dynamic logo reference
                moduleTabsList = studyMainTabProvider.buildTabs(this.studyNameMarkup, this.studyLogoMarkup,
                        this.arkContextPanelMarkup);
            }

            if (arkModule.getName().equalsIgnoreCase(au.org.theark.core.Constants.ARK_MODULE_DISEASE)) {
                //Disease
                DiseaseTabProviderImpl diseaseTabProvider = new DiseaseTabProviderImpl(arkModule.getName());
                List<ITab> diseaseTabList = diseaseTabProvider.buildTabs(this.arkContextPanelMarkup);
                moduleTabsList.addAll(diseaseTabList);
            }

            if (arkModule.getName().equalsIgnoreCase(au.org.theark.core.Constants.ARK_MODULE_PHENOTYPIC)) {
                // Pheno
                PhenotypicTabProviderImpl phenotypicTabProvidor = new PhenotypicTabProviderImpl(
                        arkModule.getName());
                List<ITab> phenotypicTabsList = phenotypicTabProvidor.buildTabs(this.arkContextPanelMarkup);
                for (ITab itab : phenotypicTabsList) {
                    moduleTabsList.add(itab);
                }
            }

            if (arkModule.getName().equalsIgnoreCase(au.org.theark.core.Constants.ARK_MODULE_LIMS)) {
                // LIMS
                LimsTabProviderImpl limsTabProvider = new LimsTabProviderImpl(arkModule.getName());
                List<ITab> limsTabList = limsTabProvider.buildTabs(this.arkContextPanelMarkup,
                        this.studyNameMarkup, this.studyLogoMarkup);
                for (ITab tab : limsTabList) {
                    moduleTabsList.add(tab);
                }
            }

            if (arkModule.getName().equalsIgnoreCase(au.org.theark.core.Constants.ARK_MODULE_WORKTRACKING)) {
                //  Work
                WorkTrackingTabProviderImpl workTrackingTabProvider = new WorkTrackingTabProviderImpl(
                        arkModule.getName());
                List<ITab> workTabList = workTrackingTabProvider.buildTabs();
                for (ITab tab : workTabList) {
                    moduleTabsList.add(tab);
                }
            }

            if (arkModule.getName().equalsIgnoreCase(au.org.theark.core.Constants.ARK_MODULE_REGISTRY)) {
                //  Registry
                RegistryTabProviderImpl regoTab = new RegistryTabProviderImpl(arkModule.getName());
                List<ITab> regoTabList = regoTab.buildTabs();
                for (ITab tab : regoTabList) {
                    moduleTabsList.add(tab);
                }
            }

            if (arkModule.getName().equalsIgnoreCase(au.org.theark.core.Constants.ARK_MODULE_REPORTING)) {
                // Reporting always displayed, but data extraction function requires role/permisssion 
                ReportTabProviderImpl reportTabProvider = new ReportTabProviderImpl(
                        (au.org.theark.core.Constants.ARK_MODULE_REPORTING));
                List<ITab> reportTabList = reportTabProvider.buildTabs();
                for (ITab tab : reportTabList) {
                    moduleTabsList.add(tab);
                }
            }

            if (arkModule.getName().equalsIgnoreCase(au.org.theark.core.Constants.ARK_MODULE_GENOMICS)) {
                // Reporting always displayed, but data extraction function requires role/permisssion 
                GenomicsTabProviderImpl genomicsTabProvider = new GenomicsTabProviderImpl(
                        (au.org.theark.core.Constants.ARK_MODULE_GENOMICS));
                List<ITab> genomicsTabList = genomicsTabProvider.buildTabs();
                for (ITab tab : genomicsTabList) {
                    moduleTabsList.add(tab);
                }
            }
            //Add the Calendar as a Module
            if (arkModule.getName().equalsIgnoreCase(au.org.theark.core.Constants.ARK_MODULE_CALENDAR)) {
                CalendarTabProviderImpl calendarTabProvider = new CalendarTabProviderImpl(
                        (au.org.theark.core.Constants.ARK_MODULE_CALENDAR));
                List<ITab> calendarTabList = calendarTabProvider.buildTabs();
                for (ITab tab : calendarTabList) {
                    moduleTabsList.add(tab);
                }
            }

        }

        //Only add the global search tab once, at the end of the tabs
        ITab globalSearchTab = studyMainTabProvider
                .createTab(au.org.theark.core.Constants.ARK_MODULE_GLOBAL_SEARCH);
        moduleTabsList.add(globalSearchTab);

        // Only display admin tab for the super user
        ArkModule arkModule = iArkCommonService
                .getArkModuleByName(au.org.theark.core.Constants.ARK_MODULE_ADMIN);
        if (arkModuleList.contains(arkModule)) {
            // Admin
            AdminTabProviderImpl adminTabProvider = new AdminTabProviderImpl(arkModule.getName());
            List<ITab> adminTabList = adminTabProvider.buildTabs();
            for (ITab tab : adminTabList) {
                moduleTabsList.add(tab);
            }
        }
    } catch (EntityNotFoundException e) {
        log.error("ArkUser [" + ldapUserName + "] was not found!");
        log.error(e.getMessage());
    }

    moduleTabbedPanel = new ArkAjaxTabbedPanel("moduleTabsList", moduleTabsList, arkContextPanelMarkup);
    moduleTabbedPanel.setOutputMarkupPlaceholderTag(true);
    studyMainTabProvider.setModuleTabbedPanel(moduleTabbedPanel);
    add(moduleTabbedPanel);
}

From source file:au.org.theark.web.pages.login.AAFLoginForm.java

License:Open Source License

private void checkAAFAuthentication() {
    final WebRequest webRequest = (WebRequest) RequestCycle.get().getRequest();
    final HttpServletRequest httpReq = (HttpServletRequest) webRequest.getContainerRequest();

    ArkUserVO user = (ArkUserVO) getModelObject();

    // TODO: UserName: httpReq.getHeader("AJP_mail").. should it be httpReq.getHeader("AJP_persistent-id") ?
    String userName = httpReq.getHeader("AJP_mail");
    String password = httpReq.getHeader("AJP_Shib-Session-ID");

    if (userName != null || password != null) {
        user.setUserName(userName);/*from w  w w.  j  a v  a2  s. c  om*/
        user.setPassword(password);
        setModelObject(user);

        if (authenticate(user)) {
            DateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss");
            log.info("\n ---- " + user.getUserName() + " logged in successfully at: "
                    + dateFormat.format(new Date()) + " ---- \n");

            // Place a default module into session
            ArkModule arkModule = iArkCommonService
                    .getArkModuleByName(au.org.theark.core.Constants.ARK_MODULE_STUDY);
            // Place a default function into session
            ArkFunction arkFunction = iArkCommonService
                    .getArkFunctionByName(au.org.theark.core.Constants.FUNCTION_KEY_VALUE_STUDY);

            // Set session attributes
            SecurityUtils.getSubject().getSession().setAttribute(au.org.theark.core.Constants.ARK_USERID,
                    user.getUserName());
            SecurityUtils.getSubject().getSession().setAttribute(au.org.theark.core.Constants.ARK_MODULE_KEY,
                    arkModule.getId());
            SecurityUtils.getSubject().getSession().setAttribute(au.org.theark.core.Constants.ARK_FUNCTION_KEY,
                    arkFunction.getId());
            SecurityUtils.getSubject().getSession().setAttribute(au.org.theark.core.Constants.SHIB_SESSION_ID,
                    password);

            setResponsePage(HomePage.class);
        }
    } else {
        this.error("There was an issue with AAF Authentication. Please contact your system administrator");
        //throw new AuthenticationException();

    }
}

From source file:au.org.theark.web.pages.login.LoginForm.java

License:Open Source License

/**
 * LoginForm constructor//from   w ww .j  a  v a  2 s .  c  o  m
 * 
 * @param id
 *           the Component identifier
 */
public LoginForm(String id) {
    // Pass in the Model to the Form so the IFormSubmitListener can set the Model Object with values that were submitted.
    super(id, new CompoundPropertyModel<ArkUserVO>(new ArkUserVO()));

    feedbackPanel.setOutputMarkupId(true);
    add(feedbackPanel);

    aafLogInButton = new AjaxButton("aafLogInButton") {
        private static final long serialVersionUID = 1L;

        @Override
        protected void onError(AjaxRequestTarget target, Form<?> form) {
            log.error("Error on aafLoginButton click");
        }

        @Override
        protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
            setResponsePage(AAFLoginPage.class);
        }
    };
    aafLogInButton.setDefaultFormProcessing(false);
    aafLogInButton.setVisible(ArkShibbolethServiceProviderContextSource.useShibboleth.equalsIgnoreCase("true"));

    signInButton = new AjaxButton("signInButton") {

        private static final long serialVersionUID = 1L;

        @Override
        protected void onError(AjaxRequestTarget target, Form<?> form) {
            target.add(feedbackPanel);
        }

        @Override
        protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
            ArkUserVO user = (ArkUserVO) getForm().getModelObject();
            if (authenticate(user)) {
                DateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss");
                log.info("\n ---- " + user.getUserName() + " logged in successfully at: "
                        + dateFormat.format(new Date()) + " ---- \n");

                // Place a default module into session
                ArkModule arkModule = iArkCommonService
                        .getArkModuleByName(au.org.theark.core.Constants.ARK_MODULE_STUDY);
                // Place a default function into session
                ArkFunction arkFunction = iArkCommonService
                        .getArkFunctionByName(au.org.theark.core.Constants.FUNCTION_KEY_VALUE_STUDY);

                // Set session attributes
                SecurityUtils.getSubject().getSession().setAttribute(au.org.theark.core.Constants.ARK_USERID,
                        user.getUserName());
                SecurityUtils.getSubject().getSession()
                        .setAttribute(au.org.theark.core.Constants.ARK_MODULE_KEY, arkModule.getId());
                SecurityUtils.getSubject().getSession()
                        .setAttribute(au.org.theark.core.Constants.ARK_FUNCTION_KEY, arkFunction.getId());

                setResponsePage(HomePage.class);
            } else {
                setResponsePage(LoginPage.class);
            }
            target.add(feedbackPanel);
        }
    };

    forgotPasswordButton = new Button("forgotPasswordButton") {

        private static final long serialVersionUID = 1L;

        @Override
        public void onSubmit() {
            setResponsePage(ResetPage.class);
        }

        @Override
        public void onError() {
            log.error("Error on click of forgotPasswordButton");
        }
    };
    forgotPasswordButton.setDefaultFormProcessing(false);

    addComponentsToForm();
}