Package org.apache.cocoon.auth

Examples of org.apache.cocoon.auth.Application


    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().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

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.