Revision 62020
Added by Konstantinos Spyrou about 2 years ago
modules/uoa-repository-manager-service/trunk/src/main/java/eu/dnetlib/repo/manager/controllers/RepositoryController.java | ||
---|---|---|
3 | 3 |
import eu.dnetlib.domain.data.Repository; |
4 | 4 |
import eu.dnetlib.domain.data.RepositoryInterface; |
5 | 5 |
import eu.dnetlib.repo.manager.domain.*; |
6 |
import eu.dnetlib.repo.manager.domain.dto.RepositoryTerms; |
|
6 | 7 |
import eu.dnetlib.repo.manager.domain.dto.User; |
7 | 8 |
import eu.dnetlib.repo.manager.exception.ResourceNotFoundException; |
8 | 9 |
import eu.dnetlib.repo.manager.service.RepositoryService; |
... | ... | |
24 | 25 |
|
25 | 26 |
import javax.ws.rs.core.Response; |
26 | 27 |
import java.io.IOException; |
28 |
import java.util.Date; |
|
27 | 29 |
import java.util.List; |
28 | 30 |
import java.util.Map; |
29 | 31 |
|
... | ... | |
64 | 66 |
@ResponseBody |
65 | 67 |
@PreAuthorize("hasAuthority('REGISTERED_USER')") |
66 | 68 |
public List<RepositorySnippet> getRepositoriesSnippetsOfUser() throws Exception { |
67 |
return repositoryService.getRepositoriesSnippetsOfUser("0", "100"); |
|
69 |
return repositoryService.getRepositoriesSnippetsOfUser("0", "100"); // FIXME
|
|
68 | 70 |
} |
69 | 71 |
|
72 |
@RequestMapping(value = "/terms", method = RequestMethod.POST, |
|
73 |
produces = MediaType.APPLICATION_JSON_VALUE) |
|
74 |
@ResponseBody |
|
75 |
@PreAuthorize("hasAuthority('REGISTERED_USER')") |
|
76 |
public void updateRepositoriesTerms(@RequestBody List<RepositoryTerms> repositoriesTerms) throws Exception { |
|
77 |
Date date = new Date(); |
|
78 |
if (repositoriesTerms != null) { |
|
79 |
for (RepositoryTerms terms : repositoriesTerms) { |
|
80 |
Repository repository = repositoryService.getRepositoryById(terms.getId()); |
|
81 |
repository.setConsentTermsOfUse(terms.getConsentTermsOfUse()); |
|
82 |
repository.setFullTextDownload(terms.getFullTextDownload()); |
|
83 |
repository.setConsentTermsOfUseDate(date); |
|
84 |
repositoryService.updateRepository(repository, SecurityContextHolder.getContext().getAuthentication()); |
|
85 |
} |
|
86 |
} |
|
87 |
} |
|
88 |
|
|
70 | 89 |
@RequestMapping(value = "/searchRegisteredRepositories/{page}/{size}", method = RequestMethod.GET, |
71 | 90 |
produces = MediaType.APPLICATION_JSON_VALUE) |
72 | 91 |
@ResponseBody |
modules/uoa-repository-manager-service/trunk/src/main/java/eu/dnetlib/repo/manager/domain/dto/RepositoryTerms.java | ||
---|---|---|
1 |
package eu.dnetlib.repo.manager.domain.dto; |
|
2 |
|
|
3 |
import java.util.Date; |
|
4 |
|
|
5 |
public class RepositoryTerms { |
|
6 |
|
|
7 |
private String id; |
|
8 |
private String name; |
|
9 |
private Boolean consentTermsOfUse; |
|
10 |
private Boolean fullTextDownload; |
|
11 |
private Date consentTermsOfUseDate; |
|
12 |
|
|
13 |
public RepositoryTerms() { |
|
14 |
} |
|
15 |
|
|
16 |
public String getId() { |
|
17 |
return id; |
|
18 |
} |
|
19 |
|
|
20 |
public void setId(String id) { |
|
21 |
this.id = id; |
|
22 |
} |
|
23 |
|
|
24 |
public String getName() { |
|
25 |
return name; |
|
26 |
} |
|
27 |
|
|
28 |
public void setName(String name) { |
|
29 |
this.name = name; |
|
30 |
} |
|
31 |
|
|
32 |
public Boolean getConsentTermsOfUse() { |
|
33 |
return consentTermsOfUse; |
|
34 |
} |
|
35 |
|
|
36 |
public void setConsentTermsOfUse(Boolean consentTermsOfUse) { |
|
37 |
this.consentTermsOfUse = consentTermsOfUse; |
|
38 |
} |
|
39 |
|
|
40 |
public Boolean getFullTextDownload() { |
|
41 |
return fullTextDownload; |
|
42 |
} |
|
43 |
|
|
44 |
public void setFullTextDownload(Boolean fullTextDownload) { |
|
45 |
this.fullTextDownload = fullTextDownload; |
|
46 |
} |
|
47 |
|
|
48 |
public Date getConsentTermsOfUseDate() { |
|
49 |
return consentTermsOfUseDate; |
|
50 |
} |
|
51 |
|
|
52 |
public void setConsentTermsOfUseDate(Date consentTermsOfUseDate) { |
|
53 |
this.consentTermsOfUseDate = consentTermsOfUseDate; |
|
54 |
} |
|
55 |
} |
modules/uoa-repository-manager-service/trunk/src/main/java/eu/dnetlib/repo/manager/service/RepositoryServiceImpl.java | ||
---|---|---|
981 | 981 |
private UriComponents searchDatasource(String page, String size) { |
982 | 982 |
|
983 | 983 |
return UriComponentsBuilder |
984 |
.fromHttpUrl(baseAddress + "/ds/search/") |
|
984 |
.fromHttpUrl(baseAddress + "/ds/searchdetails/")
|
|
985 | 985 |
.path("/{page}/{size}/") |
986 | 986 |
.queryParam("requestSortBy", "officialname") |
987 | 987 |
.queryParam("order", "ASCENDING") |
modules/uoa-repository-manager-service/trunk/src/main/java/eu/dnetlib/repo/manager/service/security/AuthoritiesUpdater.java | ||
---|---|---|
10 | 10 |
import org.springframework.security.oauth2.common.exceptions.UnauthorizedClientException; |
11 | 11 |
import org.springframework.security.web.context.HttpSessionSecurityContextRepository; |
12 | 12 |
import org.springframework.session.Session; |
13 |
//import org.springframework.session.ExpiringSession; |
|
14 | 13 |
import org.springframework.session.FindByIndexNameSessionRepository; |
15 | 14 |
import org.springframework.stereotype.Service; |
16 | 15 |
|
... | ... | |
27 | 26 |
@Autowired |
28 | 27 |
FindByIndexNameSessionRepository sessions; |
29 | 28 |
|
30 |
public void update(String email, Collection<? extends GrantedAuthority> authorities) {
|
|
29 |
public void update(String id, Update update) {
|
|
31 | 30 |
if (sessions != null) { |
32 | 31 |
Map<String, Session> map = sessions. |
33 |
findByIndexNameAndIndexValue(FindByIndexNameSessionRepository.PRINCIPAL_NAME_INDEX_NAME, email);
|
|
32 |
findByIndexNameAndIndexValue(FindByIndexNameSessionRepository.PRINCIPAL_NAME_INDEX_NAME, id);
|
|
34 | 33 |
if (map != null) { |
35 | 34 |
logger.debug(map.values().toArray().length); |
36 | 35 |
for (Session session : map.values()) { |
... | ... | |
40 | 39 |
Authentication authentication = securityContext.getAuthentication(); |
41 | 40 |
if (authentication instanceof OIDCAuthenticationToken) { |
42 | 41 |
OIDCAuthenticationToken authOIDC = (OIDCAuthenticationToken) authentication; |
43 |
logger.debug(authorities);
|
|
42 |
logger.debug(update.authorities(authOIDC.getAuthorities()));
|
|
44 | 43 |
securityContext.setAuthentication(new OIDCAuthenticationToken(authOIDC.getSub(), authOIDC.getIssuer(), |
45 |
authOIDC.getUserInfo(), authorities, authOIDC.getIdToken(),
|
|
44 |
authOIDC.getUserInfo(), update.authorities(authOIDC.getAuthorities()), authOIDC.getIdToken(),
|
|
46 | 45 |
authOIDC.getAccessTokenValue(), authOIDC.getRefreshTokenValue())); |
47 | 46 |
logger.debug("Update authorities"); |
48 | 47 |
session.setAttribute(SPRING_SECURITY_CONTEXT_KEY, securityContext); |
... | ... | |
54 | 53 |
} |
55 | 54 |
} |
56 | 55 |
|
57 |
public void update(String email, Update update) { |
|
58 |
Collection<? extends GrantedAuthority> authorities = update.authorities(SecurityContextHolder.getContext().getAuthentication().getAuthorities()); |
|
59 |
this.update(email, authorities); |
|
60 |
} |
|
61 |
|
|
62 |
public void addRole(String email, GrantedAuthority role) { |
|
63 |
this.update(email, old -> { |
|
56 |
public void addRole(String id, GrantedAuthority role) { |
|
57 |
this.update(id, old -> { |
|
64 | 58 |
HashSet<GrantedAuthority> authorities = new HashSet<>(old); |
65 | 59 |
authorities.add(role); |
66 | 60 |
return authorities; |
... | ... | |
77 | 71 |
} |
78 | 72 |
} |
79 | 73 |
|
80 |
public void removeRole(String email, GrantedAuthority role) {
|
|
81 |
this.update(email, old -> {
|
|
74 |
public void removeRole(String id, GrantedAuthority role) {
|
|
75 |
this.update(id, old -> {
|
|
82 | 76 |
HashSet<GrantedAuthority> authorities = new HashSet<>(old); |
83 | 77 |
authorities.remove(role); |
84 | 78 |
return authorities; |
modules/uoa-repository-manager-service/trunk/src/main/java/eu/dnetlib/repo/manager/service/security/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 |
|
modules/uoa-repository-manager-service/trunk/src/main/java/eu/dnetlib/repo/manager/utils/Converter.java | ||
---|---|---|
31 | 31 |
|
32 | 32 |
Repository repository = new Repository(); |
33 | 33 |
|
34 |
JSONObject datasource = repositoryObject.getJSONObject("datasource"); |
|
34 |
// JSONObject datasource = repositoryObject.getJSONObject("datasource"); |
|
35 |
JSONObject datasource = repositoryObject; |
|
35 | 36 |
|
36 | 37 |
//if( datasource.equals(null)) |
37 | 38 |
// return null; |
... | ... | |
103 | 104 |
repository.setCountryCode(countryCode); |
104 | 105 |
} |
105 | 106 |
|
107 |
repository.setConsentTermsOfUse(convertStringToBoolean(datasource.get("consentTermsOfUse").toString())); |
|
108 |
try { |
|
109 |
repository.setConsentTermsOfUseDate(convertStringToDate(datasource.get("consentTermsOfUseDate").toString())); |
|
110 |
} catch (JSONException e) { |
|
111 |
repository.setConsentTermsOfUseDate(null); |
|
112 |
} |
|
113 |
repository.setFullTextDownload(convertStringToBoolean(datasource.get("fullTextDownload").toString())); |
|
114 |
|
|
106 | 115 |
/* identities field */ |
107 | 116 |
|
108 | 117 |
return repository; |
109 | 118 |
} |
110 | 119 |
|
120 |
public static Boolean convertStringToBoolean(String value) { |
|
121 |
return value.equals("null") ? null : Boolean.valueOf(value); |
|
122 |
} |
|
123 |
|
|
111 | 124 |
public static Date convertStringToDate(String date) { |
112 | 125 |
|
113 | 126 |
if (Objects.equals(date, "null")) |
... | ... | |
169 | 182 |
repositorySnippet.setRegisteredby(repositorySnippetObject.get("registeredby").toString()); |
170 | 183 |
if (repositorySnippet.getRegisteredby().equals("null")) |
171 | 184 |
repositorySnippet.setRegisteredby(""); |
185 |
|
|
186 |
repositorySnippet.setConsentTermsOfUse(repositorySnippetObject.get("consenttermsofuse").toString()); |
|
187 |
repositorySnippet.setFullTextDownload(repositorySnippetObject.get("fulltextdownload").toString()); |
|
188 |
repositorySnippet.setConsentTermsOfUseDate(convertStringToDate(repositorySnippetObject.get("consenttermsofusedate").toString())); |
|
189 |
|
|
172 | 190 |
return repositorySnippet; |
173 | 191 |
|
174 | 192 |
} |
... | ... | |
296 | 314 |
} |
297 | 315 |
|
298 | 316 |
repositoryMap.put("subjects", ""); |
317 |
repositoryMap.put("consentTermsOfUse", repository.getConsentTermsOfUse()); |
|
318 |
repositoryMap.put("fullTextDownload", repository.getFullTextDownload()); |
|
319 |
repositoryMap.put("consentTermsOfUseDate", convertDateToString(repository.getConsentTermsOfUseDate())); |
|
299 | 320 |
|
300 | 321 |
return mapper.writeValueAsString(repositoryMap); |
301 | 322 |
} |
Also available in: Unified diff
repository terms functionality