[Trunk | Orcid Service]:

1. pom.xml: Change version from 2.0.0 to 1.0.0 (not yet released and was set to 2.0.0 as a false copy-paste).
2. UserTokensController.java & WorkController.java: Added @PreAuthorize("isAuthenticated()") in class (some methods were missing that).
3. UserTokensController.java: 
	a. Change "public String saveUserTokens(...)" to "public SingleValueWrapperResponse<Boolean> saveUserTokens(...)" - Do not return access token!
	b. Comment "decryptToken()" (/local/tokens/decrypt) and "encryptToken()" (/local/tokens/encrypt) methods - used for testing.
This commit is contained in:
Konstantina Galouni 2021-02-14 22:52:16 +00:00
parent 7d6d590cb8
commit 92a487e3f8
3 changed files with 21 additions and 27 deletions

View File

@ -5,7 +5,7 @@
<groupId>eu.dnetlib</groupId> <groupId>eu.dnetlib</groupId>
<artifactId>uoa-orcid-service</artifactId> <artifactId>uoa-orcid-service</artifactId>
<version>2.0.0-SNAPSHOT</version> <version>1.0.0-SNAPSHOT</version>
<packaging>war</packaging> <packaging>war</packaging>
<name>uoa-orcid-service</name> <name>uoa-orcid-service</name>

View File

@ -27,6 +27,7 @@ import java.util.List;
@RestController @RestController
//@RequestMapping("/orcid") //@RequestMapping("/orcid")
@PreAuthorize("isAuthenticated()")
@CrossOrigin(origins = "*") @CrossOrigin(origins = "*")
public class UserTokensController { public class UserTokensController {
private final Logger log = Logger.getLogger(this.getClass()); private final Logger log = Logger.getLogger(this.getClass());
@ -58,9 +59,8 @@ public class UserTokensController {
return new SingleValueWrapperResponse<String>(userOrcid); return new SingleValueWrapperResponse<String>(userOrcid);
} }
@PreAuthorize("isAuthenticated()")
@RequestMapping(value = "/orcid/token/save", method = RequestMethod.GET) @RequestMapping(value = "/orcid/token/save", method = RequestMethod.GET)
public String saveUserTokens(@RequestParam String code public SingleValueWrapperResponse<Boolean> saveUserTokens(@RequestParam String code
// , @RequestParam String redirect_uri // , @RequestParam String redirect_uri
) throws BadPaddingException, InvalidAlgorithmParameterException, NoSuchAlgorithmException, IllegalBlockSizeException, NoSuchPaddingException, InvalidKeyException, InvalidKeySpecException, IOException { ) throws BadPaddingException, InvalidAlgorithmParameterException, NoSuchAlgorithmException, IllegalBlockSizeException, NoSuchPaddingException, InvalidKeyException, InvalidKeySpecException, IOException {
log.debug("saveUserTokens: code="+code); log.debug("saveUserTokens: code="+code);
@ -94,14 +94,15 @@ public class UserTokensController {
if(response.getStatusCode() != HttpStatus.OK) { if(response.getStatusCode() != HttpStatus.OK) {
orcid_log.error("User tokens response code is: " + response.getStatusCode()); orcid_log.error("User tokens response code is: " + response.getStatusCode());
orcid_log.error("Unexpected Response: "+response.getBody()); orcid_log.error("Unexpected Response: "+response.getBody());
return null; return new SingleValueWrapperResponse<Boolean>(false);
} else { } else {
orcid_log.info("Response: "+response); orcid_log.info("Response: "+response);
UserTokens userTokens = userTokensService.json2UserTokens(response.getBody().toString()); UserTokens userTokens = userTokensService.json2UserTokens(response.getBody().toString());
userTokensService.saveUserTokens(userTokens); userTokensService.saveUserTokens(userTokens);
return "\""+userTokens.getAccessToken()+"\""; return new SingleValueWrapperResponse<Boolean>(true);
// return "\""+userTokens.getAccessToken()+"\"";
} }
} }
@ -151,17 +152,17 @@ public class UserTokensController {
} }
@PreAuthorize("isAuthenticated()") // @PreAuthorize("isAuthenticated()")
@RequestMapping(value = "/local/tokens/decrypt", method = RequestMethod.GET) // @RequestMapping(value = "/local/tokens/decrypt", method = RequestMethod.GET)
public UserTokens decryptToken(@RequestParam String aaiId) throws NoSuchPaddingException, InvalidKeyException, NoSuchAlgorithmException, IllegalBlockSizeException, BadPaddingException, InvalidAlgorithmParameterException, InvalidKeySpecException, IOException { // public UserTokens decryptToken(@RequestParam String aaiId) throws NoSuchPaddingException, InvalidKeyException, NoSuchAlgorithmException, IllegalBlockSizeException, BadPaddingException, InvalidAlgorithmParameterException, InvalidKeySpecException, IOException {
return userTokensService.getUserTokensByAai(aaiId); // return userTokensService.getUserTokensByAai(aaiId);
} // }
//
//
@PreAuthorize("isAuthenticated()") // @PreAuthorize("isAuthenticated()")
@RequestMapping(value = "/local/tokens/encrypt", method = RequestMethod.GET) // @RequestMapping(value = "/local/tokens/encrypt", method = RequestMethod.GET)
public UserTokens encryptToken(@RequestParam String aaiId) throws NoSuchPaddingException, InvalidKeyException, NoSuchAlgorithmException, IllegalBlockSizeException, BadPaddingException, InvalidAlgorithmParameterException, InvalidKeySpecException, IOException { // public UserTokens encryptToken(@RequestParam String aaiId) throws NoSuchPaddingException, InvalidKeyException, NoSuchAlgorithmException, IllegalBlockSizeException, BadPaddingException, InvalidAlgorithmParameterException, InvalidKeySpecException, IOException {
UserTokens userTokens = userTokensService.getEncryptedUserTokensByAai(aaiId); // UserTokens userTokens = userTokensService.getEncryptedUserTokensByAai(aaiId);
return userTokensService.encryptTokens(userTokens); // return userTokensService.encryptTokens(userTokens);
} // }
} }

