Coverage report

  %line %branch
org.apache.jetspeed.layout.impl.GetUserInformationAction
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.layout.impl;
 18  
 
 19  
 import java.security.Principal;
 20  
 import java.util.HashMap;
 21  
 import java.util.Iterator;
 22  
 import java.util.Map;
 23  
 import java.util.List;
 24  
 import java.util.ArrayList;
 25  
 import java.util.prefs.Preferences;
 26  
 
 27  
 import javax.security.auth.Subject;
 28  
 
 29  
 import org.apache.commons.logging.Log;
 30  
 import org.apache.commons.logging.LogFactory;
 31  
 import org.apache.jetspeed.Jetspeed;
 32  
 import org.apache.jetspeed.administration.PortalConfiguration;
 33  
 import org.apache.jetspeed.ajax.AJAXException;
 34  
 import org.apache.jetspeed.ajax.AjaxAction;
 35  
 import org.apache.jetspeed.ajax.AjaxBuilder;
 36  
 import org.apache.jetspeed.layout.PortletActionSecurityBehavior;
 37  
 import org.apache.jetspeed.request.RequestContext;
 38  
 import org.apache.jetspeed.security.RolePrincipal;
 39  
 import org.apache.jetspeed.security.User;
 40  
 import org.apache.jetspeed.security.UserManager;
 41  
 import org.apache.jetspeed.security.impl.RolePrincipalImpl;
 42  
 
 43  
 /**
 44  
  * Retrieve user information of the current user
 45  
  * 
 46  
  * AJAX action:
 47  
  * 		action = getuserinfo
 48  
  * 
 49  
  * AJAX Parameters:
 50  
  * 		none
 51  
  *     
 52  
  * @author <a href="mailto:mikko.wuokko@evtek.fi">Mikko Wuokko</a>
 53  
  * @version $Id: $
 54  
  */
 55  
 public class GetUserInformationAction 
 56  
     extends BaseUserAction 
 57  
     implements AjaxAction, AjaxBuilder, Constants
 58  
 {
 59  0
     protected Log log = LogFactory.getLog(GetUserInformationAction.class);
 60  
 
 61  
     public GetUserInformationAction(String template, 
 62  
                             String errorTemplate, 
 63  
                             UserManager um,
 64  
                             RolesSecurityBehavior rolesSecurityBehavior)                            
 65  
     {
 66  0
         super(template, errorTemplate, um, rolesSecurityBehavior);
 67  0
     }
 68  
     
 69  
     public boolean run(RequestContext requestContext, Map resultMap)
 70  
             throws AJAXException
 71  
     {
 72  0
         boolean success = true;
 73  0
         String status = "success";
 74  
         try
 75  
         {
 76  0
             resultMap.put(ACTION, "userinformation");
 77  
             // Get the necessary parameters off of the request
 78  0
         	if(!requestContext.getUserPrincipal().getName().equals(userManager.getAnonymousUser()))
 79  
         	{        		
 80  0
         		Principal principal = requestContext.getUserPrincipal();        		
 81  0
                 resultMap.put(USERNAME, principal.getName());
 82  0
                 resultMap.put(TYPE, principal.getClass().getName());
 83  
                 
 84  
                 // Loading the userinfo
 85  0
                 User user = userManager.getUser(principal.getName());
 86  0
                 if(user != null)
 87  
                 {
 88  0
                 	Preferences prefs = user.getUserAttributes();
 89  0
                 	String[] prefKeys = prefs.keys();
 90  0
                 	Map prefsSet = new HashMap();
 91  0
                 	for(int i = 0; i<prefKeys.length; i++)
 92  
                 	{
 93  0
                 		prefsSet.put(prefKeys[i], prefs.get(prefKeys[i], "No value"));                		
 94  
                 	}
 95  0
                 	resultMap.put(USERINFO, prefsSet);
 96  
 
 97  0
                 	List roles = new ArrayList();
 98  0
                 	Subject userSubject = user.getSubject();
 99  0
                 	if ( userSubject != null )
 100  
                 	{
 101  0
                 		Iterator rolesIter = userSubject.getPrincipals( RolePrincipalImpl.class ).iterator();
 102  0
                 		while ( rolesIter.hasNext() )
 103  
                         {
 104  0
                 			RolePrincipal role = (RolePrincipal)rolesIter.next();
 105  0
                             roles.add( role.getName() );
 106  0
                         }
 107  
                 	}
 108  0
                 	resultMap.put( ROLES, roles);
 109  
                 }
 110  0
         	}
 111  
         	else
 112  
         	{
 113  0
         		status = "failure";
 114  0
         		resultMap.put(REASON, "Not logged in");
 115  0
         		return false;
 116  
         	}
 117  0
             resultMap.put(STATUS, status);
 118  
         } 
 119  0
         catch (Exception e)
 120  
         {
 121  0
             log.error("exception with user account access", e);
 122  0
             resultMap.put(REASON, e.toString());
 123  0
             success = false;
 124  0
         }
 125  0
         return success;
 126  
     }    
 127  
 
 128  
 }

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