Skip to content

Commit

Permalink
Merge pull request #69 from mbarto/authentication
Browse files Browse the repository at this point in the history
Fixes #37: initial implementation of security integration (automatic login using georchestra security headers)
  • Loading branch information
mbarto authored Oct 24, 2019
2 parents 353a11c + 1f355c9 commit 7b5ac64
Show file tree
Hide file tree
Showing 22 changed files with 1,051 additions and 116 deletions.
15 changes: 0 additions & 15 deletions .babelrc

This file was deleted.

53 changes: 23 additions & 30 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
{
"parser": "babel-eslint", // https://github.com/babel/babel-eslint
"plugins": [
"no-only-tests", // https://github.com/levibuzolic/eslint-plugin-no-only-tests
"react" // https://github.com/yannickcr/eslint-plugin-react
],
"env": { // http://eslint.org/docs/user-guide/configuring.html#specifying-environments
"browser": true, // browser global variables
"node": true // Node.js global variables and Node.js-specific rules
"node": true, // Node.js global variables and Node.js-specific rules
"es6": true // enable all ECMAScript 6 features except for modules (this automatically sets the ecmaVersion parser option to 6).
},
"globals" : {
/* MOCHA */
Expand All @@ -17,24 +19,6 @@
"afterEach" : false,
"__DEVTOOLS__": false
},
"ecmaFeatures": {
"arrowFunctions": true,
"blockBindings": true,
"classes": true,
"defaultParams": true,
"destructuring": true,
"forOf": true,
"generators": false,
"modules": true,
"objectLiteralComputedProperties": true,
"objectLiteralDuplicateProperties": false,
"objectLiteralShorthandMethods": true,
"objectLiteralShorthandProperties": true,
"spread": true,
"superInFunctions": true,
"templateStrings": true,
"jsx": true
},
"rules": {
/**
* Strict mode
Expand All @@ -55,17 +39,22 @@
"no-shadow-restricted-names": 2, // http://eslint.org/docs/rules/no-shadow-restricted-names
"no-unused-vars": [2, { // http://eslint.org/docs/rules/no-unused-vars
"vars": "local",
"args": "after-used"
"args": "after-used",
"ignoreRestSiblings": true
}],
"no-use-before-define": 2, // http://eslint.org/docs/rules/no-use-before-define

/**
* Possible errors
*/
"no-only-tests/no-only-tests": ["error", {"block": ["it", "describe"], "focus": ["only"]}],
"comma-dangle": [2, "never"], // http://eslint.org/docs/rules/comma-dangle
"no-cond-assign": [2, "always"], // http://eslint.org/docs/rules/no-cond-assign
"no-console": 1, // http://eslint.org/docs/rules/no-console
"no-debugger": 1, // http://eslint.org/docs/rules/no-debugger
"no-undef": 2, // https://eslint.org/docs/rules/no-undef
"no-const-assign": 2, // https://eslint.org/docs/rules/no-const-assign
"no-duplicate-imports": 2, // https://eslint.org/docs/rules/no-duplicate-imports
"no-alert": 1, // http://eslint.org/docs/rules/no-alert
"no-constant-condition": 1, // http://eslint.org/docs/rules/no-constant-condition
"no-dupe-keys": 2, // http://eslint.org/docs/rules/no-dupe-keys
Expand All @@ -79,7 +68,7 @@
"no-invalid-regexp": 2, // http://eslint.org/docs/rules/no-invalid-regexp
"no-irregular-whitespace": 2, // http://eslint.org/docs/rules/no-irregular-whitespace
"no-obj-calls": 2, // http://eslint.org/docs/rules/no-obj-calls
"no-reserved-keys": 2, // http://eslint.org/docs/rules/no-reserved-keys
"quote-props": [2, "as-needed", {"keywords": true, "unnecessary": false}], // http://eslint.org/docs/rules/no-reserved-keys
"no-sparse-arrays": 2, // http://eslint.org/docs/rules/no-sparse-arrays
"no-unreachable": 2, // http://eslint.org/docs/rules/no-unreachable
"use-isnan": 2, // http://eslint.org/docs/rules/use-isnan
Expand All @@ -88,7 +77,7 @@
/**
* Best practices
*/
"consistent-return": 2, // http://eslint.org/docs/rules/consistent-return
"consistent-return": [2, {"treatUndefinedAsUnspecified": true}], // http://eslint.org/docs/rules/consistent-return
"curly": [2, "multi-line"], // http://eslint.org/docs/rules/curly
"default-case": 2, // http://eslint.org/docs/rules/default-case
"dot-notation": [2, { // http://eslint.org/docs/rules/dot-notation
Expand Down Expand Up @@ -139,9 +128,10 @@
"quotes": [
0, "single", "avoid-escape" // http://eslint.org/docs/rules/quotes
],
"camelcase": [2, { // http://eslint.org/docs/rules/camelcase
"properties": "never"
}],
"camelcase": [1, { // http://eslint.org/docs/rules/camelcase
"properties": "never",
"allow": ["^UNSAFE_"]}
],
"comma-spacing": [2, { // http://eslint.org/docs/rules/comma-spacing
"before": false,
"after": true
Expand All @@ -163,7 +153,7 @@
"no-new-object": 2, // http://eslint.org/docs/rules/no-new-object
"no-spaced-func": 2, // http://eslint.org/docs/rules/no-spaced-func
"no-trailing-spaces": 2, // http://eslint.org/docs/rules/no-trailing-spaces
"no-wrap-func": 2, // http://eslint.org/docs/rules/no-wrap-func
"no-extra-parens": [2, "functions"], // http://eslint.org/docs/rules/no-wrap-func
"no-underscore-dangle": 0, // http://eslint.org/docs/rules/no-underscore-dangle
"one-var": [2, "never"], // http://eslint.org/docs/rules/one-var
"padded-blocks": [0, "never"], // http://eslint.org/docs/rules/padded-blocks
Expand All @@ -172,12 +162,12 @@
"before": false,
"after": true
}],
"space-after-keywords": 2, // http://eslint.org/docs/rules/space-after-keywords
"keyword-spacing": [2, {"after": true}], // http://eslint.org/docs/rules/space-after-keywords
"space-before-blocks": 2, // http://eslint.org/docs/rules/space-before-blocks
"space-before-function-paren": [2, "never"], // http://eslint.org/docs/rules/space-before-function-paren
"space-infix-ops": 2, // http://eslint.org/docs/rules/space-infix-ops
"space-return-throw-case": 2, // http://eslint.org/docs/rules/space-return-throw-case
"spaced-line-comment": 2, // http://eslint.org/docs/rules/spaced-line-comment
// "space-return-throw-case": 2, // http://eslint.org/docs/rules/space-return-throw-case
"spaced-comment": 2, // http://eslint.org/docs/rules/spaced-line-comment

/**
* JSX style
Expand All @@ -194,7 +184,7 @@
"react/no-did-update-set-state": 2, // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/no-did-update-set-state.md
"react/no-multi-comp": 0, // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/no-multi-comp.md
"react/no-unknown-property": 2, // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/no-unknown-property.md
"react/prop-types": [2, { ignore: ["children"]}], // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/prop-types.md
"react/prop-types": [2, { "ignore": ["children"]}], // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/prop-types.md
"react/react-in-jsx-scope": 2, // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/react-in-jsx-scope.md
"react/self-closing-comp": 2, // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/self-closing-comp.md
"react/wrap-multilines": 2, // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/wrap-multilines.md
Expand All @@ -213,10 +203,13 @@
"/^state$/",
"getInitialState",
"getChildContext",
"UNSAFE_componentWillMount",
"componentWillMount",
"componentDidMount",
"UNSAFE_componentWillReceiveProps",
"componentWillReceiveProps",
"shouldComponentUpdate",
"UNSAFE_componentWillUpdate",
"componentWillUpdate",
"componentDidUpdate",
"componentWillUnmount",
Expand Down
2 changes: 1 addition & 1 deletion MapStore2
Submodule MapStore2 updated 1459 files
51 changes: 43 additions & 8 deletions js/app.jsx
Original file line number Diff line number Diff line change
@@ -1,26 +1,32 @@
/**
* Copyright 2016, GeoSolutions Sas.
* Copyright 2019, GeoSolutions Sas.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree.
*/

const ConfigUtils = require('@mapstore/utils/ConfigUtils');
import assign from "object-assign";
import ConfigUtils from "@mapstore/utils/ConfigUtils";
import appCfg from "@mapstore/product/appConfig";
import plugins from "./plugins";
import main from "@mapstore/product/main";
import Login from "./plugins/Login";

/**
* Add custom (overriding) translations with:
*
* ConfigUtils.setConfigProp('translationsPath', ['./MapStore2/web/client/translations', './translations']);
*/
ConfigUtils.setConfigProp('translationsPath', './MapStore2/web/client/translations');
ConfigUtils.setConfigProp('translationsPath', ['./MapStore2/web/client/translations', './translations']);
ConfigUtils.setConfigProp('themePrefix', 'GeOrchestra');

/**
* Use a custom plugins configuration file with:
*
* ConfigUtils.setLocalConfigurationFile('localConfig.json');
*/
ConfigUtils.setLocalConfigurationFile('MapStore2/web/client/localConfig.json');
ConfigUtils.setLocalConfigurationFile('localConfig.json');

/**
* Use a custom application configuration file with:
Expand All @@ -37,13 +43,42 @@ ConfigUtils.setLocalConfigurationFile('MapStore2/web/client/localConfig.json');
* }]
* });
*/
const appConfig = require('@mapstore/product/appConfig');

const appConfig = assign({}, appCfg, {
pages: [{
name: "mapviewer",
path: "/",
component: require('@mapstore/product/pages/MapViewer')
}, {
name: "mapviewer",
path: "/viewer/:mapType/:mapId",
component: require('@mapstore/product/pages/MapViewer')
}, {
name: "maps",
path: "/maps",
component: require('@mapstore/product/pages/Maps')
}, {
name: "admin",
path: "/admin",
component: require('./pages/Admin').default
}],
storeOpts: {
persist: {
// we don't want security to be persisted, so that we get updated headers for each reload
whitelist: []
}
}
});
/**
* Define a custom list of plugins with:
*
* const plugins = require('./plugins');
*/
const plugins = require('@mapstore/product/plugins');
const appPlugins = {
plugins: {
...plugins.plugins,
LoginPlugin: Login
},
requires: plugins.requires
};

require('@mapstore/product/main')(appConfig, plugins);
main(appConfig, appPlugins);
23 changes: 23 additions & 0 deletions js/components/User.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
* Copyright 2019, GeoSolutions Sas.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree.
*/
import React, { useEffect } from "react";
import loadingState from "@mapstore/components/misc/enhancers/loadingState";
const UserInfo = ({user, error}) => <span>{error && "GUEST" || user.role}</span>;
const LoadingUser = loadingState(({ user, error }) => !user && !error)(UserInfo);
const User = ({className, user, error, ...props}) => {
return <div className={className}><LoadingUser user={user} error={error} {...props} /></div>;
};

export const AutoLogin = ({ onLogin }) => {
useEffect(() => {
onLogin("", "");
}, []);
return null;
};

export default User;
23 changes: 23 additions & 0 deletions js/pages/Admin.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
* Copyright 2019, GeoSolutions Sas.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree.
*/
import React from "react";
import {connect} from "react-redux";
import Page from "@mapstore/containers/Page";

const AdminPage = ({plugins, match, role}) => {
return (<Page
id={role === "ADMIN" ? "admin" : "notallowed"}
mode="desktop"
plugins={plugins}
params={match.params}
/>);
};

export default connect(state => ({
role: state.security && state.security.user && state.security.user.role || 'GUEST'
}))(AdminPage);
Loading

0 comments on commit 7b5ac64

Please sign in to comment.