[WIP] system deposit authentication, using default repo token

This commit is contained in:
Bernaldo Mihasi 2022-10-27 09:32:26 +03:00
parent ab66a5f1da
commit 7d624a2daa
8 changed files with 57 additions and 23 deletions

View File

@ -4,6 +4,7 @@ import eu.eudat.depositinterface.repository.RepositoryDepositConfiguration;
import eu.eudat.logic.managers.DepositManager;
import eu.eudat.logic.security.claims.ClaimedAuthorities;
import eu.eudat.logic.services.ApiContext;
import eu.eudat.models.data.doi.DepositCode;
import eu.eudat.models.data.doi.DepositRequest;
import eu.eudat.models.data.helpers.responses.ResponseItem;
import eu.eudat.models.data.security.Principal;
@ -39,15 +40,16 @@ public class DepositController extends BaseController {
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<List<RepositoryDepositConfiguration>>().status(ApiMessageCode.NO_MESSAGE).payload(ids));
}
@RequestMapping(method = RequestMethod.GET, value = {"/getAccessToken"})
@RequestMapping(method = RequestMethod.POST, value = {"/getAccessToken"})
public @ResponseBody
ResponseEntity<ResponseItem<String>> getAccessToken(@RequestParam("repository") String repository, @RequestParam("code") String code, @ClaimedAuthorities(claims = {Authorities.ADMIN, Authorities.MANAGER, Authorities.USER, Authorities.ANONYMOUS}) Principal principal) throws Exception {
String accessToken = this.depositManager.authenticate(repository, code);
ResponseEntity<ResponseItem<String>> getAccessToken(@RequestBody DepositCode depositCode, @ClaimedAuthorities(claims = {Authorities.ADMIN, Authorities.MANAGER, Authorities.USER, Authorities.ANONYMOUS}) Principal principal) throws Exception {
String accessToken = this.depositManager.authenticate(depositCode.getRepositoryId(), depositCode.getCode());
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<String>().status(ApiMessageCode.NO_MESSAGE).payload(accessToken));
}
@RequestMapping(method = RequestMethod.POST, value = {"/createDoi"})
public ResponseEntity<ResponseItem<String>> createDoi(@RequestBody DepositRequest depositRequest, @ClaimedAuthorities(claims = {Authorities.ADMIN, Authorities.MANAGER, Authorities.USER, Authorities.ANONYMOUS}) Principal principal) {
public @ResponseBody
ResponseEntity<ResponseItem<String>> createDoi(@RequestBody DepositRequest depositRequest, @ClaimedAuthorities(claims = {Authorities.ADMIN, Authorities.MANAGER, Authorities.USER, Authorities.ANONYMOUS}) Principal principal) {
try {
String doi = this.depositManager.deposit(depositRequest, principal);
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<String>().status(ApiMessageCode.SUCCESS_MESSAGE).message("Successfully created DOI for Data Datamanagement Plan in question.").payload(doi));

View File

@ -2151,8 +2151,8 @@ public class DataManagementPlanManager {
}
}).orElse(null);
if (finalDoi != null) {
//dmp.setDoi(finalDoi);
//apiContext.getOperationsContext().getDatabaseRepository().getDmpDao().createOrUpdate(dmp);
dmp.setDoi(finalDoi);
apiContext.getOperationsContext().getDatabaseRepository().getDmpDao().createOrUpdate(dmp);
}
Files.deleteIfExists(file.getFile().toPath());

View File

@ -0,0 +1,21 @@
package eu.eudat.models.data.doi;
public class DepositCode {
private String repositoryId;
private String code;
public String getRepositoryId() {
return repositoryId;
}
public void setRepositoryId(String repositoryId) {
this.repositoryId = repositoryId;
}
public String getCode() {
return code;
}
public void setCode(String code) {
this.code = code;
}
}

View File

