Skip to content

Commit

Permalink
feat: implement none authorization strategy
Browse files Browse the repository at this point in the history
add new authorization strategy which tells yes you are logged in which makes it possible to connect to qlik-core

closes #284
  • Loading branch information
r-hannuschka committed Jun 25, 2020
1 parent 60f2df5 commit 975b272
Show file tree
Hide file tree
Showing 9 changed files with 53 additions and 32 deletions.
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;
3 changes: 3 additions & 0 deletions src/projects/extension/file-system/entry/root.directory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,10 @@ export class QixFsRootDirectory extends QixFsDirectoryAdapter {
*/
public async readDirectory(uri: vscode.Uri) {

console.log("read directory");

const connection = await this.getConnection(uri);
console.log(connection);
const workspace = this.fileSystemHelper.resolveWorkspace(uri);

if (!connection || !workspace) {
Expand Down
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

0 comments on commit 975b272

Please sign in to comment.