Skip to content
Snippets Groups Projects
Commit 5826bda2 authored by Sébastien DA ROCHA's avatar Sébastien DA ROCHA
Browse files

OIDC versions of user add/del/renew resources

parent eb718584
No related branches found
No related tags found
1 merge request!17Poc oidc
Pipeline #8782 passed
...@@ -265,7 +265,7 @@ export class LegacyController { ...@@ -265,7 +265,7 @@ export class LegacyController {
const token: JWTToken = req.headers.token; const token: JWTToken = req.headers.token;
try { try {
let userServices; let userServices;
if (token.authzKey == null) { if (token.authzKey == null) { // is OIDC token
userServices = await this.legacyServiceOidc.getUserResources(token.email); userServices = await this.legacyServiceOidc.getUserResources(token.email);
} else { } else {
userServices = await this.legacyService.getUserResources(token.username, token.authzKey); userServices = await this.legacyService.getUserResources(token.username, token.authzKey);
...@@ -307,6 +307,14 @@ export class LegacyController { ...@@ -307,6 +307,14 @@ export class LegacyController {
@Post('user/resources/renew') @Post('user/resources/renew')
@ApiOperation({ title: 'Renew access to a restricted access dataset for an existing user.' }) @ApiOperation({ title: 'Renew access to a restricted access dataset for an existing user.' })
@ApiImplicitHeader({
name: 'Cookie',
description: 'The JWT token containing user information',
})
@ApiImplicitHeader({
name: 'X-Xsrf-Token',
description: 'Cross Site reference token contained in the JWT token',
})
@ApiImplicitHeader({ @ApiImplicitHeader({
name: 'Cookie', name: 'Cookie',
description: 'The JWT token is sent by the browser as a cookie (refer to the config of the Authentication project to know which key is used)', description: 'The JWT token is sent by the browser as a cookie (refer to the config of the Authentication project to know which key is used)',
...@@ -320,7 +328,11 @@ export class LegacyController { ...@@ -320,7 +328,11 @@ export class LegacyController {
async renewUserResource(@Req() req, @Body() body: AccessRequest[]) { async renewUserResource(@Req() req, @Body() body: AccessRequest[]) {
const token: JWTToken = req.headers.token; const token: JWTToken = req.headers.token;
try { try {
return await this.legacyService.renewUserResource(token, body); if (token.authzKey == null) { // is OIDC token
return await this.legacyServiceOidc.renewUserResource(token, body);
} else {
return await this.legacyService.renewUserResource(token, body);
}
} catch (error) { } catch (error) {
if (error instanceof HttpException) { if (error instanceof HttpException) {
throw error; throw error;
...@@ -343,7 +355,12 @@ export class LegacyController { ...@@ -343,7 +355,12 @@ export class LegacyController {
async deleteUserResource(@Req() req, @Body() body) { async deleteUserResource(@Req() req, @Body() body) {
const token: JWTToken = req.headers.token; const token: JWTToken = req.headers.token;
try { try {
return await this.legacyService.deleteUserResource(token, body);
if (token.authzKey == null) { // is OIDC token
return await this.legacyServiceOidc.deleteUserResource(token, body);
} else {
return await this.legacyService.deleteUserResource(token, body);
}
} catch (error) { } catch (error) {
if (error instanceof HttpException) { if (error instanceof HttpException) {
throw error; throw error;
......
...@@ -149,12 +149,6 @@ export class LegacyServiceOIDC extends LegacyService { ...@@ -149,12 +149,6 @@ export class LegacyServiceOIDC extends LegacyService {
async addUserResource(token: JWTToken, accessRequests: AccessRequest[]): Promise<AccessRequestResponse> { async addUserResource(token: JWTToken, accessRequests: AccessRequest[]): Promise<AccessRequestResponse> {
this.logger.log('Entering function', `${LegacyServiceOIDC.name} - ${this.addUserResource.name}`); this.logger.log('Entering function', `${LegacyServiceOIDC.name} - ${this.addUserResource.name}`);
try { try {
// Decrypt the password
const password = decrypt(token.authzKey, await this.configService.getPrivateKey());
if (!password) {
throw new UnauthorizedException('Invalid user credentials.');
}
// Get the list of datasets // Get the list of datasets
const datasets = await this.getRestrictedAccessDatasets(); const datasets = await this.getRestrictedAccessDatasets();
...@@ -169,8 +163,7 @@ export class LegacyServiceOIDC extends LegacyService { ...@@ -169,8 +163,7 @@ export class LegacyServiceOIDC extends LegacyService {
// Request access the the specified service and the specified modes // Request access the the specified service and the specified modes
let res = await request.post(`${this.conf.legacyAuthServiceUrl}/add_user_service/`).form( let res = await request.post(`${this.conf.legacyAuthServiceUrl}/add_user_service/`).form(
{ {
password, username: token.email,
username: token.username,
service_id: accessRequest.id, service_id: accessRequest.id,
modes: accessRequest.servicesId.toString(), modes: accessRequest.servicesId.toString(),
}, },
...@@ -251,16 +244,8 @@ export class LegacyServiceOIDC extends LegacyService { ...@@ -251,16 +244,8 @@ export class LegacyServiceOIDC extends LegacyService {
async renewUserResource(token: JWTToken, accessRequests: AccessRequest[]): Promise<AccessRenewalResponse> { async renewUserResource(token: JWTToken, accessRequests: AccessRequest[]): Promise<AccessRenewalResponse> {
this.logger.log('Entering function', `${LegacyServiceOIDC.name} - ${this.renewUserResource.name}`); this.logger.log('Entering function', `${LegacyServiceOIDC.name} - ${this.renewUserResource.name}`);
try { try {
// Decrypt the password
const password = decrypt(token.authzKey, await this.configService.getPrivateKey());
if (!password) {
this.logger.warn('Invalid user credentials.', `${LegacyServiceOIDC.name} - ${this.renewUserResource.name}`);
throw new UnauthorizedException('Invalid user credentials.');
}
// Get the list of user access // Get the list of user access
const userAccess = await this.getUserResources(token.username); const userAccess = await this.getUserResources(token.email);
// Get the list of datasets // Get the list of datasets
const datasets = await this.getRestrictedAccessDatasets(); const datasets = await this.getRestrictedAccessDatasets();
// Get the list of services // Get the list of services
...@@ -354,13 +339,6 @@ export class LegacyServiceOIDC extends LegacyService { ...@@ -354,13 +339,6 @@ export class LegacyServiceOIDC extends LegacyService {
async deleteUserResource(token: JWTToken, accessRequests: AccessRequest[]): Promise<AccessDeletionResponse> { async deleteUserResource(token: JWTToken, accessRequests: AccessRequest[]): Promise<AccessDeletionResponse> {
this.logger.log('Entering function', `${LegacyServiceOIDC.name} - ${this.deleteUserResource.name}`); this.logger.log('Entering function', `${LegacyServiceOIDC.name} - ${this.deleteUserResource.name}`);
try { try {
// Decrypt the password
const password = decrypt(token.authzKey, await this.configService.getPrivateKey());
if (!password) {
this.logger.warn('Invalid user credentials.', `${LegacyServiceOIDC.name} - ${this.deleteUserResource.name}`);
throw new UnauthorizedException('Invalid user credentials.');
}
// Get the list of datasets // Get the list of datasets
const datasets = await this.getRestrictedAccessDatasets(); const datasets = await this.getRestrictedAccessDatasets();
...@@ -373,10 +351,9 @@ export class LegacyServiceOIDC extends LegacyService { ...@@ -373,10 +351,9 @@ export class LegacyServiceOIDC extends LegacyService {
for (const accessRequest of accessRequests) { for (const accessRequest of accessRequests) {
// Delete access to the specified service and the specified modes // Delete access to the specified service and the specified modes
let res = await request.post(`${this.conf.legacyAuthServiceUrl}/del_user_service/`).form( let res = await request.post(`${this.conf.legacyAuthServiceUrl}/del_user_service_oidc/`).form(
{ {
password, username: token.email,
username: token.username,
service_id: accessRequest.id, service_id: accessRequest.id,
modes: accessRequest.servicesId.toString(), modes: accessRequest.servicesId.toString(),
}, },
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment