Revision 62020
Added by Konstantinos Spyrou about 2 years ago
AuthorizationServiceImpl.java | ||
---|---|---|
5 | 5 |
import eu.dnetlib.repo.manager.domain.dto.User; |
6 | 6 |
import eu.dnetlib.repo.manager.exception.ResourceNotFoundException; |
7 | 7 |
import eu.dnetlib.repo.manager.service.aai.registry.AaiRegistryService; |
8 |
import org.apache.log4j.LogManager; |
|
9 |
import org.apache.log4j.Logger; |
|
8 | 10 |
import org.mitre.openid.connect.model.OIDCAuthenticationToken; |
9 | 11 |
import org.mitre.openid.connect.model.UserInfo; |
10 | 12 |
import org.springframework.beans.factory.annotation.Autowired; |
13 |
import org.springframework.security.core.GrantedAuthority; |
|
11 | 14 |
import org.springframework.security.core.context.SecurityContextHolder; |
12 | 15 |
import org.springframework.stereotype.Service; |
13 | 16 |
|
14 | 17 |
import java.util.ArrayList; |
18 |
import java.util.Arrays; |
|
15 | 19 |
import java.util.Collection; |
16 | 20 |
import java.util.List; |
21 |
import java.util.stream.Collectors; |
|
17 | 22 |
|
18 | 23 |
@Service("authorizationService") |
19 | 24 |
public class AuthorizationServiceImpl implements AuthorizationService { |
20 | 25 |
|
26 |
private static final Logger logger = LogManager.getLogger(AuthorizationServiceImpl.class); |
|
27 |
|
|
21 | 28 |
public static final String SUPER_ADMINISTRATOR = "SUPER_ADMINISTRATOR"; |
22 | 29 |
public static final String CONTENT_PROVIDER_DASHBOARD_ADMINISTRATOR = "CONTENT_PROVIDER_DASHBOARD_ADMINISTRATOR"; |
23 | 30 |
public static final String REGISTERED_USER = "REGISTERED_USER"; |
... | ... | |
131 | 138 |
|
132 | 139 |
@Override |
133 | 140 |
public Collection<String> getUserRoles() { |
134 |
List<String> roles; |
|
135 |
JsonArray entitlements; |
|
141 |
Collection<String> roles; |
|
136 | 142 |
UserInfo userInfo = ((OIDCAuthenticationToken) SecurityContextHolder.getContext().getAuthentication()).getUserInfo(); |
137 |
if (userInfo.getSource().getAsJsonArray("edu_person_entitlements") != null) { |
|
138 |
entitlements = userInfo.getSource().getAsJsonArray("edu_person_entitlements"); |
|
139 |
} else if (userInfo.getSource().getAsJsonArray("eduperson_entitlement") != null) { |
|
140 |
entitlements = userInfo.getSource().getAsJsonArray("eduperson_entitlement"); |
|
141 |
} else { |
|
142 |
entitlements = new JsonArray(); |
|
143 |
} |
|
144 |
roles = AuthoritiesMapper.entitlementRoles(entitlements); |
|
143 |
roles = getUserRoles(userInfo.getEmail()); |
|
144 |
|
|
145 |
logger.debug(String.format("User Roles: %s", String.join(",", roles))); |
|
145 | 146 |
return roles; |
146 | 147 |
} |
147 | 148 |
|
Also available in: Unified diff
repository terms functionality