Clover coverage report - Acegi Security System for Spring - 1.0.0-RC1
Coverage timestamp: Mon Dec 5 2005 09:05:15 EST
file stats: LOC: 57   Methods: 2
NCLOC: 26   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
SessionRegistryUtils.java 50% 90.9% 100% 86.7%
coverage coverage
 1    /* Copyright 2004, 2005 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.concurrent;
 17   
 18    import org.acegisecurity.Authentication;
 19    import org.acegisecurity.ui.WebAuthenticationDetails;
 20    import org.acegisecurity.userdetails.UserDetails;
 21   
 22    import org.springframework.util.Assert;
 23   
 24   
 25    /**
 26    * Utility methods to assist with concurrent session management.
 27    *
 28    * @author Ben Alex
 29    * @version $Id: SessionRegistryUtils.java,v 1.3 2005/11/29 13:10:09 benalex Exp $
 30    */
 31    public class SessionRegistryUtils {
 32    //~ Methods ================================================================
 33   
 34  7 public static Object obtainPrincipalFromAuthentication(Authentication auth) {
 35  7 Assert.notNull(auth, "Authentication required");
 36  7 Assert.notNull(auth.getPrincipal(),
 37    "Authentication.getPrincipal() required");
 38   
 39  7 if (auth.getPrincipal() instanceof UserDetails) {
 40  0 return ((UserDetails) auth.getPrincipal()).getUsername();
 41    } else {
 42  7 return auth.getPrincipal();
 43    }
 44    }
 45   
 46  7 public static String obtainSessionIdFromAuthentication(Authentication auth) {
 47  7 Assert.notNull(auth, "Authentication required");
 48  7 Assert.notNull(auth.getDetails(), "Authentication.getDetails() required");
 49  7 Assert.isInstanceOf(WebAuthenticationDetails.class, auth.getDetails());
 50   
 51  7 String sessionId = ((WebAuthenticationDetails) auth.getDetails())
 52    .getSessionId();
 53  7 Assert.hasText(sessionId, "WebAuthenticationDetails missing SessionId");
 54   
 55  7 return sessionId;
 56    }
 57    }