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 public class AuthenticationServiceImpl implements AuthenticationService {
27
28 public String getPrincipalName(HttpServletRequest request) {
29 String username=null;
30 Authentication auth = SecurityContextHolder.getContext().getAuthentication();
31
32 if(auth!=null){
33 Object obj = auth.getPrincipal();
34 if(obj instanceof UserWithId){
35
36 username = ((UserWithId)obj).getUserId();
37 }else if (obj instanceof UserDetails) {
38 username = ((UserDetails)obj).getUsername();
39 } else {
40 username = request.getRemoteUser();
41 }
42 }
43 return username;
44 }
45 }