KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sslexplorer > core > GlobalWarning


1 /*
2  * SSL-Explorer
3  *
4  * Copyright (C) 2003-2006 3SP LTD. All Rights Reserved
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 2 of
9  * the License, or (at your option) any later version.
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public
16  * License along with this program; if not, write to the Free Software
17  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18  */

19             
20 package com.sslexplorer.core;
21
22 import javax.servlet.http.HttpSession JavaDoc;
23
24 import com.sslexplorer.policyframework.Permission;
25 import com.sslexplorer.policyframework.ResourceType;
26
27 /**
28  * <i>Global Warnings</i> may be shown on a number of different conditions
29  * depending on the permissions a user may have.
30  * <p>
31  * There are currently 4 different ways of determining if a global warning
32  * should be displayed :- *
33  * <ul>
34  * <li>Single session. Message will be displayed to a single session onyl.</li>
35  * <li>All users. Message will be displayed to all users and on the logon
36  * screen.</li>
37  * <li>Super User. Message will be displayed to the super user only.</li>
38  * <li>Users With Permissions. Message will be displayed to any users with the
39  * any of specified permissions.</li>
40  * </ul>
41  *
42  * @author Brett Smith <a HREF="mailto: brett@3sp.com">&lt;brett@3sp.com&gt;</a>
43  */

44 public class GlobalWarning {
45     /**
46      * Message will be displayed to all users and on the logon screen
47      */

48     public final static int SINGLE_SESSION = 0;
49     
50     /**
51      * Message will be displayed to all users and on the logon screen
52      */

53     public final static int ALL_USERS = 1;
54
55     /**
56      * Message will be displayed to the super user only.
57      */

58     public final static int SUPER_USER = 2;
59
60     /**
61      * Message will be displayed to all those with access to management
62      * console
63      */

64     public final static int MANAGEMENT_USERS = 3;
65
66     /**
67      * Permissions. Message will be displayed to any users with the any of
68      * specified permissions.
69      */

70     public final static int USERS_WITH_PERMISSIONS = 4;
71
72     // Private instance variables
73
private int type;
74     private BundleActionMessage message;
75     private ResourceType requiredResourceType;
76     private Permission[] requiredPermissions;
77     private HttpSession JavaDoc session;
78
79     /**
80      * Constructor for {@link #SINGLE_SESSION} type.
81      *
82      * @param session
83      * @param message message
84      */

85     public GlobalWarning(HttpSession JavaDoc session, BundleActionMessage message) {
86         this.type = SINGLE_SESSION;
87         this.session = session;
88         this.message = message;
89     }
90
91     /**
92      * Constructor for types {@link #SUPER_USER}, {@link #MANAGEMENT_USERS}
93      * or {@link #ALL_USERS}.
94      *
95      * @param type type
96      * @param message message
97      * @throws IllegalArgumentException if incorrect type
98      */

99     public GlobalWarning(int type, BundleActionMessage message) throws IllegalArgumentException JavaDoc {
100         if(type != SUPER_USER && type != MANAGEMENT_USERS && type != ALL_USERS) {
101             throw new IllegalArgumentException JavaDoc("Illegal global warning type.");
102         }
103         this.type = type;
104         this.message = message;
105     }
106
107     /**
108      * Constructor for {@link #USERS_WITH_PERMISSIONS} type.
109      *
110      * @param requiredResourceType required resource type
111      * @param requiredPermissions required permissions
112      * @param message message
113      */

114     public GlobalWarning(ResourceType requiredResourceType, Permission[] requiredPermissions, BundleActionMessage message) {
115         this.type = USERS_WITH_PERMISSIONS;
116         this.requiredPermissions = requiredPermissions;
117         this.requiredResourceType = requiredResourceType;
118         this.message = message;
119     }
120
121     /**
122      * Get the message. Available for all types.
123      *
124      * @return message
125      */

126     public BundleActionMessage getMessage() {
127         return message;
128     }
129
130     /**
131      * Get the required permissions. Available for type of {@link #USERS_WITH_PERMISSIONS}.
132      *
133      * @return required permissions
134      */

135     public Permission[] getRequiredPermissions() {
136         return requiredPermissions;
137     }
138
139
140     /**
141      * Get the required resource type. Available for type of {@link #USERS_WITH_PERMISSIONS}.
142      *
143      * @return resource type
144      */

145     public ResourceType getRequiredResourceType() {
146         return requiredResourceType;
147     }
148
149
150     /**
151      * Get the session to display for. Available for type of {@link #SINGLE_SESSION}.
152      *
153      * @return resource type
154      */

155     public HttpSession JavaDoc getSession() {
156         return session;
157     }
158
159     /**
160      * Get the type. May be one of {@link #ALL_USERS}, {@link #SUPER_USER}
161      * or {@link #USERS_WITH_PERMISSIONS}, {@link #SINGLE_SESSION}.
162      *
163      * @return type
164      */

165     public int getType() {
166         return type;
167     }
168
169 }
170
Popular Tags