| Total Complexity | 5 |
| Total Lines | 27 |
| Duplicated Lines | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | package com.osomapps.pt.auth; |
||
| 10 | @Component |
||
| 11 | class SecurityContextHelper { |
||
| 12 | String getPrincipal() { |
||
| 13 | return ((UserDetails) SecurityContextHolder.getContext().getAuthentication().getPrincipal()) |
||
| 14 | .getUsername(); |
||
| 15 | } |
||
| 16 | |||
| 17 | String getCredentials() { |
||
| 18 | return SecurityContextHolder.getContext().getAuthentication().getCredentials().toString(); |
||
| 19 | } |
||
| 20 | |||
| 21 | CustomUserDetails getUserDetails() { |
||
| 22 | final Object details = |
||
| 23 | SecurityContextHolder.getContext().getAuthentication().getPrincipal(); |
||
| 24 | if (details instanceof CustomUserDetails) { |
||
| 25 | return (CustomUserDetails) details; |
||
| 26 | } else { |
||
| 27 | return null; |
||
| 28 | } |
||
| 29 | } |
||
| 30 | |||
| 31 | Collection<String> getAuthorities() { |
||
| 32 | final Collection<? extends GrantedAuthority> authorities = |
||
| 33 | SecurityContextHolder.getContext().getAuthentication().getAuthorities(); |
||
| 34 | return authorities.stream() |
||
| 35 | .map(authority -> authority.getAuthority()) |
||
| 36 | .collect(Collectors.toList()); |
||
| 37 | } |
||
| 39 |