
ide.auth-settings-dialog.jsx Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of DevCenter Show documentation
Show all versions of DevCenter Show documentation
Prompto Development Center POM
The newest version!
const { Modal, Button, Checkbox, FormGroup, ControlLabel, InputGroup, FormControl, HelpBlock } = ReactBootstrap;
class AuthenticationSource {
constructor(id, label, help) {
this.id = id;
this.label = label;
this.help = help;
this.disabled = false;
}
createDefaults(dialog, forTesting) {
// nothing to do
}
renderItems(dialog) {
// nothing to do
}
setStateFromValue(value, state) {
// nothing to do
}
setValueFromState(state, value) {
// nothing to do
}
}
class DataStoreAuthenticationSource extends AuthenticationSource {
constructor() {
super("STORE", "Data store", "Login and password are checked against an encrypted Prompto data store.");
this.handleUseTestSourceInDev = this.handleUseTestSourceInDev.bind(this);
this.handleStoreName = this.handleStoreName.bind(this);
}
handleUseTestSourceInDev(e, dialog) {
dialog.setState({useTestSourceInDev: e.currentTarget.checked});
}
handleStoreName(e, dialog) {
dialog.setState({storeName: e.target.value});
}
renderItems(dialog) {
const storeName = dialog.state.storeName || ""; // must not be null otherwise React sees it as uncontrolled
return
Data store name:
this.handleStoreName(e, dialog)} />
You can create a login/password data store using the 'Data Stores' application.
{!dialog.state.skipAuthInDev &&
this.handleUseTestSourceInDev(e, dialog)}>Use
'Password is login' for development
}
;
}
setStateFromValue(value, state) {
state.storeName = value.storeName;
}
setValueFromState(state, value) {
value.storeName = state.storeName;
}
}
class LDAPAuthenticationSource extends AuthenticationSource {
constructor() {
super("LDAP", "LDAP - not implemented yet", "Login and password are checked using LDAP.");
this.disabled = true;
}
}
class PasswordIsLoginAuthenticationSource extends AuthenticationSource {
constructor() {
super("TEST", "Password is login - test only", "Any login is valid, password is equal to login - for test only.");
}
}
const ALL_AUTH_SOURCES = [
new DataStoreAuthenticationSource(),
new LDAPAuthenticationSource(),
new PasswordIsLoginAuthenticationSource()
];
const ID_TO_AUTH_SOURCE_MAP = {};
ALL_AUTH_SOURCES.forEach(t => ID_TO_AUTH_SOURCE_MAP[t.id] = t);
class AuthenticationMethod {
constructor(id, label) {
this.id = id;
this.label = label;
this.disabled = false;
}
createDefaults(dialog) {
// nothing to do
}
renderItems(dialog) {
return
Select the login/password data source for this application:
{ ALL_AUTH_SOURCES.map(m=>) }
{dialog.state.source.help}
{ dialog.state.source.renderItems(dialog) }
}
setValueFromState(state, value) {
// nothing to do
}
setStateFromValue(value, state) {
// nothing to do
}
};
class NoAuthenticationMethod extends AuthenticationMethod {
constructor() {
super("NONE", "No authentication");
}
renderItems(dialog) {
// nothing to do
}
};
class BasicAuthenticationMethod extends AuthenticationMethod {
constructor() {
super("BASIC", "Browser built-in method (BASIC)");
}
};
class FormAuthenticationMethod extends AuthenticationMethod {
constructor() {
super("FORM", "Developer provided form (FORM)");
}
handleLoginFolder(e, dialog) {
dialog.setState({loginFolder: e.target.value});
}
handleLoginPage(e, dialog) {
dialog.setState({loginPage: e.target.value});
}
handleErrorFolder(e, dialog) {
dialog.setState({errorFolder: e.target.value});
}
handleErrorPage(e, dialog) {
dialog.setState({errorPage: e.target.value});
}
createDefaults(dialog) {
super.createDefaults(dialog);
const cleanName = getParam("name").toLowerCase().replace(/ /g, "-");
let { loginFolder, errorFolder } = dialog.state;
loginFolder = loginFolder || cleanName;
errorFolder = errorFolder || cleanName;
dialog.setState({loginFolder: loginFolder, errorFolder: errorFolder});
}
renderItems(dialog) {
const { loginFolder, loginPage, errorFolder, errorPage } = dialog.state;
const extension = "html";
return
Login page:
this.handleLoginFolder(e, dialog)} />
/
this.handleLoginPage(e, dialog)} placeholder={"loginPage"} />
.
This page will be displayed when the user connects to the web site.
Error page:
this.handleErrorFolder(e, dialog)} />
/
this.handleErrorPage(e, dialog)} placeholder={"errorPage"} />
.
This page will be displayed when the user connection fails.
{super.renderItems(dialog)}
;
}
setStateFromValue(value, state) {
let parts = this.extractParts(value.loginPage);
state.loginFolder = parts.folder;
state.loginPage = parts.page;
parts = this.extractParts(value.errorPage);
state.errorFolder = parts.folder;
state.errorPage = parts.page;
}
extractParts(path) {
if(!path)
return { folder: null, page: null };
else {
let idx = path.indexOf('/');
let folder = idx < 0 ? null : path.substring(0, idx);
if (folder && !folder.length)
folder = null;
if (idx > 0)
path = path.substring(idx + 1);
idx = path.indexOf('.');
let page = idx < 0 ? (path.length) : path.substring(0, idx);
if (page && !page.length)
page = null;
if (idx > 0)
path = path.substring(idx + 1);
let extension = path;
if (extension && !extension.length)
extension = null;
return {folder: folder, page: page, extension: extension};
}
}
setValueFromState(state, value) {
value.loginPage = state.loginFolder + "/" + state.loginPage + ".html";
value.errorPage = state.errorFolder + "/" + state.errorPage + ".html";
}
};
class ClientCertAuthenticationMethod extends AuthenticationMethod {
constructor() {
super("CLIENT-CERT", "Client certificate (CLIENT-CERT) - not implemented yet");
this.disabled = true;
}
};
const ALL_AUTH_METHODS = [
new NoAuthenticationMethod(),
new BasicAuthenticationMethod(),
new FormAuthenticationMethod(),
new ClientCertAuthenticationMethod()
];
const ID_TO_AUTH_METHOD_MAP = {};
ALL_AUTH_METHODS.forEach(t => ID_TO_AUTH_METHOD_MAP[t.id] = t);
class AuthenticationSettingsDialog extends React.Component {
constructor(props) {
super(props);
this.getProject = ()=>this.props.root.getProject().value;
this.state = {show: true};
this.handleClose = this.handleClose.bind(this);
this.handleMethod = this.handleMethod.bind(this);
this.handleSource = this.handleSource.bind(this);
this.handleSkipAuthInDev = this.handleSkipAuthInDev.bind(this);
this.handleWhiteList = this.handleWhiteList.bind(this);
this.handleUseDefaultWhiteList = this.handleUseDefaultWhiteList.bind(this);
this.handleSave = this.handleSave.bind(this);
this.saveSettings = this.saveSettings.bind(this);
this.setStateFromSettings();
}
setStateFromSettings() {
const settings = (this.getProject().authenticationSettings || {}).value || {};
if(settings.authenticationMethod && settings.authenticationMethod.type) {
this.state.method = new (eval(settings.authenticationMethod.type))();
this.state.method.setStateFromValue(settings.authenticationMethod.value, this.state);
} else
this.state.method = ID_TO_AUTH_METHOD_MAP["NONE"];
this.state.skipAuthInDev = settings.skipAuthInDev || false;
if(settings.authenticationSource && settings.authenticationSource.type) {
this.state.source = new (eval(settings.authenticationSource.type))();
this.state.source.setStateFromValue(settings.authenticationSource.value, this.state);
} else
this.state.source = ID_TO_AUTH_SOURCE_MAP["STORE"];
this.state.useTestSourceInDev = settings.useTestSourceInDev || false;
this.state.useDefaultWhiteList = settings.useDefaultWhiteList || false;
this.state.whiteList = (settings.whiteList || {}).value || [];
}
setSettingsFromState(settings) {
if(this.state.method.id==="NONE") {
settings.authenticationMethod = null;
settings.authenticationSource = null;
} else {
// save method
const method = settings.authenticationMethod || {};
if(method.type!==this.state.method.constructor.name) {
method.type = this.state.method.constructor.name;
method.value = {}; // TODO cleanup orphans on server
}
this.state.method.setValueFromState(this.state, method.value);
settings.authenticationMethod = method;
// save source
const source = settings.authenticationSource || {};
if(source.type!==this.state.method.constructor.name) {
source.type = this.state.source.constructor.name;
source.value = {}; // TODO cleanup orphans on server
}
this.state.source.setValueFromState(this.state, source.value);
settings.authenticationSource = source;
}
settings.skipAuthInDev = this.state.skipAuthInDev;
settings.useTestSourceInDev = this.state.useTestSourceInDev;
settings.useDefaultWhiteList = this.state.useDefaultWhiteList;
settings.whiteList = { type: "Text[]", value: this.state.whiteList };
}
componentDidMount() {
this.state.method.createDefaults(this);
this.state.source.createDefaults(this);
}
handleClose() {
this.setState({show: false});
this.props.onClose();
}
handleMethod(e) {
const id = e.currentTarget.value;
const method = ID_TO_AUTH_METHOD_MAP[id];
method.createDefaults(this);
this.setState({method: method});
}
handleSkipAuthInDev(e) {
this.setState({skipAuthInDev: e.currentTarget.checked});
}
handleWhiteList(e) {
const whiteList = e.target.value.split("\n");
this.setState({whiteList: whiteList});
}
handleUseDefaultWhiteList(e) {
this.setState({useDefaultWhiteList: e.currentTarget.checked});
}
handleSource(e) {
const id = e.currentTarget.value;
const source = ID_TO_AUTH_SOURCE_MAP[id];
source.createDefaults(this);
this.setState({source: source});
}
handleSave() {
// load latest full description before updating it
const dbId = (this.getProject().dbId.value || module.value.dbId).toString();
const params = {
params: JSON.stringify([{name: "dbId", value: dbId}, {
name: "register",
type: "Boolean",
value: false
}])
};
axios.get('/ws/run/getModuleDescription', {params: params}).then(resp => {
const response = resp.data;
if (response.error)
alert(response.error);
else
this.saveSettings(response.data);
});
}
saveSettings(project) {
const settings = (project.value.authenticationSettings || {}).value || {};
this.setSettingsFromState(settings);
project.value.authenticationSettings = { type: "AuthenticationSettings", value: settings };
const formData = new FormData();
const params = [ {name: "module", type: project.type, value: project.value} ];
formData.append("params", JSON.stringify(params));
axios.post("/ws/run/storeModule", formData).
then(response=>{
this.props.root.loadDescription();
this.handleClose()
}).catch(error=>alert(error));
}
render() {
const cleanName = this.getProject().name.toLowerCase().replace(/ /g, "-");
const showWhiteList = this.state.method.id!=="NONE";
return
Authentication settings
;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy