|  1 |     | 
     | 
  |  2 |     | 
     | 
  |  3 |     | 
     | 
  |  4 |     | 
     | 
  |  5 |     | 
     | 
  |  6 |     | 
     | 
  |  7 |     | 
     | 
  |  8 |     | 
     | 
  |  9 |     | 
     | 
  |  10 |     | 
     | 
  |  11 |     | 
     | 
  |  12 |     | 
     | 
  |  13 |     | 
     | 
  |  14 |     | 
     | 
  |  15 |     | 
     | 
  |  16 |     | 
   package org.kuali.rice.kim.service.impl;  | 
  |  17 |     | 
     | 
  |  18 |     | 
   import javax.servlet.http.HttpServletRequest;  | 
  |  19 |     | 
   import org.kuali.rice.kim.api.identity.AuthenticationService;  | 
  |  20 |     | 
     | 
  |  21 |     | 
   import org.kuali.student.common.util.security.UserWithId;  | 
  |  22 |     | 
   import org.springframework.security.core.Authentication;  | 
  |  23 |     | 
   import org.springframework.security.core.context.SecurityContextHolder;  | 
  |  24 |     | 
   import org.springframework.security.core.userdetails.UserDetails;  | 
  |  25 |     | 
     | 
  |  26 |    0 |    public class AuthenticationServiceImpl implements AuthenticationService { | 
  |  27 |     | 
         | 
  |  28 |     | 
           public String getPrincipalName(HttpServletRequest request) { | 
  |  29 |    0 |                String username=null;  | 
  |  30 |    0 |                Authentication auth = SecurityContextHolder.getContext().getAuthentication();  | 
  |  31 |     | 
                 | 
  |  32 |    0 |                if(auth!=null){ | 
  |  33 |    0 |                Object obj = auth.getPrincipal();  | 
  |  34 |    0 |                if(obj instanceof UserWithId){ | 
  |  35 |     | 
                     | 
  |  36 |    0 |                    username = ((UserWithId)obj).getUserId();  | 
  |  37 |    0 |                }else if (obj instanceof UserDetails) { | 
  |  38 |    0 |                    username = ((UserDetails)obj).getUsername();  | 
  |  39 |     | 
               } else { | 
  |  40 |    0 |                    username = request.getRemoteUser();  | 
  |  41 |     | 
               }  | 
  |  42 |     | 
           }  | 
  |  43 |    0 |                return username;  | 
  |  44 |     | 
           }  | 
  |  45 |     | 
   }  |