Coverage report

  %line %branch
org.apache.jetspeed.security.spi.impl.DefaultUserSecurityHandler
0% 
0% 

 1  
 /* 
 2  
  * Licensed to the Apache Software Foundation (ASF) under one or more
 3  
  * contributor license agreements.  See the NOTICE file distributed with
 4  
  * this work for additional information regarding copyright ownership.
 5  
  * The ASF licenses this file to You under the Apache License, Version 2.0
 6  
  * (the "License"); you may not use this file except in compliance with
 7  
  * the License.  You may obtain a copy of the License at
 8  
  *
 9  
  *     http://www.apache.org/licenses/LICENSE-2.0
 10  
  *
 11  
  * Unless required by applicable law or agreed to in writing, software
 12  
  * distributed under the License is distributed on an "AS IS" BASIS,
 13  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 14  
  * See the License for the specific language governing permissions and
 15  
  * limitations under the License.
 16  
  */
 17  
 package org.apache.jetspeed.security.spi.impl;
 18  
 
 19  
 import java.security.Principal;
 20  
 import java.util.Iterator;
 21  
 import java.util.LinkedList;
 22  
 import java.util.List;
 23  
 
 24  
 import org.apache.jetspeed.security.SecurityException;
 25  
 import org.apache.jetspeed.security.UserPrincipal;
 26  
 import org.apache.jetspeed.security.impl.UserPrincipalImpl;
 27  
 import org.apache.jetspeed.security.om.InternalUserPrincipal;
 28  
 import org.apache.jetspeed.security.om.impl.InternalUserPrincipalImpl;
 29  
 import org.apache.jetspeed.security.spi.SecurityAccess;
 30  
 import org.apache.jetspeed.security.spi.UserSecurityHandler;
 31  
 
 32  
 /**
 33  
  * @see org.apache.jetspeed.security.spi.UserSecurityHandler
 34  
  * @author <a href="mailto:dlestrat@apache.org">David Le Strat</a>
 35  
  */
 36  
 public class DefaultUserSecurityHandler implements UserSecurityHandler
 37  
 {
 38  
     /** SecurityAccess. */
 39  0
     private SecurityAccess securityAccess = null;
 40  
     
 41  
     /**
 42  
      * <p>Constructor providing access to the SecurityAccess implementation.</p>
 43  
      */
 44  
     public DefaultUserSecurityHandler(SecurityAccess securityAccess)
 45  0
     {
 46  0
         this.securityAccess = securityAccess;
 47  0
     }
 48  
     
 49  
     /**
 50  
      * @see org.apache.jetspeed.security.spi.UserSecurityHandler#isUserPrincipal(java.lang.String)
 51  
      */
 52  
     public boolean isUserPrincipal(String userName)
 53  
     {
 54  0
         return securityAccess.isKnownUser(userName);
 55  
     }
 56  
     
 57  
     /**
 58  
      * @see org.apache.jetspeed.security.spi.UserSecurityHandler#getUserPrincipal(java.lang.String)
 59  
      */
 60  
     public Principal getUserPrincipal(String username)
 61  
     {
 62  0
         UserPrincipal userPrincipal = null;
 63  0
         InternalUserPrincipal internalUser = securityAccess.getInternalUserPrincipal(username, false);
 64  0
         if (null != internalUser)
 65  
         {
 66  0
             userPrincipal = new UserPrincipalImpl(UserPrincipalImpl.getPrincipalNameFromFullPath(internalUser.getFullPath()), true, internalUser.isMappingOnly());
 67  0
             userPrincipal.setEnabled(internalUser.isEnabled());
 68  
         }
 69  0
         return userPrincipal;
 70  
     }
 71  
     
 72  
     /**
 73  
      * @see org.apache.jetspeed.security.spi.UserSecurityHandler#getUserPrincipals(java.lang.String)
 74  
      */
 75  
     public List getUserPrincipals(String filter)
 76  
     {
 77  0
         List userPrincipals = new LinkedList();
 78  0
         Iterator result = securityAccess.getInternalUserPrincipals(filter);
 79  0
         while (result.hasNext())
 80  
         {
 81  0
             InternalUserPrincipal internalUser = (InternalUserPrincipal) result.next();
 82  0
             String path = internalUser.getFullPath();
 83  0
             if (path == null)
 84  
             {
 85  0
                 continue;
 86  
             }
 87  0
             UserPrincipal userPrincipal = new UserPrincipalImpl(UserPrincipalImpl.getPrincipalNameFromFullPath(internalUser.getFullPath()));
 88  0
             userPrincipal.setEnabled(internalUser.isEnabled());
 89  0
             userPrincipals.add(userPrincipal);
 90  0
         }
 91  0
         return userPrincipals;
 92  
     }
 93  
 
 94  
     /**
 95  
      * @see org.apache.jetspeed.security.spi.UserSecurityHandler#addUserPrincipal(org.apache.jetspeed.security.UserPrincipal)
 96  
      */
 97  
     public void addUserPrincipal(UserPrincipal userPrincipal) throws SecurityException
 98  
     {
 99  0
         if ( null == securityAccess.getInternalUserPrincipal(userPrincipal.getName(), false) )
 100  
         {
 101  0
             securityAccess.setInternalUserPrincipal(new InternalUserPrincipalImpl(userPrincipal.getFullPath()), false);        
 102  
         }
 103  
         else
 104  
         {
 105  0
             throw new SecurityException(SecurityException.USER_ALREADY_EXISTS.create(userPrincipal.getName()));
 106  
         }
 107  0
     }
 108  
     
 109  
     /**
 110  
      * @see org.apache.jetspeed.security.spi.UserSecurityHandler#updateUserPrincipal(org.apache.jetspeed.security.UserPrincipal)
 111  
      */
 112  
     public void updateUserPrincipal(UserPrincipal userPrincipal) throws SecurityException
 113  
     {
 114  0
         InternalUserPrincipal internalUser = securityAccess.getInternalUserPrincipal(userPrincipal.getName(), false);
 115  0
         if ( null != internalUser )
 116  
         {
 117  0
             if ( internalUser.isEnabled() != userPrincipal.isEnabled())
 118  
             {
 119  0
                 internalUser.setEnabled(userPrincipal.isEnabled());
 120  0
                 securityAccess.setInternalUserPrincipal(internalUser, false);        
 121  
             }
 122  
         }
 123  
         else
 124  
         {
 125  0
             throw new SecurityException(SecurityException.USER_DOES_NOT_EXIST.create(userPrincipal.getName()));
 126  
         }
 127  0
     }
 128  
     
 129  
     /**
 130  
      * @see org.apache.jetspeed.security.spi.UserSecurityHandler#removeUserPrincipal(org.apache.jetspeed.security.UserPrincipal)
 131  
      */
 132  
     public void removeUserPrincipal(UserPrincipal userPrincipal) throws SecurityException
 133  
     {
 134  0
         InternalUserPrincipal internalUser = securityAccess.getInternalUserPrincipal(userPrincipal.getName(), false);
 135  0
         if (null != internalUser)
 136  
         {
 137  0
             securityAccess.removeInternalUserPrincipal(internalUser);
 138  
         }
 139  
         else
 140  
         {
 141  0
             internalUser = securityAccess.getInternalUserPrincipal(userPrincipal.getName(), true);
 142  0
             if (null != internalUser)
 143  
             {
 144  0
                 securityAccess.removeInternalUserPrincipal(internalUser);
 145  
             }
 146  
         }
 147  0
     }
 148  
 
 149  
 }

This report is generated by jcoverage, Maven and Maven JCoverage Plugin.