Skip to content

Commit

Permalink
feat(core-api): role based access control through oauth2 scopes hyper…
Browse files Browse the repository at this point in the history
…ledger#770

WORK IN PROGRESS

Fixes hyperledger#770

Signed-off-by: Peter Somogyvari <peter.somogyvari@accenture.com>
  • Loading branch information
petermetz committed Apr 7, 2021
1 parent 77ac399 commit 0679cb0
Show file tree
Hide file tree
Showing 44 changed files with 5,408 additions and 70 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -77,23 +77,23 @@ export class SupplyChainAppDummyInfrastructure {
private _quorumAccount: Account | undefined;
private _besuAccount: Account | undefined;

public get quorumAccount() {
public get quorumAccount(): Account {
if (!this._quorumAccount) {
throw new Error(`Must call deployContracts() first.`);
} else {
return this._quorumAccount;
}
}

public get besuAccount() {
public get besuAccount(): Account {
if (!this._besuAccount) {
throw new Error(`Must call deployContracts() first.`);
} else {
return this._besuAccount;
}
}

public get className() {
public get className(): string {
return SupplyChainAppDummyInfrastructure.CLASS_NAME;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,19 @@ import {
Checks,
LogLevelDesc,
LoggerProvider,
IAsyncProvider,
} from "@hyperledger/cactus-common";
import {
IAuthorizationOptions,
IExpressRequestHandler,
IWebServiceEndpoint,
} from "@hyperledger/cactus-core-api";
import { registerWebServiceEndpoint } from "@hyperledger/cactus-core";

import {
AuthorizationOptionsProvider,
registerWebServiceEndpoint,
} from "@hyperledger/cactus-core";

import {
DefaultApi as QuorumApi,
EthContractInvocationType,
Expand All @@ -26,8 +33,14 @@ export interface IInsertBambooHarvestEndpointOptions {
contractAbi: any;
apiClient: QuorumApi;
web3SigningCredential: Web3SigningCredential;
authorizationOptionsProvider?: AuthorizationOptionsProvider;
}

const K_DEFAULT_AUTHORIZATION_OPTIONS: IAuthorizationOptions = {
isSecure: true,
requiredRoles: [],
};

export class InsertBambooHarvestEndpoint implements IWebServiceEndpoint {
public static readonly HTTP_PATH = Constants.HTTP_PATH;

Expand All @@ -38,6 +51,7 @@ export class InsertBambooHarvestEndpoint implements IWebServiceEndpoint {
public static readonly CLASS_NAME = "InsertBambooHarvestEndpoint";

private readonly log: Logger;
private readonly authorizationOptionsProvider: AuthorizationOptionsProvider;

public get className(): string {
return InsertBambooHarvestEndpoint.CLASS_NAME;
Expand All @@ -57,6 +71,16 @@ export class InsertBambooHarvestEndpoint implements IWebServiceEndpoint {
const level = this.opts.logLevel || "INFO";
const label = this.className;
this.log = LoggerProvider.getOrCreate({ level, label });

this.authorizationOptionsProvider =
opts.authorizationOptionsProvider ||
AuthorizationOptionsProvider.of(K_DEFAULT_AUTHORIZATION_OPTIONS, level);

this.log.debug(`Instantiated ${this.className} OK`);
}

getAuthorizationOptionsProvider(): IAsyncProvider<IAuthorizationOptions> {
return this.authorizationOptionsProvider;
}

public registerExpress(expressApp: Express): IWebServiceEndpoint {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@ import {
Checks,
LogLevelDesc,
LoggerProvider,
IAsyncProvider,
} from "@hyperledger/cactus-common";
import {
IAuthorizationOptions,
IExpressRequestHandler,
IWebServiceEndpoint,
} from "@hyperledger/cactus-core-api";
Expand Down Expand Up @@ -59,6 +61,16 @@ export class InsertBookshelfEndpoint implements IWebServiceEndpoint {
this.log = LoggerProvider.getOrCreate({ level, label });
}

getAuthorizationOptionsProvider(): IAsyncProvider<IAuthorizationOptions> {
// TODO: make this an injectable dependency in the constructor
return {
get: async () => ({
isSecure: true,
requiredRoles: [],
}),
};
}

public registerExpress(expressApp: Express): IWebServiceEndpoint {
registerWebServiceEndpoint(expressApp, this);
return this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@ import {
Checks,
LogLevelDesc,
LoggerProvider,
IAsyncProvider,
} from "@hyperledger/cactus-common";
import {
IAuthorizationOptions,
IExpressRequestHandler,
IWebServiceEndpoint,
} from "@hyperledger/cactus-core-api";
Expand Down Expand Up @@ -42,6 +44,16 @@ export class InsertShipmentEndpoint implements IWebServiceEndpoint {
this.log = LoggerProvider.getOrCreate({ level, label });
}

getAuthorizationOptionsProvider(): IAsyncProvider<IAuthorizationOptions> {
// TODO: make this an injectable dependency in the constructor
return {
get: async () => ({
isSecure: true,
requiredRoles: [],
}),
};
}

public registerExpress(expressApp: Express): IWebServiceEndpoint {
registerWebServiceEndpoint(expressApp, this);
return this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@ import {
Checks,
LogLevelDesc,
LoggerProvider,
IAsyncProvider,
} from "@hyperledger/cactus-common";
import {
IAuthorizationOptions,
IExpressRequestHandler,
IWebServiceEndpoint,
} from "@hyperledger/cactus-core-api";
Expand Down Expand Up @@ -58,6 +60,16 @@ export class ListBambooHarvestEndpoint implements IWebServiceEndpoint {
this.log = LoggerProvider.getOrCreate({ level, label });
}

getAuthorizationOptionsProvider(): IAsyncProvider<IAuthorizationOptions> {
// TODO: make this an injectable dependency in the constructor
return {
get: async () => ({
isSecure: true,
requiredRoles: [],
}),
};
}

public registerExpress(expressApp: Express): IWebServiceEndpoint {
registerWebServiceEndpoint(expressApp, this);
return this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@ import {
Checks,
LogLevelDesc,
LoggerProvider,
IAsyncProvider,
} from "@hyperledger/cactus-common";
import {
IAuthorizationOptions,
IExpressRequestHandler,
IWebServiceEndpoint,
} from "@hyperledger/cactus-core-api";
Expand Down Expand Up @@ -58,6 +60,16 @@ export class ListBookshelfEndpoint implements IWebServiceEndpoint {
this.log = LoggerProvider.getOrCreate({ level, label });
}

getAuthorizationOptionsProvider(): IAsyncProvider<IAuthorizationOptions> {
// TODO: make this an injectable dependency in the constructor
return {
get: async () => ({
isSecure: true,
requiredRoles: [],
}),
};
}

public registerExpress(expressApp: Express): IWebServiceEndpoint {
registerWebServiceEndpoint(expressApp, this);
return this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@ import {
Checks,
LogLevelDesc,
LoggerProvider,
IAsyncProvider,
} from "@hyperledger/cactus-common";
import {
IAuthorizationOptions,
IExpressRequestHandler,
IWebServiceEndpoint,
} from "@hyperledger/cactus-core-api";
Expand Down Expand Up @@ -62,6 +64,16 @@ export class ListShipmentEndpoint implements IWebServiceEndpoint {
this.log = LoggerProvider.getOrCreate({ level, label });
}

getAuthorizationOptionsProvider(): IAsyncProvider<IAuthorizationOptions> {
// TODO: make this an injectable dependency in the constructor
return {
get: async () => ({
isSecure: true,
requiredRoles: [],
}),
};
}

public registerExpress(expressApp: Express): IWebServiceEndpoint {
registerWebServiceEndpoint(expressApp, this);
return this;
Expand Down

0 comments on commit 0679cb0

Please sign in to comment.