001/*
002 *  Copyright 2012 Anyware Services
003 *
004 *  Licensed under the Apache License, Version 2.0 (the "License");
005 *  you may not use this file except in compliance with the License.
006 *  You may obtain a copy of the License at
007 *
008 *      http://www.apache.org/licenses/LICENSE-2.0
009 *
010 *  Unless required by applicable law or agreed to in writing, software
011 *  distributed under the License is distributed on an "AS IS" BASIS,
012 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 *  See the License for the specific language governing permissions and
014 *  limitations under the License.
015 */
016package org.ametys.web.usermanagement;
017
018/**
019 * User management exception, used whenever there is an error specific to user management.
020 */
021public class UserManagementException extends Exception
022{
023    private StatusError _statusError;
024    
025    /**
026     * Enumeration for user management exception error cause
027     *
028     */
029    public enum StatusError
030    {
031        /** Error when signup is not allowed */
032        SIGNUP_NOT_ALLOWED,
033        /** Error when public signup is not allowed */
034        PUBLIC_SIGNUP_NOT_ALLOWED,
035        /** Error when no signup page is defined */
036        NO_SIGNUP_PAGE,
037        /** Error when no change password page is defined */
038        NO_PASSWORD_CHANGE_PAGE,
039        /** Provided email is not valid */
040        INVALID_EMAIL,
041        /** Error when failed to send email */
042        MAIL_ERROR,
043        /** Error when user already exists */
044        USER_ALREADY_EXISTS,
045        /** Error when temporary user already exists */
046        TEMP_USER_ALREADY_EXISTS,
047        /** Error when the token provided by user does not exists */
048        TOKEN_UNKNOWN,
049        /** Error when the token is no more valid */
050        TOKEN_EXPIRED,
051        /** Error when the token provided by user (to reset its password for example) does not exists */
052        UNKNOWN_EMAIL,
053        /** Error when login or email provided does not match any user */
054        USER_UNKNOWN,
055        /** Error when id of population provided does not match any user population */
056        POPULATION_UNKNOWN,
057        /** Error when information provided match several users */
058        NOT_UNIQUE_USER,
059        /** Error when user has no email */
060        EMPTY_EMAIL,
061        /** Error when user is not connected */
062        NOT_CONNECTED,
063        /** Error when a request to database failed */
064        DATABASE_ERROR,
065        /** Error user inputs are invalid */ 
066        INVALID_MODIFICATION,
067        /** Error when the user directory is unmodifiable */
068        UNMODIFIABLE_USER_DIRECTORY,
069        /** Error when the signup request can not be removed or resend */
070        UNMODIFIABLE_SIGNUP_REQUEST,
071        /** When the user is not allowed */
072        USER_NOT_ALLOWED
073    }
074    
075    /**
076     * User management exception.
077     */
078    public UserManagementException()
079    {
080        super();
081    }
082    
083    /**
084     * User management exception.
085     * @param error the error cause
086     */
087    public UserManagementException(StatusError error)
088    {
089        super();
090        _statusError = error;
091    }
092    
093    /**
094     * User management exception.
095     * @param message the message.
096     * @param cause the cause.
097     */
098    public UserManagementException(String message, Throwable cause)
099    {
100        super(message, cause);
101    }
102    
103    /**
104     * User management exception.
105     * @param message the message.
106     * @param error the error cause
107     * @param cause the cause.
108     */
109    public UserManagementException(String message, StatusError error, Throwable cause)
110    {
111        super(message, cause);
112        _statusError = error;
113    }
114    
115    /**
116     * User management exception.
117     * @param message the message.
118     */
119    public UserManagementException(String message)
120    {
121        super(message);
122    }
123    
124    /**
125     * User management exception.
126     * @param message the message
127     * @param error the error cause
128     */
129    public UserManagementException(String message, StatusError error)
130    {
131        super(message);
132        _statusError = error;
133    }
134    
135    /**
136     * User management exception.
137     * @param cause the cause.
138     */
139    public UserManagementException(Throwable cause)
140    {
141        super(cause);
142    }
143    
144    /**
145     * Get the error cause concerned by this user management exception
146     * @return the error cause. Can be null.
147     */
148    public StatusError getStatusError()
149    {
150        return _statusError;
151    }
152
153}