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({
|
2017-03-20 13:54:53 +00:00
|
|
|
appMeta: Ember.inject.service(),
|
2017-03-14 17:19:53 +00:00
|
|
|
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-17 19:01:32 +00:00
|
|
|
KeycloakAdminUserError: computed.empty('keycloakConfig.adminUser'),
|
|
|
|
KeycloakAdminPasswordError: computed.empty('keycloakConfig.adminPassword'),
|
2017-03-16 11:46:09 +00:00
|
|
|
keycloakConfig: {
|
|
|
|
url: '',
|
|
|
|
realm: '',
|
2017-03-16 13:33:34 +00:00
|
|
|
clientId: '',
|
|
|
|
publicKey: '',
|
2017-03-17 19:01:32 +00:00
|
|
|
adminUser: '',
|
|
|
|
adminPassword: ''
|
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:
|
2017-03-19 11:37:18 +00:00
|
|
|
// nothing to do
|
2017-03-14 17:19:53 +00:00
|
|
|
break;
|
2017-03-19 11:37:18 +00:00
|
|
|
case constants.AuthProvider.Keycloak: // eslint-disable-line no-case-declarations
|
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;
|
|
|
|
}
|
2017-03-17 19:01:32 +00:00
|
|
|
if (this.get('KeycloakAdminUserError')) {
|
|
|
|
this.$("#keycloak-admin-user").focus();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (this.get('KeycloakAdminPasswordError')) {
|
|
|
|
this.$("#keycloak-admin-password").focus();
|
|
|
|
return;
|
|
|
|
}
|
2017-03-16 11:46:09 +00:00
|
|
|
|
2017-03-17 08:46:33 +00:00
|
|
|
config = Ember.copy(this.get('keycloakConfig'));
|
2017-03-17 11:02:04 +00:00
|
|
|
Ember.set(config, 'publicKey', encoding.Base64.encode(this.get('keycloakConfig.publicKey')));
|
2017-03-14 17:19:53 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
this.get('onSave')(provider, config).then(() => {
|
|
|
|
});
|
|
|
|
},
|
2017-03-19 14:25:21 +00:00
|
|
|
|
|
|
|
onSync() {
|
|
|
|
this.get('onSync')();
|
|
|
|
}
|
2017-03-14 17:19:53 +00:00
|
|
|
}
|
|
|
|
});
|