01: /* Copyright 2004, 2005, 2006 Acegi Technology Pty Limited
02: *
03: * Licensed under the Apache License, Version 2.0 (the "License");
04: * you may not use this file except in compliance with the License.
05: * You may obtain a copy of the License at
06: *
07: * http://www.apache.org/licenses/LICENSE-2.0
08: *
09: * Unless required by applicable law or agreed to in writing, software
10: * distributed under the License is distributed on an "AS IS" BASIS,
11: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12: * See the License for the specific language governing permissions and
13: * limitations under the License.
14: */
15:
16: package org.acegisecurity.context;
17:
18: import org.springframework.util.Assert;
19:
20: /**
21: * A <code>static</code> field-based implementation of {@link
22: * org.acegisecurity.context.SecurityContextHolderStrategy}.<p>This means that all instances in the JVM share the
23: * same <code>SecurityContext</code>. This is generally useful with rich clients, such as Swing.</p>
24: *
25: * @author Ben Alex
26: * @version $Id: SecurityContextHolder.java 1324 2006-02-12 06:29:53Z benalex $
27: */
28: public class GlobalSecurityContextHolderStrategy implements
29: SecurityContextHolderStrategy {
30: //~ Static fields/initializers =====================================================================================
31:
32: private static SecurityContext contextHolder;
33:
34: //~ Methods ========================================================================================================
35:
36: public void clearContext() {
37: contextHolder = null;
38: }
39:
40: public SecurityContext getContext() {
41: if (contextHolder == null) {
42: contextHolder = new SecurityContextImpl();
43: }
44:
45: return contextHolder;
46: }
47:
48: public void setContext(SecurityContext context) {
49: Assert
50: .notNull(context,
51: "Only non-null SecurityContext instances are permitted");
52: contextHolder = context;
53: }
54: }
|