Skip to content

Commit

Permalink
Fixes georchestra#37: initial implementation of security integration …
Browse files Browse the repository at this point in the history
…(automatic login using georchestra security headers)
  • Loading branch information
mbarto committed Oct 17, 2019
1 parent adfe84f commit c93e690
Show file tree
Hide file tree
Showing 22 changed files with 1,099 additions and 117 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
43 changes: 35 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,34 @@ 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: "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);
109 changes: 109 additions & 0 deletions js/plugins.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
/**
* Copyright 2016, 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.
*/

/**
* Please, keep them sorted alphabetically
*/
module.exports = {
plugins: {
// framework plugins
AddGroupPlugin: require('@mapstore/plugins/AddGroup').default,
AnnotationsPlugin: require('@mapstore/plugins/Annotations'),
AutoMapUpdatePlugin: require('@mapstore/plugins/AutoMapUpdate'),
BackgroundSelectorPlugin: require('@mapstore/plugins/BackgroundSelector'),
BackgroundSwitcherPlugin: require('@mapstore/plugins/BackgroundSwitcher'),
BurgerMenuPlugin: require('@mapstore/plugins/BurgerMenu'),
CRSSelectorPlugin: require('@mapstore/plugins/CRSSelector'),
ContentTabs: require('@mapstore/plugins/ContentTabs'),
CookiePlugin: require('@mapstore/plugins/Cookie'),
CreateNewMapPlugin: require('@mapstore/plugins/CreateNewMap'),
Dashboard: require('@mapstore/plugins/Dashboard'),
DashboardEditor: require('@mapstore/plugins/DashboardEditor'),
DashboardsPlugin: require('@mapstore/plugins/Dashboards'),
DetailsPlugin: require('@mapstore/plugins/Details'),
DrawerMenuPlugin: require('@mapstore/plugins/DrawerMenu'),
ExpanderPlugin: require('@mapstore/plugins/Expander'),
FeatureEditorPlugin: require('@mapstore/plugins/FeatureEditor'),
FeaturedMaps: require('@mapstore/plugins/FeaturedMaps'),
FeedbackMaskPlugin: require('@mapstore/plugins/FeedbackMask'),
FloatingLegendPlugin: require('@mapstore/plugins/FloatingLegend'),
FullScreenPlugin: require('@mapstore/plugins/FullScreen'),
GeoStoryPlugin: require('@mapstore/plugins/GeoStory').default,
GeoStoryEditorPlugin: require('@mapstore/plugins/GeoStoryEditor').default,
GeoStorySavePlugin: require('@mapstore/plugins/GeoStorySave').GeoStorySave,
GeoStorySaveAsPlugin: require('@mapstore/plugins/GeoStorySave').GeoStorySaveAs,
GeoStoryNavigationPlugin: require('@mapstore/plugins/GeoStoryNavigation').default,
GlobeViewSwitcherPlugin: require('@mapstore/plugins/GlobeViewSwitcher'),
GoFull: require('@mapstore/plugins/GoFull'),
GridContainerPlugin: require('@mapstore/plugins/GridContainer'),
GroupManagerPlugin: require('@mapstore/plugins/manager/GroupManager'),
HelpLinkPlugin: require('@mapstore/plugins/HelpLink'),
HelpPlugin: require('@mapstore/plugins/Help'),
HomePlugin: require('@mapstore/plugins/Home'),
IdentifyPlugin: require('@mapstore/plugins/Identify'),
LanguagePlugin: require('@mapstore/plugins/Language'),
LocatePlugin: require('@mapstore/plugins/Locate'),
LoginPlugin: require('@mapstore/plugins/Login'),
ManagerMenuPlugin: require('@mapstore/plugins/manager/ManagerMenu'),
ManagerPlugin: require('@mapstore/plugins/manager/Manager'),
MapExportPlugin: require('@mapstore/plugins/MapExport'),
MapFooterPlugin: require('@mapstore/plugins/MapFooter'),
MapImportPlugin: require('@mapstore/plugins/MapImport'),
MapLoadingPlugin: require('@mapstore/plugins/MapLoading'),
MapPlugin: require('@mapstore/plugins/Map'),
MapSearchPlugin: require('@mapstore/plugins/MapSearch'),
MapsPlugin: require('@mapstore/plugins/Maps'),
MeasurePlugin: require('@mapstore/plugins/Measure'),
MediaEditorPlugin: require('@mapstore/plugins/MediaEditor').default,
MetadataExplorerPlugin: require('@mapstore/plugins/MetadataExplorer'),
MousePositionPlugin: require('@mapstore/plugins/MousePosition'),
NotificationsPlugin: require('@mapstore/plugins/Notifications'),
OmniBarPlugin: require('@mapstore/plugins/OmniBar'),
PlaybackPlugin: require('@mapstore/plugins/Playback.jsx'),
PrintPlugin: require('@mapstore/plugins/Print'),
QueryPanelPlugin: require('@mapstore/plugins/QueryPanel'),
RedirectPlugin: require('@mapstore/plugins/Redirect'),
RedoPlugin: require('@mapstore/plugins/History'),
RulesDataGridPlugin: require('@mapstore/plugins/RulesDataGrid'),
RulesEditorPlugin: require('@mapstore/plugins/RulesEditor'),
RulesManagerFooter: require('@mapstore/plugins/RulesManagerFooter'),
SaveAsPlugin: require('@mapstore/plugins/SaveAs'),
SavePlugin: require('@mapstore/plugins/Save'),
SaveStoryPlugin: require('@mapstore/plugins/GeoStorySave'),
ScaleBoxPlugin: require('@mapstore/plugins/ScaleBox'),
ScrollTopPlugin: require('@mapstore/plugins/ScrollTop'),
SearchPlugin: require('@mapstore/plugins/Search'),
SearchServicesConfigPlugin: require('@mapstore/plugins/SearchServicesConfig'),
SettingsPlugin: require('@mapstore/plugins/Settings'),
SharePlugin: require('@mapstore/plugins/Share'),
SnapshotPlugin: require('@mapstore/plugins/Snapshot'),
StyleEditorPlugin: require('@mapstore/plugins/StyleEditor'),
TOCItemsSettingsPlugin: require('@mapstore/plugins/TOCItemsSettings'),
TOCPlugin: require('@mapstore/plugins/TOC'),
ThematicLayerPlugin: require('@mapstore/plugins/ThematicLayer'),
ThemeSwitcherPlugin: require('@mapstore/plugins/ThemeSwitcher'),
TimelinePlugin: require('@mapstore/plugins/Timeline'),
ToolbarPlugin: require('@mapstore/plugins/Toolbar'),
TutorialPlugin: require('@mapstore/plugins/Tutorial'),
UndoPlugin: require('@mapstore/plugins/History'),
UserManagerPlugin: require('@mapstore/plugins/manager/UserManager'),
VersionPlugin: require('@mapstore/plugins/Version'),
WFSDownloadPlugin: require('@mapstore/plugins/WFSDownload'),
WidgetsBuilderPlugin: require('@mapstore/plugins/WidgetsBuilder'),
WidgetsPlugin: require('@mapstore/plugins/Widgets'),
WidgetsTrayPlugin: require('@mapstore/plugins/WidgetsTray'),
ZoomAllPlugin: require('@mapstore/plugins/ZoomAll'),
ZoomInPlugin: require('@mapstore/plugins/ZoomIn'),
ZoomOutPlugin: require('@mapstore/plugins/ZoomOut'),
NotAllowedPlugin: require('./plugins/NotAllowed').default
},
requires: {
ReactSwipe: require('react-swipeable-views').default,
SwipeHeader: require('@mapstore/components/data/identify/SwipeHeader')
}
};
Loading

0 comments on commit c93e690

Please sign in to comment.