2017-03-14 17:19:53 +00:00
|
|
|
// Copyright 2016 Documize Inc. <legal@documize.com>. All rights reserved.
|
|
|
|
//
|
|
|
|
// This software (Documize Community Edition) is licensed under
|
|
|
|
// GNU AGPL v3 http://www.gnu.org/licenses/agpl-3.0.en.html
|
|
|
|
//
|
|
|
|
// You can operate outside the AGPL restrictions by purchasing
|
|
|
|
// Documize Enterprise Edition and obtaining a commercial license
|
|
|
|
// by contacting <sales@documize.com>.
|
|
|
|
//
|
|
|
|
// https://documize.com
|
|
|
|
|
|
|
|
import Ember from 'ember';
|
|
|
|
import constants from '../utils/constants';
|
2017-03-17 08:46:33 +00:00
|
|
|
import encoding from '../utils/encoding';
|
2017-03-14 17:19:53 +00:00
|
|
|
|
|
|
|
const {
|
|
|
|
computed
|
|
|
|
} = Ember;
|
|
|
|
|
|
|
|
export default Ember.Component.extend({
|
|
|
|
isDocumizeProvider: computed.equal('authProvider', constants.AuthProvider.Documize),
|
|
|
|
isKeycloakProvider: computed.equal('authProvider', constants.AuthProvider.Keycloak),
|
2017-03-16 11:46:09 +00:00
|
|
|
|
|
|
|
KeycloakUrlError: computed.empty('keycloakConfig.url'),
|
|
|
|
KeycloakRealmError: computed.empty('keycloakConfig.realm'),
|
|
|
|
KeycloakClientIdError: computed.empty('keycloakConfig.clientId'),
|
2017-03-16 13:33:34 +00:00
|
|
|
KeycloakPublicKeyError: computed.empty('keycloakConfig.publicKey'),
|
2017-03-16 11:46:09 +00:00
|
|
|
keycloakConfig: {
|
|
|
|
url: '',
|
|
|
|
realm: '',
|
2017-03-16 13:33:34 +00:00
|
|
|
clientId: '',
|
|
|
|
publicKey: '',
|
2017-03-16 11:46:09 +00:00
|
|
|
},
|
2017-03-14 17:19:53 +00:00
|
|
|
|
|
|
|
didReceiveAttrs() {
|
|
|
|
this._super(...arguments);
|
|
|
|
|
|
|
|
let provider = this.get('authProvider');
|
|
|
|
|
|
|
|
switch (provider) {
|
|
|
|
case constants.AuthProvider.Documize:
|
|
|
|
break;
|
|
|
|
case constants.AuthProvider.Keycloak:
|
2017-03-16 11:46:09 +00:00
|
|
|
let config = this.get('authConfig');
|
|
|
|
|
|
|
|
if (is.undefined(config) || is.null(config) || is.empty(config) ) {
|
|
|
|
config = {};
|
|
|
|
} else {
|
|
|
|
config = JSON.parse(config);
|
2017-03-17 08:46:33 +00:00
|
|
|
config.publicKey = encoding.Base64.decode(config.publicKey);
|
2017-03-16 11:46:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
this.set('keycloakConfig', config);
|
2017-03-14 17:19:53 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
actions: {
|
|
|
|
onDocumize() {
|
|
|
|
this.set('authProvider', constants.AuthProvider.Documize);
|
|
|
|
},
|
|
|
|
|
|
|
|
onKeycloak() {
|
|
|
|
this.set('authProvider', constants.AuthProvider.Keycloak);
|
|
|
|
},
|
|
|
|
|
|
|
|
onSave() {
|
|
|
|
let provider = this.get('authProvider');
|
|
|
|
let config = this.get('authConfig');
|
|
|
|
|
|
|
|
switch (provider) {
|
|
|
|
case constants.AuthProvider.Documize:
|
|
|
|
config = {};
|
|
|
|
break;
|
|
|
|
case constants.AuthProvider.Keycloak:
|
2017-03-16 11:46:09 +00:00
|
|
|
if (this.get('KeycloakUrlError')) {
|
|
|
|
this.$("#keycloak-url").focus();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (this.get('KeycloakRealmError')) {
|
|
|
|
this.$("#keycloak-realm").focus();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (this.get('KeycloakClientIdError')) {
|
|
|
|
this.$("#keycloak-clientId").focus();
|
|
|
|
return;
|
|
|
|
}
|
2017-03-16 13:33:34 +00:00
|
|
|
if (this.get('KeycloakPublicKeyError')) {
|
|
|
|
this.$("#keycloak-publicKey").focus();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
let pk = this.get('keycloakConfig.publicKey');
|
|
|
|
if (is.not.startWith(pk, '-----BEGIN PUBLIC KEY-----')) {
|
|
|
|
pk = '-----BEGIN PUBLIC KEY-----' + pk;
|
|
|
|
}
|
|
|
|
if (is.not.endWith(pk, '-----END PUBLIC KEY-----')) {
|
|
|
|
pk = pk + '-----END PUBLIC KEY-----' ;
|
|
|
|
}
|
|
|
|
|
|
|
|
this.set('keycloakConfig.publicKey', pk);
|
2017-03-16 11:46:09 +00:00
|
|
|
|
2017-03-17 08:46:33 +00:00
|
|
|
config = Ember.copy(this.get('keycloakConfig'));
|
|
|
|
Ember.set(config, 'publicKey', encoding.Base64.encode(pk));
|
2017-03-14 17:19:53 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
this.get('onSave')(provider, config).then(() => {
|
|
|
|
});
|
|
|
|
},
|
|
|
|
}
|
|
|
|
});
|