Revision 60716
Added by Konstantinos Triantafyllou about 3 years ago
AuthorizationService.java | ||
---|---|---|
1 | 1 |
package eu.dnetlib.openaire.usermanagement.utils; |
2 | 2 |
|
3 |
import org.mitre.openid.connect.model.OIDCAuthenticationToken; |
|
4 |
import org.springframework.security.core.Authentication; |
|
5 |
import org.springframework.security.core.GrantedAuthority; |
|
6 |
import org.springframework.security.core.context.SecurityContextHolder; |
|
3 | 7 |
import org.springframework.stereotype.Component; |
4 | 8 |
|
9 |
import java.util.ArrayList; |
|
10 |
import java.util.List; |
|
11 |
|
|
5 | 12 |
@Component("AuthorizationService") |
6 | 13 |
public class AuthorizationService { |
7 | 14 |
|
... | ... | |
47 | 54 |
public boolean isCommunity(String type) { |
48 | 55 |
return mapType(type, false).equals("community"); |
49 | 56 |
} |
57 |
|
|
58 |
|
|
59 |
public List<String> getRoles() { |
|
60 |
Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); |
|
61 |
if (authentication != null) { |
|
62 |
List<GrantedAuthority> authorities = (List<GrantedAuthority>) authentication.getAuthorities(); |
|
63 |
if (authorities != null) { |
|
64 |
List<String> roles = new ArrayList<>(); |
|
65 |
authorities.forEach((authority) -> { |
|
66 |
roles.add(authority.getAuthority()); |
|
67 |
}); |
|
68 |
return roles; |
|
69 |
} |
|
70 |
} |
|
71 |
return null; |
|
72 |
} |
|
73 |
|
|
74 |
public String getAaiId() { |
|
75 |
Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); |
|
76 |
return authentication instanceof OIDCAuthenticationToken ? ((OIDCAuthenticationToken)authentication).getSub() : null; |
|
77 |
} |
|
78 |
|
|
79 |
public String getEmail() { |
|
80 |
Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); |
|
81 |
return authentication instanceof OIDCAuthenticationToken ? ((OIDCAuthenticationToken)authentication).getUserInfo().getEmail() : null; |
|
82 |
} |
|
50 | 83 |
} |
Also available in: Unified diff
Merge latest changes from trunk