Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: implement none authorization strategy #286

Merged
merged 1 commit into from
Jun 26, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/projects/extension/authorization/authorization.helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ export class AuthorizationHelper {

const settings = workspaceFolder.settings;
const key = this.createKey(settings);

const state = await this.resolveAuthenticationState(settings, key);
const result = !state.isLoggedIn
? await this.authorize(settings.connection, state.loginUrl as string)
Expand Down Expand Up @@ -79,7 +80,7 @@ export class AuthorizationHelper {
return new Promise((resolve) => {
const session = ConnectionHelper.createSession({...settings.connection, cookies});
session.on("traffic:received", (response) => {
if (response.method === "OnAuthenticationInformation") {
if (response.method === "OnAuthenticationInformation" || response.method === "OnConnected") {
/**
* remove all listeners so we dont have a memory leak
* method exists but not in typings so cast this one to any
Expand Down Expand Up @@ -140,6 +141,10 @@ export class AuthorizationHelper {
strategyConstructor = await (await import("./form-strategy")).default as AuthorizationStrategyConstructor;
break;

case AuthStrategy.NONE:
strategyConstructor = await (await import("./no-authorization-strategy")).default as AuthorizationStrategyConstructor;
break;

case AuthStrategy.CERTIFICATE:
break;

Expand Down
13 changes: 13 additions & 0 deletions src/projects/extension/authorization/no-authorization-strategy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { AuthorizationStrategy, AuthorizationResult } from "@core/authorization";

export class NoneAuthorizationStrategy extends AuthorizationStrategy {

public run(): Promise<AuthorizationResult> {
return Promise.resolve({
success: true,
cookies: []
});
}
}

export default NoneAuthorizationStrategy;
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
export enum AuthorizationStrategy {
CERTIFICATE,
FORM,
CUSTOM
CUSTOM,
NONE
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,21 +84,9 @@ <h3>Authorization Settings</h3>
</div>
</div>


<div [ngSwitch]="authorizationStrategyCtrl.value">

<p *ngSwitchCase="authorizationStrategy.CUSTOM">
custom strategy
</p>

<p *ngSwitchCase="authorizationStrategy.CERTIFICATE">
CERTIFICATE
</p>

<!--
Form Authorization
-->
<vsqlik-settings--form-strategy *ngSwitchDefault>
</vsqlik-settings--form-strategy>
</div>
<!--
Form Authorization
-->
<vsqlik-settings--form-strategy *ngIf="currentAuthorizationStrategy === authorizationStrategy.FORM">
</vsqlik-settings--form-strategy>
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ export class ConnectionEditComponent implements OnInit, OnDestroy {
*/
public authorizationStrategy = AuthorizationStrategy;

public currentAuthorizationStrategy: AuthorizationStrategy = AuthorizationStrategy.FORM;

/**
* form control for authorization strategy
*/
Expand Down Expand Up @@ -97,6 +99,7 @@ export class ConnectionEditComponent implements OnInit, OnDestroy {
this.connectionFormHelper.save()
.pipe(takeUntil(this.destroy$))
.subscribe((connection) => {
console.dir(connection);
this.save.emit(connection)
});
}
Expand Down Expand Up @@ -127,13 +130,16 @@ export class ConnectionEditComponent implements OnInit, OnDestroy {
* initialize authorization strategy form
*/
private initAuthorizationStrategyCtrl() {
this.authorizationStrategyCtrl = this.formbuilder.control(AuthorizationStrategy.FORM);

this.currentAuthorizationStrategy = this.workspaceFolderSetting?.connection.authorization.strategy || AuthorizationStrategy.FORM;
this.authorizationStrategyCtrl = this.formbuilder.control(this.currentAuthorizationStrategy);

/** register on value changes to update strategy */
this.authorizationStrategyCtrl.valueChanges
.pipe(takeUntil(this.destroy$))
.subscribe((value) => {
this.workspaceFolderSetting.connection.authorization.strategy = value;
.subscribe((value: string) => {
this.currentAuthorizationStrategy = parseInt(value, 10);
this.workspaceFolderSetting.connection.authorization.strategy = this.currentAuthorizationStrategy;
});
}

Expand Down Expand Up @@ -178,6 +184,9 @@ export class ConnectionEditComponent implements OnInit, OnDestroy {
return Object.assign({}, connection, {
label: this.connectionForm.controls.nameCtrl.value,
connection: {
authorization: {
strategy: this.currentAuthorizationStrategy
},
host: this.connectionForm.controls.hostCtrl.value,
port: this.connectionForm.controls.portCtrl.value,
path: this.connectionForm.controls.pathCtrl.value,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Component, OnInit, OnDestroy } from "@angular/core";
import { FormBuilder, FormControl } from "@angular/forms";
import { ConnectionFormHelper, BeforeSaveHook } from "../../utils/connection-form.helper";
import { WorkspaceFolderSetting, AuthorizationStrategy } from "../../data/api";
import { WorkspaceFolderSetting } from "../../data/api";
import { Subject } from "rxjs";
import { takeUntil } from "rxjs/operators";

Expand Down Expand Up @@ -69,15 +69,15 @@ export class FormStrategyComponent implements OnInit, OnDestroy {
* create patch for authorization settings
*/
private createPatch(settings: WorkspaceFolderSetting): WorkspaceFolderSetting {

settings.connection.authorization = {
strategy: AuthorizationStrategy.FORM,
data: {
domain: this.domainCtrl.value,
password: this.passwordCtrl.value,
settings.connection.authorization = Object.assign({},
settings.connection.authorization,
{
data: {
domain: this.domainCtrl.value,
password: this.passwordCtrl.value,
}
}
};

);
return settings;
}

Expand Down
3 changes: 2 additions & 1 deletion src/projects/shared/authorization/api/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
export enum AuthStrategy {
CERTIFICATE,
FORM,
CUSTOM
CUSTOM,
NONE
}

export interface AuthorizationData {
Expand Down
1 change: 1 addition & 0 deletions src/projects/shared/connection/utils/connection.helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ export abstract class ConnectionHelper {
rejectUnauthorized: !data.allowUntrusted,
headers
});

return ws;
}

Expand Down