Commit 5e207ee9 authored by zheng liu's avatar zheng liu

Merged in dev (pull request #78)

Dev
parents 44c6dd2d d6d3490e
...@@ -70,10 +70,11 @@ export class HttpService { ...@@ -70,10 +70,11 @@ export class HttpService {
return this.http.get<Array<HostGroup>>('/api/perms/v1/user/nodes-assets/'); return this.http.get<Array<HostGroup>>('/api/perms/v1/user/nodes-assets/');
} }
get_guacamole_token(user_id: string) { get_guacamole_token(user_id: string, authToken: string) {
const body = new HttpParams() const body = new HttpParams()
.set('username', user_id) .set('username', user_id)
.set('password', 'jumpserver'); .set('password', 'jumpserver')
.set('asset_token', authToken);
// { // {
// "authToken": "xxxxxxx", // "authToken": "xxxxxxx",
// "username": "xxxxxx", // "username": "xxxxxx",
...@@ -127,6 +128,14 @@ export class HttpService { ...@@ -127,6 +128,14 @@ export class HttpService {
return this.http.get('/api/terminal/v1/sessions/' + token + '/replay'); return this.http.get('/api/terminal/v1/sessions/' + token + '/replay');
} }
get_user_id_from_token(token: string) {
const params = new HttpParams()
.set('user-only', '1')
.set('token', token);
return this.http.get('/api/users/v1/connection-token/', {params: params});
}
} }
@Injectable() @Injectable()
......
...@@ -31,19 +31,29 @@ export class ElementGuacamoleComponent implements OnInit { ...@@ -31,19 +31,29 @@ export class ElementGuacamoleComponent implements OnInit {
// /guacamole/api/tokens will redirect to http://guacamole/api/tokens // /guacamole/api/tokens will redirect to http://guacamole/api/tokens
if (this.token) { if (this.token) {
this.userid = this._localStorage.get('user'); this.userid = this._localStorage.get('user');
this._http.get_guacamole_token(this.userid).subscribe( if (this.userid) {
data => { this._http.get_guacamole_token(this.userid, this.token).subscribe(
DataStore.guacamole_token = data['authToken']; data => {
this._http.guacamole_token_add_asset(this.token, data['authToken']).subscribe( DataStore.guacamole_token = data['authToken'];
data2 => { this._http.guacamole_token_add_asset(this.token, data['authToken']).subscribe(
this._logger.debug(data); data2 => {
this.target = document.location.origin + '/guacamole/#/client/' + data2['result'] + '?token=' + data['authToken']; this._logger.debug(data);
}, this.target = document.location.origin + '/guacamole/#/client/' + data2['result'] + '?token=' + data['authToken'];
error2 => { },
this._logger.error(error2); error2 => {
this._logger.error(error2);
}
);
});
} else {
this._http.get_user_id_from_token(this.token)
.subscribe(
data => {
this._localStorage.set('user', data['user']);
} }
); );
});
}
} else { } else {
const base = window.btoa(this.host.id + '\0' + 'c' + '\0' + 'jumpserver'); const base = window.btoa(this.host.id + '\0' + 'c' + '\0' + 'jumpserver');
if (environment.production) { if (environment.production) {
...@@ -57,7 +67,7 @@ export class ElementGuacamoleComponent implements OnInit { ...@@ -57,7 +67,7 @@ export class ElementGuacamoleComponent implements OnInit {
} }
); );
} else { } else {
this._http.get_guacamole_token(User.id).subscribe( this._http.get_guacamole_token(User.id, '').subscribe(
data => { data => {
// /guacamole/client will redirect to http://guacamole/#/client // /guacamole/client will redirect to http://guacamole/#/client
DataStore.guacamole_token = data['authToken']; DataStore.guacamole_token = data['authToken'];
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment