diff --git a/plugins/permission-backend/src/service/AllowAllPermissionPolicy.test.ts b/plugins/permission-backend/src/service/AllowAllPermissionPolicy.test.ts new file mode 100644 index 0000000000..5ebebd04e5 --- /dev/null +++ b/plugins/permission-backend/src/service/AllowAllPermissionPolicy.test.ts @@ -0,0 +1,35 @@ +/* + * Copyright 2021 The Backstage Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { + AuthorizeResult, + Permission, +} from '@backstage/plugin-permission-common'; +import { AllowAllPermissionPolicy } from './AllowAllPermissionPolicy'; + +describe('AllowAllPermissionPolicy', () => { + const policy = new AllowAllPermissionPolicy(); + + it('returns ALLOW when no identity is passed', async () => { + await expect( + policy.handle({ + permission: { + name: 'any.permission', + } as Permission, + }), + ).resolves.toEqual({ result: AuthorizeResult.ALLOW }); + }); +}); diff --git a/plugins/permission-backend/src/service/AllowAllPermissionPolicy.ts b/plugins/permission-backend/src/service/AllowAllPermissionPolicy.ts new file mode 100644 index 0000000000..bb39d4a334 --- /dev/null +++ b/plugins/permission-backend/src/service/AllowAllPermissionPolicy.ts @@ -0,0 +1,34 @@ +/* + * Copyright 2021 The Backstage Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { BackstageIdentity } from '@backstage/plugin-auth-backend'; +import { AuthorizeResult } from '@backstage/plugin-permission-common'; +import { + PermissionPolicy, + PolicyAuthorizeRequest, + PolicyResult, +} from '@backstage/plugin-permission-node'; + +export class AllowAllPermissionPolicy implements PermissionPolicy { + async handle( + _request: PolicyAuthorizeRequest, + _user?: BackstageIdentity, + ): Promise { + return { + result: AuthorizeResult.ALLOW, + }; + } +} diff --git a/plugins/permission-backend/src/service/standaloneServer.ts b/plugins/permission-backend/src/service/standaloneServer.ts index 6218d22d59..87c62c6234 100644 --- a/plugins/permission-backend/src/service/standaloneServer.ts +++ b/plugins/permission-backend/src/service/standaloneServer.ts @@ -20,8 +20,8 @@ import { } from '@backstage/backend-common'; import { Server } from 'http'; import { Logger } from 'winston'; +import { AllowAllPermissionPolicy } from './AllowAllPermissionPolicy'; import { createRouter } from './router'; -import { AuthorizeResult } from '@backstage/plugin-permission-common'; export interface ServerOptions { port: number; @@ -38,9 +38,7 @@ export async function startStandaloneServer( const router = await createRouter({ logger, config, - policy: { - handle: () => Promise.resolve({ result: AuthorizeResult.ALLOW }), - }, + policy: new AllowAllPermissionPolicy(), }); let service = createServiceBuilder(module)