Skip to content

Commit ca7f4a1

Browse files
atarix83vins01-4science
authored andcommitted
Merged in task/main-cris/DSC-2329_new (pull request DSpace#3174)
Task/main cris/DSC-2329 new Approved-by: Vincenzo Mecca
2 parents da0111d + 3c8076f commit ca7f4a1

2 files changed

Lines changed: 17 additions & 8 deletions

File tree

src/app/bitstream-page/bitstream-download-redirect.guard.ts

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ export const bitstreamDownloadRedirectGuard: CanActivateFn = (
4747
): Observable<UrlTree | boolean> => {
4848

4949
const bitstreamId = route.params.id;
50+
const accessToken: string = route.queryParams.accessToken;
5051

5152
return bitstreamDataService.findById(bitstreamId, true, false, ...BITSTREAM_PAGE_LINKS_TO_FOLLOW).pipe(
5253
getFirstCompletedRemoteData(),
@@ -79,14 +80,21 @@ export const bitstreamDownloadRedirectGuard: CanActivateFn = (
7980
if (isAuthorized && isLoggedIn && isNotEmpty(fileLink)) {
8081
hardRedirectService.redirect(fileLink);
8182
return false;
82-
} else if (isAuthorized && !isLoggedIn) {
83+
} else if (isAuthorized && !isLoggedIn && !hasValue(accessToken)) {
8384
hardRedirectService.redirect(bitstream._links.content.href);
8485
return false;
85-
} else if (!isAuthorized && isLoggedIn) {
86-
return router.createUrlTree([getForbiddenRoute()]);
87-
} else if (!isAuthorized && !isLoggedIn) {
88-
auth.setRedirectUrl(router.url);
89-
return router.createUrlTree(['login']);
86+
} else if (!isAuthorized) {
87+
// Either we have an access token, or we are logged in, or we are not logged in.
88+
// For now, the access token does not care if we are logged in or not.
89+
if (hasValue(accessToken)) {
90+
hardRedirectService.redirect(bitstream._links.content.href + '?accessToken=' + accessToken);
91+
return false;
92+
} else if (isLoggedIn) {
93+
return router.createUrlTree([getForbiddenRoute()]);
94+
} else if (!isLoggedIn) {
95+
auth.setRedirectUrl(router.url);
96+
return router.createUrlTree(['login']);
97+
}
9098
}
9199
}),
92100
);

src/app/core/auth/server-auth-request.service.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {
66
import { Injectable } from '@angular/core';
77
import { Observable } from 'rxjs';
88
import { map } from 'rxjs/operators';
9+
import { RESTURLCombiner } from 'src/app/core/url-combiner/rest-url-combiner';
910

1011
import { RemoteDataBuildService } from '../cache/builders/remote-data-build.service';
1112
import { PostRequest } from '../data/request.models';
@@ -42,8 +43,8 @@ export class ServerAuthRequestService extends AuthRequestService {
4243
* @protected
4344
*/
4445
protected createShortLivedTokenRequest(href: string): Observable<PostRequest> {
45-
// First do a call to the root endpoint in order to get an XSRF token
46-
return this.httpClient.get(this.halService.getRootHref(), { observe: 'response' }).pipe(
46+
// First do a call to the csrf endpoint in order to get an XSRF token
47+
return this.httpClient.get(new RESTURLCombiner('/security/csrf').toString(), { observe: 'response' }).pipe(
4748
// retrieve the XSRF token from the response header
4849
map((response: HttpResponse<any>) => response.headers.get(XSRF_RESPONSE_HEADER)),
4950
map((xsrfToken: string) => {

0 commit comments

Comments
 (0)