| 1 |
|
|
| 2 |
|
|
| 3 |
|
|
| 4 |
|
|
| 5 |
|
|
| 6 |
|
|
| 7 |
|
|
| 8 |
|
|
| 9 |
|
|
| 10 |
|
|
| 11 |
|
|
| 12 |
|
|
| 13 |
|
|
| 14 |
|
|
| 15 |
|
|
| 16 |
|
package org.kuali.student.common.util.security; |
| 17 |
|
|
| 18 |
|
import org.springframework.security.Authentication; |
| 19 |
|
import org.springframework.security.context.SecurityContextHolder; |
| 20 |
|
import org.springframework.security.userdetails.UserDetails; |
| 21 |
|
|
|
|
|
| 0% |
Uncovered Elements: 30 (30) |
Complexity: 7 |
Complexity Density: 0.39 |
|
| 22 |
|
public class SecurityUtils { |
| 23 |
|
|
| 24 |
|
|
| 25 |
|
|
| 26 |
|
|
| 27 |
|
@return |
| 28 |
|
|
|
|
|
| 0% |
Uncovered Elements: 16 (16) |
Complexity: 4 |
Complexity Density: 0.4 |
|
| 29 |
0
|
public static String getCurrentUserId() {... |
| 30 |
0
|
String username=null; |
| 31 |
0
|
Authentication auth = SecurityContextHolder.getContext().getAuthentication(); |
| 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 = obj.toString(); |
| 41 |
|
} |
| 42 |
|
} |
| 43 |
0
|
return username; |
| 44 |
|
} |
| 45 |
|
|
|
|
|
| 0% |
Uncovered Elements: 12 (12) |
Complexity: 3 |
Complexity Density: 0.38 |
|
| 46 |
0
|
public static String getPrincipalUserName(){... |
| 47 |
0
|
String username = "unknown"; |
| 48 |
|
|
| 49 |
0
|
Authentication auth = SecurityContextHolder.getContext().getAuthentication(); |
| 50 |
0
|
if (auth != null) { |
| 51 |
0
|
Object obj = auth.getPrincipal(); |
| 52 |
0
|
if (obj instanceof UserDetails) { |
| 53 |
0
|
username = ((UserDetails)obj).getUsername(); |
| 54 |
|
} else { |
| 55 |
0
|
username = obj.toString(); |
| 56 |
|
} |
| 57 |
|
} |
| 58 |
|
|
| 59 |
0
|
return username; |
| 60 |
|
} |
| 61 |
|
|
| 62 |
|
} |