Skip to content

Commit 1067a74

Browse files
committed
add OAuth
1 parent 3283980 commit 1067a74

17 files changed

+83
-26
lines changed

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "janusec-admin",
3-
"version": "0.9.6",
3+
"version": "0.9.7",
44
"license": "MIT",
55
"scripts": {
66
"ng": "ng",

src/app/application-detail/application-detail.component.html

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,20 @@ <h2>
7676
Enable WAF (Web Application Firewall)
7777
</mat-checkbox>
7878
</section>
79+
80+
<section>
81+
<mat-checkbox [(ngModel)]="application.oauth_required" [disabled]="readOnlyValue">
82+
OAuth2 Required (Only for Internal Employees and Internal Application, {{ oauth.display_name }})
83+
</mat-checkbox>
84+
</section>
85+
86+
<mat-form-field>
87+
<input type="number" matInput [(ngModel)]="application.session_seconds" [readonly]="readOnlyValue" placeholder="Session Expire Seconds for OAuth2"/>
88+
</mat-form-field>
89+
90+
<mat-form-field>
91+
<input matInput [(ngModel)]="application.owner" [readonly]="readOnlyValue" placeholder="Application Owner"/>
92+
</mat-form-field>
7993

8094
<mat-form-field>
8195
<input matInput #description [(ngModel)]="application.description" [readonly]="readOnlyValue" placeholder="Description"/>

src/app/application-detail/application-detail.component.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { Application, Domain, Certificate,APIResponse, Destination, IPMethod } f
55
import { ApplicationService } from '../application.service';
66
import { FormBuilder, FormGroup } from '@angular/forms';
77
import { MessageService } from '../message.service';
8+
import { OAuthInfo } from '../models'
89

910
@Component({
1011
selector: 'app-application-detail',
@@ -19,6 +20,7 @@ export class ApplicationDetailComponent implements OnInit {
1920
optionCertificates: Certificate[];
2021
no_certificate:Certificate;
2122
enum_ip_method_values: {value: number; name: string}[] = []; // number[]=[];
23+
oauth: OAuthInfo = new (OAuthInfo);
2224

2325
constructor(
2426
private route: ActivatedRoute,
@@ -52,6 +54,9 @@ export class ApplicationDetailComponent implements OnInit {
5254
this.application.domains=[];
5355
this.application.ip_method=1;
5456
this.application.destinations=[];
57+
this.application.oauth_required=false;
58+
this.application.session_seconds=86400;
59+
this.application.owner=this.applicationService.auth_user.username;
5560
this.addDomain();
5661
this.addDestination();
5762
}
@@ -175,6 +180,13 @@ export class ApplicationDetailComponent implements OnInit {
175180
this.no_certificate.id=0;
176181
this.no_certificate.common_name='No Certificate (HTTP Only)';
177182
this.getCertificates();
183+
184+
// get oauth config
185+
let self=this;
186+
this.applicationService.getResponseByURL('/janusec-admin/oauth/get',
187+
function(obj: OAuthInfo){
188+
self.oauth=obj;
189+
});
178190
}
179191

180192

src/app/application.service.ts

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,15 @@ const httpOptions = {
1212
@Injectable()
1313
export class ApplicationService {
1414
private apiUrl = '/janusec-admin/api';
15-
auth_user: AuthUser={user_id: 0, username:"", passwd:"", logged:false, need_modify_pwd: false};
15+
auth_user: AuthUser={
16+
user_id: 0,
17+
username:"",
18+
passwd:"",
19+
logged:false,
20+
is_super_admin:false,
21+
is_cert_admin:false,
22+
is_app_admin:false,
23+
need_modify_pwd: false};
1624
certificates: Certificate[] = [];
1725
applications: Application[] = [];
1826
hexNodesKey: string;
@@ -39,7 +47,7 @@ export class ApplicationService {
3947
if(response.err==null) {
4048
callback(response.object);
4149
}
42-
else this.messageService.add('Error:' + response.err);
50+
else this.messageService.add('Error: ' + response.err);
4351
});
4452
}
4553

@@ -51,7 +59,7 @@ export class ApplicationService {
5159
if(response.err==null) {
5260
callback(response.object);
5361
}
54-
else this.messageService.add('Error:' + response.err);
62+
else this.messageService.add('Error: ' + response.err);
5563
});
5664
}
5765

@@ -64,7 +72,7 @@ export class ApplicationService {
6472
if(response.err==null) {
6573
callback(response.object);
6674
}
67-
else this.messageService.add('Error:' + response.err);
75+
else this.messageService.add('Error: ' + response.err);
6876
});
6977
}
7078

src/app/certificate-detail/certificate-detail.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ <h2>
4444
</mat-form-field>
4545
<div>
4646
<button mat-raised-button [disabled]="readOnlyValue" (click)="setCertificate()" color="primary">Save</button>
47-
<button mat-raised-button (click)="changeEditable()" color="primary">{{readOnlyButtonText}}</button>
47+
<button mat-raised-button *ngIf="applicationService.auth_user.is_super_admin==true" (click)="changeEditable()" color="primary">{{readOnlyButtonText}}</button>
4848
<button *ngIf="certificate.id>0" mat-raised-button [disabled]="readOnlyValue" (click)="deleteCertificate()" color="primary">Delete</button>
4949
<button *ngIf="certificate.id==0 && certificate.common_name" mat-raised-button (click)="selfSignCertificate()" color="primary">Self-Sign Certificate</button>
5050
</div>

src/app/certificate-detail/certificate-detail.component.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ export class CertificateDetailComponent implements OnInit {
8888

8989

9090
changeEditable() {
91+
if(this.applicationService.auth_user.is_super_admin==false) return;
9192
this.readOnlyValue = !this.readOnlyValue;
9293
if(this.readOnlyValue) {
9394
this.readOnlyButtonText="Edit";

src/app/certificates/certificates.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<mat-card>Certificate Management</mat-card>
33
</div>
44
<mat-list class="mat-list-item-list-stacked">
5-
<mat-list-item (click)="addCertificate()">
5+
<mat-list-item *ngIf="applicationService.auth_user.is_cert_admin==true" (click)="addCertificate()">
66
<mat-icon matListIcon>add_circle_outline</mat-icon>
77
<h3 matLine>Add Certificate</h3>
88
</mat-list-item>

src/app/frontpage/frontpage.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<div>
2-
<mat-card>Janusec Application Gateway 0.9.6</mat-card>
2+
<mat-card>Janusec Application Gateway 0.9.7</mat-card>
33
</div>
44
<div class="inner-container">
55
<mat-card>

src/app/login-form/login-form.component.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,15 @@ export class LoginFormComponent implements OnInit {
2828
this.messageService.clear();
2929
let salt = '$2a$12$' + String(cryptojs.SHA256('Janusec'+this.username+this.password)).substring(0,22);
3030
let hashpwd = bcrypt.hashSync(this.password, salt);
31-
const login_user:AuthUser = {user_id:0, username: this.username, passwd: hashpwd, logged: false, need_modify_pwd:false};
31+
const login_user:AuthUser = {
32+
user_id:0,
33+
username: this.username,
34+
passwd: hashpwd,
35+
logged: false,
36+
is_super_admin: false,
37+
is_cert_admin: false,
38+
is_app_admin: false,
39+
need_modify_pwd:false};
3240
var self=this;
3341
this.applicationService.getResponse('login', function(obj: AuthUser){
3442
self.applicationService.auth_user=obj;
@@ -48,8 +56,7 @@ export class LoginFormComponent implements OnInit {
4856
this.applicationService.getResponseByURL('/janusec-admin/oauth/get',
4957
function(obj: OAuthInfo){
5058
self.oauth=obj;
51-
console.log(self.oauth);
52-
})
59+
});
5360
}
5461

5562

0 commit comments

Comments
 (0)