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