View File

@ -35,6 +35,7 @@ import java.util.*;
@RestController @RestController
//@RequestMapping("/orcid") //@RequestMapping("/orcid")
@PreAuthorize("isAuthenticated()")
@CrossOrigin(origins = "*") @CrossOrigin(origins = "*")
public class WorkController { public class WorkController {
private final Logger log = Logger.getLogger(this.getClass()); private final Logger log = Logger.getLogger(this.getClass());
@ -49,7 +50,6 @@ public class WorkController {
@Autowired @Autowired
private WorkService workService; private WorkService workService;
@PreAuthorize("isAuthenticated()")
@RequestMapping(value = "/local/put-code", method = RequestMethod.GET) @RequestMapping(value = "/local/put-code", method = RequestMethod.GET)
public List<String> getPutCode(@RequestParam String[] pids) { public List<String> getPutCode(@RequestParam String[] pids) {
String userOrcid = userTokensService.getCurrentUserOrcid(); String userOrcid = userTokensService.getCurrentUserOrcid();
@ -64,7 +64,6 @@ public class WorkController {
return null; return null;
} }
@PreAuthorize("isAuthenticated()")
@RequestMapping(value = "/local/put-codes", method = RequestMethod.POST) @RequestMapping(value = "/local/put-codes", method = RequestMethod.POST)
public List<List<String>> getPutCodes(@RequestBody String[][] pids) { public List<List<String>> getPutCodes(@RequestBody String[][] pids) {
String userOrcid = userTokensService.getCurrentUserOrcid(); String userOrcid = userTokensService.getCurrentUserOrcid();
@ -84,7 +83,6 @@ public class WorkController {
return putCodes; return putCodes;
} }
@PreAuthorize("isAuthenticated()")
@RequestMapping(value = "/local/works", method = RequestMethod.POST) @RequestMapping(value = "/local/works", method = RequestMethod.POST)
public List<List<Work>> getLocalWorks(@RequestBody String[][] pids) { public List<List<Work>> getLocalWorks(@RequestBody String[][] pids) {
String userOrcid = userTokensService.getCurrentUserOrcid(); String userOrcid = userTokensService.getCurrentUserOrcid();
@ -100,7 +98,6 @@ public class WorkController {
return returnedWorks; return returnedWorks;
} }
@PreAuthorize("isAuthenticated()")
@RequestMapping(value = "/orcid/work/save", method = RequestMethod.POST) @RequestMapping(value = "/orcid/work/save", method = RequestMethod.POST)
public Work saveWork(@RequestBody String resultString) throws Exception { public Work saveWork(@RequestBody String resultString) throws Exception {
log.debug("saveWork: result = " + resultString); log.debug("saveWork: result = " + resultString);
@ -295,7 +292,6 @@ public class WorkController {
} }
} }
@PreAuthorize("isAuthenticated()")
@RequestMapping(value = "/orcid/work/{putCode}/delete", method = RequestMethod.DELETE) @RequestMapping(value = "/orcid/work/{putCode}/delete", method = RequestMethod.DELETE)
public String deleteWork(@PathVariable String putCode) throws IOException, BadPaddingException, InvalidKeyException, NoSuchAlgorithmException, IllegalBlockSizeException, NoSuchPaddingException, InvalidAlgorithmParameterException, InvalidKeySpecException { public String deleteWork(@PathVariable String putCode) throws IOException, BadPaddingException, InvalidKeyException, NoSuchAlgorithmException, IllegalBlockSizeException, NoSuchPaddingException, InvalidAlgorithmParameterException, InvalidKeySpecException {
log.debug("deleteWork: putCode = " + putCode); log.debug("deleteWork: putCode = " + putCode);
@ -354,7 +350,6 @@ public class WorkController {
} }
@PreAuthorize("isAuthenticated()")
@RequestMapping(value = "/orcid/works/delete", method = RequestMethod.POST) @RequestMapping(value = "/orcid/works/delete", method = RequestMethod.POST)
public List<String> deleteWorks(@RequestBody List<String> putCodes) throws IOException, BadPaddingException, InvalidKeyException, NoSuchAlgorithmException, IllegalBlockSizeException, NoSuchPaddingException, InvalidAlgorithmParameterException, InvalidKeySpecException { public List<String> deleteWorks(@RequestBody List<String> putCodes) throws IOException, BadPaddingException, InvalidKeyException, NoSuchAlgorithmException, IllegalBlockSizeException, NoSuchPaddingException, InvalidAlgorithmParameterException, InvalidKeySpecException {
log.debug("deleteWorks: putCodes = " + putCodes); log.debug("deleteWorks: putCodes = " + putCodes);
@ -421,7 +416,6 @@ public class WorkController {
return deletedPutCodes; return deletedPutCodes;
} }
@PreAuthorize("isAuthenticated()")
@RequestMapping(value = "/orcid/work", method = RequestMethod.GET) @RequestMapping(value = "/orcid/work", method = RequestMethod.GET)
public List<String> getWorksOfReuslt(@RequestParam String[] pids, @RequestParam String orcid) throws BadPaddingException, InvalidKeyException, NoSuchAlgorithmException, IllegalBlockSizeException, NoSuchPaddingException, InvalidAlgorithmParameterException, InvalidKeySpecException, IOException { public List<String> getWorksOfReuslt(@RequestParam String[] pids, @RequestParam String orcid) throws BadPaddingException, InvalidKeyException, NoSuchAlgorithmException, IllegalBlockSizeException, NoSuchPaddingException, InvalidAlgorithmParameterException, InvalidKeySpecException, IOException {
log.debug("getWorks: pids = " + pids + " - orcid = "+orcid); log.debug("getWorks: pids = " + pids + " - orcid = "+orcid);
@ -516,7 +510,6 @@ public class WorkController {
// return response; // return response;
// } // }
@PreAuthorize("isAuthenticated()")
@RequestMapping(value = "/local/works", method = RequestMethod.GET) @RequestMapping(value = "/local/works", method = RequestMethod.GET)
public List<Work> getMyLocalWorks() { public List<Work> getMyLocalWorks() {
log.debug("getMyWorks"); log.debug("getMyWorks");