001 /*
002 GRANITE DATA SERVICES
003 Copyright (C) 2011 GRANITE DATA SERVICES S.A.S.
004
005 This file is part of Granite Data Services.
006
007 Granite Data Services is free software; you can redistribute it and/or modify
008 it under the terms of the GNU Library General Public License as published by
009 the Free Software Foundation; either version 2 of the License, or (at your
010 option) any later version.
011
012 Granite Data Services is distributed in the hope that it will be useful, but
013 WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
014 FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License
015 for more details.
016
017 You should have received a copy of the GNU Library General Public License
018 along with this library; if not, see <http://www.gnu.org/licenses/>.
019 */
020
021 package org.granite.messaging.service.security;
022
023 import org.granite.messaging.service.ServiceException;
024
025 /**
026 * @author Franck WOLFF
027 */
028 public class SecurityServiceException extends ServiceException {
029
030 private static final long serialVersionUID = 1L;
031
032 /** Code for invalid credentails (wrong username or password) */
033 public static String CODE_INVALID_CREDENTIALS = "Server.Security.InvalidCredentials";
034 /** Code for other types of authentication errors */
035 public static String CODE_AUTHENTICATION_FAILED = "Server.Security.AuthenticationFailed";
036 /** Code for illegal access to a service or method that requires authentication */
037 public static String CODE_NOT_LOGGED_IN = "Server.Security.NotLoggedIn";
038 /** Code for user session timeout */
039 public static String CODE_SESSION_EXPIRED = "Server.Security.SessionExpired";
040 /** Code for illegal access to a service or method that requires special role or profile */
041 public static String CODE_ACCESS_DENIED = "Server.Security.AccessDenied";
042
043
044 public static SecurityServiceException newInvalidCredentialsException() {
045 return new SecurityServiceException(CODE_INVALID_CREDENTIALS);
046 }
047 public static SecurityServiceException newInvalidCredentialsException(String message) {
048 return new SecurityServiceException(CODE_INVALID_CREDENTIALS, message);
049 }
050 public static SecurityServiceException newInvalidCredentialsException(String message, String details) {
051 return new SecurityServiceException(CODE_INVALID_CREDENTIALS, message, details);
052 }
053 public static SecurityServiceException newAuthenticationFailedException(String message) {
054 return new SecurityServiceException(CODE_AUTHENTICATION_FAILED, message);
055 }
056
057 public static SecurityServiceException newNotLoggedInException() {
058 return new SecurityServiceException(CODE_NOT_LOGGED_IN);
059 }
060 public static SecurityServiceException newNotLoggedInException(String message) {
061 return new SecurityServiceException(CODE_NOT_LOGGED_IN, message);
062 }
063 public static SecurityServiceException newNotLoggedInException(String message, String details) {
064 return new SecurityServiceException(CODE_NOT_LOGGED_IN, message, details);
065 }
066
067 public static SecurityServiceException newSessionExpiredException() {
068 return new SecurityServiceException(CODE_SESSION_EXPIRED);
069 }
070 public static SecurityServiceException newSessionExpiredException(String message) {
071 return new SecurityServiceException(CODE_SESSION_EXPIRED, message);
072 }
073 public static SecurityServiceException newSessionExpiredException(String message, String details) {
074 return new SecurityServiceException(CODE_SESSION_EXPIRED, message, details);
075 }
076
077 public static SecurityServiceException newAccessDeniedException() {
078 return new SecurityServiceException(CODE_ACCESS_DENIED);
079 }
080 public static SecurityServiceException newAccessDeniedException(String message) {
081 return new SecurityServiceException(CODE_ACCESS_DENIED, message);
082 }
083 public static SecurityServiceException newAccessDeniedException(String message, String details) {
084 return new SecurityServiceException(CODE_ACCESS_DENIED, message, details);
085 }
086
087
088 public SecurityServiceException(String code) {
089 this(code, null, null);
090 }
091 public SecurityServiceException(String code, String message) {
092 this(code, message, null);
093 }
094 public SecurityServiceException(String code, String message, String details) {
095 super(code, message, details);
096 }
097 }