Coverage Report - org.acegisecurity.context.GlobalSecurityContextHolderStrategy
 
Classes in this File Line Coverage Branch Coverage Complexity
GlobalSecurityContextHolderStrategy
44% 
100% 
1.333
 
 1  
 /* Copyright 2004, 2005, 2006 Acegi Technology Pty Limited
 2  
  *
 3  
  * Licensed under the Apache License, Version 2.0 (the "License");
 4  
  * you may not use this file except in compliance with the License.
 5  
  * You may obtain a copy of the License at
 6  
  *
 7  
  *     http://www.apache.org/licenses/LICENSE-2.0
 8  
  *
 9  
  * 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  
 /**
 22  
  * A <code>static</code> field-based implementation of {@link
 23  
  * org.acegisecurity.context.SecurityContextHolderStrategy}.<p>This means that all instances in the JVM share the
 24  
  * same <code>SecurityContext</code>. This is generally useful with rich clients, such as Swing.</p>
 25  
  *
 26  
  * @author Ben Alex
 27  
  * @version $Id: SecurityContextHolder.java 1324 2006-02-12 06:29:53Z benalex $
 28  
  */
 29  1
 public class GlobalSecurityContextHolderStrategy implements SecurityContextHolderStrategy {
 30  
     //~ Static fields/initializers =====================================================================================
 31  
 
 32  
     private static SecurityContext contextHolder;
 33  
 
 34  
     //~ Methods ========================================================================================================
 35  
 
 36  
     public void clearContext() {
 37  0
         contextHolder = null;
 38  0
     }
 39  
 
 40  
     public SecurityContext getContext() {
 41  2505
         if (contextHolder == null) {
 42  1
             contextHolder = new SecurityContextImpl();
 43  
         }
 44  
 
 45  2505
         return contextHolder;
 46  
     }
 47  
 
 48  
     public void setContext(SecurityContext context) {
 49  0
         Assert.notNull(context, "Only non-null SecurityContext instances are permitted");
 50  0
         contextHolder = context;
 51  0
     }
 52  
 }