Package org.apache.cocoon.auth

Examples of org.apache.cocoon.auth.AuthenticationException


    public User login(Map loginContext)
    throws AuthenticationException {
        // get user name and password
        final String name = (String)loginContext.get(ApplicationManager.LOGIN_CONTEXT_USERNAME_KEY);
        if ( name == null ) {
            throw new AuthenticationException("Required user name property is missing for login.");           
        }
        final String password = (String)loginContext.get(ApplicationManager.LOGIN_CONTEXT_PASSWORD_KEY);

        final UserInfo userinfo = this.userDAO.getUserInfo(name);
        if ( userinfo == null ) {
            return null;
        }
        boolean pwCorrect = StringUtils.equals(userinfo.getPassword(), password);
        // check retry count
        if ( this.useRetryCount ) {
            if ( !negateRetryCount ) {
                if ( userinfo.getRetryCount() >= this.defaultRetryCount ) {
                    throw new AuthenticationException(AuthenticationException.AUTHENTICATION_FAILED_ACCOUNT_IS_CLOSED);
                }
                if ( !pwCorrect ) {
                    userinfo.setRetryCount(userinfo.getRetryCount() + 1);
                    this.userDAO.storeUserInfo(userinfo);
                    if ( userinfo.getRetryCount() == this.defaultRetryCount ) {
                        throw new AuthenticationException(AuthenticationException.AUTHENTICATION_FAILED_ACCOUNT_CLOSED);
                    }
                } else {
                    // reset retry count
                    if ( userinfo.getRetryCount() != 0 ) {
                        userinfo.setRetryCount(0);
                        this.userDAO.storeUserInfo(userinfo);
                    }
                }
            } else {
                // the account is disabled when the counter is zero!
                if ( userinfo.getRetryCount() == 0 ) {
                    throw new AuthenticationException(AuthenticationException.AUTHENTICATION_FAILED_ACCOUNT_IS_CLOSED);
                }
                if ( !pwCorrect ) {
                    userinfo.setRetryCount(userinfo.getRetryCount() - 1);
                    this.userDAO.storeUserInfo(userinfo);
                    if ( userinfo.getRetryCount() == 0 ) {
                        throw new AuthenticationException(AuthenticationException.AUTHENTICATION_FAILED_ACCOUNT_CLOSED);
                    }
                } else {
                    // reset retry count
                    if ( userinfo.getRetryCount() != this.defaultRetryCount ) {
                        userinfo.setRetryCount(this.defaultRetryCount);
                        this.userDAO.storeUserInfo(userinfo);
                    }
                }
            }
        }
        // check expires
        if ( pwCorrect && this.checkExpires ) {
            final Date now = new Date();
            if ( userinfo.getExpires() != null ) {
                if ( userinfo.getExpires().before(now) ) {
                    throw new AuthenticationException(AuthenticationException.AUTHENTICATION_FAILED_PASSWORD_EXPIRED);
                }
            }
        }
        // everything still correct?
        if ( !pwCorrect ) {
View Full Code Here


    public User login(final Map loginContext)
    throws AuthenticationException {
        // get user name and password
        final String name = (String)loginContext.get(ApplicationManager.LOGIN_CONTEXT_USERNAME_KEY);
        if ( name == null ) {
            throw new AuthenticationException("Required user name property is missing for login.");           
        }
        final String password = (String)loginContext.get(ApplicationManager.LOGIN_CONTEXT_PASSWORD_KEY);
        // compare password
        if ( !StringUtils.equals(password, this.userProperties.getProperty(name)) ) {
            return null;
View Full Code Here

        try {
            source = SourceUtil.getSource(authenticationResourceName, null,
                                          null, this.resolver);
            doc = org.apache.cocoon.components.source.SourceUtil.toDOM(source);
        } catch (IOException e) {
            throw new AuthenticationException(e);
        } catch (ProcessingException e) {
            throw new AuthenticationException(e);
        } catch (SAXException e) {
            throw new AuthenticationException(e);
        } finally {
            this.resolver.release(source);
        }

        // test if authentication was successful
View Full Code Here

TOP

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

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.