@ -27,7 +27,7 @@ import java.io.IOException;
import java.nio.file.Files;
import java.util.*;
import static eu.eudat.depositinterface.repository.RepositoryDepositConfiguration.DepositAccountStatus.BothWaysDeposit;
import static eu.eudat.depositinterface.repository.RepositoryDepositConfiguration.DepositAccountStatus.*;
@Component
public class ZenodoDeposit implements RepositoryDeposit {
@ -45,6 +45,11 @@ public class ZenodoDeposit implements RepositoryDeposit {
public String deposit(DMPDepositModel dmpDepositModel, boolean update, String zenodoToken) throws Exception {
RepositoryDepositConfiguration conf = this.getConfiguration();
if(zenodoToken == null){
zenodoToken = conf.getAccessToken();
}
String zenodoUrl = conf.getRepositoryUrl();
// First step, post call to Zenodo, to create the entry.

View File

@ -2,4 +2,9 @@ export class DepositRequest {
repositoryId: string;
dmpId: string;
accessToken: string;
}
export class DepositCode {
repositoryId: string;
code: string;
}

View File

@ -1,7 +1,7 @@
import { HttpClient, HttpHeaders } from '@angular/common/http';
import { Injectable } from '@angular/core';
import { DepositConfigurationModel } from '@app/core/model/deposit/deposit-configuration';
import { DepositRequest } from '@app/core/model/deposit/deposit-request';
import { DepositCode, DepositRequest } from '@app/core/model/deposit/deposit-request';
import { Observable } from 'rxjs';
import { ConfigurationService } from '../configuration/configuration.service';
import { BaseHttpService } from '../http/base-http.service';
@ -20,11 +20,14 @@ export class DepositRepositoriesService {
return this.http.get<DepositConfigurationModel[]>(this.actionUrl + 'repos', { headers: this.headers });
}
getAccessToken(repository: string, code: string): Observable<string> {
return this.http.get<string>(this.actionUrl + 'getAccessToken?repository=' + repository + '&code=' + code, { headers: this.headers });
getAccessToken(repositoryId: string, code: string): Observable<string> {
const depositCode = new DepositCode();
depositCode.repositoryId = repositoryId;
depositCode.code = code;
return this.http.post<string>(this.actionUrl + 'getAccessToken', depositCode, { headers: this.headers });
}
createDoi(repositoryId: string, dmpId: string, accessToken: string): Observable<string> {
createDoi(repositoryId: string, dmpId: string, accessToken: string | null): Observable<string> {
const depositRequest = new DepositRequest();
depositRequest.repositoryId = repositoryId;
depositRequest.dmpId = dmpId;

View File

@ -71,15 +71,12 @@ export class DmpDepositDialogComponent extends BaseComponent implements OnInit {
+ 'http://localhost:4200/login/external/zenodo', repo, this.dmp);
break;
case 1:
// this.dmpService.getDoi(dmp.id)
// .pipe(takeUntil(this._destroyed))
// .subscribe(
// complete => {
// this.onDOICallbackSuccess();
// this.dmp.doi = complete;
// },
// error => this.onDeleteCallbackError(error)
// );
this.depositRepositoriesService.createDoi(repo.repositoryId, this.dmp.id, null)
.pipe(takeUntil(this._destroyed))
.subscribe(doi =>{
this.onDOICallbackSuccess();
this.outputRepos.push(doi);
}, error => this.onDeleteCallbackError(error));
break;
}
});
@ -104,12 +101,12 @@ export class DmpDepositDialogComponent extends BaseComponent implements OnInit {
this.depositRepositoriesService.getAccessToken(repo.repositoryId, result.oauthCode)
.pipe(takeUntil(this._destroyed))
.subscribe(token => {
console.log(token);
this.depositRepositoriesService.createDoi(repo.repositoryId, dmp.id, token)
.pipe(takeUntil(this._destroyed))
.subscribe(doi =>{
console.log(doi);
});
this.onDOICallbackSuccess();
this.outputRepos.push(doi);
}, error => this.onDeleteCallbackError(error));
});
// this.userService.registerDOIToken(result.oauthCode, this.configurationService.app + 'oauth2')
// .pipe(takeUntil(this._destroyed))

View File

@ -604,6 +604,7 @@ export class DmpOverviewComponent extends BaseComponent implements OnInit {
dialogRef.afterClosed().pipe(takeUntil(this._destroyed)).subscribe((result: string[]) => {
if (result) {
this.dmp.doi = result[0];
this.hasDOIToken = true;
}
});
}