Package org.apache.cocoon.auth

Examples of org.apache.cocoon.auth.Application


        final HttpSession session = req.getSession(false);
        if ( session != null ) {
            // remove application data from session
            session.removeAttribute(APPLICATION_KEY_PREFIX + appName);

            final Application application = this.getApplication(appName);
            final String securityHandlerKey = this.getKey(application.getSecurityHandler());

            // remove application from object model
            if ( application.equals( ApplicationUtil.getApplication(objectModel) ) ) {
                objectModel.remove(ApplicationManager.APPLICATION);
                objectModel.remove(ApplicationManager.APPLICATION_DATA);
                objectModel.remove(ApplicationManager.USER);
            }

            // remove user
            session.removeAttribute(USER + '-' + appName);

            // decrement logininfo counter
            final Map loginInfos = (Map)session.getAttribute(LOGIN_INFO_KEY);
            if ( loginInfos != null ) {
                final LoginInfo info = (LoginInfo)loginInfos.get(securityHandlerKey);
                if ( info != null ) {
                    // notify the application
                    application.userWillLogout(info.user, logoutContext);

                    info.decUsageCounter(appName);
                    if ( info.isUsed() ) {
                        session.setAttribute(LOGIN_INFO_KEY, loginInfos);
                    } else {
                        // logout from security handler
                        application.getSecurityHandler().logout(logoutContext, info.user);
                        // remove user info
                        loginInfos.remove(securityHandlerKey);
                        if ( loginInfos.size() > 0 ) {
                            session.setAttribute(LOGIN_INFO_KEY, loginInfos);
                        } else {
View Full Code Here


                    final Iterator appIter = info.getApplications().iterator();
                    SecurityHandler handler = null;
                    while ( appIter.hasNext() ) {
                        final String appName = (String)appIter.next();
                        try {
                            final Application app = (Application)applications.get(appName);
                            app.userWillLogout(info.getUser(), Collections.EMPTY_MAP);
                            handler = app.getSecurityHandler();
                        } catch (Exception ignore) {
                            // we ignore this
                        }
                    }
                    if ( handler != null ) {
View Full Code Here

    /**
     * Return the application with the name.
     */
    protected Application getApplication(final String appName) {
        final Application app = (Application) WebAppContextUtils.getCurrentWebApplicationContext().getBean(Application.class.getName() + '/' + appName);
        if ( !this.applications.containsKey(appName) ) {
            this.applications.put(appName, app);
        }
        return app;
    }
View Full Code Here

            appData = session.getAttribute(APPLICATION_KEY_PREFIX + appName);

            // if the user is logged in, we set the current application, data and user
            if ( appData != null ) {
                try {
                    final Application application = this.getApplication(appName);
                    final User user = (User)session.getAttribute(USER + '-' + appName);
                    final Application oldApp = (Application)objectModel.get(ApplicationManager.APPLICATION);
                    objectModel.put(ApplicationManager.APPLICATION, application);
                    objectModel.put(ApplicationManager.APPLICATION_DATA, appData);
                    objectModel.put(ApplicationManager.USER, user);
                    // notify application
                    // The application is only notified once per request.
View Full Code Here

    /**
     * @see org.apache.cocoon.auth.ApplicationManager#login(String, java.util.Map)
     */
    public User login(final String appName, final Map loginContext) throws Exception {
        final Map objectModel = this.processInfoProvider.getObjectModel();
        final Application application = this.getApplication(appName);
        final String securityHandlerKey = this.getKey(application.getSecurityHandler());

        User user = null;

        // first check, if we are already logged in
        if ( this.isLoggedIn(appName) ) {
            user = ApplicationUtil.getUser(objectModel);
        } else {
            final Request req = ObjectModelHelper.getRequest(objectModel);
            HttpSession session = req.getSession(false);

            LoginInfo info = null;
            Map loginInfos = null;

            if ( session != null ) {
                // is the user already logged in on the security handler?
                loginInfos = (Map)session.getAttribute(LOGIN_INFO_KEY);
                if ( loginInfos != null && loginInfos.containsKey(securityHandlerKey)) {
                    info = (LoginInfo)loginInfos.get(securityHandlerKey);
                    user = info.user;
                }
            }
            if ( user == null ) {
                user = application.getSecurityHandler().login(loginContext);
                if ( user != null ) {
                    // create new login info
                    session = req.getSession();
                    loginInfos = (Map)session.getAttribute(LOGIN_INFO_KEY);
                    if ( loginInfos == null ) {
                        loginInfos = new HashMap();
                    }
                    info = new LoginInfo(user);
                    loginInfos.put(securityHandlerKey, info);
                }
            }

            // user can be null, if login failed
            if ( user != null ) {
                info.incUsageCounter(appName);
                session.setAttribute(LOGIN_INFO_KEY, loginInfos);

                // set the user in the session
                session.setAttribute(USER + '-' + appName, user);
                objectModel.put(ApplicationManager.USER, user);

                // set the application in the object model
                objectModel.put(ApplicationManager.APPLICATION, application);

                // set the application data in the session
                Object data = ObjectUtils.NULL;
                if ( application.getApplicationStore() != null ) {
                    data = application.getApplicationStore().loadApplicationData(user, application);
                }
                session.setAttribute(APPLICATION_KEY_PREFIX + appName, data);
                objectModel.put(ApplicationManager.APPLICATION_DATA, data);

                // notify the application about successful login
                application.userDidLogin(user, loginContext);

                // notify the application about accessing
                application.userIsAccessing(user);
            }
        }

        return user;
    }
View Full Code Here

            appData = session.getAttribute(APPLICATION_KEY_PREFIX + appName);

            // if the user is logged in, we set the current application, data and user
            if ( appData != null ) {
                try {
                    final Application application = this.getApplication(appName);
                    final User user = (User)session.getAttribute(USER + '-' + appName);
                    final Application oldApp = (Application)objectModel.get(ApplicationManager.APPLICATION);
                    objectModel.put(ApplicationManager.APPLICATION, application);
                    objectModel.put(ApplicationManager.APPLICATION_DATA, appData);
                    objectModel.put(ApplicationManager.USER, user);
                    // notify application
                    // The application is only notified once per request.
                    if ( oldApp == null || !oldApp.equals(application) ) {
                        application.userIsAccessing(user);
                    }
                } catch (Exception ignore) {
                    throw new CascadingRuntimeException("Unable to get application '"
                                                        + appName + "'", ignore);
View Full Code Here

            user = ApplicationUtil.getUser(objectModel);
        } else {
            final Request req = ObjectModelHelper.getRequest(objectModel);
            Session session = req.getSession(false);

            final Application app = this.getApplication(appName);
            LoginInfo info = null;
            Map loginInfos = null;

            if ( session != null ) {
                // is the user already logged in on the security handler?
                loginInfos = (Map)session.getAttribute(LOGIN_INFO_KEY);
                if ( loginInfos != null
                      && loginInfos.containsKey(app.getSecurityHandler().getId()) ) {
                    info = (LoginInfo)loginInfos.get(app.getSecurityHandler().getId());
                    user = info.user;
                }
            }
            if ( user == null ) {
                user = app.getSecurityHandler().login(loginContext);
                if ( user != null ) {
                    // create new login info
                    session = req.getSession();
                    loginInfos = (Map)session.getAttribute(LOGIN_INFO_KEY);
                    if ( loginInfos == null ) {
                        loginInfos = new HashMap();
                    }
                    info = new LoginInfo(user);
                    loginInfos.put(app.getSecurityHandler().getId(), info);
                }
            }

            // user can be null, if login failed
            if ( user != null ) {
                info.incUsageCounter(appName);
                session.setAttribute(LOGIN_INFO_KEY, loginInfos);

                // set the user in the session
                session.setAttribute(USER + '-' + appName, user);
                objectModel.put(ApplicationManager.USER, user);

                // set the application in the object model
                objectModel.put(ApplicationManager.APPLICATION, app);

                // notify the application
                app.userDidLogin(user, loginContext);

                // set the application data in the session
                Object data = ObjectUtils.NULL;
                if ( app.getApplicationStore() != null ) {
                    data = app.getApplicationStore().loadApplicationData(user, app);
                }
                session.setAttribute(APPLICATION_KEY_PREFIX + appName, data);
                objectModel.put(ApplicationManager.APPLICATION_DATA, data);
                // notify application
                app.userIsAccessing(user);
            }
        }

        return user;
    }
View Full Code Here

    public void logout(final String appName, final Map logoutContext) {
        final Map objectModel = ContextHelper.getObjectModel( this.context );
        final Request req = ObjectModelHelper.getRequest(objectModel);
        final Session session = req.getSession(false);
        if ( session != null ) {
            Application app;

            try {
                app = this.getApplication(appName);
            } catch (Exception ignore) {
                throw new CascadingRuntimeException("Unable to get application '"
                                                    + appName + "'", ignore);
            }

            // remove application data from session
            session.removeAttribute(APPLICATION_KEY_PREFIX + appName);

            // remove application from object model
            if ( app.equals( ApplicationUtil.getApplication(objectModel) ) ) {
                objectModel.remove(ApplicationManager.APPLICATION);
                objectModel.remove(ApplicationManager.APPLICATION_DATA);
                objectModel.remove(ApplicationManager.USER);
            }

            // remove user
            session.removeAttribute(USER + '-' + appName);

            // decrement logininfo counter
            final Map loginInfos = (Map)session.getAttribute(LOGIN_INFO_KEY);
            if ( loginInfos != null ) {
                final LoginInfo info = (LoginInfo)loginInfos.get(app.getSecurityHandler().getId());
                if ( info != null ) {
                    // notify the application
                    app.userWillLogout(info.user, logoutContext);

                    info.decUsageCounter(appName);
                    if ( info.isUsed() ) {
                        session.setAttribute(LOGIN_INFO_KEY, loginInfos);
                    } else {
                        // logout from security handler
                        app.getSecurityHandler().logout(logoutContext, info.user);
                        // remove user info
                        loginInfos.remove(app.getSecurityHandler().getId());
                        if ( loginInfos.size() > 0 ) {
                            session.setAttribute(LOGIN_INFO_KEY, loginInfos);
                        } else {
                            session.removeAttribute(LOGIN_INFO_KEY);
                            // the user has left all applications, test the mode:
View Full Code Here

            appData = session.getAttribute(APPLICATION_KEY_PREFIX + appName);

            // if the user is logged in, we set the current application, data and user
            if ( appData != null ) {
                try {
                    final Application application = this.getApplication(appName);
                    final User user = (User)session.getAttribute(USER + '-' + appName);
                    final Application oldApp = (Application)objectModel.get(ApplicationManager.APPLICATION);
                    objectModel.put(ApplicationManager.APPLICATION, application);
                    objectModel.put(ApplicationManager.APPLICATION_DATA, appData);
                    objectModel.put(ApplicationManager.USER, user);
                    // notify application
                    // The application is only notified once per request.
                    if ( oldApp == null || !oldApp.equals(application) ) {
                        application.userIsAccessing(user);
                    }
                } catch (Exception ignore) {
                    throw new CascadingRuntimeException("Unable to get application '"
                                                        + appName + "'", ignore);
View Full Code Here

            user = ApplicationUtil.getUser(objectModel);
        } else {
            final Request req = ObjectModelHelper.getRequest(objectModel);
            Session session = req.getSession(false);

            final Application app = this.getApplication(appName);
            LoginInfo info = null;
            Map loginInfos = null;

            if ( session != null ) {
                // is the user already logged in on the security handler?
                loginInfos = (Map)session.getAttribute(LOGIN_INFO_KEY);
                if ( loginInfos != null
                      && loginInfos.containsKey(app.getSecurityHandler()) ) {
                    info = (LoginInfo)loginInfos.get(app.getSecurityHandler());
                    user = info.user;
                }
            }
            if ( user == null ) {
                user = app.getSecurityHandler().login(loginContext);
                if ( user != null ) {
                    // create new login info
                    session = req.getSession();
                    loginInfos = (Map)session.getAttribute(LOGIN_INFO_KEY);
                    if ( loginInfos == null ) {
                        loginInfos = new HashMap();
                    }
                    info = new LoginInfo(user);
                    loginInfos.put(app.getSecurityHandler().getId(), info);
                }
            }

            // user can be null, if login failed
            if ( user != null ) {
                info.incUsageCounter(appName);
                session.setAttribute(LOGIN_INFO_KEY, loginInfos);

                // set the user in the session
                session.setAttribute(USER + '-' + appName, user);
                objectModel.put(ApplicationManager.USER, user);

                // set the application in the object model
                objectModel.put(ApplicationManager.APPLICATION, app);

                // notify the application
                app.userDidLogin(user, loginContext);

                // set the application data in the session
                Object data = ObjectUtils.NULL;
                if ( app.getApplicationStore() != null ) {
                    data = app.getApplicationStore().loadApplicationData(user, app);
                }
                session.setAttribute(APPLICATION_KEY_PREFIX + appName, data);
                objectModel.put(ApplicationManager.APPLICATION_DATA, data);
                // notify application
                app.userIsAccessing(user);
            }
        }

        return user;
    }
View Full Code Here

TOP

Related Classes of org.apache.cocoon.auth.Application

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.