From 581191cbb3e30e5c97f7b61e4c7f405fbbf2cca9 Mon Sep 17 00:00:00 2001 From: etj Date: Tue, 24 Jan 2017 15:27:37 +0100 Subject: [PATCH] Improve LDAP support (#82). Externalize DB/LDAP selection. Add caching to LDAP queries. Downgrade log4j version to 1.x (align to GeoServer) Upgrade spring-ldap version to 2.x (align to Spring 4 core) Upgrade geoserver-manager to 1.6. Clean up obsolete pre-3.0 methods (user and groups refs by id) Clean up configuration files (#16) Remove some dead code in GWT client. Improve users and groups loading in GWT client. Clean up misplaced log4j.properties files. Authorization request filters now can only specify either the user or the group. --- .gitignore | 13 + src/gui/core/plugin/mapsui/pom.xml | 17 +- src/gui/core/plugin/userui/pom.xml | 518 +++++++++--------- .../client/controller/ProfilesController.java | 11 +- .../client/controller/RulesController.java | 59 +- .../service/GsUsersManagerRemoteService.java | 18 +- .../service/ProfilesManagerRemoteService.java | 21 +- .../gui/client/view/ProfilesView.java | 186 +------ .../geofence/gui/client/view/RulesView.java | 331 +---------- .../gui/client/widget/AddGsUserWidget.java | 4 +- .../gui/client/widget/AddProfileWidget.java | 4 +- .../gui/client/widget/ProfileGridWidget.java | 352 +++++------- .../gui/client/widget/UserGridWidget.java | 7 +- .../dialog/ProfileDetailsEditDialog.java | 154 ------ .../rule/detail/ProfileDetailsGridWidget.java | 517 ----------------- .../rule/detail/ProfileDetailsTabItem.java | 81 --- .../rule/detail/ProfileDetailsWidget.java | 85 --- .../rule/detail/UserDetailsInfoWidget.java | 162 ------ .../rule/detail/UserDetailsTabItem.java | 11 +- .../widget/rule/detail/UserDetailsWidget.java | 47 +- .../server/gwt/GsUsersManagerServiceImpl.java | 19 +- .../gwt/ProfilesManagerServiceImpl.java | 22 +- .../service/IGsUsersManagerService.java | 16 +- .../service/IProfilesManagerService.java | 15 +- .../impl/GsUsersManagerServiceImpl.java | 131 +---- .../gui/server/service/impl/LoginService.java | 6 +- .../impl/ProfilesManagerServiceImpl.java | 120 +--- .../service/impl/RulesManagerServiceImpl.java | 215 ++------ .../impl/WorkspacesManagerServiceImpl.java | 48 +- .../geofence/gui/client/GeofenceEvents.java | 23 +- .../gui/client/model/GSUserModel.java | 21 +- .../gui/client/model/UserGroupModel.java | 16 +- .../client/model/data/ProfileCustomProps.java | 204 ------- .../model/data/UserLimitsInfoModel.java | 197 ------- .../src/main/resources/log4j.properties | 13 - src/gui/pom.xml | 351 ++++++------ src/gui/web/pom.xml | 28 +- .../server/service/impl/StartupService.java | 10 +- .../geofence-datasource-ovr.properties | 51 +- .../geofence-datasource-ovr.properties.sample | 59 +- .../main/resources/geofence-ldap.properties | 9 - .../web/src/main/resources/log4j.properties | 27 - src/gui/web/src/main/resources/log4j.xml | 84 +-- src/gui/web/war/WEB-INF/remoting-servlet.xml | 3 +- src/gui/web/war/WEB-INF/web.xml | 20 +- .../geoserver/geofence/core/model/GSUser.java | 130 ++--- .../geofence/core/model/UserGroup.java | 110 +--- src/services/core/persistence/pom.xml | 42 +- .../geofence/core/dao/GSUserDAO.java | 12 +- .../geofence/core/dao/RegistrableDAO.java | 12 + .../geofence/core/dao/UserGroupDAO.java | 7 +- .../core/dao/impl/AdminRuleDAOImpl.java | 7 +- .../geofence/core/dao/impl/GFUserDAOImpl.java | 6 +- .../core/dao/impl/GSInstanceDAOImpl.java | 6 +- .../geofence/core/dao/impl/GSUserDAOImpl.java | 40 +- .../core/dao/impl/LayerDetailsDAOImpl.java | 6 +- .../core/dao/impl/PrioritizableDAOImpl.java | 19 +- .../geofence/core/dao/impl/RuleDAOImpl.java | 6 +- .../core/dao/impl/RuleLimitsDAOImpl.java | 6 +- .../core/dao/impl/UserGroupDAOImpl.java | 7 +- .../core/dao/util/GeofenceDaoRegistry.java | 109 ++++ .../src/main/resources/applicationContext.xml | 67 ++- .../geofence/core/dao/BaseDAOTest.java | 22 +- .../geofence/core/dao/UserDAOTest.java | 66 +-- .../core/dao/util/DaoRegistryTest.java | 80 +++ .../resources/geofence-datasource.properties | 15 - .../geofence/services/UserAdminService.java | 8 +- .../geofence/services/dto/ShortGroup.java | 10 +- .../geofence/services/dto/ShortUser.java | 10 +- .../services/exception/NotFoundServiceEx.java | 8 +- .../geoserver/geofence/spi/UserResolver.java | 4 +- src/services/core/services-impl/pom.xml | 52 +- .../services/AdminRuleAdminServiceImpl.java | 19 +- .../services/AuthorizationServiceImpl.java | 9 +- .../services/DefaultUserResolver.java | 33 +- .../services/GFUserAdminServiceImpl.java | 8 +- .../services/InstanceAdminServiceImpl.java | 40 +- .../services/RuleAdminServiceImpl.java | 6 +- .../services/RuleReaderServiceImpl.java | 50 +- .../services/UserAdminServiceImpl.java | 53 +- .../services/UserGroupAdminServiceImpl.java | 23 +- .../geofence/services/util/FilterUtils.java | 6 +- .../services/RuleReaderCatalogModeTest.java | 10 +- .../services/RuleReaderServiceImplTest.java | 232 ++++---- .../geofence/services/ServiceTestBase.java | 6 +- .../services/UserAdminServiceImplTest.java | 43 +- .../test/AbstractSpringContextTest.java | 6 +- src/services/core/webtest/pom.xml | 13 +- .../geofence/servicetest/MainTest.java | 6 +- src/services/modules/ldap/pom.xml | 122 +++-- .../dao/ldap/LdapAttributesMapper.java | 22 - .../geofence/dao/utils/LdapUtils.java | 63 --- .../geofence/ldap/LdapAttributesMapper.java | 21 + .../ldap/dao/impl/BaseAttributesMapper.java | 113 ++-- .../geofence/ldap/dao/impl/BaseDAO.java | 256 --------- .../ldap/dao/impl/GSUserAttributesMapper.java | 56 +- .../ldap/dao/impl/GSUserDAOLdapImpl.java | 198 +++---- .../geofence/ldap/dao/impl/LDAPBaseDAO.java | 282 ++++++++++ .../ldap/dao/impl/RuleDAOLdapImpl.java | 155 ------ .../dao/impl/UserGroupAttributesMapper.java | 49 +- .../ldap/dao/impl/UserGroupDAOLdapImpl.java | 30 +- .../geofence/ldap/utils/LdapUtils.java | 47 ++ ...cationContext-geofence-ldap-datasource.xml | 60 ++ ...licationContext-geofenceLdapDatasource.xml | 68 --- .../resources/applicationContext-override.xml | 59 -- .../src/main/resources/applicationContext.xml | 108 ++-- .../geofence/ldap/dao/impl/BaseDAOTest.java | 117 ++-- .../ldap/dao/impl/GSUserDAOLdapImplTest.java | 129 +++-- .../dao/impl/UserGroupDAOLdapImplTest.java | 91 +-- .../src/test/resources/applicationContext.xml | 84 --- .../modules/ldap/src/test/resources/data.ldif | 70 ++- .../geofence-datasource-ovr.properties | 40 ++ .../resources/geofence-ldap-ovr.properties | 5 - .../test/resources/geofence-ldap.properties | 10 - .../ldap/src/test/resources/log4j.properties | 18 + src/services/modules/login/impl/pom.xml | 31 +- .../geofence/login/LoginServiceImpl.java | 7 +- .../login/cxf/BasicAuthInterceptor.java | 8 +- .../geofence/login/util/GrantAll.java | 10 +- .../geofence/login/util/MD5Util.java | 6 +- .../geofence/login/util/SessionManager.java | 8 +- .../resources/applicationContext-test.xml | 29 +- src/services/modules/rest/api/pom.xml | 10 +- .../services/rest/RESTGSInstanceService.java | 6 +- .../services/rest/model/RESTInputRule.java | 19 +- .../services/rest/model/RESTOutputRule.java | 20 +- .../rest/model/ModelPrintoutFakeTest.java | 4 +- src/services/modules/rest/client/pom.xml | 11 +- .../services/rest/GeoFenceClientTest.java | 61 ++- src/services/modules/rest/impl/pom.xml | 19 +- .../rest/auth/AuthenticationHandler.java | 8 +- .../rest/auth/AuthorizationHandler.java | 6 +- .../GeofenceAuthenticationInterceptor.java | 8 +- .../rest/auth/GeofenceSecurityContext.java | 8 +- .../rest/impl/BaseRESTServiceImpl.java | 35 +- .../rest/impl/RESTAdminRuleServiceImpl.java | 28 +- .../rest/impl/RESTBatchServiceImpl.java | 7 +- .../rest/impl/RESTConfigServiceImpl.java | 12 +- .../rest/impl/RESTInstanceServiceImpl.java | 18 +- .../rest/impl/RESTRuleServiceImpl.java | 38 +- .../rest/impl/RESTUserGroupServiceImpl.java | 15 +- .../rest/impl/RESTUserServiceImpl.java | 25 +- .../services/rest/utils/InstanceCleaner.java | 7 +- .../rest/utils/MultiPolygonUtils.java | 8 +- .../services/rest/impl/RESTBaseTest.java | 6 +- .../rest/impl/RESTRuleServiceImplTest.java | 10 +- .../impl/RESTUserGroupServiceImplTest.java | 6 +- .../rest/impl/RESTUserServiceImplTest.java | 8 +- .../rest/model/ModelPrintoutFakeTest.java | 6 +- .../impl/src/test/resources/xsl/rules.xsl | 88 +++ src/services/modules/rest/test/pom.xml | 16 +- .../services/servicetest/MainTest.java | 6 +- src/services/pom.xml | 55 +- 153 files changed, 2956 insertions(+), 5726 deletions(-) delete mode 100644 src/gui/core/plugin/userui/src/main/java/org/geoserver/geofence/gui/client/widget/dialog/ProfileDetailsEditDialog.java delete mode 100644 src/gui/core/plugin/userui/src/main/java/org/geoserver/geofence/gui/client/widget/rule/detail/ProfileDetailsGridWidget.java delete mode 100644 src/gui/core/plugin/userui/src/main/java/org/geoserver/geofence/gui/client/widget/rule/detail/ProfileDetailsTabItem.java delete mode 100644 src/gui/core/plugin/userui/src/main/java/org/geoserver/geofence/gui/client/widget/rule/detail/ProfileDetailsWidget.java delete mode 100644 src/gui/core/plugin/userui/src/main/java/org/geoserver/geofence/gui/client/widget/rule/detail/UserDetailsInfoWidget.java delete mode 100644 src/gui/core/resources/src/main/java/org/geoserver/geofence/gui/client/model/data/ProfileCustomProps.java delete mode 100644 src/gui/core/resources/src/main/java/org/geoserver/geofence/gui/client/model/data/UserLimitsInfoModel.java delete mode 100644 src/gui/core/resources/src/main/resources/log4j.properties delete mode 100644 src/gui/web/src/main/resources/geofence-ldap.properties delete mode 100644 src/gui/web/src/main/resources/log4j.properties create mode 100644 src/services/core/persistence/src/main/java/org/geoserver/geofence/core/dao/RegistrableDAO.java create mode 100644 src/services/core/persistence/src/main/java/org/geoserver/geofence/core/dao/util/GeofenceDaoRegistry.java create mode 100644 src/services/core/persistence/src/test/java/org/geoserver/geofence/core/dao/util/DaoRegistryTest.java delete mode 100644 src/services/core/persistence/src/test/resources/geofence-datasource.properties delete mode 100644 src/services/modules/ldap/src/main/java/org/geoserver/geofence/dao/ldap/LdapAttributesMapper.java delete mode 100644 src/services/modules/ldap/src/main/java/org/geoserver/geofence/dao/utils/LdapUtils.java create mode 100644 src/services/modules/ldap/src/main/java/org/geoserver/geofence/ldap/LdapAttributesMapper.java delete mode 100644 src/services/modules/ldap/src/main/java/org/geoserver/geofence/ldap/dao/impl/BaseDAO.java create mode 100644 src/services/modules/ldap/src/main/java/org/geoserver/geofence/ldap/dao/impl/LDAPBaseDAO.java delete mode 100644 src/services/modules/ldap/src/main/java/org/geoserver/geofence/ldap/dao/impl/RuleDAOLdapImpl.java create mode 100644 src/services/modules/ldap/src/main/java/org/geoserver/geofence/ldap/utils/LdapUtils.java create mode 100644 src/services/modules/ldap/src/main/resources/applicationContext-geofence-ldap-datasource.xml delete mode 100644 src/services/modules/ldap/src/main/resources/applicationContext-geofenceLdapDatasource.xml delete mode 100644 src/services/modules/ldap/src/main/resources/applicationContext-override.xml delete mode 100644 src/services/modules/ldap/src/test/resources/applicationContext.xml create mode 100644 src/services/modules/ldap/src/test/resources/geofence-datasource-ovr.properties delete mode 100644 src/services/modules/ldap/src/test/resources/geofence-ldap-ovr.properties delete mode 100644 src/services/modules/ldap/src/test/resources/geofence-ldap.properties create mode 100644 src/services/modules/ldap/src/test/resources/log4j.properties create mode 100644 src/services/modules/rest/impl/src/test/resources/xsl/rules.xsl diff --git a/.gitignore b/.gitignore index a7d0f0a0..62f65a87 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,16 @@ target *iml *idea + +src/gui/core/plugin/mapsui/war/ +src/gui/core/plugin/userui/war/ + +src/gui/web/war/WEB-INF/classes/ +src/gui/web/war/WEB-INF/deploy/ +src/gui/web/war/WEB-INF/spatial-lib/ +src/gui/web/war/geofence/ + +**/gwt-unitCache/ +**/geofence_db/ +**/nbproject/ + diff --git a/src/gui/core/plugin/mapsui/pom.xml b/src/gui/core/plugin/mapsui/pom.xml index cf13c80b..78f7f2fe 100644 --- a/src/gui/core/plugin/mapsui/pom.xml +++ b/src/gui/core/plugin/mapsui/pom.xml @@ -1,11 +1,9 @@ 4.0.0 @@ -26,15 +24,6 @@ UTF-8 - - @@ -156,8 +145,8 @@ - org.apache.logging.log4j - log4j-api + log4j + log4j diff --git a/src/gui/core/plugin/userui/pom.xml b/src/gui/core/plugin/userui/pom.xml index a0df1b3b..1ea21640 100644 --- a/src/gui/core/plugin/userui/pom.xml +++ b/src/gui/core/plugin/userui/pom.xml @@ -1,295 +1,293 @@ - 4.0.0 + 4.0.0 - - org.geoserver.geofence - geofence-gui-plugin - 3.2-SNAPSHOT - + + org.geoserver.geofence + geofence-gui-plugin + 3.2-SNAPSHOT + - org.geoserver.geofence - geofence-gui-userui - jar + org.geoserver.geofence + geofence-gui-userui + jar - GeoFence - GUI - User plugin + GeoFence - GUI - User plugin - - UTF-8 - + + UTF-8 + - + - - com.google.gwt - gwt-user - provided - + + com.google.gwt + gwt-user + provided + - - - com.extjs - gxt - + + + com.extjs + gxt + - - - - - org.geoserver.geofence - geofence-gui-resources - - - org.geoserver.geofence - geofence-login-api - - - org.geoserver.geofence - geofence-generic-api - + + + + + org.geoserver.geofence + geofence-gui-resources + + + org.geoserver.geofence + geofence-login-api + + + org.geoserver.geofence + geofence-generic-api + - - it.geosolutions - geoserver-manager - + + it.geosolutions + geoserver-manager + - - - - - net.sf.json-lib - json-lib - 2.4 - jdk15 - + + + + + net.sf.json-lib + json-lib + 2.4 + jdk15 + - - - - - org.springframework.security - spring-security-acl - - - org.springframework - spring-expression - - - - - org.springframework.security - spring-security-core - - - org.springframework - spring-expression - - - - - org.springframework.security - spring-security-taglibs - - - org.springframework - spring-expression - - - + + + + + org.springframework.security + spring-security-acl + + + org.springframework + spring-expression + + + + + org.springframework.security + spring-security-core + + + org.springframework + spring-expression + + + + + org.springframework.security + spring-security-taglibs + + + org.springframework + spring-expression + + + - - commons-httpclient - commons-httpclient - + + commons-httpclient + commons-httpclient + - org.apache.logging.log4j - log4j-api + log4j + log4j - - - org.springframework - spring-test - test - - - commons-collections - commons-collections - - - xerces - xercesImpl - - - + + + org.springframework + spring-test + test + + + commons-collections + commons-collections + + + xerces + xercesImpl + + + - - junit - junit - 4.7 - test - - + + junit + junit + 4.7 + test + + - + - - - - org.codehaus.mojo - gwt-maven-plugin - ${gwt.version} - - true - war - true - true - -Xmx1024M -Xss1024k -Dgwt.nowarn.legacy.tools - - - - - - resources - - - - clean - clean - - clean - - - - compile - compile - - compile - - - - generateAsync - generate-sources - - generateAsync - - - - + + + + org.codehaus.mojo + gwt-maven-plugin + ${gwt.version} + + true + war + true + true + -Xmx1024M -Xss1024k -Dgwt.nowarn.legacy.tools + + + + + + resources + + + + clean + clean + + clean + + + + compile + compile + + compile + + + + generateAsync + generate-sources + + generateAsync + + + + - - - org.apache.maven.plugins - maven-compiler-plugin + + + org.apache.maven.plugins + maven-compiler-plugin 3.1 - - 1.5 - 1.5 - - + + 1.5 + 1.5 + + - - maven-resources-plugin - + + maven-resources-plugin + - - org.apache.maven.plugins - maven-antrun-plugin - - - remove-build-files - clean - - - - - - - - run - - - - - + + org.apache.maven.plugins + maven-antrun-plugin + + + remove-build-files + clean + + + + + + + + run + + + + + - - - - ${basedir}/src/main/java - - **/*.txt - **/*.sql - **/*.html - **/*.xml - **/*.utf - **/*.properties - **/*.serialized - **/*.xsd - META-INF/*.jai - META-INF/mailcap - META-INF/services/** - applicationContext.xml - **/*.ftl - **/*.css - **/*.js - **/*.png - **/*.gif - **/*.sld - **/*.ico - - - - ${basedir}/src/main/resources - - **/* - - - + + + + ${basedir}/src/main/java + + **/*.txt + **/*.sql + **/*.html + **/*.xml + **/*.utf + **/*.properties + **/*.serialized + **/*.xsd + META-INF/*.jai + META-INF/mailcap + META-INF/services/** + applicationContext.xml + **/*.ftl + **/*.css + **/*.js + **/*.png + **/*.gif + **/*.sld + **/*.ico + + + + ${basedir}/src/main/resources + + **/* + + + - + - - - disableUsersUI - - - - maven-antrun-plugin - 1.7 - - - compile - - - - - - - - run - - - - - - - - + + + disableUsersUI + + + + maven-antrun-plugin + 1.7 + + + compile + + + + + + + + run + + + + + + + + diff --git a/src/gui/core/plugin/userui/src/main/java/org/geoserver/geofence/gui/client/controller/ProfilesController.java b/src/gui/core/plugin/userui/src/main/java/org/geoserver/geofence/gui/client/controller/ProfilesController.java index b4aa209b..07c235d8 100644 --- a/src/gui/core/plugin/userui/src/main/java/org/geoserver/geofence/gui/client/controller/ProfilesController.java +++ b/src/gui/core/plugin/userui/src/main/java/org/geoserver/geofence/gui/client/controller/ProfilesController.java @@ -1,4 +1,4 @@ -/* (c) 2014 Open Source Geospatial Foundation - all rights reserved +/* (c) 2014 - 2017 Open Source Geospatial Foundation - all rights reserved * This code is licensed under the GPL 2.0 license, available at the root * application directory. */ @@ -53,21 +53,12 @@ public ProfilesController() registerEventTypes( GeofenceEvents.INIT_MAPS_UI_MODULE, - - - GeofenceEvents.UPDATE_PROFILE, GeofenceEvents.DELETE_PROFILE, GeofenceEvents.SAVE_PROFILE, - - - GeofenceEvents.CREATE_NEW_PROFILE, - - - GeofenceEvents.ATTACH_BOTTOM_TAB_WIDGETS); } diff --git a/src/gui/core/plugin/userui/src/main/java/org/geoserver/geofence/gui/client/controller/RulesController.java b/src/gui/core/plugin/userui/src/main/java/org/geoserver/geofence/gui/client/controller/RulesController.java index deb1ecaf..6d26272e 100644 --- a/src/gui/core/plugin/userui/src/main/java/org/geoserver/geofence/gui/client/controller/RulesController.java +++ b/src/gui/core/plugin/userui/src/main/java/org/geoserver/geofence/gui/client/controller/RulesController.java @@ -1,4 +1,4 @@ -/* (c) 2014 Open Source Geospatial Foundation - all rights reserved +/* (c) 2014 - 2017 Open Source Geospatial Foundation - all rights reserved * This code is licensed under the GPL 2.0 license, available at the root * application directory. */ @@ -77,17 +77,11 @@ public RulesController() registerEventTypes(GeofenceEvents.INIT_MAPS_UI_MODULE, GeofenceEvents.ATTACH_BOTTOM_TAB_WIDGETS, - - - GeofenceEvents.RULE_UPDATE_GRID_COMBO, GeofenceEvents.RULE_UPDATE_EDIT_GRID_COMBO, GeofenceEvents.RULE_APPLY_CHANGES_GRID_COMBO, GeofenceEvents.RULE_ADD, GeofenceEvents.RULE_DEL, GeofenceEvents.RULE_PRIORITY_UP, GeofenceEvents.RULE_PRIORITY_DOWN, GeofenceEvents.RULE_SAVE, - - - GeofenceEvents.EDIT_RULE_DETAILS, GeofenceEvents.EDIT_RULE, GeofenceEvents.EDIT_RULE_UPDATE, GeofenceEvents.RULE_CUSTOM_PROP_ADD, GeofenceEvents.RULE_CUSTOM_PROP_DEL, GeofenceEvents.RULE_CUSTOM_PROP_UPDATE_KEY, @@ -96,50 +90,22 @@ public RulesController() GeofenceEvents.RULE_EDITOR_DIALOG_HIDE,GeofenceEvents.RULE_EDITOR_DIALOG_SHOW, - - - GeofenceEvents.INJECT_WKT, GeoGWTEvents.INJECT_WKT, - GeofenceEvents.ATTRIBUTE_UPDATE_GRID_COMBO, - - - GeofenceEvents.SAVE_LAYER_DETAILS, GeofenceEvents.LOAD_LAYER_DETAILS, - - - GeofenceEvents.AVAILABLE_STYLES_UPDATE_GRID, - - - - GeofenceEvents.RULE_PROFILE_CUSTOM_PROP_UPDATE_KEY, - GeofenceEvents.RULE_PROFILE_CUSTOM_PROP_UPDATE_VALUE, - GeofenceEvents.RULE_PROFILE_CUSTOM_PROP_DEL, - GeofenceEvents.RULE_PROFILE_CUSTOM_PROP_ADD, - GeofenceEvents.RULE_PROFILE_CUSTOM_PROP_APPLY_CHANGES, - - - - GeofenceEvents.EDIT_PROFILE_DETAILS, - - - GeofenceEvents.SAVE_LAYER_LIMITS, GeofenceEvents.LOAD_LAYER_LIMITS, GeofenceEvents.LOAD_RULES, - - - - GeofenceEvents.EDIT_USER_DETAILS, GeofenceEvents.LOAD_USER_LIMITS, - GeofenceEvents.SAVE_USER_LIMITS, GeofenceEvents.SAVE_USER_GROUPS); + GeofenceEvents.EDIT_USER_DETAILS, + GeofenceEvents.SAVE_USER_GROUPS); } @@ -889,13 +855,14 @@ public boolean checkUniqueRule(List list, RuleModel rule) { RuleModel r = (RuleModel) itr.next(); if ((r.getId() != rule.getId()) && - (((r.getUsername() != null) && (rule.getUsername()!= null) && r.getUsername().equals(rule.getUsername())) || ((r.getUsername() == null) && (rule.getUsername()== null))) && - (((r.getRolename() != null) && (rule.getRolename()!= null) && r.getRolename().equals(rule.getRolename())) || ((r.getRolename() == null) && (rule.getRolename()== null))) && - (((r.getInstance() != null) && (rule.getInstance()!= null) && r.getInstance().getName().equals(rule.getInstance().getName())) || ((r.getInstance() == null) && (rule.getInstance() == null))) && - (((r.getService() != null) && (rule.getService() != null) && r.getService().equals(rule.getService())) || ((r.getService() == null) && (rule.getService() == null))) && - (((r.getRequest() != null) && (rule.getRequest() != null) && r.getRequest().equals(rule.getRequest())) || ((r.getRequest() == null) && (rule.getRequest() == null))) && - (((r.getWorkspace()!= null) && (rule.getWorkspace() != null) && r.getWorkspace().equals(rule.getWorkspace())) || ((r.getWorkspace() == null) && (rule.getWorkspace() == null))) && - (((r.getLayer() != null) && (rule.getLayer() != null) && r.getLayer().equals(rule.getLayer())) || ((r.getLayer() == null) && (rule.getLayer() == null)))) + (isEqual(r.getUsername(), rule.getUsername())) && + (isEqual(r.getRolename(), rule.getRolename())) && + (isEqual(r.getInstance(), rule.getInstance())) && + (isEqual(r.getSourceIPRange(), rule.getSourceIPRange())) && + (isEqual(r.getService(), rule.getService())) && + (isEqual(r.getRequest(), rule.getRequest())) && + (isEqual(r.getWorkspace(), rule.getWorkspace())) && + (isEqual(r.getLayer(), rule.getLayer()))) { res = true; } @@ -905,6 +872,10 @@ public boolean checkUniqueRule(List list, RuleModel rule) return res; } + private boolean isEqual(Object s1, Object s2) { + return ((s1 != null) && (s2 != null) && s1.equals(s2)) || + ((s1 == null) && (s2 == null)); + } /** * Forward to tab widget. * diff --git a/src/gui/core/plugin/userui/src/main/java/org/geoserver/geofence/gui/client/service/GsUsersManagerRemoteService.java b/src/gui/core/plugin/userui/src/main/java/org/geoserver/geofence/gui/client/service/GsUsersManagerRemoteService.java index 52534a83..ed9419b2 100644 --- a/src/gui/core/plugin/userui/src/main/java/org/geoserver/geofence/gui/client/service/GsUsersManagerRemoteService.java +++ b/src/gui/core/plugin/userui/src/main/java/org/geoserver/geofence/gui/client/service/GsUsersManagerRemoteService.java @@ -1,4 +1,4 @@ -/* (c) 2014 Open Source Geospatial Foundation - all rights reserved +/* (c) 2014 - 2017 Open Source Geospatial Foundation - all rights reserved * This code is licensed under the GPL 2.0 license, available at the root * application directory. */ @@ -12,8 +12,6 @@ import org.geoserver.geofence.gui.client.ApplicationException; import org.geoserver.geofence.gui.client.model.GSUserModel; import org.geoserver.geofence.gui.client.model.UsernameModel; -import org.geoserver.geofence.gui.client.model.data.UserLimitsInfoModel; - /** * The Interface GsUsersManagerRemoteService. @@ -55,20 +53,6 @@ public interface GsUsersManagerRemoteService extends RemoteService * the application exception */ public void deleteGsUser(GSUserModel user) throws ApplicationException; - - /** - * @param user - * @return UserLimitInfo - * @throws ApplicationException - */ - public UserLimitsInfoModel getUserLimitsInfo(GSUserModel user) throws ApplicationException; - - /** - * @param user - * @return UserLimitInfo - * @throws ApplicationException - */ - public UserLimitsInfoModel saveUserLimitsInfo(UserLimitsInfoModel userLimitInfo) throws ApplicationException; /** * This service returns to the client the information about the need for load the users and group management tabs diff --git a/src/gui/core/plugin/userui/src/main/java/org/geoserver/geofence/gui/client/service/ProfilesManagerRemoteService.java b/src/gui/core/plugin/userui/src/main/java/org/geoserver/geofence/gui/client/service/ProfilesManagerRemoteService.java index e44c9452..c22b4973 100644 --- a/src/gui/core/plugin/userui/src/main/java/org/geoserver/geofence/gui/client/service/ProfilesManagerRemoteService.java +++ b/src/gui/core/plugin/userui/src/main/java/org/geoserver/geofence/gui/client/service/ProfilesManagerRemoteService.java @@ -1,12 +1,10 @@ -/* (c) 2014 Open Source Geospatial Foundation - all rights reserved +/* (c) 2014 - 2017 Open Source Geospatial Foundation - all rights reserved * This code is licensed under the GPL 2.0 license, available at the root * application directory. */ package org.geoserver.geofence.gui.client.service; -import java.util.List; - import com.extjs.gxt.ui.client.data.PagingLoadResult; import com.google.gwt.user.client.rpc.RemoteService; import com.google.gwt.user.client.rpc.RemoteServiceRelativePath; @@ -14,7 +12,6 @@ import org.geoserver.geofence.gui.client.ApplicationException; import org.geoserver.geofence.gui.client.model.RolenameModel; import org.geoserver.geofence.gui.client.model.UserGroupModel; -import org.geoserver.geofence.gui.client.model.data.ProfileCustomProps; /** @@ -57,20 +54,4 @@ public interface ProfilesManagerRemoteService extends RemoteService * the application exception */ public void deleteProfile(UserGroupModel profile) throws ApplicationException; - - /** - * @param ruleId - * @param customProps - * @throws ApplicationException - */ - public PagingLoadResult getProfileCustomProps(int offset, int limit, UserGroupModel profile) - throws ApplicationException; - - /** - * @param ruleId - * @param customProps - * @throws ApplicationException - */ - public void setProfileProps(Long profileId, List customProps) throws ApplicationException; - } diff --git a/src/gui/core/plugin/userui/src/main/java/org/geoserver/geofence/gui/client/view/ProfilesView.java b/src/gui/core/plugin/userui/src/main/java/org/geoserver/geofence/gui/client/view/ProfilesView.java index 394c3dfb..702eb6e7 100644 --- a/src/gui/core/plugin/userui/src/main/java/org/geoserver/geofence/gui/client/view/ProfilesView.java +++ b/src/gui/core/plugin/userui/src/main/java/org/geoserver/geofence/gui/client/view/ProfilesView.java @@ -1,4 +1,4 @@ -/* (c) 2014 Open Source Geospatial Foundation - all rights reserved +/* (c) 2014 - 2017 Open Source Geospatial Foundation - all rights reserved * This code is licensed under the GPL 2.0 license, available at the root * application directory. */ @@ -67,188 +67,4 @@ private void onCreateNewProfile(AppEvent event) this.addProfile.show(); } -// /** -// * On edit profile. -// * -// * @param event -// * the event -// */ -// private void onEditUser(AppEvent event) { -// if (event.getData() != null && event.getData() instanceof GSUser) { -// this.userEditorDialog.reset(); -// this.userEditorDialog.setModel((GSUser) event.getData()); -// this.userEditorDialog.show(); -// } else { -// // TODO: i18n!! -// Dispatcher.forwardEvent(GeofenceEvents.SEND_ERROR_MESSAGE, new String[] { -// "Users Editor", "Could not found any associated profile!" }); -// } -// } - -// /** -// * On rule custom prop add. -// * -// * @param event -// * the event -// */ -// private void onRuleCustomPropAdd(AppEvent event) { -// if (event.getData() != null) { -// LayerCustomPropsTabItem layersCustomPropsItem = (LayerCustomPropsTabItem) this.userEditorDialog -// .getTabWidget().getItemByItemId( -// RuleDetailsEditDialog.RULE_LAYER_CUSTOM_PROPS_DIALOG_ID); -// final LayerCustomPropsGridWidget layerCustomPropsInfo = layersCustomPropsItem -// .getLayerCustomPropsWidget().getLayerCustomPropsInfo(); -// LayerCustomProps model = new LayerCustomProps(); -// model.setPropKey("_new"); -// layerCustomPropsInfo.getStore().add(model); -// -// layerCustomPropsInfo.getGrid().repaint(); -// } else { -// // TODO: i18n!! -// Dispatcher.forwardEvent(GeofenceEvents.SEND_ERROR_MESSAGE, new String[] { -// "Rules Details Editor", "Could not found any associated rule!" }); -// } -// } -// -// /** -// * On rule custom prop remove. -// * -// * @param event -// * the event -// */ -// private void onRuleCustomPropRemove(AppEvent event) { -// if (event.getData() != null) { -// Map updateDTO = event.getData(); -// -// LayerCustomPropsTabItem layersCustomPropsItem = (LayerCustomPropsTabItem) this.userEditorDialog -// .getTabWidget().getItemByItemId( -// RuleDetailsEditDialog.RULE_LAYER_CUSTOM_PROPS_DIALOG_ID); -// final LayerCustomPropsGridWidget layerCustomPropsInfo = layersCustomPropsItem -// .getLayerCustomPropsWidget().getLayerCustomPropsInfo(); -// -// for (Long ruleId : updateDTO.keySet()) { -// LayerCustomProps dto = updateDTO.get(ruleId); -// -// for (LayerCustomProps prop : layerCustomPropsInfo.getStore().getModels()) { -// if (prop.getPropKey().equals(dto.getPropKey())) -// layerCustomPropsInfo.getStore().remove(prop); -// } -// } -// -// layerCustomPropsInfo.getGrid().repaint(); -// -// } else { -// // TODO: i18n!! -// Dispatcher.forwardEvent(GeofenceEvents.SEND_ERROR_MESSAGE, new String[] { -// "Rules Details Editor", "Could not found any associated rule!" }); -// } -// } -// -// /** -// * On rule custom prop update key. -// * -// * @param event -// * the event -// */ -// private void onRuleCustomPropUpdateKey(AppEvent event) { -// if (event.getData() != null) { -// LayerCustomPropsTabItem layersCustomPropsItem = (LayerCustomPropsTabItem) this.userEditorDialog -// .getTabWidget().getItemByItemId( -// RuleDetailsEditDialog.RULE_LAYER_CUSTOM_PROPS_DIALOG_ID); -// final LayerCustomPropsGridWidget layerCustomPropsInfo = layersCustomPropsItem -// .getLayerCustomPropsWidget().getLayerCustomPropsInfo(); -// -// Map updateDTO = event.getData(); -// -// for (String key : updateDTO.keySet()) { -// for (LayerCustomProps prop : layerCustomPropsInfo.getStore().getModels()) { -// if (prop.getPropKey().equals(key)) { -// layerCustomPropsInfo.getStore().remove(prop); -// LayerCustomProps newModel = updateDTO.get(key); -// layerCustomPropsInfo.getStore().add(newModel); -// } -// } -// } -// -// layerCustomPropsInfo.getGrid().repaint(); -// } else { -// // TODO: i18n!! -// Dispatcher.forwardEvent(GeofenceEvents.SEND_ERROR_MESSAGE, new String[] { -// "Rules Details Editor", "Could not found any associated rule!" }); -// } -// } -// -// /** -// * On rule custom prop update value. -// * -// * @param event -// * the event -// */ -// private void onRuleCustomPropUpdateValue(AppEvent event) { -// if (event.getData() != null) { -// LayerCustomPropsTabItem layersCustomPropsItem = (LayerCustomPropsTabItem) this.userEditorDialog -// .getTabWidget().getItemByItemId( -// RuleDetailsEditDialog.RULE_LAYER_CUSTOM_PROPS_DIALOG_ID); -// final LayerCustomPropsGridWidget layerCustomPropsInfo = layersCustomPropsItem -// .getLayerCustomPropsWidget().getLayerCustomPropsInfo(); -// -// Map updateDTO = event.getData(); -// -// for (String key : updateDTO.keySet()) { -// for (LayerCustomProps prop : layerCustomPropsInfo.getStore().getModels()) { -// if (prop.getPropKey().equals(key)) { -// layerCustomPropsInfo.getStore().remove(prop); -// LayerCustomProps newModel = updateDTO.get(key); -// layerCustomPropsInfo.getStore().add(newModel); -// } -// } -// } -// -// layerCustomPropsInfo.getGrid().repaint(); -// } else { -// // TODO: i18n!! -// Dispatcher.forwardEvent(GeofenceEvents.SEND_ERROR_MESSAGE, new String[] { -// "Rules Details Editor", "Could not found any associated rule!" }); -// } -// } -// -// /** -// * On rule custom prop save. -// * -// * @param event -// * the event -// */ -// private void onRuleCustomPropSave(AppEvent event) { -// Long ruleId = event.getData(); -// -// LayerCustomPropsTabItem layersCustomPropsItem = (LayerCustomPropsTabItem) this.userEditorDialog -// .getTabWidget().getItemByItemId( -// RuleDetailsEditDialog.RULE_LAYER_CUSTOM_PROPS_DIALOG_ID); -// final LayerCustomPropsGridWidget layerCustomPropsInfo = layersCustomPropsItem -// .getLayerCustomPropsWidget().getLayerCustomPropsInfo(); -// -// rulesManagerServiceRemote.setDetailsProps(ruleId, layerCustomPropsInfo.getStore() -// .getModels(), new AsyncCallback>() { -// -// public void onFailure(Throwable caught) { -// -// Dispatcher.forwardEvent(GeofenceEvents.SEND_ERROR_MESSAGE, new String[] { -// I18nProvider.getMessages().ruleServiceName(), -// "Error occurred while saving Rule Custom Properties!" }); -// } -// -// public void onSuccess(PagingLoadResult result) { -// -// // grid.getStore().sort(BeanKeyValue.PRIORITY.getValue(), -// // SortDir.ASC); -// layerCustomPropsInfo.getStore().getLoader().load(); -// layerCustomPropsInfo.getGrid().repaint(); -// -// Dispatcher.forwardEvent(GeofenceEvents.BIND_MEMBER_DISTRIBUTION_NODES, result); -// Dispatcher.forwardEvent(GeofenceEvents.SEND_INFO_MESSAGE, new String[] { -// I18nProvider.getMessages().ruleServiceName(), -// I18nProvider.getMessages().ruleFetchSuccessMessage() }); -// } -// }); -// } } diff --git a/src/gui/core/plugin/userui/src/main/java/org/geoserver/geofence/gui/client/view/RulesView.java b/src/gui/core/plugin/userui/src/main/java/org/geoserver/geofence/gui/client/view/RulesView.java index cea70419..9b784694 100644 --- a/src/gui/core/plugin/userui/src/main/java/org/geoserver/geofence/gui/client/view/RulesView.java +++ b/src/gui/core/plugin/userui/src/main/java/org/geoserver/geofence/gui/client/view/RulesView.java @@ -1,4 +1,4 @@ -/* (c) 2014 Open Source Geospatial Foundation - all rights reserved +/* (c) 2014 - 2017 Open Source Geospatial Foundation - all rights reserved * This code is licensed under the GPL 2.0 license, available at the root * application directory. */ @@ -13,8 +13,6 @@ import org.geoserver.geofence.gui.client.model.data.LayerCustomProps; import org.geoserver.geofence.gui.client.model.data.LayerDetailsInfo; import org.geoserver.geofence.gui.client.model.data.LayerLimitsInfo; -import org.geoserver.geofence.gui.client.model.data.ProfileCustomProps; -import org.geoserver.geofence.gui.client.model.data.UserLimitsInfoModel; import org.geoserver.geofence.gui.client.service.GsUsersManagerRemoteServiceAsync; import org.geoserver.geofence.gui.client.service.InstancesManagerRemoteServiceAsync; import org.geoserver.geofence.gui.client.service.ProfilesManagerRemoteServiceAsync; @@ -22,22 +20,17 @@ import org.geoserver.geofence.gui.client.service.WorkspacesManagerRemoteServiceAsync; import org.geoserver.geofence.gui.client.widget.EditRuleWidget; import org.geoserver.geofence.gui.client.widget.GridStatus; -import org.geoserver.geofence.gui.client.widget.dialog.ProfileDetailsEditDialog; import org.geoserver.geofence.gui.client.widget.dialog.RuleDetailsEditDialog; import org.geoserver.geofence.gui.client.widget.dialog.UserDetailsEditDialog; import org.geoserver.geofence.gui.client.widget.rule.detail.LayerAttributesGridWidget; import org.geoserver.geofence.gui.client.widget.rule.detail.LayerAttributesTabItem; import org.geoserver.geofence.gui.client.widget.rule.detail.LayerCustomPropsGridWidget; import org.geoserver.geofence.gui.client.widget.rule.detail.LayerCustomPropsTabItem; -import org.geoserver.geofence.gui.client.widget.rule.detail.ProfileDetailsGridWidget; -import org.geoserver.geofence.gui.client.widget.rule.detail.ProfileDetailsTabItem; import org.geoserver.geofence.gui.client.widget.rule.detail.RuleDetailsGridWidget; import org.geoserver.geofence.gui.client.widget.rule.detail.RuleDetailsInfoWidget; import org.geoserver.geofence.gui.client.widget.rule.detail.RuleDetailsTabItem; import org.geoserver.geofence.gui.client.widget.rule.detail.RuleLimitsInfoWidget; import org.geoserver.geofence.gui.client.widget.rule.detail.RuleLimitsTabItem; -import org.geoserver.geofence.gui.client.widget.rule.detail.UserDetailsInfoWidget; -import org.geoserver.geofence.gui.client.widget.rule.detail.UserDetailsTabItem; import it.geosolutions.geogwt.gui.client.GeoGWTEvents; import java.util.Map; @@ -78,9 +71,6 @@ public class RulesView extends View { /** The rule editor dialog. */ private RuleDetailsEditDialog ruleEditorDialog; - /** The profile editor dialog. */ - private ProfileDetailsEditDialog profileEditorDialog; - /** The user editor dialog. */ private UserDetailsEditDialog userDetailsEditDialog; @@ -99,10 +89,6 @@ public RulesView(Controller controller) { rulesManagerServiceRemote, workspacesManagerServiceRemote); ruleEditorDialog.setClosable(false); - this.profileEditorDialog = new ProfileDetailsEditDialog( - profilesManagerServiceRemote); - profileEditorDialog.setClosable(false); - this.userDetailsEditDialog = new UserDetailsEditDialog( usersManagerServiceRemote, profilesManagerServiceRemote); userDetailsEditDialog.setClosable(false); @@ -171,26 +157,6 @@ protected void handleEvent(AppEvent event) { // logger } - if (event.getType() == GeofenceEvents.RULE_PROFILE_CUSTOM_PROP_UPDATE_KEY) { - onRuleProfileCustomPropUpdateKey(event); - } - - if (event.getType() == GeofenceEvents.RULE_PROFILE_CUSTOM_PROP_UPDATE_VALUE) { - onRuleProfileCustomPropUpdateValue(event); - } - - if (event.getType() == GeofenceEvents.RULE_PROFILE_CUSTOM_PROP_DEL) { - onRuleProfileCustomPropRemove(event); - } - - if (event.getType() == GeofenceEvents.RULE_PROFILE_CUSTOM_PROP_ADD) { - onRuleProfileCustomPropAdd(event); - } - - if (event.getType() == GeofenceEvents.RULE_PROFILE_CUSTOM_PROP_APPLY_CHANGES) { - onRuleProfileCustomPropSave(event); - } - if (event.getType() == GeofenceEvents.RULE_EDITOR_DIALOG_HIDE) { ruleEditorDialog.hide(); } @@ -198,10 +164,6 @@ protected void handleEvent(AppEvent event) { ruleEditorDialog.show(); } - if (event.getType() == GeofenceEvents.EDIT_PROFILE_DETAILS) { - onEditProfileDetails(event); - } - if (event.getType() == GeofenceEvents.SAVE_LAYER_LIMITS) { onSaveLayerLimits(event); } @@ -214,14 +176,6 @@ protected void handleEvent(AppEvent event) { onEditUserDetails(event); } - if (event.getType() == GeofenceEvents.LOAD_USER_LIMITS) { - onLoadUserLimits(event); - } - - if (event.getType() == GeofenceEvents.SAVE_USER_LIMITS) { - onSaveUserLimits(event); - } - if (event.getType() == GeofenceEvents.SAVE_USER_GROUPS) { onSaveUserGroups(event); } @@ -233,45 +187,6 @@ protected void handleEvent(AppEvent event) { } - /** - * @param event - */ - private void onSaveUserLimits(AppEvent event) { - UserLimitsInfoModel userInfo = event.getData(); - - this.usersManagerServiceRemote.saveUserLimitsInfo(userInfo, - new AsyncCallback() { - - public void onFailure(Throwable caught) { - Dispatcher - .forwardEvent( - GeofenceEvents.SEND_ERROR_MESSAGE, - new String[] { - I18nProvider.getMessages() - .ruleServiceName(), - "Error occurred while saving User Details!" }); - } - - public void onSuccess(UserLimitsInfoModel result) { - UserDetailsTabItem userDetailsTabItem = (UserDetailsTabItem) userDetailsEditDialog - .getTabWidget() - .getItemByItemId( - UserDetailsEditDialog.USER_DETAILS_DIALOG_ID); - - UserDetailsInfoWidget userDetailsInfoWidget = userDetailsTabItem - .getUserDetailsWidget().getUserDetailsInfo(); - userDetailsInfoWidget.bindModelData(result); - - Dispatcher.forwardEvent( - GeofenceEvents.SEND_INFO_MESSAGE, new String[] { - I18nProvider.getMessages() - .userServiceName(), - I18nProvider.getMessages() - .userFetchSuccessMessage() }); - } - }); - } - /** * @param event */ @@ -302,52 +217,6 @@ public void onSuccess(Void result) { }); } - /** - * @param event - */ - private void onLoadUserLimits(AppEvent event) { - GSUserModel user = event.getData(); - - this.usersManagerServiceRemote.getUserLimitsInfo(user, - new AsyncCallback() { - - public void onFailure(Throwable caught) { - Dispatcher - .forwardEvent( - GeofenceEvents.SEND_ERROR_MESSAGE, - new String[] { - I18nProvider.getMessages() - .ruleServiceName(), - "Error occurred while getting User Details!" }); - } - - public void onSuccess(UserLimitsInfoModel result) { - if (result != null) { - UserDetailsTabItem userDetailsTabItem = (UserDetailsTabItem) userDetailsEditDialog - .getTabWidget() - .getItemByItemId( - UserDetailsEditDialog.USER_DETAILS_DIALOG_ID); - - UserDetailsInfoWidget userDetailsWidget = userDetailsTabItem - .getUserDetailsWidget() - .getUserDetailsInfo(); - - userDetailsWidget.bindModelData(result); - - Dispatcher - .forwardEvent( - GeofenceEvents.SEND_INFO_MESSAGE, - new String[] { - I18nProvider.getMessages() - .userServiceName(), - I18nProvider - .getMessages() - .userFetchSuccessMessage() }); - } - } - }); - } - /** * @param event */ @@ -448,204 +317,6 @@ public void onSuccess(LayerLimitsInfo result) { }); } - /** - * @param event - */ - private void onEditProfileDetails(AppEvent event) { - if ((event.getData() != null) && (event.getData() instanceof UserGroupModel)) { - this.profileEditorDialog.reset(); - this.profileEditorDialog.setModel((UserGroupModel) event.getData()); - this.profileEditorDialog.show(); - } else { - // TODO: i18n!! - Dispatcher.forwardEvent(GeofenceEvents.SEND_ERROR_MESSAGE, - new String[] { "Groups Details Editor", - "Could not found any associated groups!" }); - } - } - - /** - * @param event - */ - private void onRuleProfileCustomPropSave(AppEvent event) { - - Long profileId = event.getData(); - - ProfileDetailsTabItem profileDetailsTabItem = (ProfileDetailsTabItem) this.profileEditorDialog - .getTabWidget().getItemByItemId( - ProfileDetailsEditDialog.PROFILE_DETAILS_DIALOG_ID); - - final ProfileDetailsGridWidget profileCustomPropsInfo = profileDetailsTabItem - .getProfileDetailsWidget().getProfileDetailsInfo(); - - profilesManagerServiceRemote.setProfileProps(profileId, - profileCustomPropsInfo.getStore().getModels(), - new AsyncCallback() { - - public void onFailure(Throwable caught) { - - Dispatcher - .forwardEvent( - GeofenceEvents.SEND_ERROR_MESSAGE, - new String[] { - I18nProvider.getMessages() - .ruleServiceName(), - "Error occurred while saving Rule Custom Properties!" }); - } - - public void onSuccess(Void result) { - profileCustomPropsInfo.getStore().getLoader().load(); - - Dispatcher.forwardEvent( - GeofenceEvents.SEND_INFO_MESSAGE, new String[] { - I18nProvider.getMessages() - .ruleServiceName(), - I18nProvider.getMessages() - .ruleFetchSuccessMessage() }); - } - }); - } - - /** - * @param event - */ - private void onRuleProfileCustomPropAdd(AppEvent event) { - - if (event.getData() != null) { - - ProfileDetailsTabItem profileDetailsTabItem = (ProfileDetailsTabItem) this.profileEditorDialog - .getTabWidget().getItemByItemId( - ProfileDetailsEditDialog.PROFILE_DETAILS_DIALOG_ID); - - final ProfileDetailsGridWidget profileCustomPropsInfo = profileDetailsTabItem - .getProfileDetailsWidget().getProfileDetailsInfo(); - - ProfileCustomProps model = new ProfileCustomProps(); - model.setPropKey("_new"); - profileCustomPropsInfo.getStore().add(model); - - Dispatcher.forwardEvent(GeofenceEvents.SEND_INFO_MESSAGE, - new String[] { "GeoServer Rules: Layer Custom Properties", - "Add Property" }); - - } else { - // TODO: i18n!! - Dispatcher.forwardEvent(GeofenceEvents.SEND_ERROR_MESSAGE, - new String[] { "Rules Details Editor", - "Could not found any associated rule!" }); - } - } - - /** - * @param event - */ - private void onRuleProfileCustomPropRemove(AppEvent event) { - if (event.getData() != null) { - Map updateDTO = event.getData(); - - ProfileDetailsTabItem profileDetailsTabItem = (ProfileDetailsTabItem) this.profileEditorDialog - .getTabWidget().getItemByItemId( - ProfileDetailsEditDialog.PROFILE_DETAILS_DIALOG_ID); - - final ProfileDetailsGridWidget profileCustomPropsInfo = profileDetailsTabItem - .getProfileDetailsWidget().getProfileDetailsInfo(); - - for (Long ruleId : updateDTO.keySet()) { - ProfileCustomProps dto = updateDTO.get(ruleId); - - for (ProfileCustomProps prop : profileCustomPropsInfo - .getStore().getModels()) { - if (prop.getPropKey().equals(dto.getPropKey())) { - profileCustomPropsInfo.getStore().remove(prop); - } - } - } - - profileCustomPropsInfo.getGrid().repaint(); - - } else { - // TODO: i18n!! - Dispatcher.forwardEvent(GeofenceEvents.SEND_ERROR_MESSAGE, - new String[] { "Rules Details Editor", - "Could not found any associated rule!" }); - } - } - - /** - * @param event - */ - private void onRuleProfileCustomPropUpdateValue(AppEvent event) { - - if (event.getData() != null) { - - ProfileDetailsTabItem profileDetailsTabItem = (ProfileDetailsTabItem) this.profileEditorDialog - .getTabWidget().getItemByItemId( - ProfileDetailsEditDialog.PROFILE_DETAILS_DIALOG_ID); - - final ProfileDetailsGridWidget profileCustomPropsInfo = profileDetailsTabItem - .getProfileDetailsWidget().getProfileDetailsInfo(); - - Map updateDTO = event.getData(); - - for (String key : updateDTO.keySet()) { - for (ProfileCustomProps prop : profileCustomPropsInfo - .getStore().getModels()) { - if (prop.getPropKey().equals(key)) { - profileCustomPropsInfo.getStore().remove(prop); - - ProfileCustomProps newModel = updateDTO.get(key); - profileCustomPropsInfo.getStore().add(newModel); - } - } - } - - profileCustomPropsInfo.getGrid().repaint(); - - } else { - // TODO: i18n!! - Dispatcher.forwardEvent(GeofenceEvents.SEND_ERROR_MESSAGE, - new String[] { "Group Details Editor", - "Could not found any associated rule!" }); - } - } - - /** - * @param event - */ - private void onRuleProfileCustomPropUpdateKey(AppEvent event) { - - if (event.getData() != null) { - - ProfileDetailsTabItem profileDetailsTabItem = (ProfileDetailsTabItem) this.profileEditorDialog - .getTabWidget().getItemByItemId( - ProfileDetailsEditDialog.PROFILE_DETAILS_DIALOG_ID); - - final ProfileDetailsGridWidget profileCustomPropsInfo = profileDetailsTabItem - .getProfileDetailsWidget().getProfileDetailsInfo(); - - Map updateDTO = event.getData(); - - for (String key : updateDTO.keySet()) { - for (ProfileCustomProps prop : profileCustomPropsInfo - .getStore().getModels()) { - if (prop.getPropKey().equals(key)) { - profileCustomPropsInfo.getStore().remove(prop); - - ProfileCustomProps newModel = updateDTO.get(key); - profileCustomPropsInfo.getStore().add(newModel); - } - } - } - - profileCustomPropsInfo.getGrid().repaint(); - } else { - // TODO: i18n!! - Dispatcher.forwardEvent(GeofenceEvents.SEND_ERROR_MESSAGE, - new String[] { "Group Details Editor", - "Could not found any associated rule!" }); - } - } - /** * @param event */ diff --git a/src/gui/core/plugin/userui/src/main/java/org/geoserver/geofence/gui/client/widget/AddGsUserWidget.java b/src/gui/core/plugin/userui/src/main/java/org/geoserver/geofence/gui/client/widget/AddGsUserWidget.java index a7bc639a..38bd186b 100644 --- a/src/gui/core/plugin/userui/src/main/java/org/geoserver/geofence/gui/client/widget/AddGsUserWidget.java +++ b/src/gui/core/plugin/userui/src/main/java/org/geoserver/geofence/gui/client/widget/AddGsUserWidget.java @@ -1,4 +1,4 @@ -/* (c) 2014 Open Source Geospatial Foundation - all rights reserved +/* (c) 2014 - 2017 Open Source Geospatial Foundation - all rights reserved * This code is licensed under the GPL 2.0 license, available at the root * application directory. */ @@ -110,7 +110,7 @@ protected EventType getSubmitEvent() public void execute() { this.saveStatus.setBusy("Operation in progress"); - this.user.setId(-1); + this.user.setId(-1l); this.user.setName(userName.getValue()); this.user.setPassword(password.getValue()); this.user.setFullName(fullName.getValue()); diff --git a/src/gui/core/plugin/userui/src/main/java/org/geoserver/geofence/gui/client/widget/AddProfileWidget.java b/src/gui/core/plugin/userui/src/main/java/org/geoserver/geofence/gui/client/widget/AddProfileWidget.java index 27b6c9c3..d11f6303 100644 --- a/src/gui/core/plugin/userui/src/main/java/org/geoserver/geofence/gui/client/widget/AddProfileWidget.java +++ b/src/gui/core/plugin/userui/src/main/java/org/geoserver/geofence/gui/client/widget/AddProfileWidget.java @@ -1,4 +1,4 @@ -/* (c) 2014 Open Source Geospatial Foundation - all rights reserved +/* (c) 2014 - 2017 Open Source Geospatial Foundation - all rights reserved * This code is licensed under the GPL 2.0 license, available at the root * application directory. */ @@ -76,7 +76,7 @@ protected EventType getSubmitEvent() public void execute() { this.saveStatus.setBusy("Operation in progress"); - this.profile.setId(-1); + this.profile.setId(-1l); this.profile.setName(profileName.getValue()); this.profile.setDateCreation(new Date()); this.profile.setEnabled(true); diff --git a/src/gui/core/plugin/userui/src/main/java/org/geoserver/geofence/gui/client/widget/ProfileGridWidget.java b/src/gui/core/plugin/userui/src/main/java/org/geoserver/geofence/gui/client/widget/ProfileGridWidget.java index 60f0bb82..586ca56a 100644 --- a/src/gui/core/plugin/userui/src/main/java/org/geoserver/geofence/gui/client/widget/ProfileGridWidget.java +++ b/src/gui/core/plugin/userui/src/main/java/org/geoserver/geofence/gui/client/widget/ProfileGridWidget.java @@ -1,12 +1,10 @@ -/* (c) 2014 Open Source Geospatial Foundation - all rights reserved +/* (c) 2014 - 2017 Open Source Geospatial Foundation - all rights reserved * This code is licensed under the GPL 2.0 license, available at the root * application directory. */ package org.geoserver.geofence.gui.client.widget; -import org.geoserver.geofence.gui.client.widget.GeofenceGridWidget; -import org.geoserver.geofence.gui.client.widget.SearchFilterField; import java.util.ArrayList; import java.util.List; @@ -41,6 +39,7 @@ import com.extjs.gxt.ui.client.widget.toolbar.PagingToolBar; import com.extjs.gxt.ui.client.widget.toolbar.SeparatorToolItem; import com.google.gwt.user.client.rpc.AsyncCallback; +import com.google.gwt.user.client.ui.Widget; import org.geoserver.geofence.gui.client.Constants; import org.geoserver.geofence.gui.client.GeofenceEvents; @@ -113,14 +112,15 @@ public ColumnModel prepareColumnModel() { ColumnConfig profileNameColumn = new ColumnConfig(); profileNameColumn.setId(BeanKeyValue.NAME.getValue()); profileNameColumn.setHeader("Role Name"); - profileNameColumn.setWidth(160); - profileNameColumn.setRenderer(this.createProfileNameTextBox()); + profileNameColumn.setWidth(200); +// profileNameColumn.setRenderer(this.createProfileNameTextBox()); configs.add(profileNameColumn); ColumnConfig dateCreationColumn = new ColumnConfig(); dateCreationColumn.setId(BeanKeyValue.DATE_CREATION.getValue()); dateCreationColumn.setHeader("Date Creation"); dateCreationColumn.setWidth(180); + dateCreationColumn.setHidden(true); configs.add(dateCreationColumn); ColumnConfig profileEnabledColumn = new ColumnConfig(); @@ -132,14 +132,6 @@ public ColumnModel prepareColumnModel() { profileEnabledColumn.setSortable(false); configs.add(profileEnabledColumn); -// ColumnConfig detailsActionColumn = new ColumnConfig(); -// detailsActionColumn.setId("detailsProfile"); -// detailsActionColumn.setWidth(80); -// detailsActionColumn.setRenderer(this.createProfileDetailsButton()); -// detailsActionColumn.setMenuDisabled(true); -// detailsActionColumn.setSortable(false); -// configs.add(detailsActionColumn); - ColumnConfig removeActionColumn = new ColumnConfig(); removeActionColumn.setId("removeProfile"); removeActionColumn.setWidth(80); @@ -211,18 +203,18 @@ protected boolean doSelect(Store store, // TODO: temporally disabled! addProfileButton.setEnabled(false); - addProfileButton.addListener(Events.OnClick, - new Listener() { - - public void handleEvent(ButtonEvent be) { - Dispatcher.forwardEvent( - GeofenceEvents.SEND_INFO_MESSAGE, new String[] { - "GeoServer Group", "Add Group" }); + addProfileButton.addListener(Events.OnClick, new Listener() + { + public void handleEvent(ButtonEvent be) + { + Dispatcher.forwardEvent( + GeofenceEvents.SEND_INFO_MESSAGE, + new String[]{ "GeoServer Group", "Add Group"}); - Dispatcher - .forwardEvent(GeofenceEvents.CREATE_NEW_PROFILE); - } - }); + Dispatcher.forwardEvent( + GeofenceEvents.CREATE_NEW_PROFILE); + } + }); this.toolBar.bind(loader); this.toolBar.add(new SeparatorToolItem()); @@ -314,144 +306,123 @@ public void loaderLoad(LoadEvent le) { * * @return the grid cell renderer */ - private GridCellRenderer createProfileNameTextBox() { - GridCellRenderer buttonRendered = new GridCellRenderer() { - - private boolean init; - - public Object render(final UserGroupModel model, String property, - ColumnData config, int rowIndex, int colIndex, - ListStore store, Grid grid) { - - if (!init) { - init = true; - grid.addListener(Events.ColumnResize, - new Listener>() { - - public void handleEvent(GridEvent be) { - for (int i = 0; i < be.getGrid().getStore() - .getCount(); i++) { - if ((be.getGrid().getView() - .getWidget(i, be.getColIndex()) != null) - && (be.getGrid() - .getView() - .getWidget( - i, - be.getColIndex()) instanceof BoxComponent)) { - ((BoxComponent) be - .getGrid() - .getView() - .getWidget(i, - be.getColIndex())) - .setWidth(be.getWidth() - 10); - } - } - } - }); - } - - TextField profileNameTextBox = new TextField(); - profileNameTextBox.setWidth(150); - // TODO: add correct tooltip text here! - // profileNameTextBox("Test"); - - profileNameTextBox.setValue(model.getName()); - - profileNameTextBox.addListener(Events.Change, - new Listener() { - - public void handleEvent(FieldEvent be) { - Dispatcher.forwardEvent( - GeofenceEvents.SEND_INFO_MESSAGE, - new String[] { - "GeoServer role", - "Role name changed to -> " - + be.getField() - .getValue() }); - - model.setName((String) be.getField().getValue()); - Dispatcher.forwardEvent( - GeofenceEvents.UPDATE_PROFILE, model); - } - }); - - return profileNameTextBox; - } - }; - - return buttonRendered; - } + private GridCellRenderer createProfileNameTextBox() + { + GridCellRenderer buttonRendered = new GridCellRenderer() + { + + private boolean init; + + public Object render(final UserGroupModel model, String property, + ColumnData config, int rowIndex, int colIndex, + ListStore store, Grid grid) + { + + if (!init) { + init = true; + grid.addListener(Events.ColumnResize, new Listener>() + { + public void handleEvent(GridEvent be) + { + for (int i = 0; i < be.getGrid().getStore().getCount(); i++) { + Widget w = be.getGrid().getView().getWidget(i, be.getColIndex()); + if (w != null && w instanceof BoxComponent) { + ((BoxComponent) w).setWidth(be.getWidth() - 10); + } + } + } + }); + } + + TextField profileNameTextBox = new TextField(); + profileNameTextBox.setWidth(150); + // TODO: add correct tooltip text here! + // profileNameTextBox("Test"); + + profileNameTextBox.setValue(model.getName()); + + profileNameTextBox.addListener(Events.Change, new Listener() + { + public void handleEvent(FieldEvent be) + { + Dispatcher.forwardEvent( + GeofenceEvents.SEND_INFO_MESSAGE, + new String[]{ + "GeoServer role", + "Role name changed to -> " + be.getField().getValue()}); + + model.setName((String) be.getField().getValue()); + Dispatcher.forwardEvent( GeofenceEvents.UPDATE_PROFILE, model); + } + }); + + return profileNameTextBox; + } + }; + + return buttonRendered; + } /** * Creates the enable check box. * * @return the grid cell renderer */ - private GridCellRenderer createEnableCheckBox() { - - GridCellRenderer buttonRendered = new GridCellRenderer() { - - private boolean init; - - public Object render(final UserGroupModel model, String property, - ColumnData config, int rowIndex, int colIndex, - ListStore store, Grid grid) { - - if (!init) { - init = true; - grid.addListener(Events.ColumnResize, - new Listener>() { - - public void handleEvent(GridEvent be) { - for (int i = 0; i < be.getGrid().getStore() - .getCount(); i++) { - if ((be.getGrid().getView() - .getWidget(i, be.getColIndex()) != null) - && (be.getGrid() - .getView() - .getWidget( - i, - be.getColIndex()) instanceof BoxComponent)) { - ((BoxComponent) be - .getGrid() - .getView() - .getWidget(i, - be.getColIndex())) - .setWidth(be.getWidth() - 10); - } - } - } - }); - } - - CheckBox profileEnabledButton = new CheckBox(); - // TODO: add correct tooltip text here! - // profileEnabledButton.setToolTip("Test"); - - profileEnabledButton.setValue(model.isEnabled()); - - profileEnabledButton.addListener(Events.OnClick, - new Listener() { - - public void handleEvent(FieldEvent be) { - Dispatcher.forwardEvent( - GeofenceEvents.SEND_INFO_MESSAGE, - new String[] { "GeoServer Group", - "Enable check!" }); - - model.setEnabled((Boolean) be.getField() - .getValue()); - Dispatcher.forwardEvent( - GeofenceEvents.UPDATE_PROFILE, model); - } - }); - - return profileEnabledButton; - } - }; - - return buttonRendered; - } + private GridCellRenderer createEnableCheckBox() + { + GridCellRenderer buttonRendered = new GridCellRenderer() + { + private boolean init; + + public Object render(final UserGroupModel model, String property, + ColumnData config, int rowIndex, int colIndex, + ListStore store, Grid grid) + { + + if (!init) { + init = true; + grid.addListener(Events.ColumnResize, + new Listener>() + { + + public void handleEvent(GridEvent be) + { + for (int i = 0; i < be.getGrid().getStore().getCount(); i++) { + if ((be.getGrid().getView().getWidget(i, be.getColIndex()) != null) + && (be.getGrid().getView().getWidget(i,be.getColIndex()) instanceof BoxComponent)) { + ((BoxComponent) be.getGrid().getView().getWidget(i,be.getColIndex())).setWidth(be.getWidth() - 10); + } + } + } + }); + } + + CheckBox profileEnabledButton = new CheckBox(); + // TODO: add correct tooltip text here! + // profileEnabledButton.setToolTip("Test"); + + profileEnabledButton.setValue(model.isEnabled()); + + profileEnabledButton.addListener(Events.OnClick, new Listener() + { + + public void handleEvent(FieldEvent be) + { + Dispatcher.forwardEvent( + GeofenceEvents.SEND_INFO_MESSAGE, + new String[]{"GeoServer Group", "Enable check!"}); + + model.setEnabled((Boolean) be.getField().getValue()); + Dispatcher.forwardEvent(GeofenceEvents.UPDATE_PROFILE, model); + } + }); + + return profileEnabledButton; + } + }; + + return buttonRendered; + } /** * Creates the profile delete button. @@ -539,73 +510,4 @@ public void handleEvent(MessageBoxEvent ce) { return buttonRendered; } - /** - * Creates the profile details button. - * - * @return the grid cell renderer - */ - private GridCellRenderer createProfileDetailsButton() { - GridCellRenderer buttonRendered = new GridCellRenderer() { - - private boolean init; - - public Object render(final UserGroupModel model, String property, - ColumnData config, int rowIndex, int colIndex, - ListStore store, Grid grid) { - - if (!init) { - init = true; - grid.addListener(Events.ColumnResize, - new Listener>() { - - public void handleEvent(GridEvent be) { - for (int i = 0; i < be.getGrid().getStore() - .getCount(); i++) { - if ((be.getGrid().getView() - .getWidget(i, be.getColIndex()) != null) - && (be.getGrid() - .getView() - .getWidget( - i, - be.getColIndex()) instanceof BoxComponent)) { - ((BoxComponent) be - .getGrid() - .getView() - .getWidget(i, - be.getColIndex())) - .setWidth(be.getWidth() - 10); - } - } - } - }); - } - - Button detailsProfileButton = new Button("Details"); - detailsProfileButton.setIcon(Resources.ICONS.table()); - - detailsProfileButton.addListener(Events.OnClick, - new Listener() { - - public void handleEvent(ButtonEvent be) { - Dispatcher.forwardEvent( - GeofenceEvents.SEND_INFO_MESSAGE, - new String[] { - "GeoServer Group", - "Group Details: " - + model.getName() }); - - Dispatcher.forwardEvent( - GeofenceEvents.EDIT_PROFILE_DETAILS, - model); - } - }); - - return detailsProfileButton; - } - - }; - - return buttonRendered; - } - } diff --git a/src/gui/core/plugin/userui/src/main/java/org/geoserver/geofence/gui/client/widget/UserGridWidget.java b/src/gui/core/plugin/userui/src/main/java/org/geoserver/geofence/gui/client/widget/UserGridWidget.java index c7a38b5a..97c1b433 100644 --- a/src/gui/core/plugin/userui/src/main/java/org/geoserver/geofence/gui/client/widget/UserGridWidget.java +++ b/src/gui/core/plugin/userui/src/main/java/org/geoserver/geofence/gui/client/widget/UserGridWidget.java @@ -1,14 +1,11 @@ -/* (c) 2014 Open Source Geospatial Foundation - all rights reserved +/* (c) 2014 - 2017 Open Source Geospatial Foundation - all rights reserved * This code is licensed under the GPL 2.0 license, available at the root * application directory. */ package org.geoserver.geofence.gui.client.widget; -import org.geoserver.geofence.gui.client.widget.GeofenceGridWidget; -import org.geoserver.geofence.gui.client.widget.SearchFilterField; import java.util.ArrayList; -import java.util.Arrays; import java.util.List; import com.extjs.gxt.ui.client.data.BasePagingLoadResult; @@ -33,8 +30,6 @@ import com.extjs.gxt.ui.client.widget.MessageBox; import com.extjs.gxt.ui.client.widget.button.Button; import com.extjs.gxt.ui.client.widget.form.CheckBox; -import com.extjs.gxt.ui.client.widget.form.ComboBox; -import com.extjs.gxt.ui.client.widget.form.ComboBox.TriggerAction; import com.extjs.gxt.ui.client.widget.form.TextField; import com.extjs.gxt.ui.client.widget.grid.CellEditor; import com.extjs.gxt.ui.client.widget.grid.ColumnConfig; diff --git a/src/gui/core/plugin/userui/src/main/java/org/geoserver/geofence/gui/client/widget/dialog/ProfileDetailsEditDialog.java b/src/gui/core/plugin/userui/src/main/java/org/geoserver/geofence/gui/client/widget/dialog/ProfileDetailsEditDialog.java deleted file mode 100644 index 97e2cbb3..00000000 --- a/src/gui/core/plugin/userui/src/main/java/org/geoserver/geofence/gui/client/widget/dialog/ProfileDetailsEditDialog.java +++ /dev/null @@ -1,154 +0,0 @@ -/* (c) 2014 Open Source Geospatial Foundation - all rights reserved - * This code is licensed under the GPL 2.0 license, available at the root - * application directory. - */ - -package org.geoserver.geofence.gui.client.widget.dialog; - -import com.extjs.gxt.ui.client.widget.Dialog; -import com.extjs.gxt.ui.client.widget.button.Button; -import com.extjs.gxt.ui.client.widget.toolbar.FillToolItem; - -import org.geoserver.geofence.gui.client.i18n.I18nProvider; -import org.geoserver.geofence.gui.client.model.UserGroupModel; -import org.geoserver.geofence.gui.client.service.ProfilesManagerRemoteServiceAsync; -import org.geoserver.geofence.gui.client.widget.SaveStaus; -import org.geoserver.geofence.gui.client.widget.rule.detail.ProfileDetailsTabItem; -import org.geoserver.geofence.gui.client.widget.tab.TabWidget; - - -/** - * ProfileDetailsEditDialog class. - * - * @author Tobia di Pisa - * - */ -public class ProfileDetailsEditDialog extends Dialog -{ - - /** The Constant PROFILE_DETAILS_DIALOG_ID. */ - public static final String PROFILE_DETAILS_DIALOG_ID = "profileDetailsDialog"; - - /** The save status. */ - private SaveStaus saveStatus; - - /** The done. */ - private Button done; - - /** The model. */ - private UserGroupModel profile; - - /** The rules manager service remote. */ - private ProfilesManagerRemoteServiceAsync ProfilesManagerRemoteServiceAsync; - - /** The tab widget. */ - private TabWidget tabWidget; - - /** - * Instantiates a new rule details edit dialog. - * - * @param rulesManagerServiceRemote - * the rules manager service remote - */ - public ProfileDetailsEditDialog(ProfilesManagerRemoteServiceAsync ProfilesManagerRemoteServiceAsync) - { - this.ProfilesManagerRemoteServiceAsync = ProfilesManagerRemoteServiceAsync; - - setTabWidget(new TabWidget()); - - setResizable(false); - setButtons(""); - setClosable(true); - setModal(true); - setWidth(700); - setHeight(427); - setId(I18nProvider.getMessages().profileDialogId()); - - add(this.getTabWidget()); - } - - /* (non-Javadoc) - * @see com.extjs.gxt.ui.client.widget.Dialog#createButtons() - */ - @Override - protected void createButtons() - { - super.createButtons(); - - this.saveStatus = new SaveStaus(); - this.saveStatus.setAutoWidth(true); - - getButtonBar().add(saveStatus); - - getButtonBar().add(new FillToolItem()); - - } - - /* (non-Javadoc) - * @see com.extjs.gxt.ui.client.widget.Window#show() - */ - @Override - public void show() - { - super.show(); - - if (getModel() != null) - { - setHeading("Editing Profile Details for Profile #" + profile.getId()); - this.tabWidget.add(new ProfileDetailsTabItem(PROFILE_DETAILS_DIALOG_ID, profile, - ProfilesManagerRemoteServiceAsync)); - - } - - } - - /** - * Reset. - */ - public void reset() - { - this.tabWidget.removeAll(); - this.saveStatus.clearStatus(""); - } - - /** - * Sets the model. - * - * @param model - * the new model - */ - public void setModel(UserGroupModel profile) - { - this.profile = profile; - } - - /* (non-Javadoc) - * @see com.extjs.gxt.ui.client.widget.Component#getModel() - */ - public UserGroupModel getModel() - { - return this.profile; - } - - /** - * Sets the tab widget. - * - * @param tabWidget - * the new tab widget - */ - public void setTabWidget(TabWidget tabWidget) - { - this.tabWidget = tabWidget; - } - - /** - * Gets the tab widget. - * - * @return the tab widget - */ - public TabWidget getTabWidget() - { - return tabWidget; - } - -} diff --git a/src/gui/core/plugin/userui/src/main/java/org/geoserver/geofence/gui/client/widget/rule/detail/ProfileDetailsGridWidget.java b/src/gui/core/plugin/userui/src/main/java/org/geoserver/geofence/gui/client/widget/rule/detail/ProfileDetailsGridWidget.java deleted file mode 100644 index 2280b94c..00000000 --- a/src/gui/core/plugin/userui/src/main/java/org/geoserver/geofence/gui/client/widget/rule/detail/ProfileDetailsGridWidget.java +++ /dev/null @@ -1,517 +0,0 @@ -/* (c) 2014 Open Source Geospatial Foundation - all rights reserved - * This code is licensed under the GPL 2.0 license, available at the root - * application directory. - */ - -package org.geoserver.geofence.gui.client.widget.rule.detail; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import com.extjs.gxt.ui.client.data.BasePagingLoadResult; -import com.extjs.gxt.ui.client.data.BasePagingLoader; -import com.extjs.gxt.ui.client.data.LoadEvent; -import com.extjs.gxt.ui.client.data.ModelData; -import com.extjs.gxt.ui.client.data.PagingLoadConfig; -import com.extjs.gxt.ui.client.data.PagingLoadResult; -import com.extjs.gxt.ui.client.data.PagingLoader; -import com.extjs.gxt.ui.client.data.RpcProxy; -import com.extjs.gxt.ui.client.event.ButtonEvent; -import com.extjs.gxt.ui.client.event.Events; -import com.extjs.gxt.ui.client.event.FieldEvent; -import com.extjs.gxt.ui.client.event.GridEvent; -import com.extjs.gxt.ui.client.event.Listener; -import com.extjs.gxt.ui.client.event.LoadListener; -import com.extjs.gxt.ui.client.mvc.Dispatcher; -import com.extjs.gxt.ui.client.store.ListStore; -import com.extjs.gxt.ui.client.widget.BoxComponent; -import com.extjs.gxt.ui.client.widget.ComponentManager; -import com.extjs.gxt.ui.client.widget.button.Button; -import com.extjs.gxt.ui.client.widget.form.TextField; -import com.extjs.gxt.ui.client.widget.grid.ColumnConfig; -import com.extjs.gxt.ui.client.widget.grid.ColumnData; -import com.extjs.gxt.ui.client.widget.grid.ColumnModel; -import com.extjs.gxt.ui.client.widget.grid.Grid; -import com.extjs.gxt.ui.client.widget.grid.GridCellRenderer; -import com.extjs.gxt.ui.client.widget.toolbar.PagingToolBar; -import com.extjs.gxt.ui.client.widget.toolbar.SeparatorToolItem; -import com.google.gwt.user.client.rpc.AsyncCallback; - -import org.geoserver.geofence.gui.client.GeofenceEvents; -import org.geoserver.geofence.gui.client.Resources; -import org.geoserver.geofence.gui.client.i18n.I18nProvider; -import org.geoserver.geofence.gui.client.model.BeanKeyValue; -import org.geoserver.geofence.gui.client.model.UserGroupModel; -import org.geoserver.geofence.gui.client.model.data.ProfileCustomProps; -import org.geoserver.geofence.gui.client.service.ProfilesManagerRemoteServiceAsync; -import org.geoserver.geofence.gui.client.widget.GeofenceGridWidget; - - -/** - * The Class ProfileDetailsGridWidget. - */ -public class ProfileDetailsGridWidget extends GeofenceGridWidget -{ - - /** The profile service. */ - private ProfilesManagerRemoteServiceAsync profilesService; - - /** The proxy. */ - private RpcProxy> proxy; - - /** The loader. */ - private PagingLoader> loader; - - /** The tool bar. */ - private PagingToolBar toolBar; - - private UserGroupModel profile; - - /** - * Instantiates a new profile custom props grid widget. - * @param theRule - * - * @param rulesService - * the rules service - */ - public ProfileDetailsGridWidget(UserGroupModel profile, ProfilesManagerRemoteServiceAsync profilesService) - { - super(); - this.profile = profile; - this.profilesService = profilesService; - } - - /* - * (non-Javadoc) - * - * @see org.geoserver.geofence.gui.client.widget.GeofenceGridWidget#setGridProperties () - */ - @Override - public void setGridProperties() - { - grid.setLoadMask(true); - grid.setAutoWidth(true); - } - - /* (non-Javadoc) - * @see org.geoserver.geofence.gui.client.widget.GeofenceGridWidget#prepareColumnModel() - */ - @Override - public ColumnModel prepareColumnModel() - { - List configs = new ArrayList(); - - ColumnConfig profilePropKeyColumn = new ColumnConfig(); - profilePropKeyColumn.setId(BeanKeyValue.PROFILE_PROP_KEY.getValue()); - profilePropKeyColumn.setHeader("Key"); - profilePropKeyColumn.setWidth(210); - profilePropKeyColumn.setRenderer(this.createPropKeyTextBox()); - profilePropKeyColumn.setMenuDisabled(true); - profilePropKeyColumn.setSortable(false); - configs.add(profilePropKeyColumn); - - ColumnConfig profilePropValueColumn = new ColumnConfig(); - profilePropValueColumn.setId(BeanKeyValue.PROFILE_PROP_VALUE.getValue()); - profilePropValueColumn.setHeader("Value"); - profilePropValueColumn.setWidth(260); - profilePropValueColumn.setRenderer(this.createPropValueTextBox()); - profilePropValueColumn.setMenuDisabled(true); - profilePropValueColumn.setSortable(false); - configs.add(profilePropValueColumn); - - ColumnConfig removeActionColumn = new ColumnConfig(); - removeActionColumn.setId("removeProfileCustomProp"); - removeActionColumn.setWidth(30); - removeActionColumn.setRenderer(this.createDeleteButton()); - removeActionColumn.setMenuDisabled(true); - removeActionColumn.setSortable(false); - configs.add(removeActionColumn); - - return new ColumnModel(configs); - } - - /** - * - * @return - */ - private GridCellRenderer createPropKeyTextBox() - { - - GridCellRenderer textRendered = new GridCellRenderer() - { - - private boolean init; - - public Object render(final ProfileCustomProps model, String property, ColumnData config, - int rowIndex, int colIndex, ListStore store, Grid grid) - { - - if (!init) - { - init = true; - grid.addListener(Events.ColumnResize, new Listener>() - { - - public void handleEvent(GridEvent be) - { - for (int i = 0; i < be.getGrid().getStore().getCount(); i++) - { - if ((be.getGrid().getView().getWidget(i, be.getColIndex()) != null) && - (be.getGrid().getView().getWidget(i, be.getColIndex()) instanceof BoxComponent)) - { - ((BoxComponent) be.getGrid().getView().getWidget(i, - be.getColIndex())).setWidth(be.getWidth() - 10); - } - } - } - }); - } - - TextField propKey = new TextField(); - propKey.setWidth(200); - propKey.setAllowBlank(false); - propKey.setValue(model.getPropKey()); - - propKey.addListener(Events.Change, new Listener() - { - - public void handleEvent(FieldEvent be) - { - Dispatcher.forwardEvent(GeofenceEvents.SEND_INFO_MESSAGE, - new String[] - { - "GeoServer Rules: Profile Custom Properties", - "Key " + model.getPropKey() + ": Key changed -> " + - be.getField().getValue() - }); - -// Map updateDTO = new HashMap(); -// ProfileCustomProps newModel = new ProfileCustomProps(); -// newModel.setPropKey((String) be.getField().getValue()); -// newModel.setPropValue(model.getPropValue()); -// updateDTO.put(model.getPropKey(), newModel); -// Dispatcher.forwardEvent(GeofenceEvents.RULE_PROFILE_CUSTOM_PROP_UPDATE_KEY, updateDTO); - - model.setPropKey((String) be.getField().getValue()); - } - - }); - - return propKey; - } - - }; - - return textRendered; - } - - /** - * - * @return - */ - private GridCellRenderer createPropValueTextBox() - { - - GridCellRenderer textRendered = new GridCellRenderer() - { - - private boolean init; - - public Object render(final ProfileCustomProps model, String property, ColumnData config, - int rowIndex, int colIndex, ListStore store, Grid grid) - { - - if (!init) - { - init = true; - grid.addListener(Events.ColumnResize, new Listener>() - { - - public void handleEvent(GridEvent be) - { - for (int i = 0; i < be.getGrid().getStore().getCount(); i++) - { - if ((be.getGrid().getView().getWidget(i, be.getColIndex()) != null) && - (be.getGrid().getView().getWidget(i, be.getColIndex()) instanceof BoxComponent)) - { - ((BoxComponent) be.getGrid().getView().getWidget(i, - be.getColIndex())).setWidth(be.getWidth() - 10); - } - } - } - }); - } - - TextField propValue = new TextField(); - propValue.setWidth(250); - propValue.setAllowBlank(true); - propValue.setValue(model.getPropValue()); - - propValue.addListener(Events.Change, new Listener() - { - - public void handleEvent(FieldEvent be) - { - Dispatcher.forwardEvent(GeofenceEvents.SEND_INFO_MESSAGE, - new String[] - { - "GeoServer Rules: Profile Custom Properties", - "Key " + model.getPropKey() + ": Value changed -> " + - be.getField().getValue() - }); - -// Map updateDTO = new HashMap(); -// ProfileCustomProps newModel = new ProfileCustomProps(); -// newModel.setPropKey(model.getPropKey()); -// newModel.setPropValue((String) be.getField().getValue()); -// updateDTO.put(model.getPropKey(), newModel); -// Dispatcher.forwardEvent(GeofenceEvents.RULE_PROFILE_CUSTOM_PROP_UPDATE_VALUE, updateDTO); - - model.setPropValue((String) be.getField().getValue()); - } - - }); - - return propValue; - } - - }; - - return textRendered; - } - - /** - * Creates the profile delete button. - * - * @return the grid cell renderer - */ - private GridCellRenderer createDeleteButton() - { - GridCellRenderer buttonRendered = new GridCellRenderer() - { - - private boolean init; - - public Object render(final ProfileCustomProps model, String property, ColumnData config, - int rowIndex, int colIndex, ListStore store, Grid grid) - { - - if (!init) - { - init = true; - grid.addListener(Events.ColumnResize, new Listener>() - { - - public void handleEvent(GridEvent be) - { - for (int i = 0; i < be.getGrid().getStore().getCount(); i++) - { - if ((be.getGrid().getView().getWidget(i, be.getColIndex()) != null) && - (be.getGrid().getView().getWidget(i, be.getColIndex()) instanceof BoxComponent)) - { - ((BoxComponent) be.getGrid().getView().getWidget(i, - be.getColIndex())).setWidth(be.getWidth() - 10); - } - } - } - }); - } - - Button removeButton = new Button(); - removeButton.setBorders(false); - removeButton.setIcon(Resources.ICONS.delete()); - removeButton.setEnabled(true); - - removeButton.addListener(Events.OnClick, new Listener() - { - - public void handleEvent(ButtonEvent be) - { - Dispatcher.forwardEvent(GeofenceEvents.SEND_INFO_MESSAGE, - new String[] { "GeoServer Rules: Profile Custom Properties", "Remove Property" }); - - Map updateDTO = new HashMap(); - updateDTO.put(profile.getId(), model); - Dispatcher.forwardEvent(GeofenceEvents.RULE_PROFILE_CUSTOM_PROP_DEL, updateDTO); - } - }); - - return removeButton; - } - - }; - - return buttonRendered; - } - - /* - * (non-Javadoc) - * - * @see org.geoserver.geofence.gui.client.widget.DGWATCHGridWidget#createStore() - */ - @Override - public void createStore() - { - this.toolBar = new PagingToolBar(org.geoserver.geofence.gui.client.Constants.DEFAULT_PAGESIZE); - - // Loader fro rulesService - this.proxy = new RpcProxy>() - { - - @Override - protected void load(Object loadConfig, AsyncCallback> callback) - { - profilesService.getProfileCustomProps(((PagingLoadConfig) loadConfig).getOffset(), ((PagingLoadConfig) loadConfig).getLimit(), profile, callback); - } - - }; - loader = new BasePagingLoader>(proxy); - loader.setRemoteSort(true); - store = new ListStore(loader); -// store.sort(BeanKeyValue.PROFILE_PROP_KEY.getValue(), SortDir.ASC); - - Button addRuleCustomPropertyButton = new Button("Add Property"); - addRuleCustomPropertyButton.setIcon(Resources.ICONS.add()); - - addRuleCustomPropertyButton.addListener(Events.OnClick, new Listener() - { - - public void handleEvent(ButtonEvent be) - { - Dispatcher.forwardEvent(GeofenceEvents.SEND_INFO_MESSAGE, - new String[] { "GeoServer Rules: Layer Custom Properties", "Add Property" }); - - Map updateDTO = new HashMap(); - updateDTO.put(profile.getId(), null); - Dispatcher.forwardEvent(GeofenceEvents.RULE_PROFILE_CUSTOM_PROP_ADD, updateDTO); - } - }); - - Button saveRuleCustomPropertiesButton = new Button("Save"); - saveRuleCustomPropertiesButton.setIcon(Resources.ICONS.save()); - - saveRuleCustomPropertiesButton.addListener(Events.OnClick, new Listener() - { - - public void handleEvent(ButtonEvent be) - { - Dispatcher.forwardEvent(GeofenceEvents.SEND_INFO_MESSAGE, - new String[] { "GeoServer Rules: Layer Custom Properties", "Apply Changes" }); - - Dispatcher.forwardEvent(GeofenceEvents.RULE_PROFILE_CUSTOM_PROP_APPLY_CHANGES, profile.getId()); - } - }); - - Button cancelButton = new Button("Cancel"); - cancelButton.addListener(Events.OnClick, new Listener() - { - public void handleEvent(ButtonEvent be) - { - // ///////////////////////////////////////////////////////// - // Getting the Profile details edit dialogs and hiding this - // ///////////////////////////////////////////////////////// - ComponentManager.get().get(I18nProvider.getMessages().profileDialogId()).hide(); - } - }); - - this.toolBar.bind(loader); - this.toolBar.add(new SeparatorToolItem()); - this.toolBar.add(addRuleCustomPropertyButton); - this.toolBar.add(new SeparatorToolItem()); - this.toolBar.add(saveRuleCustomPropertiesButton); - this.toolBar.add(cancelButton); - - setUpLoadListener(); - } - - /** - * Gets the loader. - * - * @return the loader - */ - public PagingLoader> getLoader() - { - return loader; - } - - /** - * Gets the tool bar. - * - * @return the tool bar - */ - public PagingToolBar getToolBar() - { - return toolBar; - } - - /** - * Clear grid elements. - */ - public void clearGridElements() - { - this.store.removeAll(); - this.toolBar.clear(); - this.toolBar.disable(); - } - - /** - * Sets the up load listener. - */ - private void setUpLoadListener() - { - loader.addLoadListener(new LoadListener() - { - - @Override - public void loaderBeforeLoad(LoadEvent le) - { - if (!toolBar.isEnabled()) - { - toolBar.enable(); - } - } - - @Override - public void loaderLoad(LoadEvent le) - { - - // TODO: change messages here!! - - BasePagingLoadResult result = le.getData(); - if (!result.getData().isEmpty()) - { - int size = result.getData().size(); - String message = ""; - if (size == 1) - { - message = I18nProvider.getMessages().recordLabel(); - } - else - { - message = I18nProvider.getMessages().recordPluralLabel(); - } - Dispatcher.forwardEvent(GeofenceEvents.SEND_INFO_MESSAGE, - new String[] - { - I18nProvider.getMessages().remoteServiceName(), - I18nProvider.getMessages().foundLabel() + " " + result.getData().size() + - " " + message - }); - } - else - { - Dispatcher.forwardEvent(GeofenceEvents.SEND_INFO_MESSAGE, - new String[] - { - I18nProvider.getMessages().remoteServiceName(), - I18nProvider.getMessages().recordNotFoundMessage() - }); - } - } - - }); - } - -} diff --git a/src/gui/core/plugin/userui/src/main/java/org/geoserver/geofence/gui/client/widget/rule/detail/ProfileDetailsTabItem.java b/src/gui/core/plugin/userui/src/main/java/org/geoserver/geofence/gui/client/widget/rule/detail/ProfileDetailsTabItem.java deleted file mode 100644 index f2b2fc74..00000000 --- a/src/gui/core/plugin/userui/src/main/java/org/geoserver/geofence/gui/client/widget/rule/detail/ProfileDetailsTabItem.java +++ /dev/null @@ -1,81 +0,0 @@ -/* (c) 2014 Open Source Geospatial Foundation - all rights reserved - * This code is licensed under the GPL 2.0 license, available at the root - * application directory. - */ - -package org.geoserver.geofence.gui.client.widget.rule.detail; - -import com.extjs.gxt.ui.client.Style.Scroll; -import com.extjs.gxt.ui.client.widget.TabItem; - -import org.geoserver.geofence.gui.client.Resources; -import org.geoserver.geofence.gui.client.model.UserGroupModel; -import org.geoserver.geofence.gui.client.service.ProfilesManagerRemoteServiceAsync; - - -/** - * The Class ProfileDetailsTabItem. - */ -public class ProfileDetailsTabItem extends TabItem -{ - - /** The profile details widget. */ - private ProfileDetailsWidget profileDetailsWidget; - - private UserGroupModel profile; - - /** - * Instantiates a new profile details tab item. - * - * @param tabItemId - * the tab item id - */ - private ProfileDetailsTabItem(String tabItemId) - { - // TODO: add I18n message - // super(I18nProvider.getMessages().profiles()); - super("Role Details"); - setId(tabItemId); - setIcon(Resources.ICONS.table()); - } - - /** - * Instantiates a new Profile Details tab item. - * - * @param tabItemId - * the tab item id - * @param model - * @param rulesService - * the rules service - */ - public ProfileDetailsTabItem(String tabItemId, UserGroupModel profile, ProfilesManagerRemoteServiceAsync profilesService) - { - this(tabItemId); - this.profile = profile; - - setProfileDetailsWidget(new ProfileDetailsWidget(this.profile, profilesService)); - add(getProfileDetailsWidget()); - - setScrollMode(Scroll.NONE); - - getProfileDetailsWidget().getProfileDetailsInfo().getLoader().load(0, org.geoserver.geofence.gui.client.Constants.DEFAULT_PAGESIZE); - - } - - /** - * @return the profileDetailsWidget - */ - public ProfileDetailsWidget getProfileDetailsWidget() - { - return profileDetailsWidget; - } - - /** - * @param profileDetailsWidget the profileDetailsWidget to set - */ - public void setProfileDetailsWidget(ProfileDetailsWidget profileDetailsWidget) - { - this.profileDetailsWidget = profileDetailsWidget; - } - -} diff --git a/src/gui/core/plugin/userui/src/main/java/org/geoserver/geofence/gui/client/widget/rule/detail/ProfileDetailsWidget.java b/src/gui/core/plugin/userui/src/main/java/org/geoserver/geofence/gui/client/widget/rule/detail/ProfileDetailsWidget.java deleted file mode 100644 index 052a7e06..00000000 --- a/src/gui/core/plugin/userui/src/main/java/org/geoserver/geofence/gui/client/widget/rule/detail/ProfileDetailsWidget.java +++ /dev/null @@ -1,85 +0,0 @@ -/* (c) 2014 Open Source Geospatial Foundation - all rights reserved - * This code is licensed under the GPL 2.0 license, available at the root - * application directory. - */ - -package org.geoserver.geofence.gui.client.widget.rule.detail; - -import com.extjs.gxt.ui.client.Style.Scroll; -import com.extjs.gxt.ui.client.widget.ContentPanel; -import com.extjs.gxt.ui.client.widget.layout.FitLayout; - -import org.geoserver.geofence.gui.client.model.UserGroupModel; -import org.geoserver.geofence.gui.client.service.ProfilesManagerRemoteServiceAsync; - - -/** - * The Class ProfileDetailsWidget. - * - * @author Tobia di Pisa - * - */ -public class ProfileDetailsWidget extends ContentPanel -{ - - /** The profile details info. */ - private ProfileDetailsGridWidget profileDetailsInfo; - - private UserGroupModel profile; - - /** - * Instantiates a new layer custom props widget. - * @param model - * - * @param rulesService - * the rules service - */ - public ProfileDetailsWidget(UserGroupModel profile, ProfilesManagerRemoteServiceAsync profilesService) - { - this.profile = profile; - - setHeaderVisible(false); - setFrame(true); - setHeight(330); - setLayout(new FitLayout()); - - setProfileDetailsInfo(new ProfileDetailsGridWidget(this.profile, profilesService)); - - add(getProfileDetailsInfo().getGrid()); - - super.setMonitorWindowResize(true); - - setScrollMode(Scroll.NONE); - - setBottomComponent(this.getProfileDetailsInfo().getToolBar()); - } - - /* - * (non-Javadoc) - * - * @see com.extjs.gxt.ui.client.widget.Component#onWindowResize(int, int) - */ - @Override - protected void onWindowResize(int width, int height) - { - super.setWidth(width - 5); - super.layout(); - } - - /** - * @return the profileDetailsInfo - */ - public ProfileDetailsGridWidget getProfileDetailsInfo() - { - return profileDetailsInfo; - } - - /** - * @param profileDetailsInfo the profileDetailsInfo to set - */ - public void setProfileDetailsInfo(ProfileDetailsGridWidget profileDetailsInfo) - { - this.profileDetailsInfo = profileDetailsInfo; - } - -} diff --git a/src/gui/core/plugin/userui/src/main/java/org/geoserver/geofence/gui/client/widget/rule/detail/UserDetailsInfoWidget.java b/src/gui/core/plugin/userui/src/main/java/org/geoserver/geofence/gui/client/widget/rule/detail/UserDetailsInfoWidget.java deleted file mode 100644 index 7eb2c5c0..00000000 --- a/src/gui/core/plugin/userui/src/main/java/org/geoserver/geofence/gui/client/widget/rule/detail/UserDetailsInfoWidget.java +++ /dev/null @@ -1,162 +0,0 @@ -/* (c) 2014 Open Source Geospatial Foundation - all rights reserved - * This code is licensed under the GPL 2.0 license, available at the root - * application directory. - */ - -package org.geoserver.geofence.gui.client.widget.rule.detail; - -import com.extjs.gxt.ui.client.event.Events; -import com.extjs.gxt.ui.client.event.FieldEvent; -import com.extjs.gxt.ui.client.event.Listener; -import com.extjs.gxt.ui.client.widget.form.FieldSet; -import com.extjs.gxt.ui.client.widget.form.FormPanel; -import com.extjs.gxt.ui.client.widget.form.TextArea; -import com.extjs.gxt.ui.client.widget.layout.FormLayout; - -import org.geoserver.geofence.gui.client.model.GSUserModel; -import org.geoserver.geofence.gui.client.model.data.UserLimitsInfoModel; -import org.geoserver.geofence.gui.client.service.GsUsersManagerRemoteServiceAsync; -import org.geoserver.geofence.gui.client.widget.GeofenceFormBindingWidget; - - -/** - * The Class UserDetailsInfoWidget. - */ -public class UserDetailsInfoWidget extends GeofenceFormBindingWidget -{ - - /** The user. */ - private GSUserModel user; - - /** The user service. */ - private GsUsersManagerRemoteServiceAsync usersService; - - /** The user details widget. */ - private UserDetailsWidget userDetailsWidget; - - /** The allowed area. */ - private TextArea allowedArea; - - /** - * Instantiates a new rule details info widget. - * - * @param model - * the model - * @param workspacesService - * the workspaces service - * @param ruleDetailsWidget - * the rule details widget - */ - public UserDetailsInfoWidget(GSUserModel model, GsUsersManagerRemoteServiceAsync usersService, - UserDetailsWidget userDetailsWidget) - { - - super(); - this.user = model; - this.usersService = usersService; - this.userDetailsWidget = userDetailsWidget; - formPanel = createFormPanel(); - } - - /* (non-Javadoc) - * @see org.geoserver.geofence.gui.client.widget.GeofenceFormBindingWidget#createFormPanel() - */ - @Override - public FormPanel createFormPanel() - { - FormPanel fp = new FormPanel(); - fp.setFrame(true); - fp.setHeaderVisible(false); - fp.setAutoHeight(true); - - FieldSet fieldSet = new FieldSet(); - fieldSet.setHeading("User Limits"); - fieldSet.setCheckboxToggle(false); - fieldSet.setCollapsible(true); - - FormLayout layout = new FormLayout(); - fieldSet.setLayout(layout); - - allowedArea = new TextArea(); - allowedArea.setFieldLabel("Allowed Area"); - allowedArea.setPreventScrollbars(true); - allowedArea.addListener(Events.Change, new Listener() - { - - public void handleEvent(FieldEvent be) - { - userDetailsWidget.enableSaveButton(); - } - - }); - - fieldSet.add(allowedArea); - - fp.add(fieldSet); - - return fp; - } - - /** - * Gets the model data. - * - * @return the model data - */ - public UserLimitsInfoModel getModelData() - { - UserLimitsInfoModel userInfo = new UserLimitsInfoModel(); - - String area = allowedArea.getValue(); - - String wkt, srid; - if (area != null) - { - if (area.indexOf("SRID=") != -1) - { - String[] allowedAreaArray = area.split(";"); - - srid = allowedAreaArray[0].split("=")[1]; - wkt = allowedAreaArray[1]; - } - else - { - srid = "4326"; - wkt = area; - } - } - else - { - srid = null; - wkt = null; - } - - userInfo.setAllowedArea(wkt); - userInfo.setSrid(srid); - userInfo.setUserId(user.getId()); - - return userInfo; - } - - /** - * Bind model data. - * - * @param layerDetailsInfo - * the layer details info - */ - public void bindModelData(UserLimitsInfoModel userInfo) - { - this.bindModel(userInfo); - - String area = userInfo.getAllowedArea(); - String srid = userInfo.getSrid(); - if ((area != null) && (srid != null)) - { - allowedArea.setValue("SRID=" + srid + ";" + area); - } - else - { - allowedArea.setValue(""); - } - } - -} diff --git a/src/gui/core/plugin/userui/src/main/java/org/geoserver/geofence/gui/client/widget/rule/detail/UserDetailsTabItem.java b/src/gui/core/plugin/userui/src/main/java/org/geoserver/geofence/gui/client/widget/rule/detail/UserDetailsTabItem.java index a660187a..2fc0787e 100644 --- a/src/gui/core/plugin/userui/src/main/java/org/geoserver/geofence/gui/client/widget/rule/detail/UserDetailsTabItem.java +++ b/src/gui/core/plugin/userui/src/main/java/org/geoserver/geofence/gui/client/widget/rule/detail/UserDetailsTabItem.java @@ -1,11 +1,10 @@ -/* (c) 2014 Open Source Geospatial Foundation - all rights reserved +/* (c) 2014 - 2017 Open Source Geospatial Foundation - all rights reserved * This code is licensed under the GPL 2.0 license, available at the root * application directory. */ package org.geoserver.geofence.gui.client.widget.rule.detail; -import org.geoserver.geofence.gui.client.GeofenceEvents; import org.geoserver.geofence.gui.client.Resources; import org.geoserver.geofence.gui.client.model.GSUserModel; import org.geoserver.geofence.gui.client.service.GsUsersManagerRemoteServiceAsync; @@ -15,7 +14,6 @@ import com.extjs.gxt.ui.client.event.BaseEvent; import com.extjs.gxt.ui.client.event.Events; import com.extjs.gxt.ui.client.event.Listener; -import com.extjs.gxt.ui.client.mvc.Dispatcher; import com.extjs.gxt.ui.client.widget.TabItem; @@ -53,7 +51,7 @@ private UserDetailsTabItem(String tabItemId) * the tab item id * @param model * the model - * @param profilesManagerServiceRemote + * @param profilesManagerServiceRemote * @param workspacesService * the workspaces service */ @@ -72,11 +70,6 @@ public UserDetailsTabItem(String tabItemId, GSUserModel model, GsUsersManagerRem public void handleEvent(BaseEvent be) { - if (userDetailsWidget.getUserDetailsInfo().getModel() == null) - { - Dispatcher.forwardEvent(GeofenceEvents.LOAD_USER_LIMITS, user); - } - if (userDetailsWidget.getProfilesInfo().getStore().getCount() < 1) { userDetailsWidget.getProfilesInfo().getLoader().load(); diff --git a/src/gui/core/plugin/userui/src/main/java/org/geoserver/geofence/gui/client/widget/rule/detail/UserDetailsWidget.java b/src/gui/core/plugin/userui/src/main/java/org/geoserver/geofence/gui/client/widget/rule/detail/UserDetailsWidget.java index 2a73f850..a7f44472 100644 --- a/src/gui/core/plugin/userui/src/main/java/org/geoserver/geofence/gui/client/widget/rule/detail/UserDetailsWidget.java +++ b/src/gui/core/plugin/userui/src/main/java/org/geoserver/geofence/gui/client/widget/rule/detail/UserDetailsWidget.java @@ -1,4 +1,4 @@ -/* (c) 2014 Open Source Geospatial Foundation - all rights reserved +/* (c) 2014 - 2017 Open Source Geospatial Foundation - all rights reserved * This code is licensed under the GPL 2.0 license, available at the root * application directory. */ @@ -41,9 +41,6 @@ public class UserDetailsWidget extends ContentPanel /** The user. */ private GSUserModel user; - /** The user details info. */ - private UserDetailsInfoWidget userDeatilsInfo; - /** The profiles info. */ private ProfilesGridWidget profilesInfo; @@ -66,10 +63,10 @@ public class UserDetailsWidget extends ContentPanel * the model * @param usersService * the user service - * @param profilesManagerServiceRemote + * @param profilesManagerServiceRemote */ - public UserDetailsWidget(GSUserModel model, - GsUsersManagerRemoteServiceAsync usersService, + public UserDetailsWidget(GSUserModel model, + GsUsersManagerRemoteServiceAsync usersService, final ProfilesManagerRemoteServiceAsync profilesManagerServiceRemote) { this.user = model; @@ -81,12 +78,9 @@ public UserDetailsWidget(GSUserModel model, setWidth(690); setLayout(new FitLayout()); - userDeatilsInfo = new UserDetailsInfoWidget(this.user, usersService, this); - //add(userDeatilsInfo.getFormPanel()); - profilesInfo = new ProfilesGridWidget(this.user, usersService, profilesManagerServiceRemote, this); add(profilesInfo.getGrid()); - + super.setMonitorWindowResize(true); setScrollMode(Scroll.AUTOY); @@ -109,8 +103,8 @@ public void handleEvent(ButtonEvent be) Dispatcher.forwardEvent(GeofenceEvents.SAVE_USER_LIMITS, userInfoModel);*/ profilesManagerServiceRemote.getProfiles(-1, -1, true, new AsyncCallback>() { - - public void onSuccess(PagingLoadResult result) { + + public void onSuccess(PagingLoadResult result) { Set groups = new HashSet(); for (UserGroupModel gg : profilesInfo.getStore().getModels()) { @@ -118,17 +112,17 @@ public void onSuccess(PagingLoadResult result) { if(gg.getName().equals(gg_r.getName()) && gg.isEnabled()){ groups.add(gg_r); } - + } } user.setUserGroups(groups); Dispatcher.forwardEvent(GeofenceEvents.SAVE_USER_GROUPS, user); - + Dispatcher.forwardEvent(GeofenceEvents.SEND_INFO_MESSAGE, new String[] { "GeoServer Users: Users Roles", "Apply Changes Successfull!" }); } - + public void onFailure(Throwable caught) { Dispatcher.forwardEvent(GeofenceEvents.SEND_ERROR_MESSAGE, new String[] { "GeoServer Users: Users Roles", "Error Occurred while assigning roles to the user!" }); @@ -167,27 +161,6 @@ protected void onWindowResize(int width, int height) super.layout(); } - /** - * Sets the user limits info. - * - * @param userDetailsInfoWidget - * the new user limits info - */ - public void setUserDetailsInfo(UserDetailsInfoWidget userDetailsInfoWidget) - { - this.userDeatilsInfo = userDetailsInfoWidget; - } - - /** - * Gets the user limits info. - * - * @return the user limits info - */ - public UserDetailsInfoWidget getUserDetailsInfo() - { - return userDeatilsInfo; - } - /** * Disable save button. */ diff --git a/src/gui/core/plugin/userui/src/main/java/org/geoserver/geofence/gui/server/gwt/GsUsersManagerServiceImpl.java b/src/gui/core/plugin/userui/src/main/java/org/geoserver/geofence/gui/server/gwt/GsUsersManagerServiceImpl.java index 9a39ebcd..603cbca2 100644 --- a/src/gui/core/plugin/userui/src/main/java/org/geoserver/geofence/gui/server/gwt/GsUsersManagerServiceImpl.java +++ b/src/gui/core/plugin/userui/src/main/java/org/geoserver/geofence/gui/server/gwt/GsUsersManagerServiceImpl.java @@ -1,4 +1,4 @@ -/* (c) 2014 Open Source Geospatial Foundation - all rights reserved +/* (c) 2014 - 2017 Open Source Geospatial Foundation - all rights reserved * This code is licensed under the GPL 2.0 license, available at the root * application directory. */ @@ -11,7 +11,6 @@ import org.geoserver.geofence.gui.client.ApplicationException; import org.geoserver.geofence.gui.client.model.GSUserModel; import org.geoserver.geofence.gui.client.model.UsernameModel; -import org.geoserver.geofence.gui.client.model.data.UserLimitsInfoModel; import org.geoserver.geofence.gui.client.service.GsUsersManagerRemoteService; import org.geoserver.geofence.gui.server.service.IGsUsersManagerService; import org.geoserver.geofence.gui.spring.ApplicationContextUtil; @@ -73,22 +72,6 @@ public void deleteGsUser(GSUserModel user) throws ApplicationException gsUserManagerService.deleteUser(user); } - /* (non-Javadoc) - * @see org.geoserver.geofence.gui.client.service.GsUsersManagerRemoteService#getUserLimitsInfo(org.geoserver.geofence.gui.client.model.GSUser) - */ - public UserLimitsInfoModel getUserLimitsInfo(GSUserModel user) throws ApplicationException - { - return gsUserManagerService.getUserLimitsInfo(user); - } - - /* (non-Javadoc) - * @see org.geoserver.geofence.gui.client.service.GsUsersManagerRemoteService#saveUserLimitsInfo(org.geoserver.geofence.gui.client.model.GSUser) - */ - public UserLimitsInfoModel saveUserLimitsInfo(UserLimitsInfoModel userLimitInfo) throws ApplicationException - { - return gsUserManagerService.saveUserLimitsInfo(userLimitInfo); - } - /* (non-Javadoc) * @see org.geoserver.geofence.gui.client.service.GsUsersManagerRemoteService#activateUserGroupTabs() */ diff --git a/src/gui/core/plugin/userui/src/main/java/org/geoserver/geofence/gui/server/gwt/ProfilesManagerServiceImpl.java b/src/gui/core/plugin/userui/src/main/java/org/geoserver/geofence/gui/server/gwt/ProfilesManagerServiceImpl.java index 927cf02e..c627f9f1 100644 --- a/src/gui/core/plugin/userui/src/main/java/org/geoserver/geofence/gui/server/gwt/ProfilesManagerServiceImpl.java +++ b/src/gui/core/plugin/userui/src/main/java/org/geoserver/geofence/gui/server/gwt/ProfilesManagerServiceImpl.java @@ -1,19 +1,16 @@ -/* (c) 2014 Open Source Geospatial Foundation - all rights reserved +/* (c) 2014 - 2017 Open Source Geospatial Foundation - all rights reserved * This code is licensed under the GPL 2.0 license, available at the root * application directory. */ package org.geoserver.geofence.gui.server.gwt; -import java.util.List; - import com.extjs.gxt.ui.client.data.PagingLoadResult; import com.google.gwt.user.server.rpc.RemoteServiceServlet; import org.geoserver.geofence.gui.client.ApplicationException; import org.geoserver.geofence.gui.client.model.RolenameModel; import org.geoserver.geofence.gui.client.model.UserGroupModel; -import org.geoserver.geofence.gui.client.model.data.ProfileCustomProps; import org.geoserver.geofence.gui.client.service.ProfilesManagerRemoteService; import org.geoserver.geofence.gui.server.service.IProfilesManagerService; import org.geoserver.geofence.gui.spring.ApplicationContextUtil; @@ -76,21 +73,4 @@ public void saveProfile(UserGroupModel profile) throws ApplicationException profilesManagerService.saveProfile(profile); } - /* (non-Javadoc) - * @see org.geoserver.geofence.gui.client.service.ProfilesManagerRemoteService#getProfileCustomProps(com.extjs.gxt.ui.client.data.PagingLoadConfig, org.geoserver.geofence.gui.client.model.Rule) - */ - public PagingLoadResult getProfileCustomProps(int offset, int limit, - UserGroupModel profile) throws ApplicationException - { - return profilesManagerService.getProfileCustomProps(offset, limit, profile); - } - - /* (non-Javadoc) - * @see org.geoserver.geofence.gui.client.service.ProfilesManagerRemoteService#setProfileProps(java.lang.Long, java.util.List) - */ - public void setProfileProps(Long profileId, List customProps) throws ApplicationException - { - profilesManagerService.setProfileProps(profileId, customProps); - } - } diff --git a/src/gui/core/plugin/userui/src/main/java/org/geoserver/geofence/gui/server/service/IGsUsersManagerService.java b/src/gui/core/plugin/userui/src/main/java/org/geoserver/geofence/gui/server/service/IGsUsersManagerService.java index a2eac775..a76a4fb0 100644 --- a/src/gui/core/plugin/userui/src/main/java/org/geoserver/geofence/gui/server/service/IGsUsersManagerService.java +++ b/src/gui/core/plugin/userui/src/main/java/org/geoserver/geofence/gui/server/service/IGsUsersManagerService.java @@ -1,4 +1,4 @@ -/* (c) 2014 Open Source Geospatial Foundation - all rights reserved +/* (c) 2014 - 2017 Open Source Geospatial Foundation - all rights reserved * This code is licensed under the GPL 2.0 license, available at the root * application directory. */ @@ -10,7 +10,6 @@ import org.geoserver.geofence.gui.client.ApplicationException; import org.geoserver.geofence.gui.client.model.GSUserModel; import org.geoserver.geofence.gui.client.model.UsernameModel; -import org.geoserver.geofence.gui.client.model.data.UserLimitsInfoModel; /** @@ -50,19 +49,6 @@ public interface IGsUsersManagerService * the profile */ public void deleteUser(GSUserModel user); - - - /** - * @param user - * @return UserLimitInfo - */ - public UserLimitsInfoModel getUserLimitsInfo(GSUserModel user); - - /** - * @param user - * @return UserLimitInfo - */ - public UserLimitsInfoModel saveUserLimitsInfo(UserLimitsInfoModel userLimitInfo); /** * @return diff --git a/src/gui/core/plugin/userui/src/main/java/org/geoserver/geofence/gui/server/service/IProfilesManagerService.java b/src/gui/core/plugin/userui/src/main/java/org/geoserver/geofence/gui/server/service/IProfilesManagerService.java index 20e49552..bbf0213d 100644 --- a/src/gui/core/plugin/userui/src/main/java/org/geoserver/geofence/gui/server/service/IProfilesManagerService.java +++ b/src/gui/core/plugin/userui/src/main/java/org/geoserver/geofence/gui/server/service/IProfilesManagerService.java @@ -1,4 +1,4 @@ -/* (c) 2014 Open Source Geospatial Foundation - all rights reserved +/* (c) 2014 - 2017 Open Source Geospatial Foundation - all rights reserved * This code is licensed under the GPL 2.0 license, available at the root * application directory. */ @@ -12,7 +12,6 @@ import org.geoserver.geofence.gui.client.ApplicationException; import org.geoserver.geofence.gui.client.model.RolenameModel; import org.geoserver.geofence.gui.client.model.UserGroupModel; -import org.geoserver.geofence.gui.client.model.data.ProfileCustomProps; // TODO: Auto-generated Javadoc @@ -52,16 +51,4 @@ public interface IProfilesManagerService */ public void saveProfile(UserGroupModel profile); - /** - * @param config - * @param rule - * @return - */ - public PagingLoadResult getProfileCustomProps(int offset, int limit, UserGroupModel profile); - - /** - * @param ruleId - * @param customProps - */ - public void setProfileProps(Long profileId, List customProps); } diff --git a/src/gui/core/plugin/userui/src/main/java/org/geoserver/geofence/gui/server/service/impl/GsUsersManagerServiceImpl.java b/src/gui/core/plugin/userui/src/main/java/org/geoserver/geofence/gui/server/service/impl/GsUsersManagerServiceImpl.java index ea279e5d..814d5dbc 100644 --- a/src/gui/core/plugin/userui/src/main/java/org/geoserver/geofence/gui/server/service/impl/GsUsersManagerServiceImpl.java +++ b/src/gui/core/plugin/userui/src/main/java/org/geoserver/geofence/gui/server/service/impl/GsUsersManagerServiceImpl.java @@ -1,4 +1,4 @@ -/* (c) 2014 Open Source Geospatial Foundation - all rights reserved +/* (c) 2014 - 2017 Open Source Geospatial Foundation - all rights reserved * This code is licensed under the GPL 2.0 license, available at the root * application directory. */ @@ -16,7 +16,6 @@ import org.geoserver.geofence.gui.client.ApplicationException; import org.geoserver.geofence.gui.client.model.GSUserModel; import org.geoserver.geofence.gui.client.model.UserGroupModel; -import org.geoserver.geofence.gui.client.model.data.UserLimitsInfoModel; import org.geoserver.geofence.gui.client.model.data.rpc.RpcPageLoadResult; import org.geoserver.geofence.gui.server.service.IGsUsersManagerService; import org.geoserver.geofence.gui.service.GeofenceRemoteService; @@ -60,7 +59,7 @@ public PagingLoadResult getGsUsers(int offset, int limit, boolean f if (full) { GSUserModel all_user = new GSUserModel(); - all_user.setId(-1); + all_user.setId(-1l); all_user.setName("*"); all_user.setFullName("*"); all_user.setEnabled(true); @@ -76,7 +75,7 @@ public PagingLoadResult getGsUsers(int offset, int limit, boolean f int page = (start == 0) ? start : (start / limit); - List usersList = geofenceRemoteService.getUserAdminService().getList(null, page, limit); + List usersList = geofenceRemoteService.getUserAdminService().getFullList(null, page, limit); if (usersList == null) { @@ -87,25 +86,10 @@ public PagingLoadResult getGsUsers(int offset, int limit, boolean f throw new ApplicationException("No user found on server"); } - for (ShortUser short_usr : usersList) + for (org.geoserver.geofence.core.model.GSUser remote_user : usersList) { - org.geoserver.geofence.core.model.GSUser remote_user; - try - { - remote_user = geofenceRemoteService.getUserAdminService().getFull(short_usr.getId()); - } - catch (NotFoundServiceEx e) - { - if (logger.isErrorEnabled()) - { - logger.error("Details for profile " + short_usr.getName() + - " not found on Server!"); - } - throw new ApplicationException(e); - } - GSUserModel local_user = new GSUserModel(); - local_user.setId(short_usr.getId()); + local_user.setId(remote_user.getId()); local_user.setName(remote_user.getName()); local_user.setFullName(remote_user.getFullName()); local_user.setEnabled(remote_user.getEnabled()); @@ -116,15 +100,15 @@ public PagingLoadResult getGsUsers(int offset, int limit, boolean f /*logger.error("TODO: profile refactoring!!!");*/ //org.geoserver.geofence.core.model.UserGroup remote_profile = remote_user.getGroups().iterator().next(); - for(org.geoserver.geofence.core.model.UserGroup remote_profile : remote_user.getGroups()) - { - UserGroupModel local_group = new UserGroupModel(); - local_group.setId(remote_profile.getId()); - local_group.setName(remote_profile.getName()); - local_group.setDateCreation(remote_profile.getDateCreation()); - local_group.setEnabled(remote_profile.getEnabled()); - local_user.getUserGroups().add(local_group); - } +// for(org.geoserver.geofence.core.model.UserGroup remote_profile : remote_user.getGroups()) +// { +// UserGroupModel local_group = new UserGroupModel(); +// local_group.setId(remote_profile.getId()); +// local_group.setName(remote_profile.getName()); +// local_group.setDateCreation(remote_profile.getDateCreation()); +// local_group.setEnabled(remote_profile.getEnabled()); +// local_user.getUserGroups().add(local_group); +// } usersListDTO.add(local_user); } @@ -254,93 +238,6 @@ public void deleteUser(GSUserModel user) throws ApplicationException throw new ApplicationException(e.getLocalizedMessage(), e.getCause()); } } - - /* (non-Javadoc) - * @see org.geoserver.geofence.gui.server.service.IGsUsersManagerService#getUserLimitsInfo(org.geoserver.geofence.gui.client.model.GSUser) - */ - public UserLimitsInfoModel getUserLimitsInfo(GSUserModel user) throws ApplicationException - { - Long userId = user.getId(); - org.geoserver.geofence.core.model.GSUser gsUser = null; - UserLimitsInfoModel userLimitInfo = null; - - logger.error("TODO: allowed area removed from base model!!!"); - - try - { - gsUser = geofenceRemoteService.getUserAdminService().get(userId); - - if (gsUser != null) - { - userLimitInfo = new UserLimitsInfoModel(); - userLimitInfo.setUserId(userId); - -// MultiPolygon the_geom = gsUser.getAllowedArea(); -// -// if (the_geom != null) -// { -// userLimitInfo.setAllowedArea(the_geom.toText()); -// userLimitInfo.setSrid(String.valueOf(the_geom.getSRID())); -// } -// else -// { - userLimitInfo.setAllowedArea(null); - userLimitInfo.setSrid(null); -// } - } - } - catch (NotFoundServiceEx e) - { - logger.error(e.getMessage(), e); - throw new ApplicationException(e.getMessage(), e); - } - - return userLimitInfo; - } - - /* (non-Javadoc) - * @see org.geoserver.geofence.gui.server.service.IGsUsersManagerService#saveUserLimitsInfo(org.geoserver.geofence.gui.client.model.GSUser) - */ - public UserLimitsInfoModel saveUserLimitsInfo(UserLimitsInfoModel userLimitInfo) throws ApplicationException - { - logger.error("TODO: allowed area removed from base model!!!"); - - Long userId = userLimitInfo.getUserId(); - org.geoserver.geofence.core.model.GSUser gsUser = null; - - try - { - gsUser = geofenceRemoteService.getUserAdminService().get(userId); - -// String allowedArea = userLimitInfo.getAllowedArea(); -// -// if (allowedArea != null) -// { -// WKTReader wktReader = new WKTReader(); -// MultiPolygon the_geom = (MultiPolygon) wktReader.read(allowedArea); -// the_geom.setSRID(Integer.valueOf(userLimitInfo.getSrid()).intValue()); -// gsUser.setAllowedArea(the_geom); -// } -// else -// { -// gsUser.setAllowedArea(null); -// } -// -// geofenceRemoteService.getUserAdminService().update(gsUser); - } - catch (NotFoundServiceEx e) - { - logger.error(e.getMessage(), e); - throw new ApplicationException(e.getMessage(), e); - } -// catch (ParseException e) -// { -// logger.error(e.getMessage(), e); -// throw new ApplicationException(e.getMessage(), e); -// } - - return userLimitInfo; - } /* (non-Javadoc) * @see org.geoserver.geofence.gui.server.service.IGsUsersManagerService#activateUserGroupTabs() diff --git a/src/gui/core/plugin/userui/src/main/java/org/geoserver/geofence/gui/server/service/impl/LoginService.java b/src/gui/core/plugin/userui/src/main/java/org/geoserver/geofence/gui/server/service/impl/LoginService.java index afd8add2..df692bba 100644 --- a/src/gui/core/plugin/userui/src/main/java/org/geoserver/geofence/gui/server/service/impl/LoginService.java +++ b/src/gui/core/plugin/userui/src/main/java/org/geoserver/geofence/gui/server/service/impl/LoginService.java @@ -1,4 +1,4 @@ -/* (c) 2014 Open Source Geospatial Foundation - all rights reserved +/* (c) 2014 - 2017 Open Source Geospatial Foundation - all rights reserved * This code is licensed under the GPL 2.0 license, available at the root * application directory. */ @@ -23,8 +23,8 @@ import org.geoserver.geofence.gui.service.GeofenceRemoteService; import org.geoserver.geofence.services.exception.NotFoundServiceEx; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; +import org.apache.log4j.LogManager; +import org.apache.log4j.Logger; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; diff --git a/src/gui/core/plugin/userui/src/main/java/org/geoserver/geofence/gui/server/service/impl/ProfilesManagerServiceImpl.java b/src/gui/core/plugin/userui/src/main/java/org/geoserver/geofence/gui/server/service/impl/ProfilesManagerServiceImpl.java index 550f4ab8..caec43e1 100644 --- a/src/gui/core/plugin/userui/src/main/java/org/geoserver/geofence/gui/server/service/impl/ProfilesManagerServiceImpl.java +++ b/src/gui/core/plugin/userui/src/main/java/org/geoserver/geofence/gui/server/service/impl/ProfilesManagerServiceImpl.java @@ -1,4 +1,4 @@ -/* (c) 2014 Open Source Geospatial Foundation - all rights reserved +/* (c) 2014 - 2017 Open Source Geospatial Foundation - all rights reserved * This code is licensed under the GPL 2.0 license, available at the root * application directory. */ @@ -7,7 +7,6 @@ import org.geoserver.geofence.gui.client.ApplicationException; import org.geoserver.geofence.gui.client.model.UserGroupModel; -import org.geoserver.geofence.gui.client.model.data.ProfileCustomProps; import org.geoserver.geofence.gui.client.model.data.rpc.RpcPageLoadResult; import org.geoserver.geofence.gui.server.service.IProfilesManagerService; import org.geoserver.geofence.gui.service.GeofenceRemoteService; @@ -19,8 +18,6 @@ import java.util.Iterator; import java.util.List; import java.util.Map; -import java.util.SortedSet; -import java.util.TreeSet; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -64,7 +61,7 @@ public PagingLoadResult getProfiles(int offset, int limit, boole if (full) { UserGroupModel all_profile = new UserGroupModel(); - all_profile.setId(-1); + all_profile.setId(-1l); all_profile.setName("*"); all_profile.setEnabled(true); all_profile.setDateCreation(null); @@ -95,31 +92,11 @@ public PagingLoadResult getProfiles(int offset, int limit, boole { ShortGroup short_profile = it.next(); - org.geoserver.geofence.core.model.UserGroup remote_profile; - try - { - remote_profile = geofenceRemoteService.getUserGroupAdminService().get( - short_profile.getId()); - } - catch (NotFoundServiceEx e) - { - if (logger.isErrorEnabled()) - { - logger.error("Details for profile " + short_profile.getName() + - " not found on Server!"); - } - throw new ApplicationException("Details for profile " + short_profile.getName() + - " not found on Server!"); - } - UserGroupModel local_profile = new UserGroupModel(); local_profile.setId(short_profile.getId()); - local_profile.setName(remote_profile.getName()); - local_profile.setDateCreation(remote_profile.getDateCreation()); - local_profile.setEnabled(remote_profile.getEnabled()); - // TODO: use specific API methods in order to load UserGroup custom props - // local_profile.setCustomProps(remote_profile.getCustomProps()); + local_profile.setName(short_profile.getName()); + local_profile.setEnabled(short_profile.isEnabled()); profileListDTO.add(local_profile); } @@ -217,13 +194,9 @@ public void saveProfile(UserGroupModel profile) { try { - remote_profile = new org.geoserver.geofence.core.model.UserGroup(); - ShortGroup short_profile = new ShortGroup(); short_profile.setName(profile.getName()); short_profile.setEnabled(profile.isEnabled()); - // removed by ETj -// short_profile.setDateCreation(profile.getDateCreation()); geofenceRemoteService.getUserGroupAdminService().insert(short_profile); } catch (Exception e) @@ -234,89 +207,4 @@ public void saveProfile(UserGroupModel profile) } } - /* (non-Javadoc) - * @see org.geoserver.geofence.gui.server.service.IProfilesManagerService#getProfileCustomProps(com.extjs.gxt.ui.client.data.PagingLoadConfig, org.geoserver.geofence.gui.client.model.Rule) - */ - public PagingLoadResult getProfileCustomProps(int offset, int limit, UserGroupModel profile) - { - int start = offset; - Long t = new Long(0); - - List customPropsDTO = new ArrayList(); - - if ((profile != null) && (profile.getId() >= 0)) - { - try - { - logger.error("TODO: profile refactoring!!! custom props have been removed"); - Map customProperties = new HashMap(); - customProperties.put("NOTE", "Custom properties are no longer supported. Code is unstable"); -// Map customProperties = geofenceRemoteService.getUserGroupAdminService().getCustomProps(profile.getId()); - - if (customProperties == null) - { - if (logger.isErrorEnabled()) - { - logger.error("No property found on server"); - } - throw new ApplicationException("No rule found on server"); - } - - long rulesCount = customProperties.size(); - - t = new Long(rulesCount); - - int page = (start == 0) ? start : (start / limit); - - SortedSet sortedset = new TreeSet(customProperties.keySet()); - Iterator it = sortedset.iterator(); - - while (it.hasNext()) - { - String key = it.next(); - ProfileCustomProps property = new ProfileCustomProps(); - property.setPropKey(key); - property.setPropValue(customProperties.get(key)); - customPropsDTO.add(property); - } - -// for (String key : customProperties.keySet()) { -// ProfileCustomProps property = new ProfileCustomProps(); -// property.setPropKey(key); -// property.setPropValue(customProperties.get(key)); -// customPropsDTO.add(property); -// } - } - catch (Exception e) - { - // do nothing! - } - } - - return new RpcPageLoadResult(customPropsDTO, offset, t.intValue()); - } - - /** (non-Javadoc) - * @deprecated custom props have been removed - */ - public void setProfileProps(Long profileId, List customProps) - { - Map props = new HashMap(); - - for (ProfileCustomProps prop : customProps) - { - props.put(prop.getPropKey(), prop.getPropValue()); - } - -// LayerDetails details = null; -// try { -// details = geofenceRemoteService.getRuleAdminService().getDetails(ruleId); -// } catch (Exception e) { -// details = new LayerDetails(); -// geofenceRemoteService.getRuleAdminService().setDetails(ruleId, details); -// } - - logger.error("TODO: profile refactoring!!! custom props have been removed"); -// geofenceRemoteService.getUserGroupAdminService().setCustomProps(profileId, props); - } } diff --git a/src/gui/core/plugin/userui/src/main/java/org/geoserver/geofence/gui/server/service/impl/RulesManagerServiceImpl.java b/src/gui/core/plugin/userui/src/main/java/org/geoserver/geofence/gui/server/service/impl/RulesManagerServiceImpl.java index 8f97ddb4..ea955de7 100644 --- a/src/gui/core/plugin/userui/src/main/java/org/geoserver/geofence/gui/server/service/impl/RulesManagerServiceImpl.java +++ b/src/gui/core/plugin/userui/src/main/java/org/geoserver/geofence/gui/server/service/impl/RulesManagerServiceImpl.java @@ -1,4 +1,4 @@ -/* (c) 2014 Open Source Geospatial Foundation - all rights reserved +/* (c) 2014 - 2017 Open Source Geospatial Foundation - all rights reserved * This code is licensed under the GPL 2.0 license, available at the root * application directory. */ @@ -31,11 +31,9 @@ import java.net.MalformedURLException; import java.util.ArrayList; -import java.util.HashMap; import java.util.HashSet; import java.util.Iterator; import java.util.List; -import java.util.Map; import java.util.Set; import org.slf4j.Logger; @@ -50,6 +48,7 @@ import com.vividsolutions.jts.geom.Polygon; import com.vividsolutions.jts.io.ParseException; import com.vividsolutions.jts.io.WKTReader; +import org.apache.commons.lang.StringUtils; import org.geoserver.geofence.core.model.GSInstance; import org.geoserver.geofence.core.model.IPAddressRange; import org.geoserver.geofence.core.model.Rule; @@ -332,170 +331,8 @@ private org.geoserver.geofence.core.model.GSInstance getInstance( return remote_instance; } -// /** -// * Gets the profile. -// * -// * @param profile -// * the profile -// * @return the profile -// */ -// private org.geoserver.geofence.core.model.UserGroup getProfile( -// UserGroup profile) { -// org.geoserver.geofence.core.model.UserGroup remote_profile = null; -// try { -// if ((profile != null) && (profile.getId() != -1)) { -// remote_profile = geofenceRemoteService -// .getUserGroupAdminService().get(profile.getId()); -// } -// } catch (Exception e) { -// logger.info(e.getMessage(), e); -// } -// -// return remote_profile; -// } -// -// /** -// * Gets the profile. -// * -// * @param profile -// * the profile -// * @return the profile -// */ -// private org.geoserver.geofence.core.model.GSUser getUser(GSUser user) { -// org.geoserver.geofence.core.model.GSUser remote_user = null; -// try { -// if ((user != null) && (user.getId() != -1)) { -// remote_user = geofenceRemoteService.getUserAdminService().get( -// user.getId()); -// } -// } catch (Exception e) { -// logger.info(e.getMessage(), e); -// } -// -// return remote_user; -// } - - /* - * (non-Javadoc) - * - * @see org.geoserver.geofence.gui.server.service.IRulesManagerService# - * getLayerCustomProps(com.extjs .gxt.ui.client.data.PagingLoadConfig, - * org.geoserver.geofence.gui.client.model.Rule) - */ -// public PagingLoadResult getLayerCustomProps(int offset, -// int limit, Rule rule) { -// int start = offset; -// Long t = new Long(0); -// -// List customPropsDTO = new ArrayList(); -// -// if ((rule != null) && (rule.getId() >= 0)) { -// try { -// Map customProperties = geofenceRemoteService -// .getRuleAdminService().getDetailsProps(rule.getId()); -// -// if (customProperties == null) { -// if (logger.isErrorEnabled()) { -// logger.error("No property found on server"); -// } -// throw new ApplicationException("No rule found on server"); -// } -// -// long rulesCount = customProperties.size(); -// -// t = new Long(rulesCount); -// -// int page = (start == 0) ? start : (start / limit); -// -// SortedSet sortedset = new TreeSet( -// customProperties.keySet()); -// Iterator it = sortedset.iterator(); -// -// while (it.hasNext()) { -// String key = it.next(); -// LayerCustomProps property = new LayerCustomProps(); -// property.setPropKey(key); -// property.setPropValue(customProperties.get(key)); -// customPropsDTO.add(property); -// } -// -// // for (String key : customProperties.keySet()) { -// // -// // LayerCustomProps property = new LayerCustomProps(); -// // property.setPropKey(key); -// // property.setPropValue(customProperties.get(key)); -// // customPropsDTO.add(property); -// // } -// } catch (Exception e) { -// // do nothing! -// } -// } -// -// return new RpcPageLoadResult(customPropsDTO, offset, -// t.intValue()); -// } - - /* - * (non-Javadoc) - * - * @see org.geoserver.geofence.gui.server.service.IRulesManagerService# - * setDetailsProps(java.lang .Long, - * org.geoserver.geofence.gui.client.model.data.LayerCustomProps) - */ public void setDetailsProps(Long ruleId, List customProps) { - logger.error("TODO: rule refactoring!!! custom props have been removed"); - - Map props = new HashMap(); - - for (LayerCustomProps prop : customProps) { - props.put(prop.getPropKey(), prop.getPropValue()); - } - - LayerDetails details = null; - try { - details = geofenceRemoteService.getRuleAdminService().get(ruleId) - .getLayerDetails(); - - if (details == null) { - details = new LayerDetails(); - - org.geoserver.geofence.core.model.Rule rule = geofenceRemoteService - .getRuleAdminService().get(ruleId); - org.geoserver.geofence.core.model.GSInstance gsInstance = rule - .getInstance(); - GeoServerRESTReader gsreader = new GeoServerRESTReader( - gsInstance.getBaseURL(), gsInstance.getUsername(), - gsInstance.getPassword()); - - if ((rule.getWorkspace() == null) - && !rule.getLayer().equalsIgnoreCase("*")) { - // RESTLayerGroup group = - // gsreader.getLayerGroup(rule.getLayer()); - details.setType(LayerType.LAYERGROUP); - } else { - RESTLayer layer = gsreader.getLayer(rule.getLayer()); - - if (layer.getType().equals(RESTLayer.TYPE.VECTOR)) { - details.setType(LayerType.VECTOR); - } else { - details.setType(LayerType.RASTER); - } - } - - // REMOVED BY ETj -// details.setCustomProps(props); -// geofenceRemoteService.getRuleAdminService().setDetails(ruleId, -// details); - } else { -// geofenceRemoteService.getRuleAdminService().setDetailsProps( -// ruleId, props); - } - - } catch (Exception e) { - logger.error(e.getMessage(), e); - throw new ApplicationException(e.getMessage(), e); - } } /* @@ -571,16 +408,23 @@ private List loadAttribute(RuleModel rule) { GSInstanceModel gsInstance = rule.getInstance(); GeoServerRESTReader gsreader; + String ws = rule.getWorkspace(); + if(StringUtils.isBlank(ws) || "*".equals(ws)) + throw new ApplicationException("A workspace name is needed"); + + String layername = rule.getLayer(); + if(StringUtils.isBlank(layername) || "*".equals(layername)) + throw new ApplicationException("A layer name is needed"); + try { - gsreader = new GeoServerRESTReader(gsInstance.getBaseURL(), + gsreader = new GeoServerRESTReader( + gsInstance.getBaseURL(), gsInstance.getUsername(), gsInstance.getPassword()); - RESTLayer layer = gsreader.getLayer(rule.getLayer()); - - if (layer.getType().equals(RESTLayer.TYPE.VECTOR)) { -// layerAttributes = new HashSet(); + RESTLayer layer = gsreader.getLayer(ws, layername); - // /////////////////////// + if (layer.getType().equals(RESTLayer.Type.VECTOR)) { + // /////////////////////// // Vector Layer // /////////////////////// RESTFeatureType featureType = gsreader.getFeatureType(layer); @@ -592,11 +436,10 @@ private List loadAttribute(RuleModel rule) { layAttrUI.setAccessType("READWRITE"); layerAttributesDTO.add(layAttrUI); - } } else { - // /////////////////////// + // /////////////////////// // Raster Layer // /////////////////////// layerAttributesDTO = null; @@ -694,17 +537,27 @@ public LayerDetailsInfo saveLayerDetailsInfo( // Reload layer info from GeoServer // (in the rule we may have changed the layer) - org.geoserver.geofence.core.model.Rule rule = geofenceRemoteService - .getRuleAdminService().get(ruleId); - org.geoserver.geofence.core.model.GSInstance gsInstance = rule - .getInstance(); + org.geoserver.geofence.core.model.Rule rule = + geofenceRemoteService.getRuleAdminService().get(ruleId); + org.geoserver.geofence.core.model.GSInstance gsInstance = + rule.getInstance(); + + String ws = rule.getWorkspace(); + if(StringUtils.isBlank(ws) || "*".equals(ws)) + throw new ApplicationException("Rule is missing the needed workspace name"); + + String layername = rule.getLayer(); + if(StringUtils.isBlank(layername) || "*".equals(layername)) + throw new ApplicationException("Rule is missing the needed layer name"); + GeoServerRESTReader gsreader = new GeoServerRESTReader( - gsInstance.getBaseURL(), gsInstance.getUsername(), - gsInstance.getPassword()); - RESTLayer layer = gsreader.getLayer(rule.getLayer()); + gsInstance.getBaseURL(), + gsInstance.getUsername(),gsInstance.getPassword()); + + RESTLayer layer = gsreader.getLayer(ws, layername); if (layer != null) { - if (layer.getType().equals(RESTLayer.TYPE.VECTOR)) { + if (layer.getType().equals(RESTLayer.Type.VECTOR)) { details.setType(LayerType.VECTOR); } else { details.setType(LayerType.RASTER); diff --git a/src/gui/core/plugin/userui/src/main/java/org/geoserver/geofence/gui/server/service/impl/WorkspacesManagerServiceImpl.java b/src/gui/core/plugin/userui/src/main/java/org/geoserver/geofence/gui/server/service/impl/WorkspacesManagerServiceImpl.java index 73d1429a..63792345 100644 --- a/src/gui/core/plugin/userui/src/main/java/org/geoserver/geofence/gui/server/service/impl/WorkspacesManagerServiceImpl.java +++ b/src/gui/core/plugin/userui/src/main/java/org/geoserver/geofence/gui/server/service/impl/WorkspacesManagerServiceImpl.java @@ -1,4 +1,4 @@ -/* (c) 2014 Open Source Geospatial Foundation - all rights reserved +/* (c) 2014 - 2017 Open Source Geospatial Foundation - all rights reserved * This code is licensed under the GPL 2.0 license, available at the root * application directory. */ @@ -27,6 +27,9 @@ import org.geoserver.geofence.services.exception.NotFoundServiceEx; import it.geosolutions.geoserver.rest.GeoServerRESTReader; import it.geosolutions.geoserver.rest.decoder.RESTAbstractList; +import it.geosolutions.geoserver.rest.decoder.RESTCoverageList; +import it.geosolutions.geoserver.rest.decoder.RESTCoverageStoreList; +import it.geosolutions.geoserver.rest.decoder.RESTFeatureTypeList; import it.geosolutions.geoserver.rest.decoder.RESTLayer; import it.geosolutions.geoserver.rest.decoder.RESTStyleList; import it.geosolutions.geoserver.rest.decoder.RESTWorkspaceList; @@ -34,6 +37,7 @@ import it.geosolutions.geoserver.rest.decoder.utils.NameLinkElem; import java.util.SortedSet; import java.util.TreeSet; +import org.apache.commons.lang.StringUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -125,7 +129,7 @@ public PagingLoadResult getLayers(int offset, int limit, String baseURL, try { GeoServerRESTReader gsreader = new GeoServerRESTReader(baseURL, gsInstance.getUsername(), gsInstance.getPassword()); - + if (workspace.equals("*") && workspaceConfigOpts.isShowDefaultGroups() && service.equals("WMS")) { RESTAbstractList layerGroups = gsreader.getLayerGroups(); @@ -137,32 +141,26 @@ public PagingLoadResult getLayers(int offset, int limit, String baseURL, // { // layersListDTO.add(new Layer(group.getName())); // } - layersListDTO.add(new Layer(lg.getName())); + layersListDTO.add(new Layer(lg.getName())); } } } else { SortedSet sortedLayerNames = new TreeSet(); - RESTAbstractList layers = gsreader.getLayers(); if (workspace.equals("*")) { // load all layers + RESTAbstractList layers = gsreader.getLayers(); if (layers != null) for (NameLinkElem layerLink : layers) { sortedLayerNames.add(layerLink.getName()); } } else { - if ((layers != null) && !layers.isEmpty()) { - - for (NameLinkElem layerNL : layers) { - // next block is really too slow - RESTLayer layer = gsreader.getLayer(layerNL.getName()); - if(layer.getResourceUrl().contains("workspaces/" + workspace + "/")) { - sortedLayerNames.add(layerNL.getName()); - //layersListDTO.add(new Layer(layerNL.getName())); - } - } - } + + if(StringUtils.isBlank(workspace)) + throw new ApplicationException("A workspace name is needed"); + + sortedLayerNames = getWorkspaceLayers(gsreader, workspace); } // return the sorted layers list for (String layerName : sortedLayerNames) { @@ -178,6 +176,26 @@ public PagingLoadResult getLayers(int offset, int limit, String baseURL, return new RpcPageLoadResult(layersListDTO, 0, layersListDTO.size()); } + public SortedSet getWorkspaceLayers(GeoServerRESTReader reader, String workspace) { + + SortedSet layerNames = new TreeSet(); + + RESTFeatureTypeList featureTypes = reader.getFeatureTypes(workspace); + for (NameLinkElem ft : featureTypes) { + layerNames.add(ft.getName()); + } + + RESTCoverageStoreList coverageStores = reader.getCoverageStores(workspace); + for (NameLinkElem csName : coverageStores) { + RESTCoverageList coverages = reader.getCoverages(workspace, csName.getName()); + for (NameLinkElem coverage : coverages) { + layerNames.add(coverage.getName()); + } + } + + return layerNames; + } + /* * (non-Javadoc) * diff --git a/src/gui/core/resources/src/main/java/org/geoserver/geofence/gui/client/GeofenceEvents.java b/src/gui/core/resources/src/main/java/org/geoserver/geofence/gui/client/GeofenceEvents.java index 1bd211c3..6fc67396 100644 --- a/src/gui/core/resources/src/main/java/org/geoserver/geofence/gui/client/GeofenceEvents.java +++ b/src/gui/core/resources/src/main/java/org/geoserver/geofence/gui/client/GeofenceEvents.java @@ -1,4 +1,4 @@ -/* (c) 2014 Open Source Geospatial Foundation - all rights reserved +/* (c) 2014 - 2017 Open Source Geospatial Foundation - all rights reserved * This code is licensed under the GPL 2.0 license, available at the root * application directory. */ @@ -199,9 +199,6 @@ public class GeofenceEvents { /** **/ public static final EventType LOAD_RULES = new EventType(); - /** **/ - public static final EventType LOAD_USER_LIMITS = new EventType(); - /** The Constant LOAD_WATCH_AOI. */ public static final EventType LOAD_WATCH_AOI = new EventType(); @@ -277,21 +274,6 @@ public class GeofenceEvents { /** The Constant RULE_PRIORITY_UP. */ public static final EventType RULE_PRIORITY_UP = new EventType(); - /** **/ - public static final EventType RULE_PROFILE_CUSTOM_PROP_ADD = new EventType(); - - /** **/ - public static final EventType RULE_PROFILE_CUSTOM_PROP_APPLY_CHANGES = new EventType(); - - /** **/ - public static final EventType RULE_PROFILE_CUSTOM_PROP_DEL = new EventType(); - - /** **/ - public static final EventType RULE_PROFILE_CUSTOM_PROP_UPDATE_KEY = new EventType(); - - /** **/ - public static final EventType RULE_PROFILE_CUSTOM_PROP_UPDATE_VALUE = new EventType(); - /** The Constant RULE_SAVE. */ public static final EventType RULE_SAVE = new EventType(); @@ -337,9 +319,6 @@ public class GeofenceEvents { /** **/ public static final EventType SAVE_USER_GROUPS = new EventType(); - /** **/ - public static final EventType SAVE_USER_LIMITS = new EventType(); - /** The Constant SAVE_WATCH. */ public static final EventType SAVE_WATCH = new EventType(); diff --git a/src/gui/core/resources/src/main/java/org/geoserver/geofence/gui/client/model/GSUserModel.java b/src/gui/core/resources/src/main/java/org/geoserver/geofence/gui/client/model/GSUserModel.java index d45d3561..c8277b1c 100644 --- a/src/gui/core/resources/src/main/java/org/geoserver/geofence/gui/client/model/GSUserModel.java +++ b/src/gui/core/resources/src/main/java/org/geoserver/geofence/gui/client/model/GSUserModel.java @@ -1,4 +1,4 @@ -/* (c) 2014 Open Source Geospatial Foundation - all rights reserved +/* (c) 2014 - 2017 Open Source Geospatial Foundation - all rights reserved * This code is licensed under the GPL 2.0 license, available at the root * application directory. */ @@ -21,10 +21,10 @@ public class GSUserModel extends BeanModel implements IsSerializable { /** The Constant serialVersionUID. */ - private static final long serialVersionUID = 270623297309308741L; + private static final long serialVersionUID = 70623297309308741L; /** The id. */ - private long id; + private Long id; /** The name. */ private String name; @@ -66,7 +66,7 @@ public GSUserModel() * * @return the id */ - public long getId() + public Long getId() { return id; } @@ -77,7 +77,7 @@ public long getId() * @param id * the new id */ - public void setId(long id) + public void setId(Long id) { this.id = id; } @@ -302,7 +302,7 @@ public int hashCode() result = (prime * result) + ((emailAddress == null) ? 0 : emailAddress.hashCode()); result = (prime * result) + (enabled ? 1231 : 1237); result = (prime * result) + ((fullName == null) ? 0 : fullName.hashCode()); - result = (prime * result) + (int) (id ^ (id >>> 32)); + result = (prime * result) + (id == null? 0 : (int) (id ^ (id >>> 32))); result = (prime * result) + ((name == null) ? 0 : name.hashCode()); result = (prime * result) + ((password == null) ? 0 : password.hashCode()); result = (prime * result) + ((path == null) ? 0 : path.hashCode()); @@ -367,7 +367,14 @@ else if (!fullName.equals(other.fullName)) { return false; } - if (id != other.id) + if (id == null) + { + if (other.id != null) + { + return false; + } + } + else if (!id.equals(other.id)) { return false; } diff --git a/src/gui/core/resources/src/main/java/org/geoserver/geofence/gui/client/model/UserGroupModel.java b/src/gui/core/resources/src/main/java/org/geoserver/geofence/gui/client/model/UserGroupModel.java index 5197e766..78cf1ff7 100644 --- a/src/gui/core/resources/src/main/java/org/geoserver/geofence/gui/client/model/UserGroupModel.java +++ b/src/gui/core/resources/src/main/java/org/geoserver/geofence/gui/client/model/UserGroupModel.java @@ -1,4 +1,4 @@ -/* (c) 2014 Open Source Geospatial Foundation - all rights reserved +/* (c) 2014 - 2017 Open Source Geospatial Foundation - all rights reserved * This code is licensed under the GPL 2.0 license, available at the root * application directory. */ @@ -22,7 +22,7 @@ public class UserGroupModel extends BeanModel implements IsSerializable private static final long serialVersionUID = 3475163929906592234L; /** The id. */ - private long id; + private Long id; /** The name. */ private String name; @@ -52,7 +52,7 @@ public UserGroupModel() * * @return the id */ - public long getId() + public Long getId() { return id; } @@ -63,7 +63,7 @@ public long getId() * @param id * the new id */ - public void setId(long id) + public void setId(Long id) { this.id = id; } @@ -181,7 +181,7 @@ public int hashCode() { + ((dateCreation == null) ? 0 : dateCreation.hashCode()); result = prime * result + (enabled ? 1231 : 1237); result = prime * result + ((extId == null) ? 0 : extId.hashCode()); - result = prime * result + (int) (id ^ (id >>> 32)); + result = prime * result + ( id == null? 0 : (int) (id ^ (id >>> 32))); result = prime * result + ((name == null) ? 0 : name.hashCode()); result = prime * result + ((path == null) ? 0 : path.hashCode()); return result; @@ -219,7 +219,11 @@ public boolean equals(Object obj) { } else if (!extId.equals(other.extId)) { return false; } - if (id != other.id) { + if (id == null) { + if (other.id != null) { + return false; + } + } else if (!id.equals(other.id)) { return false; } if (name == null) { diff --git a/src/gui/core/resources/src/main/java/org/geoserver/geofence/gui/client/model/data/ProfileCustomProps.java b/src/gui/core/resources/src/main/java/org/geoserver/geofence/gui/client/model/data/ProfileCustomProps.java deleted file mode 100644 index 06210111..00000000 --- a/src/gui/core/resources/src/main/java/org/geoserver/geofence/gui/client/model/data/ProfileCustomProps.java +++ /dev/null @@ -1,204 +0,0 @@ -/* (c) 2014 Open Source Geospatial Foundation - all rights reserved - * This code is licensed under the GPL 2.0 license, available at the root - * application directory. - */ - -package org.geoserver.geofence.gui.client.model.data; - -import com.extjs.gxt.ui.client.data.BeanModel; -import com.google.gwt.user.client.rpc.IsSerializable; - -import org.geoserver.geofence.gui.client.model.BeanKeyValue; - - -/** - * The Class ProfileCustomProps. - */ -public class ProfileCustomProps extends BeanModel implements IsSerializable -{ - - /** The Constant serialVersionUID. */ - private static final long serialVersionUID = 8661646874896039507L; - - /** The prop key. */ - private String propKey; - - /** The prop value. */ - private String propValue; - - /** The path. */ - private String path; - - /** - * Instantiates a new layer custom props. - */ - public ProfileCustomProps() - { - super(); - setPath("geofence/resources/images/layer.jpg"); - } - - /** - * Sets the layer. - * - * @param propKey - * the new layer - */ - public void setPropKey(String propKey) - { - this.propKey = propKey; - set(BeanKeyValue.PROFILE_PROP_KEY.getValue(), this.propKey); - } - - /** - * Sets the path. - * - * @param path - * the new path - */ - public void setPath(String path) - { - this.path = path; - set(BeanKeyValue.PATH.getValue(), path); - } - - /** - * Gets the path. - * - * @return the path - */ - public String getPath() - { - return path; - } - - /** - * Gets the layer. - * - * @return the layer - */ - public String getPropKey() - { - return propKey; - } - - /** - * Sets the path. - * - * @param propValue - * the new path - */ - public void setPropValue(String propValue) - { - this.propValue = propValue; - set(BeanKeyValue.PROFILE_PROP_VALUE.getValue(), this.propValue); - } - - /** - * Gets the path. - * - * @return the path - */ - public String getPropValue() - { - return propValue; - } - - /* (non-Javadoc) - * @see java.lang.Object#hashCode() - */ - @Override - public int hashCode() - { - final int prime = 31; - int result = 1; - result = (prime * result) + ((path == null) ? 0 : path.hashCode()); - result = (prime * result) + ((propKey == null) ? 0 : propKey.hashCode()); - result = (prime * result) + ((propValue == null) ? 0 : propValue.hashCode()); - - return result; - } - - /* (non-Javadoc) - * @see java.lang.Object#equals(java.lang.Object) - */ - @Override - public boolean equals(Object obj) - { - if (this == obj) - { - return true; - } - if (obj == null) - { - return false; - } - if (!(obj instanceof ProfileCustomProps)) - { - return false; - } - - ProfileCustomProps other = (ProfileCustomProps) obj; - if (path == null) - { - if (other.path != null) - { - return false; - } - } - else if (!path.equals(other.path)) - { - return false; - } - if (propKey == null) - { - if (other.propKey != null) - { - return false; - } - } - else if (!propKey.equals(other.propKey)) - { - return false; - } - if (propValue == null) - { - if (other.propValue != null) - { - return false; - } - } - else if (!propValue.equals(other.propValue)) - { - return false; - } - - return true; - } - - /* (non-Javadoc) - * @see java.lang.Object#toString() - */ - @Override - public String toString() - { - StringBuilder builder = new StringBuilder(); - builder.append("ProfileCustomProps ["); - if (path != null) - { - builder.append("path=").append(path).append(", "); - } - if (propKey != null) - { - builder.append("propKey=").append(propKey).append(", "); - } - if (propValue != null) - { - builder.append("propValue=").append(propValue); - } - builder.append("]"); - - return builder.toString(); - } - -} diff --git a/src/gui/core/resources/src/main/java/org/geoserver/geofence/gui/client/model/data/UserLimitsInfoModel.java b/src/gui/core/resources/src/main/java/org/geoserver/geofence/gui/client/model/data/UserLimitsInfoModel.java deleted file mode 100644 index dbb9550f..00000000 --- a/src/gui/core/resources/src/main/java/org/geoserver/geofence/gui/client/model/data/UserLimitsInfoModel.java +++ /dev/null @@ -1,197 +0,0 @@ -/* (c) 2014 Open Source Geospatial Foundation - all rights reserved - * This code is licensed under the GPL 2.0 license, available at the root - * application directory. - */ - -package org.geoserver.geofence.gui.client.model.data; - -import com.extjs.gxt.ui.client.data.BeanModel; -import com.google.gwt.user.client.rpc.IsSerializable; - -import org.geoserver.geofence.gui.client.model.BeanKeyValue; - - -/** - * Class UserLimitsInfo. - * - * @author Tobia di Pisa - * - */ -public class UserLimitsInfoModel extends BeanModel implements IsSerializable -{ - - /** The Constant serialVersionUID. */ - private static final long serialVersionUID = 1760111388826438170L; - - private Long userId; - - private String allowedArea; - - private String srid; - - - /** - * Instantiates a new limits. - */ - public UserLimitsInfoModel() - { - super(); - } - - /** - * @return the userId - */ - public Long getUserId() - { - return userId; - } - - /** - * @param userId the userId to set - */ - public void setUserId(Long userId) - { - this.userId = userId; - } - - /** - * @return the allowedArea - * @deprecated removed from base model - */ - public String getAllowedArea() - { - return allowedArea; - } - - /** - * @param allowedArea the allowedArea to set - * @deprecated removed from base model - */ - public void setAllowedArea(String allowedArea) - { - this.allowedArea = allowedArea; - set(BeanKeyValue.USER_ALLOWED_AREA.getValue(), this.allowedArea); - } - - /** - * @return the srid - * @deprecated removed from base model - */ - public String getSrid() - { - return srid; - } - - /** - * @param srid the srid to set - * @deprecated removed from base model - */ - public void setSrid(String srid) - { - this.srid = srid; - set(BeanKeyValue.USER_ALLOWED_AREA_SRID.getValue(), this.srid); - } - - /* (non-Javadoc) - * @see java.lang.Object#hashCode() - */ - @Override - public int hashCode() - { - final int prime = 31; - int result = 1; - result = (prime * result) + ((userId == null) ? 0 : userId.hashCode()); - result = (prime * result) + ((allowedArea == null) ? 0 : allowedArea.hashCode()); - result = (prime * result) + ((srid == null) ? 0 : srid.hashCode()); - - return result; - } - - /* (non-Javadoc) - * @see java.lang.Object#equals(java.lang.Object) - */ - @Override - public boolean equals(Object obj) - { - if (this == obj) - { - return true; - } - if (obj == null) - { - return false; - } - if (!(obj instanceof Grant)) - { - return false; - } - - UserLimitsInfoModel other = (UserLimitsInfoModel) obj; - - if (userId == null) - { - if (other.userId != null) - { - return false; - } - } - else if (!userId.equals(other.userId)) - { - return false; - } - - if (allowedArea == null) - { - if (other.allowedArea != null) - { - return false; - } - } - else if (!allowedArea.equals(other.allowedArea)) - { - return false; - } - - if (srid == null) - { - if (other.srid != null) - { - return false; - } - } - else if (!srid.equals(other.srid)) - { - return false; - } - - return true; - } - - /* (non-Javadoc) - * @see java.lang.Object#toString() - */ - @Override - public String toString() - { - StringBuilder builder = new StringBuilder(); - builder.append("LayerLimitsForm ["); - - if (userId != null) - { - builder.append("userId=").append(userId).append(", "); - } - if (allowedArea != null) - { - builder.append("allowedArea=").append(allowedArea).append(", "); - } - if (srid != null) - { - builder.append("srid=").append(srid).append(", "); - } - - builder.append("]"); - - return builder.toString(); - } - -} diff --git a/src/gui/core/resources/src/main/resources/log4j.properties b/src/gui/core/resources/src/main/resources/log4j.properties deleted file mode 100644 index bc5e1c7e..00000000 --- a/src/gui/core/resources/src/main/resources/log4j.properties +++ /dev/null @@ -1,13 +0,0 @@ -# /* (c) 2014 Open Source Geospatial Foundation - all rights reserved -# * This code is licensed under the GPL 2.0 license, available at the root -# * application directory. -# */ -# -log4j.rootLogger=INFO, stdout -#log4j.rootLogger=INFO, stdout, file - -# stdout is set to be a ConsoleAppender with PatternLayout. -log4j.appender.stdout=org.apache.log4j.ConsoleAppender -log4j.appender.stdout.layout=org.apache.log4j.PatternLayout -# Print the date in ISO 8601 format -log4j.appender.stdout.layout.ConversionPattern=%d %5p [%t] (%F:%L) - %m%n \ No newline at end of file diff --git a/src/gui/pom.xml b/src/gui/pom.xml index f1ab84b7..0f20b727 100644 --- a/src/gui/pom.xml +++ b/src/gui/pom.xml @@ -1,6 +1,6 @@ - + - - - + + + org.geoserver.geofence geofence-gui-core @@ -156,9 +143,9 @@ ${geofence-version} - - - + + + org.geoserver.geofence geofence-model-internal @@ -207,15 +194,15 @@ ${geofence-version} - + org.geoserver.geofence geofence-ldap ${geofence-version} - - - + + + it.geosolutions.geogwt.core @@ -229,18 +216,18 @@ ${geogwt-version} - - - - - it.geosolutions - geoserver-manager - ${gsmanager-version} - + + + + + it.geosolutions + geoserver-manager + 1.6.0 + - - - + + + org.springframework @@ -303,37 +290,37 @@ org.springframework.security spring-security-acl ${spring.security.version} - - - org.springframework - spring-expression - - + + + org.springframework + spring-expression + + org.springframework.security spring-security-core ${spring.security.version} - - - org.springframework - spring-expression - - + + + org.springframework + spring-expression + + org.springframework.security spring-security-taglibs ${spring.security.version} - - - org.springframework - spring-expression - - + + + org.springframework + spring-expression + + - + org.springframework spring-test @@ -351,33 +338,33 @@ - - - com.google.gwt - gwt-user - ${gwt.version} - - - com.google.gwt - gwt-servlet - ${gwt.version} - runtime - - - - - - - com.extjs - gxt - ${extjs.version} - - - + + + com.google.gwt + gwt-user + ${gwt.version} + + + com.google.gwt + gwt-servlet + ${gwt.version} + runtime + + + + + + + com.extjs + gxt + ${extjs.version} + + + org.opengis geoapi @@ -399,69 +386,69 @@ 1.0-beta-2 - - - - - org.geotools - gt-main - ${gt-version} - - - org.geotools - gt-api - ${gt-version} - - - org.geotools - gt-referencing - ${gt-version} - - - org.geotools - gt-metadata - ${gt-version} - - - org.geotools - gt-shapefile - ${gt-version} - - - org.geotools - gt-epsg-extension - ${gt-version} - - - org.geotools - gt-epsg-wkt - ${gt-version} - - - org.geotools - gt-epsg-hsql - ${gt-version} - - - org.geotools - gt-epsg-h2 - ${gt-version} - - - org.geotools - gt-wms - ${gt-version} - - - org.geotools - gt-wfs - ${gt-version} - - - - - - + + + + + org.geotools + gt-main + ${gt-version} + + + org.geotools + gt-api + ${gt-version} + + + org.geotools + gt-referencing + ${gt-version} + + + org.geotools + gt-metadata + ${gt-version} + + + org.geotools + gt-shapefile + ${gt-version} + + + org.geotools + gt-epsg-extension + ${gt-version} + + + org.geotools + gt-epsg-wkt + ${gt-version} + + + org.geotools + gt-epsg-hsql + ${gt-version} + + + org.geotools + gt-epsg-h2 + ${gt-version} + + + org.geotools + gt-wms + ${gt-version} + + + org.geotools + gt-wfs + ${gt-version} + + + + + + commons-lang commons-lang @@ -498,9 +485,9 @@ 1.4 - - - + + + javax.xml.ws jaxws-api @@ -569,9 +556,9 @@ ${cxf-version} - - - + + + com.trg trg-dao @@ -593,9 +580,9 @@ ${hibernate-generic-dao-version} - - - + + + org.postgis postgis-jdbc @@ -612,47 +599,27 @@ 1.10 - - - + + + dom4j dom4j 1.6.1 - - - - - org.apache.logging.log4j - log4j-api - 2.0.2 - - - org.apache.logging.log4j - log4j-core - 2.0.2 - - - org.apache.logging.log4j - log4j-slf4j-impl - 2.0.2 - - - org.apache.logging.log4j - log4j-web - 2.0.2 - + + + - org.apache.logging.log4j - log4j-jcl - 2.0.2 + log4j + log4j + 1.2.17 - - - + + + javax.servlet servlet-api @@ -668,8 +635,8 @@ 1.2 - - + + org.hibernatespatial hibernate-spatial-postgis @@ -695,13 +662,13 @@ - - - + + + org.apache.maven.wagon wagon-ftp - 2.3 + 2.10 diff --git a/src/gui/web/pom.xml b/src/gui/web/pom.xml index d017634b..78bb98ab 100644 --- a/src/gui/web/pom.xml +++ b/src/gui/web/pom.xml @@ -1,11 +1,9 @@ 4.0.0 @@ -96,26 +94,9 @@ - - - org.apache.logging.log4j - log4j-api - - - org.apache.logging.log4j - log4j-core - - - org.apache.logging.log4j - log4j-slf4j-impl - - org.apache.logging.log4j - log4j-web - - - org.apache.logging.log4j - log4j-jcl + log4j + log4j @@ -366,6 +347,9 @@ manual + + + diff --git a/src/gui/web/src/main/java/org/geoserver/geofence/gui/server/service/impl/StartupService.java b/src/gui/web/src/main/java/org/geoserver/geofence/gui/server/service/impl/StartupService.java index a9bc796b..11c093e9 100644 --- a/src/gui/web/src/main/java/org/geoserver/geofence/gui/server/service/impl/StartupService.java +++ b/src/gui/web/src/main/java/org/geoserver/geofence/gui/server/service/impl/StartupService.java @@ -1,4 +1,4 @@ -/* (c) 2014 Open Source Geospatial Foundation - all rights reserved +/* (c) 2014 - 2017 Open Source Geospatial Foundation - all rights reserved * This code is licensed under the GPL 2.0 license, available at the root * application directory. */ @@ -10,14 +10,14 @@ import org.geoserver.geofence.gui.server.service.IStartupService; import org.geoserver.geofence.login.util.MD5Util; import org.geoserver.geofence.services.GFUserAdminServiceImpl; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; -import org.springframework.beans.factory.InitializingBean; +import org.apache.log4j.LogManager; +import org.apache.log4j.Logger; + +import org.springframework.beans.factory.InitializingBean; import org.springframework.beans.factory.annotation.Autowired; -// TODO: Auto-generated Javadoc /** * The Class StartupService. */ diff --git a/src/gui/web/src/main/resources/geofence-datasource-ovr.properties b/src/gui/web/src/main/resources/geofence-datasource-ovr.properties index 12ee1a52..4f4fd8e4 100644 --- a/src/gui/web/src/main/resources/geofence-datasource-ovr.properties +++ b/src/gui/web/src/main/resources/geofence-datasource-ovr.properties @@ -1,8 +1,17 @@ -# /* (c) 2014 Open Source Geospatial Foundation - all rights reserved -# * This code is licensed under the GPL 2.0 license, available at the root -# * application directory. -# */ -# +# (c) 2014 - 2017 Open Source Geospatial Foundation - all rights reserved +# This code is licensed under the GPL 2.0 license, available at the root +# application directory. + +################################################################################ +## These are default values, please DO NOT modify this file. +## If you need to customise these values, please create a new property file +## outside the webapp dir, and put into the system var "-Dgeofence-ovr" the +## path of your file. +## +## Take as example the file geofence-datasource-ovr.properties.sample which also +## contains some info about each setting. +################################################################################ + geofenceVendorAdapter.databasePlatform=org.hibernatespatial.geodb.GeoDBDialect geofenceDataSource.driverClassName=org.h2.Driver geofenceDataSource.url=jdbc:h2:geofence_db/geofence @@ -10,39 +19,9 @@ geofenceDataSource.username=sa geofenceDataSource.password=sa geofenceEntityManagerFactory.jpaPropertyMap[hibernate.default_schema]=public -################################################################################ -## Other setup entries -################################################################################ -## hbm2ddl.auto may assume one of these values: -## - validate: validates the DB schema at startup against the internal model. May fail on oracle spatial. -## - update: updates the schema, according to the internal model. Updating automatically the production DB is dangerous. -## - create-drop: drop the existing schema and recreates it according to the internal model. REALLY DANGEROUS, YOU WILL LOSE YOUR DATA. -## You may want not to redefine the property entirely, in order to leave the defult value (no action). - geofenceEntityManagerFactory.jpaPropertyMap[hibernate.hbm2ddl.auto]=update geofenceEntityManagerFactory.jpaPropertyMap[javax.persistence.validation.mode]=none geofenceEntityManagerFactory.jpaPropertyMap[hibernate.validator.apply_to_ddl]=false geofenceEntityManagerFactory.jpaPropertyMap[hibernate.validator.autoregister_listeners]=false -## -## ShowSQL is set to true in the configuration file; putting showsql=false in -## this file, you can easily check that this override file has been properly applied. - -# geofenceVendorAdapter.generateDdl=false -# geofenceVendorAdapter.showSql=false - -## Set to "true" in specific use cases -# workspaceConfigOpts.showDefaultGroups=false - - - -################################################################################ -## Disable second level cache. -## This is needed in a geofence-clustered environment. - -#geofenceEntityManagerFactory.jpaPropertyMap[hibernate.cache.use_second_level_cache]=false - -################################################################################ -## Use external ehcache configuration file. -## Useful to change cache settings, for example diskStore path. -#geofenceEntityManagerFactory.jpaPropertyMap[hibernate.cache.provider_configuration_file_resource_path]=file:/path/to/geofence-ehcache-override.xml \ No newline at end of file +### END ######################################################################## diff --git a/src/gui/web/src/main/resources/geofence-datasource-ovr.properties.sample b/src/gui/web/src/main/resources/geofence-datasource-ovr.properties.sample index 4032be77..1c822172 100644 --- a/src/gui/web/src/main/resources/geofence-datasource-ovr.properties.sample +++ b/src/gui/web/src/main/resources/geofence-datasource-ovr.properties.sample @@ -2,10 +2,8 @@ ## GeoFence property override file ## ################################################################################ -## Please note that the property keys in this ovr file *do not* have the same -## meaning of the keys in the geofence-datasource.properties file. -## If you need more info about this, please check the doc about -## Spring's PropertyOverrideConfigurer and PropertyPlaceholderConfigurer. +## If you need more info about this file, please check the doc about +## Spring's PropertyOverrideConfigurer ################################################################################ ################################################################################ @@ -14,7 +12,7 @@ ################################################################################ ## When customizing the backend DBMS, make sure you have in your classpath both ## the proper JDBC driver jar and the hibernate dialect. -## +## Also make sure to only have one dialect jar in your classpath. #geofenceVendorAdapter.databasePlatform=org.hibernatespatial.postgis.PostgisDialect #geofenceDataSource.driverClassName=org.postgresql.Driver @@ -34,7 +32,9 @@ ## You may want not to redefine the property entirely, in order to leave the defult value (no action). #geofenceEntityManagerFactory.jpaPropertyMap[hibernate.hbm2ddl.auto]=validate - +#geofenceEntityManagerFactory.jpaPropertyMap[javax.persistence.validation.mode]=none +#geofenceEntityManagerFactory.jpaPropertyMap[hibernate.validator.apply_to_ddl]=false +#geofenceEntityManagerFactory.jpaPropertyMap[hibernate.validator.autoregister_listeners]=false ## ## ShowSQL is set to true in the configuration file; putting showsql=false in @@ -43,11 +43,6 @@ # geofenceVendorAdapter.generateDdl=false # geofenceVendorAdapter.showSql=false -## Set to "true" for e-GEOS -# workspaceConfigOpts.showDefaultGroups=false - - - ################################################################################ ## Disable second level cache. ## This is needed in a geofence-clustered environment. @@ -70,4 +65,44 @@ #geofenceGlobalConfiguration.baseLayerStyle= #geofenceGlobalConfiguration.mapCenterLon=0 #geofenceGlobalConfiguration.mapCenterLat=0 -#geofenceGlobalConfiguration.mapZoom=2 \ No newline at end of file +#geofenceGlobalConfiguration.mapZoom=2 + +################################################################################ +## LDAP + +##### Switch the DAOs from DB to LDAP +#geofence_dao_registry.selectedType = LDAP + +##### LDAP directory connection params +#geofenceLdapSource.url = ldap://10.10.100.4:11389 +#geofenceLdapSource.base = dc=comune,dc=intranet +#geofenceLdapSource.userDn = cn=queryuser,ou=OU2,ou=OU1,dc=comune,dc=intranet +#geofenceLdapSource.password = secret + +##### Max number of records retrieved +#geofenceLdapTemplate.defaultCountLimit = 100 + +##### User filters +### Base LDAP tree node for users +#gsUserDAO_LDAP.searchBase = ou=Users,ou=OU2,ou=OU1 +### Filter used to get all users +#gsUserDAO_LDAP.searchFilter = objectClass=user + +##### Group filters +## Base LDAP tree node for groups +#userGroupDAO_LDAP.searchBase = OU=Groups,OU=OU3 +## Filter used to get all groups +#userGroupDAO_LDAP.searchFilter = objectClass=group + +##### Mapping LDAP user attributes to internal +#geofenceLdapUserMapper.map[id] = distinguishedName +#geofenceLdapUserMapper.map[username] = cn +#geofenceLdapUserMapper.map[email] = mail +#geofenceLdapUserMapper.map[name] = givenName +#geofenceLdapUserMapper.map[surname] = sn +#geofenceLdapUserMapper.map[password] = + +##### Mapping LDAP group attributes to internal +#geofenceLdapGroupMapper.map[id] = distinguishedName +#geofenceLdapGroupMapper.map[groupname] = cn +#geofenceLdapGroupMapper.map[member] = member diff --git a/src/gui/web/src/main/resources/geofence-ldap.properties b/src/gui/web/src/main/resources/geofence-ldap.properties deleted file mode 100644 index 9ed6aaf9..00000000 --- a/src/gui/web/src/main/resources/geofence-ldap.properties +++ /dev/null @@ -1,9 +0,0 @@ -# /* (c) 2014 Open Source Geospatial Foundation - all rights reserved -# * This code is licensed under the GPL 2.0 license, available at the root -# * application directory. -# */ -# -geofenceLdapSource.url=ldap://localhost:10389 -geofenceLdapSource.base=dc=example,dc=com -geofenceLdapSource.user=uid=admin,ou=system -geofenceLdapSource.password=secret diff --git a/src/gui/web/src/main/resources/log4j.properties b/src/gui/web/src/main/resources/log4j.properties deleted file mode 100644 index e6b6449f..00000000 --- a/src/gui/web/src/main/resources/log4j.properties +++ /dev/null @@ -1,27 +0,0 @@ -# /* (c) 2014 Open Source Geospatial Foundation - all rights reserved -# * This code is licensed under the GPL 2.0 license, available at the root -# * application directory. -# */ -# -log4j.appender.file=org.apache.log4j.RollingFileAppender -log4j.appender.file.File=/tmp/logs/geofence.log -log4j.appender.file.MaxFileSize=10MB -log4j.appender.file.MaxBackupIndex=1 -log4j.appender.file.layout=org.apache.log4j.PatternLayout -log4j.appender.file.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n - -# Direct log messages to stdout -log4j.appender.stdout=org.apache.log4j.ConsoleAppender -log4j.appender.stdout.Target=System.out -log4j.appender.stdout.layout=org.apache.log4j.PatternLayout -log4j.appender.stdout.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n - -# Root logger option -log4j.rootLogger=INFO, file, stdout - -# Log everything. Good for troubleshooting -#log4j.logger.org.hibernate=DEBUG -#log4j.logger.com.trg=DEBUG - -# Log all JDBC parameters -#log4j.logger.org.hibernate.type=ALL diff --git a/src/gui/web/src/main/resources/log4j.xml b/src/gui/web/src/main/resources/log4j.xml index 955f7c4d..40608286 100644 --- a/src/gui/web/src/main/resources/log4j.xml +++ b/src/gui/web/src/main/resources/log4j.xml @@ -1,54 +1,30 @@ - - - - - - - /tmp/logs - - - - - - - - - - %d{ABSOLUTE} %5p %c{1}:%L - %m%n - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/gui/web/war/WEB-INF/remoting-servlet.xml b/src/gui/web/war/WEB-INF/remoting-servlet.xml index 26fdd781..22a00b2c 100644 --- a/src/gui/web/war/WEB-INF/remoting-servlet.xml +++ b/src/gui/web/war/WEB-INF/remoting-servlet.xml @@ -6,7 +6,6 @@ xmlns:cxf="http://cxf.apache.org/core" xmlns:jaxws="http://cxf.apache.org/jaxws" xmlns:jaxrs="http://cxf.apache.org/jaxrs" - xmlns:dgservices="http://services.dgwatch.digitalglobe.com" xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd @@ -25,4 +24,4 @@ - \ No newline at end of file + diff --git a/src/gui/web/war/WEB-INF/web.xml b/src/gui/web/war/WEB-INF/web.xml index 05d03c23..308fb94a 100644 --- a/src/gui/web/war/WEB-INF/web.xml +++ b/src/gui/web/war/WEB-INF/web.xml @@ -26,7 +26,7 @@ - org.apache.logging.log4j.web.Log4jServletContextListener + org.springframework.web.util.Log4jConfigListener @@ -44,7 +44,7 @@ Georepository CUSTOM security filter /* - + ConfigurationRemote @@ -69,11 +69,11 @@ remoteLoggingServiceImpl - com.google.gwt.logging.server.RemoteLoggingServiceImpl - - - remoteLoggingServiceImpl - /geofence/logging + com.google.gwt.logging.server.RemoteLoggingServiceImpl + + + remoteLoggingServiceImpl + /geofence/logging @@ -105,7 +105,7 @@ InstancesManagerRemoteService /geofence/InstancesManagerRemoteService - + RulesManagerRemoteService org.geoserver.geofence.gui.server.gwt.RulesManagerServiceImpl @@ -123,7 +123,7 @@ WorkspacesManagerRemoteService /geofence/WorkspacesManagerRemoteService - + @@ -177,7 +177,7 @@ remoting /remoting/* - + Application.html diff --git a/src/services/core/model/src/main/java/org/geoserver/geofence/core/model/GSUser.java b/src/services/core/model/src/main/java/org/geoserver/geofence/core/model/GSUser.java index f5d9a7c9..79802ee4 100644 --- a/src/services/core/model/src/main/java/org/geoserver/geofence/core/model/GSUser.java +++ b/src/services/core/model/src/main/java/org/geoserver/geofence/core/model/GSUser.java @@ -1,4 +1,4 @@ -/* (c) 2014 Open Source Geospatial Foundation - all rights reserved +/* (c) 2014 - 2017 Open Source Geospatial Foundation - all rights reserved * This code is licensed under the GPL 2.0 license, available at the root * application directory. */ @@ -10,6 +10,7 @@ import java.io.Serializable; import java.util.Date; import java.util.HashSet; +import java.util.Objects; import java.util.Set; import javax.persistence.Column; @@ -95,15 +96,6 @@ public class GSUser implements Identifiable, Serializable { @Column(nullable=false) private boolean admin = false; -// /** The user. */ -// @ManyToOne(optional = false) -// @ForeignKey(name="fk_user_profile") -// private UserGroup profile; - -// @Type(type = "org.hibernatespatial.GeometryUserType") -// @Column(name = "allowedArea") -// private MultiPolygon allowedArea; - /** Groups to which the user is associated */ @ManyToMany(fetch= FetchType.LAZY) @JoinTable( name = "gf_user_usergroups", joinColumns = @JoinColumn(name = "user_id"), inverseJoinColumns=@JoinColumn(name = "group_id") ) @@ -112,15 +104,6 @@ public class GSUser implements Identifiable, Serializable { @Fetch(FetchMode.SUBSELECT) // without this, hibernate will duplicate results(!) private Set userGroups = new HashSet(); -// @org.hibernate.annotations.CollectionOfElements -// @JoinTable( name = "gf_user_usergroups", -// joinColumns = @JoinColumn(name = "gsuser_id")) -//// @Column(name = "propvalue") -// @ForeignKey(name="fk_uug_group", inverseName="fk_uug_user") -// private Set userGroups = new HashSet(); -// - - /** * Instantiates a new user. */ @@ -273,106 +256,77 @@ public void setGroups(Set groups) { this.userGroups = groups; } -// /** -// * @deprecated LIMIT rules should be used -// */ -// @Deprecated -// @XmlJavaTypeAdapter(MultiPolygonAdapter.class) -// public MultiPolygon getAllowedArea() { -// return allowedArea; -// } -// -// /** -// * @deprecated LIMIT rules should be used -// */ -// @Deprecated -// public void setAllowedArea(MultiPolygon allowedArea) { -// this.allowedArea = allowedArea; -// } - - - /* (non-Javadoc) - * @see java.lang.Object#hashCode() - */ @Override - public int hashCode() { - final int prime = 31; - int result = 1; - result = prime * result + ((dateCreation == null) ? 0 : dateCreation.hashCode()); - result = prime * result + (Boolean.valueOf(enabled).hashCode()); - result = prime * result + (Boolean.valueOf(admin).hashCode()); - result = prime * result + (int) (id ^ (id >>> 32)); - result = prime * result + ((name == null) ? 0 : name.hashCode()); - result = prime * result + ((userGroups == null) ? 0 : userGroups.hashCode()); -// result = prime * result + ((allowedArea == null) ? 0 : allowedArea.hashCode()); -// result = prime * result + ((allowedArea == null) ? 0 : allowedArea.getSRID()); - return result; + public int hashCode() + { + int hash = 7; + hash = 29 * hash + Objects.hashCode(this.id); + hash = 29 * hash + Objects.hashCode(this.extId); + hash = 29 * hash + Objects.hashCode(this.name); + hash = 29 * hash + Objects.hashCode(this.fullName); + hash = 29 * hash + Objects.hashCode(this.password); + hash = 29 * hash + Objects.hashCode(this.emailAddress); + hash = 29 * hash + Objects.hashCode(this.dateCreation); + hash = 29 * hash + (this.enabled ? 1 : 0); + hash = 29 * hash + (this.admin ? 1 : 0); + hash = 29 * hash + Objects.hashCode(this.userGroups); + return hash; } - /* (non-Javadoc) - * @see java.lang.Object#equals(java.lang.Object) - */ @Override - public boolean equals(Object obj) { + public boolean equals(Object obj) + { if (this == obj) { return true; } if (obj == null) { return false; } - if (!(obj instanceof GSUser)) { + if (getClass() != obj.getClass()) { return false; } - GSUser other = (GSUser) obj; - if (dateCreation == null) { - if (other.dateCreation != null) { - return false; - } - } else if (!dateCreation.equals(other.dateCreation)) { + final GSUser other = (GSUser) obj; + if (this.enabled != other.enabled) { return false; } - if(enabled != other.enabled) { + if (this.admin != other.admin) { return false; } - if(admin != other.admin) { + if (!Objects.equals(this.extId, other.extId)) { return false; } - if (id != other.id) { + if (!Objects.equals(this.name, other.name)) { return false; } - if (name == null) { - if (other.name != null) { - return false; - } - } else if (!name.equals(other.name)) { + if (!Objects.equals(this.fullName, other.fullName)) { return false; } - -// if (allowedArea == null) { -// if (other.allowedArea != null) { -// return false; -// } -// } else if (!allowedArea.equals(other.allowedArea)) { -// return false; -// } else if(other.allowedArea != null && other.allowedArea.getSRID() != allowedArea.getSRID()) { -// return false; -// } - - if ( this.userGroups != other.userGroups && (this.userGroups == null || !this.userGroups.equals(other.userGroups)) ) { + if (!Objects.equals(this.password, other.password)) { + return false; + } + if (!Objects.equals(this.emailAddress, other.emailAddress)) { + return false; + } + if (!Objects.equals(this.id, other.id)) { + return false; + } + if (!Objects.equals(this.dateCreation, other.dateCreation)) { + return false; + } + if (!Objects.equals(this.userGroups, other.userGroups)) { return false; } - return true; } - /* (non-Javadoc) - * @see java.lang.Object#toString() - */ @Override public String toString() { StringBuilder builder = new StringBuilder(); builder.append("User ["); - builder.append("id=").append(id).append(", "); + if(id != null) + builder.append("id=").append(id).append(", "); + if(extId != null) + builder.append("extid=").append(extId).append(", "); if (name != null) builder.append("name=").append(name).append(", "); // if (userGroups != null) diff --git a/src/services/core/model/src/main/java/org/geoserver/geofence/core/model/UserGroup.java b/src/services/core/model/src/main/java/org/geoserver/geofence/core/model/UserGroup.java index d3ec05b2..08e42c20 100644 --- a/src/services/core/model/src/main/java/org/geoserver/geofence/core/model/UserGroup.java +++ b/src/services/core/model/src/main/java/org/geoserver/geofence/core/model/UserGroup.java @@ -1,4 +1,4 @@ -/* (c) 2014 Open Source Geospatial Foundation - all rights reserved +/* (c) 2014 - 2017 Open Source Geospatial Foundation - all rights reserved * This code is licensed under the GPL 2.0 license, available at the root * application directory. */ @@ -7,6 +7,7 @@ import java.io.Serializable; import java.util.Date; +import java.util.Objects; import javax.persistence.Column; import javax.persistence.Entity; @@ -44,7 +45,8 @@ public class UserGroup implements Identifiable, Serializable { @Column private Long id; - /** External Id. An ID used in an external systems. + /** External Id. + * An ID used in an external systems. * This field should simplify Geofence integration in complex systems. */ @Column(nullable=true, updatable=false, unique=true) @@ -63,15 +65,6 @@ public class UserGroup implements Identifiable, Serializable { @Column(nullable=false) private boolean enabled; -// /** Custom properties associated to the profile */ -// @org.hibernate.annotations.CollectionOfElements -// @JoinTable( name = "gf_group_custom_props", -// joinColumns = @JoinColumn(name = "profile_id")) -// @org.hibernate.annotations.MapKey(columns =@Column(name = "propkey")) -// @Column(name = "propvalue") -// @ForeignKey(name="fk_custom_profile") -// private Map customProps = new HashMap(); - /** * Instantiates a new profile. */ @@ -163,102 +156,57 @@ public void setEnabled(Boolean enabled) { this.enabled = enabled; } -// @XmlJavaTypeAdapter(MapAdapter.class) -// public Map getCustomProps() { -// return customProps; -// } -// -// public void setCustomProps(Map customProps) { -// this.customProps = customProps; -// } - - /* (non-Javadoc) - * @see java.lang.Object#hashCode() - */ @Override - public int hashCode() { - final int prime = 31; - int result = 1; - result = prime * result + ((dateCreation == null) ? 0 : dateCreation.hashCode()); - result = prime * result + Boolean.valueOf(enabled).hashCode(); - result = prime * result + (int) (id ^ (id >>> 32)); - result = prime * result + ((name == null) ? 0 : name.hashCode()); - return result; + public int hashCode() + { + int hash = 7; + hash = 97 * hash + Objects.hashCode(this.id); + hash = 97 * hash + Objects.hashCode(this.extId); + hash = 97 * hash + Objects.hashCode(this.name); + hash = 97 * hash + Objects.hashCode(this.dateCreation); + hash = 97 * hash + (this.enabled ? 1 : 0); + return hash; } @Override - public boolean equals(Object obj) { - if ( obj == null ) { + public boolean equals(Object obj) + { + if (this == obj) { + return true; + } + if (obj == null) { return false; } - if ( getClass() != obj.getClass() ) { + if (getClass() != obj.getClass()) { return false; } final UserGroup other = (UserGroup) obj; - if ( this.id != other.id && (this.id == null || !this.id.equals(other.id)) ) { + if (this.enabled != other.enabled) { return false; } - if ( (this.extId == null) ? (other.extId != null) : !this.extId.equals(other.extId) ) { + if (!Objects.equals(this.extId, other.extId)) { return false; } - if ( (this.name == null) ? (other.name != null) : !this.name.equals(other.name) ) { + if (!Objects.equals(this.name, other.name)) { return false; } - if ( this.dateCreation != other.dateCreation && (this.dateCreation == null || !this.dateCreation.equals(other.dateCreation)) ) { + if (!Objects.equals(this.id, other.id)) { return false; } - if ( this.enabled != other.enabled ) { + if (!Objects.equals(this.dateCreation, other.dateCreation)) { return false; } return true; } - /* (non-Javadoc) - * @see java.lang.Object#equals(java.lang.Object) - */ -// @Override -// public boolean equals(Object obj) { -// if (this == obj) { -// return true; -// } -// if (obj == null) { -// return false; -// } -// if (!(obj instanceof UserGroup)) { -// return false; -// } -// UserGroup other = (UserGroup) obj; -// if (dateCreation == null) { -// if (other.dateCreation != null) { -// return false; -// } -// } else if (!dateCreation.equals(other.dateCreation)) { -// return false; -// } -// if ( enabled != other.enabled) { -// return false; -// } -// if (id != other.id) { -// return false; -// } -// if (name == null) { -// if (other.name != null) { -// return false; -// } -// } else if (!name.equals(other.name)) { -// return false; -// } -// return true; -// } - - /* (non-Javadoc) - * @see java.lang.Object#toString() - */ @Override public String toString() { StringBuilder builder = new StringBuilder(this.getClass().getSimpleName()); builder.append("["); - builder.append("id:").append(id); + if(id != null) + builder.append("id:").append(id); + if(extId != null) + builder.append(" ext:").append(extId); if (name != null) builder.append(" name:").append(name); if( ! enabled ) diff --git a/src/services/core/persistence/pom.xml b/src/services/core/persistence/pom.xml index e063b103..d0bd465c 100644 --- a/src/services/core/persistence/pom.xml +++ b/src/services/core/persistence/pom.xml @@ -1,12 +1,12 @@ - + 4.0.0 @@ -19,7 +19,7 @@ geofence-persistence jar GeoFence - Core - Persistence - + @@ -42,7 +42,7 @@ commons-collections commons-collections - + commons-codec commons-codec @@ -51,16 +51,17 @@ - + dom4j dom4j + - org.apache.logging.log4j - log4j-api + log4j + log4j - + @@ -91,7 +92,7 @@ - + com.googlecode.genericdao dao @@ -102,11 +103,6 @@ search-jpa-hibernate - - org.apache.logging.log4j - log4j-slf4j-impl - - commons-dbcp @@ -118,7 +114,7 @@ hibernate-spatial-h2-geodb test - + @@ -166,7 +162,7 @@ - + asm @@ -190,22 +186,16 @@ org.aspectj aspectjweaver - - - + junit junit test - + - + @@ -243,5 +233,5 @@ - + diff --git a/src/services/core/persistence/src/main/java/org/geoserver/geofence/core/dao/GSUserDAO.java b/src/services/core/persistence/src/main/java/org/geoserver/geofence/core/dao/GSUserDAO.java index 32f71165..c2fee6f2 100644 --- a/src/services/core/persistence/src/main/java/org/geoserver/geofence/core/dao/GSUserDAO.java +++ b/src/services/core/persistence/src/main/java/org/geoserver/geofence/core/dao/GSUserDAO.java @@ -1,4 +1,4 @@ -/* (c) 2014 Open Source Geospatial Foundation - all rights reserved +/* (c) 2014 - 2017 Open Source Geospatial Foundation - all rights reserved * This code is licensed under the GPL 2.0 license, available at the root * application directory. */ @@ -6,9 +6,6 @@ package org.geoserver.geofence.core.dao; import org.geoserver.geofence.core.model.GSUser; -import org.geoserver.geofence.core.model.UserGroup; - -import java.util.Set; /** * Public interface to define operations on GSUsers @@ -16,13 +13,8 @@ * @author Emanuele Tajariol (etj at geo-solutions.it) */ -public interface GSUserDAO extends RestrictedGenericDAO { - - Set getGroups(Long id); +public interface GSUserDAO extends RestrictedGenericDAO, RegistrableDAO { - /** Fetch a GSUser with all of its related groups */ - GSUser getFull(Long id); /** Fetch a GSUser with all of its related groups */ GSUser getFull(String name); - } diff --git a/src/services/core/persistence/src/main/java/org/geoserver/geofence/core/dao/RegistrableDAO.java b/src/services/core/persistence/src/main/java/org/geoserver/geofence/core/dao/RegistrableDAO.java new file mode 100644 index 00000000..ccff8773 --- /dev/null +++ b/src/services/core/persistence/src/main/java/org/geoserver/geofence/core/dao/RegistrableDAO.java @@ -0,0 +1,12 @@ +/* (c) 2017 Open Source Geospatial Foundation - all rights reserved + * This code is licensed under the GPL 2.0 license, available at the root + * application directory. + */ +package org.geoserver.geofence.core.dao; + +/** + * @author Emanuele Tajariol (etj at geo-solutions.it) + */ +public interface RegistrableDAO +{ +} diff --git a/src/services/core/persistence/src/main/java/org/geoserver/geofence/core/dao/UserGroupDAO.java b/src/services/core/persistence/src/main/java/org/geoserver/geofence/core/dao/UserGroupDAO.java index e3bbd330..8f8149eb 100644 --- a/src/services/core/persistence/src/main/java/org/geoserver/geofence/core/dao/UserGroupDAO.java +++ b/src/services/core/persistence/src/main/java/org/geoserver/geofence/core/dao/UserGroupDAO.java @@ -1,4 +1,4 @@ -/* (c) 2014 Open Source Geospatial Foundation - all rights reserved +/* (c) 2014 - 2017 Open Source Geospatial Foundation - all rights reserved * This code is licensed under the GPL 2.0 license, available at the root * application directory. */ @@ -9,10 +9,9 @@ /** * Public interface to define operations on UserGroups - * + * * @author Emanuele Tajariol (etj at geo-solutions.it) */ -public interface UserGroupDAO - extends RestrictedGenericDAO { +public interface UserGroupDAO extends RestrictedGenericDAO, RegistrableDAO { } diff --git a/src/services/core/persistence/src/main/java/org/geoserver/geofence/core/dao/impl/AdminRuleDAOImpl.java b/src/services/core/persistence/src/main/java/org/geoserver/geofence/core/dao/impl/AdminRuleDAOImpl.java index 63ae02e1..4d2589b2 100644 --- a/src/services/core/persistence/src/main/java/org/geoserver/geofence/core/dao/impl/AdminRuleDAOImpl.java +++ b/src/services/core/persistence/src/main/java/org/geoserver/geofence/core/dao/impl/AdminRuleDAOImpl.java @@ -1,4 +1,4 @@ -/* (c) 2015-2016 Open Source Geospatial Foundation - all rights reserved +/* (c) 2015 - 2017 Open Source Geospatial Foundation - all rights reserved * This code is licensed under the GPL 2.0 license, available at the root * application directory. */ @@ -13,12 +13,13 @@ import static org.geoserver.geofence.core.dao.util.SearchUtil.*; import org.geoserver.geofence.core.model.enums.InsertPosition; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; import org.geoserver.geofence.core.dao.AdminRuleDAO; import org.geoserver.geofence.core.dao.DuplicateKeyException; import org.geoserver.geofence.core.model.AdminRule; +import org.apache.log4j.LogManager; +import org.apache.log4j.Logger; + import org.springframework.transaction.annotation.Transactional; /** diff --git a/src/services/core/persistence/src/main/java/org/geoserver/geofence/core/dao/impl/GFUserDAOImpl.java b/src/services/core/persistence/src/main/java/org/geoserver/geofence/core/dao/impl/GFUserDAOImpl.java index b24f883e..cb44fc6f 100644 --- a/src/services/core/persistence/src/main/java/org/geoserver/geofence/core/dao/impl/GFUserDAOImpl.java +++ b/src/services/core/persistence/src/main/java/org/geoserver/geofence/core/dao/impl/GFUserDAOImpl.java @@ -1,4 +1,4 @@ -/* (c) 2014 Open Source Geospatial Foundation - all rights reserved +/* (c) 2014 - 2017 Open Source Geospatial Foundation - all rights reserved * This code is licensed under the GPL 2.0 license, available at the root * application directory. */ @@ -15,8 +15,8 @@ import org.springframework.transaction.annotation.Transactional; import com.googlecode.genericdao.search.ISearch; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; +import org.apache.log4j.LogManager; +import org.apache.log4j.Logger; /** diff --git a/src/services/core/persistence/src/main/java/org/geoserver/geofence/core/dao/impl/GSInstanceDAOImpl.java b/src/services/core/persistence/src/main/java/org/geoserver/geofence/core/dao/impl/GSInstanceDAOImpl.java index 39e34fb0..aa6b88b3 100644 --- a/src/services/core/persistence/src/main/java/org/geoserver/geofence/core/dao/impl/GSInstanceDAOImpl.java +++ b/src/services/core/persistence/src/main/java/org/geoserver/geofence/core/dao/impl/GSInstanceDAOImpl.java @@ -1,4 +1,4 @@ -/* (c) 2014 Open Source Geospatial Foundation - all rights reserved +/* (c) 2014 - 2017 Open Source Geospatial Foundation - all rights reserved * This code is licensed under the GPL 2.0 license, available at the root * application directory. */ @@ -12,8 +12,8 @@ import org.geoserver.geofence.core.dao.GSInstanceDAO; import org.geoserver.geofence.core.model.GSInstance; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; +import org.apache.log4j.LogManager; +import org.apache.log4j.Logger; import org.springframework.transaction.annotation.Transactional; diff --git a/src/services/core/persistence/src/main/java/org/geoserver/geofence/core/dao/impl/GSUserDAOImpl.java b/src/services/core/persistence/src/main/java/org/geoserver/geofence/core/dao/impl/GSUserDAOImpl.java index 468db640..1cef5c36 100644 --- a/src/services/core/persistence/src/main/java/org/geoserver/geofence/core/dao/impl/GSUserDAOImpl.java +++ b/src/services/core/persistence/src/main/java/org/geoserver/geofence/core/dao/impl/GSUserDAOImpl.java @@ -1,4 +1,4 @@ -/* (c) 2014 Open Source Geospatial Foundation - all rights reserved +/* (c) 2014 - 2017 Open Source Geospatial Foundation - all rights reserved * This code is licensed under the GPL 2.0 license, available at the root * application directory. */ @@ -18,8 +18,8 @@ import com.googlecode.genericdao.search.ISearch; import com.googlecode.genericdao.search.Search; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; +import org.apache.log4j.LogManager; +import org.apache.log4j.Logger; /** @@ -56,14 +56,6 @@ public List search(ISearch search) return super.search(search); } - - @Override - public GSUser getFull(Long id) { - Search search = new Search(GSUser.class); - search.addFilterEqual("id", id); - return searchFull(search); - } - @Override public GSUser getFull(String name) { Search search = new Search(GSUser.class); @@ -115,18 +107,6 @@ protected GSUser searchFull(Search search) { @Override public GSUser merge(GSUser entity) { -// // Workaround: if area srid has changed (and vertices did not), the geometry will not be updated on db -// // Check for test UserDAOTest.testUpdateSRID(). -// MultiPolygon oldMp = entity.getAllowedArea(); -// if (oldMp != null) -// { -// entity.setAllowedArea(null); -// super.merge(entity); -// em().flush(); -// entity.setAllowedArea(oldMp); -// } - - // end workaround return super.merge(entity); } @@ -142,18 +122,4 @@ public boolean removeById(Long id) return super.removeById(id); } - @Override - public Set getGroups(Long id) { - GSUser user = find(id); - if(user == null) - return null; - - Set groups = user.getGroups(); - if ( (groups != null) && !Hibernate.isInitialized(groups) ) { - Hibernate.initialize(groups); // fetch the groups - } - - return groups; - } - } diff --git a/src/services/core/persistence/src/main/java/org/geoserver/geofence/core/dao/impl/LayerDetailsDAOImpl.java b/src/services/core/persistence/src/main/java/org/geoserver/geofence/core/dao/impl/LayerDetailsDAOImpl.java index 1415dcf2..8a61c386 100644 --- a/src/services/core/persistence/src/main/java/org/geoserver/geofence/core/dao/impl/LayerDetailsDAOImpl.java +++ b/src/services/core/persistence/src/main/java/org/geoserver/geofence/core/dao/impl/LayerDetailsDAOImpl.java @@ -1,4 +1,4 @@ -/* (c) 2014 Open Source Geospatial Foundation - all rights reserved +/* (c) 2014 - 2017 Open Source Geospatial Foundation - all rights reserved * This code is licensed under the GPL 2.0 license, available at the root * application directory. */ @@ -13,8 +13,8 @@ import org.geoserver.geofence.core.dao.LayerDetailsDAO; import org.geoserver.geofence.core.model.LayerAttribute; import org.geoserver.geofence.core.model.LayerDetails; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; +import org.apache.log4j.LogManager; +import org.apache.log4j.Logger; import org.hibernate.Hibernate; import org.springframework.transaction.annotation.Transactional; diff --git a/src/services/core/persistence/src/main/java/org/geoserver/geofence/core/dao/impl/PrioritizableDAOImpl.java b/src/services/core/persistence/src/main/java/org/geoserver/geofence/core/dao/impl/PrioritizableDAOImpl.java index 2ca2a956..677cee83 100644 --- a/src/services/core/persistence/src/main/java/org/geoserver/geofence/core/dao/impl/PrioritizableDAOImpl.java +++ b/src/services/core/persistence/src/main/java/org/geoserver/geofence/core/dao/impl/PrioritizableDAOImpl.java @@ -1,24 +1,23 @@ -/* (c) 2015 Open Source Geospatial Foundation - all rights reserved +/* (c) 2015 - 2017 Open Source Geospatial Foundation - all rights reserved * This code is licensed under the GPL 2.0 license, available at the root * application directory. */ package org.geoserver.geofence.core.dao.impl; -import org.geoserver.geofence.core.dao.PrioritizableDAO; -import com.googlecode.genericdao.search.Field; -import com.googlecode.genericdao.search.ISearch; import java.util.List; - import javax.persistence.Query; -import com.googlecode.genericdao.search.Search; - +import org.geoserver.geofence.core.dao.PrioritizableDAO; import org.geoserver.geofence.core.model.enums.InsertPosition; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; import org.geoserver.geofence.core.model.Prioritizable; -import org.geoserver.geofence.core.model.Rule; + +import com.googlecode.genericdao.search.Field; +import com.googlecode.genericdao.search.ISearch; +import com.googlecode.genericdao.search.Search; + +import org.apache.log4j.LogManager; +import org.apache.log4j.Logger; import org.springframework.transaction.annotation.Transactional; diff --git a/src/services/core/persistence/src/main/java/org/geoserver/geofence/core/dao/impl/RuleDAOImpl.java b/src/services/core/persistence/src/main/java/org/geoserver/geofence/core/dao/impl/RuleDAOImpl.java index 659da6bb..a36aac97 100644 --- a/src/services/core/persistence/src/main/java/org/geoserver/geofence/core/dao/impl/RuleDAOImpl.java +++ b/src/services/core/persistence/src/main/java/org/geoserver/geofence/core/dao/impl/RuleDAOImpl.java @@ -1,4 +1,4 @@ -/* (c) 2014-2016 Open Source Geospatial Foundation - all rights reserved +/* (c) 2014 - 2017 Open Source Geospatial Foundation - all rights reserved * This code is licensed under the GPL 2.0 license, available at the root * application directory. */ @@ -17,8 +17,8 @@ import org.geoserver.geofence.core.model.enums.GrantType; import org.geoserver.geofence.core.model.enums.InsertPosition; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; +import org.apache.log4j.LogManager; +import org.apache.log4j.Logger; import org.geoserver.geofence.core.dao.DuplicateKeyException; import org.springframework.transaction.annotation.Transactional; diff --git a/src/services/core/persistence/src/main/java/org/geoserver/geofence/core/dao/impl/RuleLimitsDAOImpl.java b/src/services/core/persistence/src/main/java/org/geoserver/geofence/core/dao/impl/RuleLimitsDAOImpl.java index 09d53096..efffcc6c 100644 --- a/src/services/core/persistence/src/main/java/org/geoserver/geofence/core/dao/impl/RuleLimitsDAOImpl.java +++ b/src/services/core/persistence/src/main/java/org/geoserver/geofence/core/dao/impl/RuleLimitsDAOImpl.java @@ -1,4 +1,4 @@ -/* (c) 2014 Open Source Geospatial Foundation - all rights reserved +/* (c) 2014 - 2017 Open Source Geospatial Foundation - all rights reserved * This code is licensed under the GPL 2.0 license, available at the root * application directory. */ @@ -12,8 +12,8 @@ import org.geoserver.geofence.core.dao.RuleLimitsDAO; import org.geoserver.geofence.core.model.RuleLimits; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; +import org.apache.log4j.LogManager; +import org.apache.log4j.Logger; import org.springframework.transaction.annotation.Transactional; diff --git a/src/services/core/persistence/src/main/java/org/geoserver/geofence/core/dao/impl/UserGroupDAOImpl.java b/src/services/core/persistence/src/main/java/org/geoserver/geofence/core/dao/impl/UserGroupDAOImpl.java index 9788b2f8..d9c7cbfe 100644 --- a/src/services/core/persistence/src/main/java/org/geoserver/geofence/core/dao/impl/UserGroupDAOImpl.java +++ b/src/services/core/persistence/src/main/java/org/geoserver/geofence/core/dao/impl/UserGroupDAOImpl.java @@ -1,4 +1,4 @@ -/* (c) 2014 Open Source Geospatial Foundation - all rights reserved +/* (c) 2014 - 2017 Open Source Geospatial Foundation - all rights reserved * This code is licensed under the GPL 2.0 license, available at the root * application directory. */ @@ -13,8 +13,8 @@ import org.geoserver.geofence.core.dao.UserGroupDAO; import org.geoserver.geofence.core.model.UserGroup; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; +import org.apache.log4j.LogManager; +import org.apache.log4j.Logger; import org.springframework.transaction.annotation.Transactional; @@ -29,7 +29,6 @@ public class UserGroupDAOImpl extends BaseDAO // extends GenericDAOImpl implements UserGroupDAO { - private static final Logger LOGGER = LogManager.getLogger(UserGroupDAOImpl.class); @Override diff --git a/src/services/core/persistence/src/main/java/org/geoserver/geofence/core/dao/util/GeofenceDaoRegistry.java b/src/services/core/persistence/src/main/java/org/geoserver/geofence/core/dao/util/GeofenceDaoRegistry.java new file mode 100644 index 00000000..92ac7b05 --- /dev/null +++ b/src/services/core/persistence/src/main/java/org/geoserver/geofence/core/dao/util/GeofenceDaoRegistry.java @@ -0,0 +1,109 @@ +/* (c) 2017 Open Source Geospatial Foundation - all rights reserved + * This code is licensed under the GPL 2.0 license, available at the root + * application directory. + */ + +package org.geoserver.geofence.core.dao.util; + +import java.util.Arrays; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Map; +import java.util.Set; +import org.apache.log4j.LogManager; +import org.apache.log4j.Logger; +import org.geoserver.geofence.core.dao.GSUserDAO; +import org.geoserver.geofence.core.dao.RegistrableDAO; +import org.geoserver.geofence.core.dao.UserGroupDAO; +import org.springframework.beans.BeansException; +import org.springframework.context.ApplicationContext; +import org.springframework.context.ApplicationContextAware; + +/** + * Allow DAO pluggabily and externalization of the DAO type selection. + * + * @author Emanuele Tajariol (etj at geo-solutions.it) + */ +public class GeofenceDaoRegistry implements ApplicationContextAware +{ + private static final Logger LOGGER = LogManager.getLogger(GeofenceDaoRegistry.class); + + private static final Set REGISTERABLE_CLASSES = new HashSet<>(Arrays.asList(GSUserDAO.class, UserGroupDAO.class)); + + public static class DaoRegistrar + { + private String name; + private RegistrableDAO dao; + + public DaoRegistrar(String name, RegistrableDAO dao) + { + this.name = name; + this.dao = dao; + } + } + + private Map> registry = new HashMap<>(); + private String selectedType; + + + private GeofenceDaoRegistry() + { + for (Class registerableClass : REGISTERABLE_CLASSES) { + registry.put(registerableClass, new HashMap<>()); + } + } + + public GeofenceDaoRegistry(String defaultType) + { + this(); + this.selectedType = defaultType; + } + + public void setSelectedType(String selectedType) + { + this.selectedType = selectedType; + } + + public T getDao(Class t) { + + Map registryMap = registry.get(t); + if(registryMap == null) + throw new IllegalArgumentException("Unregistered class " + t); + + T dao = (T)registryMap.get(selectedType); + if(dao == null) + throw new IllegalArgumentException("DAO not found for class " +t.getSimpleName()+ " and type " + selectedType); + + LOGGER.info("Returning DAO type " + selectedType + " for class " + t.getSimpleName()); + return dao; + } + + @Override + public void setApplicationContext(ApplicationContext applicationContext) throws BeansException + { + Map registrars = applicationContext.getBeansOfType(DaoRegistrar.class); + for (GeofenceDaoRegistry.DaoRegistrar registrar : registrars.values()) { + addRegistrar(registrar); + } + } + + protected void addRegistrar(DaoRegistrar registrar) { + RegistrableDAO dao = registrar.dao; + + for (Class registerableClass : REGISTERABLE_CLASSES) { + if(registerableClass.isAssignableFrom(dao.getClass())) { + LOGGER.info("Registering DAO type " + registrar.name + " for class " + dao.getClass().getSimpleName()); + + Map registryMap = registry.get(registerableClass); + registryMap.put(registrar.name, dao); + return; + } else if (LOGGER.isDebugEnabled()) { + LOGGER.debug("Skipping DAO type " + registrar.name + ": " + dao.getClass() + " is not a " + registerableClass); + } + } + LOGGER.error("Cannot register DAO class " + registrar.dao.getClass() + " with type " + registrar.name); + throw new IllegalArgumentException("Cannot register DAO class " + dao.getClass() + " with type " + registrar.name); + } + + +} diff --git a/src/services/core/persistence/src/main/resources/applicationContext.xml b/src/services/core/persistence/src/main/resources/applicationContext.xml index 0b66123d..5571472b 100644 --- a/src/services/core/persistence/src/main/resources/applicationContext.xml +++ b/src/services/core/persistence/src/main/resources/applicationContext.xml @@ -1,25 +1,22 @@ - + @@ -42,12 +39,12 @@ factory-method="getInstanceForEntityManagerFactory"> - + - + @@ -55,7 +52,7 @@ - + @@ -78,5 +75,39 @@ - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/services/core/persistence/src/test/java/org/geoserver/geofence/core/dao/BaseDAOTest.java b/src/services/core/persistence/src/test/java/org/geoserver/geofence/core/dao/BaseDAOTest.java index 5779028e..f0fc75f2 100644 --- a/src/services/core/persistence/src/test/java/org/geoserver/geofence/core/dao/BaseDAOTest.java +++ b/src/services/core/persistence/src/test/java/org/geoserver/geofence/core/dao/BaseDAOTest.java @@ -1,33 +1,27 @@ -/* (c) 2014 Open Source Geospatial Foundation - all rights reserved +/* (c) 2014 - 2017 Open Source Geospatial Foundation - all rights reserved * This code is licensed under the GPL 2.0 license, available at the root * application directory. */ package org.geoserver.geofence.core.dao; -import org.geoserver.geofence.core.dao.UserGroupDAO; -import org.geoserver.geofence.core.dao.RuleLimitsDAO; -import org.geoserver.geofence.core.dao.RuleDAO; -import org.geoserver.geofence.core.dao.GSUserDAO; -import org.geoserver.geofence.core.dao.LayerDetailsDAO; -import org.geoserver.geofence.core.dao.GFUserDAO; +import java.util.List; + import com.vividsolutions.jts.geom.MultiPolygon; import com.vividsolutions.jts.geom.Polygon; import com.vividsolutions.jts.io.ParseException; import com.vividsolutions.jts.io.WKTReader; + import org.geoserver.geofence.core.model.GFUser; import org.geoserver.geofence.core.model.UserGroup; -import java.util.List; - +import org.geoserver.geofence.core.model.GSUser; +import org.geoserver.geofence.core.model.Rule; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; +import org.apache.log4j.LogManager; +import org.apache.log4j.Logger; import org.springframework.context.support.ClassPathXmlApplicationContext; -import org.geoserver.geofence.core.model.GSUser; -import org.geoserver.geofence.core.model.Rule; - import org.junit.Before; import static org.junit.Assert.*; import org.junit.rules.TestName; diff --git a/src/services/core/persistence/src/test/java/org/geoserver/geofence/core/dao/UserDAOTest.java b/src/services/core/persistence/src/test/java/org/geoserver/geofence/core/dao/UserDAOTest.java index 5e84a533..d76c64cf 100644 --- a/src/services/core/persistence/src/test/java/org/geoserver/geofence/core/dao/UserDAOTest.java +++ b/src/services/core/persistence/src/test/java/org/geoserver/geofence/core/dao/UserDAOTest.java @@ -1,11 +1,10 @@ -/* (c) 2014 Open Source Geospatial Foundation - all rights reserved +/* (c) 2014 - 2017 Open Source Geospatial Foundation - all rights reserved * This code is licensed under the GPL 2.0 license, available at the root * application directory. */ package org.geoserver.geofence.core.dao; -import com.vividsolutions.jts.geom.MultiPolygon; import org.geoserver.geofence.core.model.GSUser; import org.geoserver.geofence.core.model.UserGroup; import java.util.Set; @@ -14,7 +13,7 @@ import org.junit.Test; /** - * + * * @author ETj (etj at geo-solutions.it) */ public class UserDAOTest extends BaseDAOTest { @@ -33,63 +32,12 @@ public void testPersistUser() throws Exception { { GSUser loaded = userDAO.find(id); assertNotNull("Can't retrieve user", loaded); - -// assertNull(loaded.getAllowedArea()); -// loaded.setAllowedArea(buildMultiPolygon()); -// userDAO.merge(loaded); } -// { -// GSUser loaded2 = userDAO.find(id); -// assertNotNull("Can't retrieve user", loaded2); -// assertNotNull(loaded2.getAllowedArea()); -// } - userDAO.removeById(id); assertNull("User not deleted", userDAO.find(id)); } -// @Test -// public void testUpdateSRID() throws Exception { -// -// final int srid2 = 4326; -// final int srid1 = 8307; -// -// long id; -// { -// GSUser user = createUserAndGroup(getName()); -// MultiPolygon mp = buildMultiPolygon(); -// mp.setSRID(srid1); -// user.setAllowedArea(mp); -// userDAO.persist(user); -// id = user.getId(); -// } -// -// // test save & load -// { -// GSUser loaded = userDAO.find(id); -// assertNotNull("Can't retrieve user", loaded); -// assertEquals("bad SRID", srid1, loaded.getAllowedArea().getSRID()); -// -// MultiPolygon mp = buildMultiPolygon(); -// mp.setSRID(srid2); -// loaded.setAllowedArea(mp); -// assertEquals("SRID not set", srid2, loaded.getAllowedArea().getSRID()); -// -// userDAO.merge(loaded); -// } -// -// { -// GSUser loaded = userDAO.find(id); -// assertNotNull("Can't retrieve user", loaded); -// assertEquals("SRID not updated", srid2, loaded.getAllowedArea().getSRID()); -// } -// -// userDAO.removeById(id); -// assertNull("User not deleted", userDAO.find(id)); -// } - - @Test public void testGroups() throws Exception { @@ -98,7 +46,7 @@ public void testGroups() throws Exception { { UserGroup g1 = createUserGroup(name.getMethodName()+"1"); gid1 = g1.getId(); - + UserGroup g2 = createUserGroup(name.getMethodName()+"2"); gid2 = g2.getId(); @@ -109,9 +57,9 @@ public void testGroups() throws Exception { } { - GSUser loaded = userDAO.find(uid1); + GSUser loaded = userDAO.getFull("u0"); assertNotNull("Can't retrieve user", loaded); - Set grps = userDAO.getGroups(uid1); + Set grps = loaded.getGroups(); assertEquals("Bad number of usergroups", 1, grps.size()); assertEquals("Bad assigned usergroup", gid1, grps.iterator().next().getId()); @@ -124,9 +72,9 @@ public void testGroups() throws Exception { } { - GSUser loaded = userDAO.find(uid1); + GSUser loaded = userDAO.getFull("u0"); assertNotNull("Can't retrieve user", loaded); - Set grps = userDAO.getGroups(uid1); + Set grps = loaded.getGroups(); assertEquals("Bad number of usergroups", 2, grps.size()); } } diff --git a/src/services/core/persistence/src/test/java/org/geoserver/geofence/core/dao/util/DaoRegistryTest.java b/src/services/core/persistence/src/test/java/org/geoserver/geofence/core/dao/util/DaoRegistryTest.java new file mode 100644 index 00000000..53271449 --- /dev/null +++ b/src/services/core/persistence/src/test/java/org/geoserver/geofence/core/dao/util/DaoRegistryTest.java @@ -0,0 +1,80 @@ +/* (c) 2017 Open Source Geospatial Foundation - all rights reserved + * This code is licensed under the GPL 2.0 license, available at the root + * application directory. + */ +package org.geoserver.geofence.core.dao.util; + +import org.geoserver.geofence.core.dao.GSUserDAO; +import org.geoserver.geofence.core.dao.impl.GSUserDAOImpl; +import org.junit.Test; +import static org.junit.Assert.*; + +/** + * + * @author ETj + */ +public class DaoRegistryTest +{ + + public DaoRegistryTest() + { + } + + @Test + public void testGetDefault() + { + GeofenceDaoRegistry registry = new GeofenceDaoRegistry("DEFAULTTYPE"); + registry.addRegistrar(new GeofenceDaoRegistry.DaoRegistrar("DEFAULTTYPE", new GSUserDAOImpl())); + + GSUserDAO dao = registry.getDao(GSUserDAO.class); // should not throw + } + + @Test + public void testGet() + { + GeofenceDaoRegistry registry = new GeofenceDaoRegistry("DEFAULTTYPE"); + registry.addRegistrar(new GeofenceDaoRegistry.DaoRegistrar("DEFAULTTYPE", new GSUserTestDAO("t1"))); + registry.addRegistrar(new GeofenceDaoRegistry.DaoRegistrar("TYPE1", new GSUserTestDAO("t2"))); + + { + GSUserDAO dao = registry.getDao(GSUserDAO.class); + assertTrue(dao instanceof GSUserTestDAO); + assertEquals("t1", ((GSUserTestDAO)dao).name); + } + + registry.setSelectedType("TYPE1"); + + { + GSUserDAO dao = registry.getDao(GSUserDAO.class); + assertTrue(dao instanceof GSUserTestDAO); + assertEquals("t2", ((GSUserTestDAO)dao).name); + } + } + + @Test + public void testGetMissingDefault() + { + GeofenceDaoRegistry registry = new GeofenceDaoRegistry("DEFAULTTYPE"); + + try { + GSUserDAO dao = registry.getDao(GSUserDAO.class); + fail("Missing DAO not trapped"); + } catch (Exception e) { + } + } + + private static class GSUserTestDAO extends GSUserDAOImpl { + + private String name; + + public GSUserTestDAO(String name) + { + this.name = name; + } + + public String getName() + { + return name; + } + } +} diff --git a/src/services/core/persistence/src/test/resources/geofence-datasource.properties b/src/services/core/persistence/src/test/resources/geofence-datasource.properties deleted file mode 100644 index 5fb0048c..00000000 --- a/src/services/core/persistence/src/test/resources/geofence-datasource.properties +++ /dev/null @@ -1,15 +0,0 @@ -# /* (c) 2014 Open Source Geospatial Foundation - all rights reserved -# * This code is licensed under the GPL 2.0 license, available at the root -# * application directory. -# */ -# -geofenceVendorAdapter.databasePlatform=org.hibernatespatial.postgis.PostgisDialect -#geofenceVendorAdapter.databasePlatform= org.hibernatespatial.oracle.OracleSpatial10gDialect -#geofenceVendorAdapter.databasePlatform=org.hibernatespatial.geodb.GeoDBDialect - -geofenceDataSource.driver=org.postgresql.Driver -geofenceDataSource.url=jdbc:postgresql://localhost:5432/geofence -geofenceDataSource.schema=geofence_test -geofenceDataSource.username=geofence_test -geofenceDataSource.password=geofence_test - diff --git a/src/services/core/services-api/src/main/java/org/geoserver/geofence/services/UserAdminService.java b/src/services/core/services-api/src/main/java/org/geoserver/geofence/services/UserAdminService.java index b56fd6c9..d30ca753 100644 --- a/src/services/core/services-api/src/main/java/org/geoserver/geofence/services/UserAdminService.java +++ b/src/services/core/services-api/src/main/java/org/geoserver/geofence/services/UserAdminService.java @@ -1,4 +1,4 @@ -/* (c) 2014 Open Source Geospatial Foundation - all rights reserved +/* (c) 2014 - 2017 Open Source Geospatial Foundation - all rights reserved * This code is licensed under the GPL 2.0 license, available at the root * application directory. */ @@ -6,13 +6,11 @@ package org.geoserver.geofence.services; import org.geoserver.geofence.core.model.GSUser; -import org.geoserver.geofence.core.model.UserGroup; import org.geoserver.geofence.services.dto.ShortUser; import org.geoserver.geofence.services.exception.BadRequestServiceEx; import org.geoserver.geofence.services.exception.NotFoundServiceEx; import java.util.List; -import java.util.Set; /** @@ -43,9 +41,7 @@ public interface UserAdminService extends GetProviderService @Override GSUser get(long id) throws NotFoundServiceEx; GSUser get(String name) throws NotFoundServiceEx; - GSUser getFull(long id) throws NotFoundServiceEx; - - Set getUserGroups(long id); + GSUser getFull(String name) throws NotFoundServiceEx; long getCount(String nameLike); diff --git a/src/services/core/services-api/src/main/java/org/geoserver/geofence/services/dto/ShortGroup.java b/src/services/core/services-api/src/main/java/org/geoserver/geofence/services/dto/ShortGroup.java index bc7f28ce..c8b2e915 100644 --- a/src/services/core/services-api/src/main/java/org/geoserver/geofence/services/dto/ShortGroup.java +++ b/src/services/core/services-api/src/main/java/org/geoserver/geofence/services/dto/ShortGroup.java @@ -1,4 +1,4 @@ -/* (c) 2014 Open Source Geospatial Foundation - all rights reserved +/* (c) 2014 - 2017 Open Source Geospatial Foundation - all rights reserved * This code is licensed under the GPL 2.0 license, available at the root * application directory. */ @@ -22,8 +22,8 @@ @XmlType(propOrder = {"id", "extId", "name"}) public class ShortGroup implements Serializable { - private static final long serialVersionUID = -8410646966443187827L; - private long id; + private static final long serialVersionUID = -43187828L; + private Long id; private String name; private String extId; private Boolean enabled; @@ -38,11 +38,11 @@ public ShortGroup(UserGroup group) { this.extId = group.getExtId(); } - public long getId() { + public Long getId() { return id; } - public void setId(long id) { + public void setId(Long id) { this.id = id; } diff --git a/src/services/core/services-api/src/main/java/org/geoserver/geofence/services/dto/ShortUser.java b/src/services/core/services-api/src/main/java/org/geoserver/geofence/services/dto/ShortUser.java index fb6c85b4..a0f4f44a 100644 --- a/src/services/core/services-api/src/main/java/org/geoserver/geofence/services/dto/ShortUser.java +++ b/src/services/core/services-api/src/main/java/org/geoserver/geofence/services/dto/ShortUser.java @@ -1,4 +1,4 @@ -/* (c) 2014 Open Source Geospatial Foundation - all rights reserved +/* (c) 2014 - 2017 Open Source Geospatial Foundation - all rights reserved * This code is licensed under the GPL 2.0 license, available at the root * application directory. */ @@ -19,9 +19,9 @@ public class ShortUser implements Serializable { - private static final long serialVersionUID = -2484627092672856852L; + private static final long serialVersionUID = -24846270926852L; - private long id; + private Long id; private String name; @@ -41,12 +41,12 @@ public ShortUser(GFUser user) this.name = user.getName(); } - public long getId() + public Long getId() { return id; } - public void setId(long id) + public void setId(Long id) { this.id = id; } diff --git a/src/services/core/services-api/src/main/java/org/geoserver/geofence/services/exception/NotFoundServiceEx.java b/src/services/core/services-api/src/main/java/org/geoserver/geofence/services/exception/NotFoundServiceEx.java index 7437d4cb..3b26c13d 100644 --- a/src/services/core/services-api/src/main/java/org/geoserver/geofence/services/exception/NotFoundServiceEx.java +++ b/src/services/core/services-api/src/main/java/org/geoserver/geofence/services/exception/NotFoundServiceEx.java @@ -1,4 +1,4 @@ -/* (c) 2014 Open Source Geospatial Foundation - all rights reserved +/* (c) 2014 - 2017 Open Source Geospatial Foundation - all rights reserved * This code is licensed under the GPL 2.0 license, available at the root * application directory. */ @@ -26,6 +26,12 @@ public NotFoundServiceEx(String message, Long id) this.message = message + " (id:" + id + ")"; } + public NotFoundServiceEx(String message, String name) + { + super(Response.Status.NOT_FOUND); + this.message = message + " (name:" + name + ")"; + } + @Override public String getMessage() { diff --git a/src/services/core/services-api/src/main/java/org/geoserver/geofence/spi/UserResolver.java b/src/services/core/services-api/src/main/java/org/geoserver/geofence/spi/UserResolver.java index ff6b9010..ecbd96a2 100644 --- a/src/services/core/services-api/src/main/java/org/geoserver/geofence/spi/UserResolver.java +++ b/src/services/core/services-api/src/main/java/org/geoserver/geofence/spi/UserResolver.java @@ -1,4 +1,4 @@ -/* (c) 2015 Open Source Geospatial Foundation - all rights reserved +/* (c) 2015 - 2017 Open Source Geospatial Foundation - all rights reserved * This code is licensed under the GPL 2.0 license, available at the root * application directory. */ @@ -13,8 +13,10 @@ */ public interface UserResolver { + @Deprecated boolean existsUser(String username); + @Deprecated boolean existsRole(String rolename); Set getRoles(String username); diff --git a/src/services/core/services-impl/pom.xml b/src/services/core/services-impl/pom.xml index d787aff5..93191fe1 100644 --- a/src/services/core/services-impl/pom.xml +++ b/src/services/core/services-impl/pom.xml @@ -1,14 +1,12 @@ - + 4.0.0 @@ -24,9 +22,9 @@ - - - + + + org.geoserver.geofence @@ -43,7 +41,7 @@ geofence-services-api - + @@ -60,15 +58,15 @@ commons-codec commons-codec - + - + org.springframework spring-beans @@ -93,22 +91,26 @@ dom4j + + log4j + log4j + + - - + org.hibernatespatial hibernate-spatial-h2-geodb @@ -131,24 +133,30 @@ search-jpa-hibernate - + + javax.servlet servlet-api provided - + + + org.apache.cxf @@ -156,7 +164,7 @@ test - + junit junit @@ -164,9 +172,9 @@ - + - + diff --git a/src/services/core/services-impl/src/main/java/org/geoserver/geofence/services/AdminRuleAdminServiceImpl.java b/src/services/core/services-impl/src/main/java/org/geoserver/geofence/services/AdminRuleAdminServiceImpl.java index c795f810..10f81f78 100644 --- a/src/services/core/services-impl/src/main/java/org/geoserver/geofence/services/AdminRuleAdminServiceImpl.java +++ b/src/services/core/services-impl/src/main/java/org/geoserver/geofence/services/AdminRuleAdminServiceImpl.java @@ -1,24 +1,20 @@ -/* (c) 2015 Open Source Geospatial Foundation - all rights reserved +/* (c) 2015 - 2017 Open Source Geospatial Foundation - all rights reserved * This code is licensed under the GPL 2.0 license, available at the root * application directory. */ package org.geoserver.geofence.services; -import com.googlecode.genericdao.search.Filter; -import com.googlecode.genericdao.search.Search; -import org.geoserver.geofence.core.model.enums.InsertPosition; -import org.geoserver.geofence.services.dto.RuleFilter; -import org.geoserver.geofence.services.dto.ShortAdminRule; - import java.util.ArrayList; import java.util.List; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; +import com.googlecode.genericdao.search.Filter; +import com.googlecode.genericdao.search.Search; import org.geoserver.geofence.core.dao.AdminRuleDAO; import org.geoserver.geofence.core.model.AdminRule; - +import org.geoserver.geofence.core.model.enums.InsertPosition; +import org.geoserver.geofence.services.dto.RuleFilter; +import org.geoserver.geofence.services.dto.ShortAdminRule; import org.geoserver.geofence.services.exception.BadRequestServiceEx; import org.geoserver.geofence.services.exception.NotFoundServiceEx; @@ -28,6 +24,9 @@ import static org.geoserver.geofence.services.util.FilterUtils.addPagingConstraints; import static org.geoserver.geofence.services.util.FilterUtils.addStringCriteria; +import org.apache.log4j.LogManager; +import org.apache.log4j.Logger; + /** * * @author ETj (etj at geo-solutions.it) diff --git a/src/services/core/services-impl/src/main/java/org/geoserver/geofence/services/AuthorizationServiceImpl.java b/src/services/core/services-impl/src/main/java/org/geoserver/geofence/services/AuthorizationServiceImpl.java index 295e01ac..f8e56b27 100644 --- a/src/services/core/services-impl/src/main/java/org/geoserver/geofence/services/AuthorizationServiceImpl.java +++ b/src/services/core/services-impl/src/main/java/org/geoserver/geofence/services/AuthorizationServiceImpl.java @@ -1,4 +1,4 @@ -/* (c) 2015 Open Source Geospatial Foundation - all rights reserved +/* (c) 2015 - 2017 Open Source Geospatial Foundation - all rights reserved * This code is licensed under the GPL 2.0 license, available at the root * application directory. */ @@ -6,9 +6,12 @@ package org.geoserver.geofence.services; import com.googlecode.genericdao.search.Search; + import java.util.List; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; + +import org.apache.log4j.LogManager; +import org.apache.log4j.Logger; + import org.geoserver.geofence.core.dao.GSUserDAO; import org.geoserver.geofence.core.model.GSUser; import org.geoserver.geofence.services.dto.AuthUser; diff --git a/src/services/core/services-impl/src/main/java/org/geoserver/geofence/services/DefaultUserResolver.java b/src/services/core/services-impl/src/main/java/org/geoserver/geofence/services/DefaultUserResolver.java index 9d226715..ee7c075e 100644 --- a/src/services/core/services-impl/src/main/java/org/geoserver/geofence/services/DefaultUserResolver.java +++ b/src/services/core/services-impl/src/main/java/org/geoserver/geofence/services/DefaultUserResolver.java @@ -1,14 +1,16 @@ -/* (c) 2015 Open Source Geospatial Foundation - all rights reserved +/* (c) 2015 - 2017 Open Source Geospatial Foundation - all rights reserved * This code is licensed under the GPL 2.0 license, available at the root * application directory. */ package org.geoserver.geofence.services; -import com.googlecode.genericdao.search.Search; import java.util.HashSet; -import java.util.List; import java.util.Set; + +import org.apache.log4j.LogManager; +import org.apache.log4j.Logger; + import org.geoserver.geofence.core.dao.GSUserDAO; import org.geoserver.geofence.core.dao.UserGroupDAO; import org.geoserver.geofence.core.model.GSUser; @@ -23,33 +25,40 @@ */ public class DefaultUserResolver implements UserResolver { + private final static Logger LOGGER = LogManager.getLogger(DefaultUserResolver.class); + private GSUserDAO userDAO; private UserGroupDAO userGroupDAO; @Override + @Deprecated public boolean existsUser(String username) { - return userDAO.getFull(username) != null; + throw new IllegalStateException("This method is deprecated and should not be invoked"); } @Override public Set getRoles(String username) { GSUser user = userDAO.getFull(username); - Set ret = new HashSet(); - for (UserGroup role : user.getGroups()) { - ret.add(role.getName()); + Set ret = new HashSet<>(); + if(user != null) { + for (UserGroup role : user.getGroups()) { + ret.add(role.getName()); + } } + + if(LOGGER.isDebugEnabled()) { + LOGGER.debug("Groups for user " + username + ": " + ret); + } + return ret; } @Override + @Deprecated public boolean existsRole(String rolename) { - Search search = new Search(UserGroup.class); - search.addFilterEqual("name", rolename); - List groups = userGroupDAO.search(search); - - return ! groups.isEmpty(); + throw new IllegalStateException("This method is deprecated and should not be invoked"); } //========================================================================= diff --git a/src/services/core/services-impl/src/main/java/org/geoserver/geofence/services/GFUserAdminServiceImpl.java b/src/services/core/services-impl/src/main/java/org/geoserver/geofence/services/GFUserAdminServiceImpl.java index 610b63a5..c0c85846 100644 --- a/src/services/core/services-impl/src/main/java/org/geoserver/geofence/services/GFUserAdminServiceImpl.java +++ b/src/services/core/services-impl/src/main/java/org/geoserver/geofence/services/GFUserAdminServiceImpl.java @@ -1,20 +1,18 @@ -/* (c) 2014 Open Source Geospatial Foundation - all rights reserved +/* (c) 2014 - 2017 Open Source Geospatial Foundation - all rights reserved * This code is licensed under the GPL 2.0 license, available at the root * application directory. */ package org.geoserver.geofence.services; -import org.geoserver.geofence.services.GFUserAdminService; import com.googlecode.genericdao.search.Search; import org.geoserver.geofence.services.dto.ShortUser; import java.util.ArrayList; import java.util.List; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; - +import org.apache.log4j.LogManager; +import org.apache.log4j.Logger; import org.geoserver.geofence.core.dao.GFUserDAO; import org.geoserver.geofence.core.model.GFUser; diff --git a/src/services/core/services-impl/src/main/java/org/geoserver/geofence/services/InstanceAdminServiceImpl.java b/src/services/core/services-impl/src/main/java/org/geoserver/geofence/services/InstanceAdminServiceImpl.java index c230492e..520977dd 100644 --- a/src/services/core/services-impl/src/main/java/org/geoserver/geofence/services/InstanceAdminServiceImpl.java +++ b/src/services/core/services-impl/src/main/java/org/geoserver/geofence/services/InstanceAdminServiceImpl.java @@ -1,19 +1,17 @@ -/* (c) 2014 Open Source Geospatial Foundation - all rights reserved +/* (c) 2014 - 2017 Open Source Geospatial Foundation - all rights reserved * This code is licensed under the GPL 2.0 license, available at the root * application directory. */ package org.geoserver.geofence.services; -import org.geoserver.geofence.services.InstanceAdminService; import com.googlecode.genericdao.search.Search; import org.geoserver.geofence.core.model.GSInstance; import java.util.List; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; - +import org.apache.log4j.LogManager; +import org.apache.log4j.Logger; import org.geoserver.geofence.core.dao.GSInstanceDAO; import org.geoserver.geofence.services.dto.ShortInstance; @@ -57,7 +55,6 @@ public GSInstance get(long id) throws NotFoundServiceEx { throw new NotFoundServiceEx("GSInstance not found", id); } -// return new ShortInstance(instance); return instance; } @@ -90,9 +87,7 @@ public boolean delete(long id) throws NotFoundServiceEx { @Override public List getAll() { - List found = instanceDAO.findAll(); - return found; -// return convertToShortList(found); + return instanceDAO.findAll(); } @Override @@ -114,9 +109,7 @@ public List getFullList(String nameLike, Integer page, Integer entri searchCriteria.addFilterILike("name", nameLike); } - List found = instanceDAO.search(searchCriteria); - return found; -// return convertToShortList(found); + return instanceDAO.search(searchCriteria); } @Override @@ -125,7 +118,7 @@ public List getList(String nameLike, Integer page, Integer entrie } private List convertToShortList(List list) { - List swList = new ArrayList(list.size()); + List swList = new ArrayList<>(list.size()); for (GSInstance item : list) { swList.add(new ShortInstance(item)); } @@ -146,27 +139,6 @@ public long getCount(String nameLike) { // ========================================================================== -// @Override -// public Map getCustomProps(Long id) { -// return instanceDAO.getCustomProps(id); -// } -// -// @Override -// public void setCustomProps(Long id, Map props) { -// instanceDAO.setCustomProps(id, props); -// } - - // ========================================================================== - -// private List convertToShortList(List list) { -// List swList = new ArrayList(list.size()); -// for (GSInstance instance : list) { -// swList.add(new ShortInstance(instance)); -// } -// -// return swList; -// } - public void setInstanceDAO(GSInstanceDAO instanceDAO) { this.instanceDAO = instanceDAO; } diff --git a/src/services/core/services-impl/src/main/java/org/geoserver/geofence/services/RuleAdminServiceImpl.java b/src/services/core/services-impl/src/main/java/org/geoserver/geofence/services/RuleAdminServiceImpl.java index 86074da2..7b5e98b0 100644 --- a/src/services/core/services-impl/src/main/java/org/geoserver/geofence/services/RuleAdminServiceImpl.java +++ b/src/services/core/services-impl/src/main/java/org/geoserver/geofence/services/RuleAdminServiceImpl.java @@ -1,4 +1,4 @@ -/* (c) 2014, 2015 Open Source Geospatial Foundation - all rights reserved +/* (c) 2014 - 2017 Open Source Geospatial Foundation - all rights reserved * This code is licensed under the GPL 2.0 license, available at the root * application directory. */ @@ -24,8 +24,8 @@ import java.util.List; import java.util.Set; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; +import org.apache.log4j.LogManager; +import org.apache.log4j.Logger; import org.geoserver.geofence.services.exception.BadRequestServiceEx; import org.geoserver.geofence.services.exception.NotFoundServiceEx; diff --git a/src/services/core/services-impl/src/main/java/org/geoserver/geofence/services/RuleReaderServiceImpl.java b/src/services/core/services-impl/src/main/java/org/geoserver/geofence/services/RuleReaderServiceImpl.java index 3a2712a6..4ef2311d 100644 --- a/src/services/core/services-impl/src/main/java/org/geoserver/geofence/services/RuleReaderServiceImpl.java +++ b/src/services/core/services-impl/src/main/java/org/geoserver/geofence/services/RuleReaderServiceImpl.java @@ -1,4 +1,4 @@ -/* (c) 2014, 2015 Open Source Geospatial Foundation - all rights reserved +/* (c) 2014 - 2017 Open Source Geospatial Foundation - all rights reserved * This code is licensed under the GPL 2.0 license, available at the root * application directory. */ @@ -38,8 +38,9 @@ import java.util.Map.Entry; import java.util.Set; import java.util.TreeMap; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; +import org.apache.commons.lang.StringUtils; +import org.apache.log4j.LogManager; +import org.apache.log4j.Logger; import org.geoserver.geofence.core.dao.AdminRuleDAO; import org.geoserver.geofence.core.model.AdminRule; import org.geoserver.geofence.core.model.enums.AdminGrantType; @@ -89,15 +90,17 @@ public List getMatchingRules( public List getMatchingRules(RuleFilter filter) { Map> found = getRules(filter); - Map sorted = new TreeMap(); + Map sorted = new TreeMap<>(); for (List list : found.values()) { for (Rule rule : list) { - sorted.put(rule.getId(), rule); + sorted.put(rule.getPriority(), rule); } } - List plainList = new ArrayList(); + LOGGER.warn(sorted.size() + " matching rules for filter " + filter); + List plainList = new ArrayList<>(); for (Rule rule : sorted.values()) { + LOGGER.warn( " -- " + rule); plainList.add(rule); } @@ -278,7 +281,7 @@ private static Set unionAllowedStyles(Set a0, Set a1) { private AccessInfoInternal resolveRuleset(List ruleList) { - List limits = new ArrayList(); + List limits = new ArrayList<>(); AccessInfoInternal ret = null; for (Rule rule : ruleList) { @@ -326,13 +329,14 @@ private String validateUsername(TextFilter filter) { switch(filter.getType()) { case NAMEVALUE: String name = filter.getText(); - if (userResolver.existsUser(name)) - return name; + if(StringUtils.isBlank(name) ) + throw new BadRequestServiceEx("Blank user name"); + return name.trim(); case DEFAULT: case ANY: return null; default: - throw new IllegalStateException("Unknown filter type '"+filter+"'"); + throw new BadRequestServiceEx("Unknown user filter type '"+filter+"'"); } } @@ -341,13 +345,14 @@ private String validateRolename(TextFilter filter) { switch(filter.getType()) { case NAMEVALUE: String name = filter.getText(); - if (userResolver.existsRole(name)) - return name; + if(StringUtils.isBlank(name) ) + throw new BadRequestServiceEx("Blank role name"); + return name.trim(); case DEFAULT: case ANY: return null; default: - throw new IllegalStateException("Unknown filter type '"+filter+"'"); + throw new BadRequestServiceEx("Unknown role filter type '"+filter+"'"); } } @@ -483,7 +488,7 @@ protected Map> getRules(RuleFilter filter) throws BadRequestS return Collections.EMPTY_MAP; // shortcut here, in order to avoid loading the rules } - Map> ret = new HashMap>(); + Map> ret = new HashMap<>(); if(finalRoleFilter.isEmpty()) { List found = getRuleAux(filter, filter.getRole()); @@ -528,17 +533,18 @@ protected Map> getRules(RuleFilter filter) throws BadRequestS */ protected Set validateUserRoles(RuleFilter filter) throws BadRequestServiceEx { - // username can be null if - // 1) name is defined in the filter, but the user has not been found in the db - // 2) the user filter asks for ANY or DEFAULT + // username can be null if the user filter asks for ANY or DEFAULT String username = validateUsername(filter.getUser()); - // rolename can be null if - // 1) id or name are defined in the filter, but the group has not been found in the db - // 2) the group filter asks for ANY or DEFAULT + // rolename can be null if the group filter asks for ANY or DEFAULT String rolename = validateRolename(filter.getRole()); - Set finalRoleFilter = new HashSet(); + // filtering by both user and role is pointless + if(username != null && rolename != null) { + throw new BadRequestServiceEx("You can filter either by user or role"); + } + + Set finalRoleFilter = new HashSet<>(); // If both user and group are defined in filter // if user doensn't belong to group, no rule is returned @@ -664,7 +670,7 @@ public AuthUser authorize(String username, String password) { // ========================================================================== private List convertToShortList(List list) { - List shortList = new ArrayList(list.size()); + List shortList = new ArrayList<>(list.size()); for (Rule rule : list) { shortList.add(new ShortRule(rule)); } diff --git a/src/services/core/services-impl/src/main/java/org/geoserver/geofence/services/UserAdminServiceImpl.java b/src/services/core/services-impl/src/main/java/org/geoserver/geofence/services/UserAdminServiceImpl.java index 2b74f2e8..dc2cf9f9 100644 --- a/src/services/core/services-impl/src/main/java/org/geoserver/geofence/services/UserAdminServiceImpl.java +++ b/src/services/core/services-impl/src/main/java/org/geoserver/geofence/services/UserAdminServiceImpl.java @@ -1,27 +1,23 @@ -/* (c) 2014 Open Source Geospatial Foundation - all rights reserved +/* (c) 2014 - 2017 Open Source Geospatial Foundation - all rights reserved * This code is licensed under the GPL 2.0 license, available at the root * application directory. */ package org.geoserver.geofence.services; -import org.geoserver.geofence.services.UserAdminService; import com.googlecode.genericdao.search.Search; import org.geoserver.geofence.core.dao.GSUserDAO; import org.geoserver.geofence.core.model.GSUser; -import org.geoserver.geofence.core.model.UserGroup; import org.geoserver.geofence.services.dto.ShortUser; import java.util.ArrayList; import java.util.List; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; - +import org.apache.log4j.LogManager; +import org.apache.log4j.Logger; import org.geoserver.geofence.services.exception.BadRequestServiceEx; import org.geoserver.geofence.services.exception.NotFoundServiceEx; -import java.util.Set; /** * @@ -78,48 +74,13 @@ else if(users.size() > 1) @Override - public GSUser getFull(long id) throws NotFoundServiceEx { + public GSUser getFull(String name) throws NotFoundServiceEx { - GSUser user = userDAO.getFull(id); + GSUser user = userDAO.getFull(name); if(user == null) - throw new NotFoundServiceEx("User not found", id); + throw new NotFoundServiceEx("User not found", name); return user; } -// Search search = new Search(GSUser.class); -// search.addFetch("userGroups"); -// search.addFilterEqual("id", id); -// List users = userDAO.search(search); -// switch(users.size()) { -// case 0: -// throw new NotFoundServiceEx("User not found", id); -// case 1: -// return users.get(0); -// default: -// if(users.size() == users.get(0).getGroups().size()) { // normal hibernate behaviour -// if(LOGGER.isDebugEnabled()) { // perform some more consistency tests only when debugging -// for (GSUser user : users) { -// if(user.getId() != users.get(0).getId() || -// user.getGroups().size() != users.get(0).getGroups().size()) { -// LOGGER.error("Inconsistent userlist " + user); -// } -// } -// } -// -// return users.get(0); -// } else { -// LOGGER.error("Too many users with id " + id); -// for (GSUser user : users) { -// LOGGER.error(" " + user + " grp:"+user.getGroups().size()); -// } -// throw new IllegalStateException("Found more than one user (id:"+id+")"); -// } -// } -// } - - @Override - public Set getUserGroups(long id) { - return userDAO.getGroups(id); - } @Override public boolean delete(long id) throws NotFoundServiceEx { @@ -179,7 +140,7 @@ public long getCount(String nameLike) { // ========================================================================== private List convertToShortList(List list) { - List swList = new ArrayList(list.size()); + List swList = new ArrayList<>(list.size()); for (GSUser user : list) { swList.add(new ShortUser(user)); } diff --git a/src/services/core/services-impl/src/main/java/org/geoserver/geofence/services/UserGroupAdminServiceImpl.java b/src/services/core/services-impl/src/main/java/org/geoserver/geofence/services/UserGroupAdminServiceImpl.java index 768c84bd..047b537c 100644 --- a/src/services/core/services-impl/src/main/java/org/geoserver/geofence/services/UserGroupAdminServiceImpl.java +++ b/src/services/core/services-impl/src/main/java/org/geoserver/geofence/services/UserGroupAdminServiceImpl.java @@ -1,21 +1,18 @@ -/* (c) 2014 Open Source Geospatial Foundation - all rights reserved +/* (c) 2014 - 2017 Open Source Geospatial Foundation - all rights reserved * This code is licensed under the GPL 2.0 license, available at the root * application directory. */ package org.geoserver.geofence.services; -import org.geoserver.geofence.services.UserGroupAdminService; import com.googlecode.genericdao.search.Search; import org.geoserver.geofence.core.dao.UserGroupDAO; -import org.geoserver.geofence.core.model.GSUser; import org.geoserver.geofence.core.model.UserGroup; import java.util.List; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; - +import org.apache.log4j.LogManager; +import org.apache.log4j.Logger; import org.geoserver.geofence.services.dto.ShortGroup; import org.geoserver.geofence.services.exception.BadRequestServiceEx; @@ -39,7 +36,7 @@ public long insert(ShortGroup group) { if(group.isEnabled() !=null) p.setEnabled(group.isEnabled()); - + userGroupDAO.persist(p); return p.getId(); } @@ -133,18 +130,8 @@ protected Search buildCriteria(Integer page, Integer entries, String nameLike) t } // ========================================================================== -// @Override -// public Map getCustomProps(Long id) { -// return userGroupDAO.getCustomProps(id); -// } -// -// @Override -// public void setCustomProps(Long id, Map props) { -// userGroupDAO.setCustomProps(id, props); -// } - // ========================================================================== private List convertToShortList(List list) { - List swList = new ArrayList(list.size()); + List swList = new ArrayList<>(list.size()); for (UserGroup group : list) { swList.add(new ShortGroup(group)); } diff --git a/src/services/core/services-impl/src/main/java/org/geoserver/geofence/services/util/FilterUtils.java b/src/services/core/services-impl/src/main/java/org/geoserver/geofence/services/util/FilterUtils.java index b948f0f6..a88fe3ed 100644 --- a/src/services/core/services-impl/src/main/java/org/geoserver/geofence/services/util/FilterUtils.java +++ b/src/services/core/services-impl/src/main/java/org/geoserver/geofence/services/util/FilterUtils.java @@ -1,4 +1,4 @@ -/* (c) 2015 Open Source Geospatial Foundation - all rights reserved +/* (c) 2015 - 2017 Open Source Geospatial Foundation - all rights reserved * This code is licensed under the GPL 2.0 license, available at the root * application directory. */ @@ -10,8 +10,8 @@ import java.util.ArrayList; import java.util.Collections; import java.util.List; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; +import org.apache.log4j.LogManager; +import org.apache.log4j.Logger; import org.geoserver.geofence.core.model.IPRangeProvider; import org.geoserver.geofence.services.dto.RuleFilter; import org.geoserver.geofence.services.exception.BadRequestServiceEx; diff --git a/src/services/core/services-impl/src/test/java/org/geoserver/geofence/services/RuleReaderCatalogModeTest.java b/src/services/core/services-impl/src/test/java/org/geoserver/geofence/services/RuleReaderCatalogModeTest.java index 64470417..34deb55d 100644 --- a/src/services/core/services-impl/src/test/java/org/geoserver/geofence/services/RuleReaderCatalogModeTest.java +++ b/src/services/core/services-impl/src/test/java/org/geoserver/geofence/services/RuleReaderCatalogModeTest.java @@ -1,4 +1,4 @@ -/* (c) 2014 Open Source Geospatial Foundation - all rights reserved +/* (c) 2014 - 2017 Open Source Geospatial Foundation - all rights reserved * This code is licensed under the GPL 2.0 license, available at the root * application directory. */ @@ -49,7 +49,7 @@ public void testCatalogModeBothNull() throws NotFoundServiceEx { insertRule(new Rule(20, "u1", null, null,null, null, null, null, "l1", GrantType.LIMIT), null); - insertRule(new Rule(20, null, "g1", null,null, null, null, null, "l1", GrantType.ALLOW), null); + insertRule(new Rule(21, null, "g1", null,null, null, null, null, "l1", GrantType.ALLOW), null); LOGGER.info("SETUP ENDED, STARTING TESTS========================================"); @@ -77,7 +77,7 @@ public void testCatalogModeOneNull() throws NotFoundServiceEx { insertRule(new Rule(20, "u1", null, null,null, null, null, null, "l1", GrantType.LIMIT), null); - insertRule(new Rule(20, null, "g1", null,null, null, null, null, "l1", GrantType.ALLOW), CatalogMode.MIXED); + insertRule(new Rule(21, null, "g1", null,null, null, null, null, "l1", GrantType.ALLOW), CatalogMode.MIXED); LOGGER.info("SETUP ENDED, STARTING TESTS========================================"); @@ -105,7 +105,7 @@ public void testCatalogModeNoNull() throws NotFoundServiceEx { insertRule(new Rule(20, "u1", null, null, null, null, null, null, "l1", GrantType.LIMIT), CatalogMode.HIDE); - insertRule(new Rule(20, null, "g1", null, null, null, null, null, "l1", GrantType.ALLOW), CatalogMode.MIXED); + insertRule(new Rule(21, null, "g1", null, null, null, null, null, "l1", GrantType.ALLOW), CatalogMode.MIXED); LOGGER.info("SETUP ENDED, STARTING TESTS========================================"); @@ -132,7 +132,7 @@ public void testCatalogModeTwoGroups() throws NotFoundServiceEx { insertRule(new Rule(20, null, "g2", null, null, null, null, null, "l1", GrantType.ALLOW), CatalogMode.HIDE); - insertRule(new Rule(20, null, "g1", null, null, null, null, null, "l1", GrantType.ALLOW), CatalogMode.MIXED); + insertRule(new Rule(21, null, "g1", null, null, null, null, null, "l1", GrantType.ALLOW), CatalogMode.MIXED); LOGGER.info("SETUP ENDED, STARTING TESTS========================================"); diff --git a/src/services/core/services-impl/src/test/java/org/geoserver/geofence/services/RuleReaderServiceImplTest.java b/src/services/core/services-impl/src/test/java/org/geoserver/geofence/services/RuleReaderServiceImplTest.java index 6d1605e0..5d3b277f 100644 --- a/src/services/core/services-impl/src/test/java/org/geoserver/geofence/services/RuleReaderServiceImplTest.java +++ b/src/services/core/services-impl/src/test/java/org/geoserver/geofence/services/RuleReaderServiceImplTest.java @@ -1,4 +1,4 @@ -/* (c) 2014,2015 Open Source Geospatial Foundation - all rights reserved +/* (c) 2014 - 2017 Open Source Geospatial Foundation - all rights reserved * This code is licensed under the GPL 2.0 license, available at the root * application directory. */ @@ -58,8 +58,8 @@ public void testGetRulesForUsersAndGroup() { filter = new RuleFilter(RuleFilter.SpecialFilterType.ANY); assertEquals(0, ruleAdminService.count(filter)); - UserGroup g1 = createRole("p1"); - UserGroup g2 = createRole("p2"); + UserGroup p1 = createRole("p1"); + UserGroup p2 = createRole("p2"); String u1 = "TestUser1"; @@ -68,11 +68,11 @@ public void testGetRulesForUsersAndGroup() { GSUser user1 = new GSUser(); user1.setName(u1); - user1.getGroups().add(g1); + user1.getGroups().add(p1); GSUser user2 = new GSUser(); user2.setName(u2); - user2.getGroups().add(g2); + user2.getGroups().add(p2); UserGroup g3a = createRole("g3a"); UserGroup g3b = createRole("g3b"); @@ -92,18 +92,17 @@ public void testGetRulesForUsersAndGroup() { ruleAdminService.insert(new Rule(50, null,"g3a", null,null, null, null, null, null, GrantType.ALLOW)); ruleAdminService.insert(new Rule(60, null,"g3b", null,null, null, null, null, null, GrantType.ALLOW)); - assertEquals(3, ruleReaderService.getMatchingRules(u1,"p1", "Z","*", "*", "*","*","*").size()); - assertEquals(0, ruleReaderService.getMatchingRules(u1,"Z", "Z","*", null, null,null,null).size()); - assertEquals(1, ruleReaderService.getMatchingRules(u1,"*", "Z","*", null, null,null,null).size()); - assertEquals(1, ruleReaderService.getMatchingRules(u1,"*", "*","*", null, null,null,null).size()); - assertEquals(1, ruleReaderService.getMatchingRules(u2,"p2", "", "*", "*", "*","*","*").size()); - assertEquals(2, ruleReaderService.getMatchingRules(u1,"p1", "", "*", "s1", "*","*","*").size()); - assertEquals(2, ruleReaderService.getMatchingRules(u3,"*", "","*", "s1", "*","*","*").size()); -// assertEquals(1, ruleReaderService.getMatchingRules(user1.getName(),"","", null, null,null,null).size()); -// assertEquals(3, ruleReaderService.getMatchingRules(user1.getName(),g1.getName(),"", "*", "*","*","*").size()); -// assertEquals(1, ruleReaderService.getMatchingRules(user2.getName(),g2.getName(),"", "*", "*","*","*").size()); -// assertEquals(2, ruleReaderService.getMatchingRules(user1.getName(),g1.getName(),"", "s1", "*","*","*").size()); -// assertEquals(1, ruleReaderService.getMatchingRules(user1.getName(),"","", "ZZ", "*","*","*").size()); + assertEquals(3, ruleReaderService.getMatchingRules(u1, "*", "Z","*", "*", "*","*","*").size()); + assertEquals(3, ruleReaderService.getMatchingRules("*", "p1", "Z","*", "*", "*","*","*").size()); + assertEquals(1, ruleReaderService.getMatchingRules(u1, "*", "Z","*", null, null,null,null).size()); + assertEquals(0, ruleReaderService.getMatchingRules("*", "Z", "Z","*", null, null,null,null).size()); + assertEquals(1, ruleReaderService.getMatchingRules(u1, "*", "Z","*", null, null,null,null).size()); + assertEquals(1, ruleReaderService.getMatchingRules(u1, "*", "Z","*", null, null,null,null).size()); + assertEquals(1, ruleReaderService.getMatchingRules(u2, "*", "Z","*", "*", "*","*","*").size()); + assertEquals(1, ruleReaderService.getMatchingRules("*", "p2", "Z","*", "*", "*","*","*").size()); + assertEquals(2, ruleReaderService.getMatchingRules(u1, "*", "Z","*", "s1", "*","*","*").size()); + assertEquals(2, ruleReaderService.getMatchingRules("*", "p1", "Z","*", "s1", "*","*","*").size()); + assertEquals(2, ruleReaderService.getMatchingRules(u3, "*", "Z","*", "s1", "*","*","*").size()); } private static RuleFilter createFilter(String userName, String groupName, String service) { @@ -139,11 +138,17 @@ public void testGetRulesForGroupOnly() { ruleAdminService.insert(r3); ruleAdminService.insert(r4); - assertEquals(0, ruleReaderService.getMatchingRules("","","", "*", null, null,null,null).size()); - assertEquals(3, ruleReaderService.getMatchingRules("",g1.getName(),"","*", "*", "*","*","*").size()); - assertEquals(1, ruleReaderService.getMatchingRules("",g2.getName(),"","*", "*", "*","*","*").size()); - assertEquals(2, ruleReaderService.getMatchingRules("",g1.getName(),"","*", "s1", "*","*","*").size()); - assertEquals(0, ruleReaderService.getMatchingRules("","","", "*", "ZZ", "*","*","*").size()); + assertEquals(4, ruleReaderService.getMatchingRules("*","*","*", "*", "*", "*","*","*").size()); + assertEquals(3, ruleReaderService.getMatchingRules("*","*","*", "*", "s1", "*","*","*").size()); + assertEquals(1, ruleReaderService.getMatchingRules("*","*","*", "*", "ZZ", "*","*","*").size()); + + assertEquals(3, ruleReaderService.getMatchingRules("*","p1","*", "*", "*", "*","*","*").size()); + assertEquals(2, ruleReaderService.getMatchingRules("*","p1","*", "*", "s1", "*","*","*").size()); + assertEquals(1, ruleReaderService.getMatchingRules("*","p1","*", "*", "ZZ", "*","*","*").size()); + + assertEquals(1, ruleReaderService.getMatchingRules("*","p2","*", "*", "*", "*","*","*").size()); + assertEquals(1, ruleReaderService.getMatchingRules("*","p2","*", "*", "s1", "*","*","*").size()); + assertEquals(0, ruleReaderService.getMatchingRules("*","p2","*", "*", "ZZ", "*","*","*").size()); filter = createFilter(null, g1.getName(), null); assertEquals(3, ruleReaderService.getMatchingRules(filter).size()); @@ -156,8 +161,7 @@ public void testGetRulesForGroupOnly() { public void testGetInfo() { assertEquals(0, ruleAdminService.count(new RuleFilter(RuleFilter.SpecialFilterType.ANY))); - int pri = -1; - List rules = new ArrayList(); + List rules = new ArrayList<>(); rules.add(new Rule(100+rules.size(), null, null, null,null, "WCS", null, null, null, GrantType.ALLOW)); rules.add(new Rule(100+rules.size(), null, null, null,null, "s1", "r2", "w2", "l2", GrantType.ALLOW)); @@ -165,45 +169,52 @@ public void testGetInfo() { rules.add(new Rule(100+rules.size(), null, null, null,null, null, null, null, null, GrantType.DENY)); for (Rule rule : rules) { - if(rule != null) - ruleAdminService.insert(rule); + ruleAdminService.insert(rule); } assertEquals(4, ruleAdminService.count(new RuleFilter(RuleFilter.SpecialFilterType.ANY))); + RuleFilter baseFilter = new RuleFilter(RuleFilter.SpecialFilterType.ANY); + baseFilter.setUser("u0"); + baseFilter.setRole("p0"); + baseFilter.setInstance("i0"); + baseFilter.setService("WCS"); + baseFilter.setRequest(RuleFilter.SpecialFilterType.ANY); + baseFilter.setWorkspace("W0"); + baseFilter.setLayer("l0"); + + AccessInfo accessInfo; { - RuleFilter ruleFilter = new RuleFilter(RuleFilter.SpecialFilterType.ANY); - ruleFilter.setUser("u0"); - ruleFilter.setRole("p0"); - ruleFilter.setInstance("i0"); - ruleFilter.setService("WCS"); - ruleFilter.setRequest(RuleFilter.SpecialFilterType.ANY); - ruleFilter.setWorkspace("W0"); - ruleFilter.setLayer("l0"); - - assertEquals(4, ruleReaderService.getMatchingRules(new RuleFilter(RuleFilter.SpecialFilterType.ANY)).size()); - List matchingRules = ruleReaderService.getMatchingRules(ruleFilter); - LOGGER.info("Matching rules: " + matchingRules); - assertEquals(2, matchingRules.size()); - accessInfo = ruleReaderService.getAccessInfo(ruleFilter); - assertEquals(GrantType.ALLOW, accessInfo.getGrant()); - assertNull(accessInfo.getAreaWkt()); + RuleFilter ruleFilter = new RuleFilter(baseFilter); + ruleFilter.setUser(SpecialFilterType.ANY); + + assertEquals(2, ruleReaderService.getMatchingRules(ruleFilter).size()); + assertEquals(GrantType.ALLOW, ruleReaderService.getAccessInfo(ruleFilter).getGrant()); } { - RuleFilter ruleFilter = new RuleFilter(RuleFilter.SpecialFilterType.ANY); - ruleFilter.setUser("u0"); - ruleFilter.setRole("p0"); - ruleFilter.setInstance("i0"); + RuleFilter ruleFilter = new RuleFilter(baseFilter); + ruleFilter.setRole(SpecialFilterType.ANY); + + assertEquals(2, ruleReaderService.getMatchingRules(ruleFilter).size()); + assertEquals(GrantType.ALLOW, ruleReaderService.getAccessInfo(ruleFilter).getGrant()); + } + { + RuleFilter ruleFilter = new RuleFilter(baseFilter); + ruleFilter.setUser(SpecialFilterType.ANY); ruleFilter.setService("UNMATCH"); - ruleFilter.setRequest(RuleFilter.SpecialFilterType.ANY); - ruleFilter.setWorkspace("W0"); - ruleFilter.setLayer("l0"); assertEquals(1, ruleReaderService.getMatchingRules(ruleFilter).size()); - accessInfo = ruleReaderService.getAccessInfo(ruleFilter); - assertEquals(GrantType.DENY, accessInfo.getGrant()); + assertEquals(GrantType.DENY, ruleReaderService.getAccessInfo(ruleFilter).getGrant()); + } + { + RuleFilter ruleFilter = new RuleFilter(baseFilter); + ruleFilter.setRole(SpecialFilterType.ANY); + ruleFilter.setService("UNMATCH"); + + assertEquals(1, ruleReaderService.getMatchingRules(ruleFilter).size()); + assertEquals(GrantType.DENY, ruleReaderService.getAccessInfo(ruleFilter).getGrant()); } } @@ -211,7 +222,7 @@ public void testGetInfo() { public void testResolveLazy() { assertEquals(0, ruleAdminService.count(new RuleFilter(RuleFilter.SpecialFilterType.ANY))); - List rules = new ArrayList(); + List rules = new ArrayList<>(); rules.add(new Rule(100+rules.size(), null, null, null,null, "WCS", null, null, null, GrantType.ALLOW)); rules.add(new Rule(100+rules.size(), null, null, null,null, "s1", "r2", "w2", "l2", GrantType.ALLOW)); @@ -248,25 +259,19 @@ public void testResolveLazy() { public void testNoDefault() { assertEquals(0, ruleAdminService.count(new RuleFilter(SpecialFilterType.ANY))); - int pri = -1; - Rule rules[] = new Rule[100]; + ruleAdminService.insert(new Rule(0, null, null, null,null, "WCS", null, null, null, GrantType.ALLOW)); - pri++; rules[pri] = new Rule(pri, null, null, null,null, "WCS", null, null, null, GrantType.ALLOW); + assertEquals(1, ruleReaderService.getMatchingRules("u0","*","i0",null, "WCS", null,"W0","l0").size()); + assertEquals(GrantType.ALLOW, ruleReaderService.getAccessInfo("u0","*","i0",null, "WCS", null,"W0","l0").getGrant()); - for (Rule rule : rules) { - if(rule != null) - ruleAdminService.insert(rule); - } + assertEquals(1, ruleReaderService.getMatchingRules("*","p0","i0",null, "WCS", null,"W0","l0").size()); + assertEquals(GrantType.ALLOW, ruleReaderService.getAccessInfo("*","p0","i0",null, "WCS", null,"W0","l0").getGrant()); - AccessInfo accessInfo; + assertEquals(0, ruleReaderService.getMatchingRules("u0","*","i0",null, "UNMATCH", null,"W0","l0").size()); + assertEquals(GrantType.DENY, ruleReaderService.getAccessInfo("u0","*","i0",null, "UNMATCH", null,"W0","l0").getGrant()); - assertEquals(1, ruleReaderService.getMatchingRules("u0","p0","i0",null, "WCS", null,"W0","l0").size()); - accessInfo = ruleReaderService.getAccessInfo("u0","p0","i0",null, "WCS", null,"W0","l0"); - assertEquals(GrantType.ALLOW, accessInfo.getGrant()); - - assertEquals(0, ruleReaderService.getMatchingRules("u0","p0","i0",null, "UNMATCH", null,"W0","l0").size()); - accessInfo = ruleReaderService.getAccessInfo("u0","p0","i0",null, "UNMATCH", null,"W0","l0"); - assertEquals(GrantType.DENY, accessInfo.getGrant()); + assertEquals(0, ruleReaderService.getMatchingRules("*","p0","i0",null, "UNMATCH", null,"W0","l0").size()); + assertEquals(GrantType.DENY, ruleReaderService.getAccessInfo("*","p0","i0",null, "UNMATCH", null,"W0","l0").getGrant()); } @Test @@ -279,7 +284,7 @@ public void testGroups() { GSUser u1 = createUser("u1", g1); GSUser u2 = createUser("u2", g2); - List rules = new ArrayList(); + List rules = new ArrayList<>(); rules.add(new Rule(rules.size()+10, null, "p1", null, null, "s1", "r1", "w1", "l1", GrantType.ALLOW)); rules.add(new Rule(rules.size()+10, null, "p1", null, null, null, null, null, null, GrantType.DENY)); @@ -310,7 +315,6 @@ public void testGroups() { RuleFilter filter; filter = new RuleFilter(RuleFilter.SpecialFilterType.ANY); filter.setUser(u2.getName()); - filter.setRole(g1.getName()); assertEquals(0, ruleReaderService.getMatchingRules(filter).size()); assertEquals(GrantType.DENY, ruleReaderService.getAccessInfo(filter).getGrant()); @@ -403,53 +407,6 @@ protected MultiPolygon buildMultiPolygon(String multip) { } } -// @Test -// public void testArea() throws NotFoundServiceEx, ParseException { -// assertEquals(0, ruleAdminService.getCountAll()); -// -// final String MULTIPOLYGONWKT0 = "MULTIPOLYGON(((10 0, 0 -10, -10 0, 0 10, 10 0)))"; -// final String MULTIPOLYGONWKT1 = "MULTIPOLYGON(((6 6, 6 -6, -6 -6 , -6 6, 6 6)))"; -// -// UserGroup g1 = createUserGroup("p1"); -// GSUser u1 = createGFUser("u1", g1); -// u1.setAllowedArea(buildMultiPolygon(MULTIPOLYGONWKT0)); -// userAdminService.update(u1); -// -// Rule r0 = new Rule(10, u1, g1, null, null, null, null, null, GrantType.LIMIT); -// Rule r1 = new Rule(20, null, g1, null, null, null, null, null, GrantType.ALLOW); -// -// -// ruleAdminService.insert(r0); -// ruleAdminService.insert(r1); -// -// RuleLimits limits = new RuleLimits(); -// limits.setAllowedArea(buildMultiPolygon(MULTIPOLYGONWKT1)); -// ruleAdminService.setLimits(r0.getId(), limits); -// -// LOGGER.info("SETUP ENDED, STARTING TESTS"); -// -// assertEquals(2, ruleAdminService.getCountAll()); -// -// //=== -// -// RuleFilter filterU1; -// filterU1 = new RuleFilter(RuleFilter.SpecialFilterType.ANY); -// filterU1.setUser(u1.getId()); -// -// -// assertEquals(2, ruleReaderService.getMatchingRules(filterU1).size()); -// -// AccessInfo accessInfo = ruleReaderService.getAccessInfo(filterU1); -// assertEquals(GrantType.ALLOW, accessInfo.getGrant()); -//// assertNotNull(accessInfo.getArea()); -//// assertEquals(9, accessInfo.getArea().getNumPoints()); -// -// assertNotNull(accessInfo.getAreaWkt()); -// GeometryAdapter ga = new GeometryAdapter(); -// Geometry area = ga.unmarshal(accessInfo.getAreaWkt()); -// assertEquals(9, area.getNumPoints()); -// } - @Test public void testAttrib() throws NotFoundServiceEx { assertEquals(0, ruleAdminService.getCountAll()); @@ -460,14 +417,15 @@ public void testAttrib() throws NotFoundServiceEx { UserGroup g3 = createRole("g3"); UserGroup g4 = createRole("g4"); - GSUser u1 = createUser("u1", g1); - GSUser u2 = createUser("u2", g2); - GSUser u3 = createUser("u3", g1, g2); - GSUser u4 = createUser("u4", g1, g3); - GSUser u5 = createUser("u5", g1, g4); + createUser("u1", g1); + createUser("u2", g2); + createUser("u12", g1, g2); + createUser("u13", g1, g3); + createUser("u14", g1, g4); + int pri = 0; { - Rule r1 = new Rule(20, null, "g1", null,null, null, null, null, "l1", GrantType.ALLOW); + Rule r1 = new Rule(pri++, null, "g1", null,null, null, null, null, "l1", GrantType.ALLOW); ruleAdminService.insert(r1); LayerDetails d1 = new LayerDetails(); @@ -480,7 +438,7 @@ public void testAttrib() throws NotFoundServiceEx { ruleAdminService.setDetails(r1.getId(), d1); } { - Rule r1 = new Rule(20, null, "g2", null,null, null, null, null, "l1", GrantType.ALLOW); + Rule r1 = new Rule(pri++, null, "g2", null,null, null, null, null, "l1", GrantType.ALLOW); ruleAdminService.insert(r1); LayerDetails d1 = new LayerDetails(); @@ -493,7 +451,7 @@ public void testAttrib() throws NotFoundServiceEx { ruleAdminService.setDetails(r1.getId(), d1); } { - Rule r1 = new Rule(20, null, "g3", null,null, null, null, null, "l1", GrantType.ALLOW); + Rule r1 = new Rule(pri++, null, "g3", null,null, null, null, null, "l1", GrantType.ALLOW); ruleAdminService.insert(r1); LayerDetails d1 = new LayerDetails(); @@ -501,7 +459,7 @@ public void testAttrib() throws NotFoundServiceEx { ruleAdminService.setDetails(r1.getId(), d1); } { - Rule r1 = new Rule(20, null, "g4", null,null, null, null, null, "l1", GrantType.DENY); + Rule r1 = new Rule(pri++, null, "g4", null,null, null, null, null, "l1", GrantType.DENY); ruleAdminService.insert(r1); } } @@ -555,7 +513,7 @@ public void testAttrib() throws NotFoundServiceEx { { RuleFilter filter; filter = new RuleFilter(RuleFilter.SpecialFilterType.ANY); - filter.setUser("u3"); + filter.setUser("u12"); filter.setLayer("l1"); assertEquals(2, ruleReaderService.getMatchingRules(filter).size()); @@ -581,7 +539,7 @@ public void testAttrib() throws NotFoundServiceEx { { RuleFilter filter; filter = new RuleFilter(RuleFilter.SpecialFilterType.ANY); - filter.setUser("u4"); + filter.setUser("u13"); filter.setLayer("l1"); assertEquals(2, ruleReaderService.getMatchingRules(filter).size()); @@ -681,18 +639,18 @@ public void testIPAddress() { // test without address filtering - assertEquals(0, ruleReaderService.getMatchingRules("","","", "*", null, null,null,null).size()); - assertEquals(3, ruleReaderService.getMatchingRules("",g1.getName(),"","*", "*", "*","*","*").size()); - assertEquals(1, ruleReaderService.getMatchingRules("",g2.getName(),"","*", "*", "*","*","*").size()); - assertEquals(2, ruleReaderService.getMatchingRules("",g1.getName(),"","*", "s1", "*","*","*").size()); - assertEquals(0, ruleReaderService.getMatchingRules("","","", "*", "ZZ", "*","*","*").size()); + assertEquals(4, ruleReaderService.getMatchingRules("*","*", "*", "*", "*", "*","*","*").size()); + assertEquals(3, ruleReaderService.getMatchingRules("*","g1","*", "*", "*", "*","*","*").size()); + assertEquals(1, ruleReaderService.getMatchingRules("*","g2","*", "*", "*", "*","*","*").size()); + assertEquals(2, ruleReaderService.getMatchingRules("*","g1","*", "*", "s1", "*","*","*").size()); + assertEquals(1, ruleReaderService.getMatchingRules("*","*", "*", "*", "ZZ", "*","*","*").size()); // test with address filtering - assertEquals(3, ruleReaderService.getMatchingRules("*","*","*","10.10.100.4", "*", "*","*","*").size()); - assertEquals(2, ruleReaderService.getMatchingRules("*","g1","*","10.10.100.4", "*", "*","*","*").size()); - assertEquals(1, ruleReaderService.getMatchingRules("*","*","*","10.10.1.4", "*", "*","*","*").size()); - assertEquals(2, ruleReaderService.getMatchingRules("*","*","*","192.168.1.1", "*", "*","*","*").size()); - assertEquals(1, ruleReaderService.getMatchingRules("*","*","*",null, "*", "*","*","*").size()); + assertEquals(3, ruleReaderService.getMatchingRules("*","*", "*", "10.10.100.4", "*", "*","*","*").size()); + assertEquals(2, ruleReaderService.getMatchingRules("*","g1","*", "10.10.100.4", "*", "*","*","*").size()); + assertEquals(1, ruleReaderService.getMatchingRules("*","*", "*", "10.10.1.4", "*", "*","*","*").size()); + assertEquals(2, ruleReaderService.getMatchingRules("*","*", "*", "192.168.1.1", "*", "*","*","*").size()); + assertEquals(1, ruleReaderService.getMatchingRules("*","*", "*", null, "*", "*","*","*").size()); assertEquals(0, ruleReaderService.getMatchingRules("*","*","*","BAD", "*", "*","*","*").size()); } diff --git a/src/services/core/services-impl/src/test/java/org/geoserver/geofence/services/ServiceTestBase.java b/src/services/core/services-impl/src/test/java/org/geoserver/geofence/services/ServiceTestBase.java index 96e9d17a..75456955 100644 --- a/src/services/core/services-impl/src/test/java/org/geoserver/geofence/services/ServiceTestBase.java +++ b/src/services/core/services-impl/src/test/java/org/geoserver/geofence/services/ServiceTestBase.java @@ -1,4 +1,4 @@ -/* (c) 2014, 2015 Open Source Geospatial Foundation - all rights reserved +/* (c) 2014 - 2017 Open Source Geospatial Foundation - all rights reserved * This code is licensed under the GPL 2.0 license, available at the root * application directory. */ @@ -19,8 +19,8 @@ import java.util.Arrays; import java.util.List; import junit.framework.TestCase; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; +import org.apache.log4j.LogManager; +import org.apache.log4j.Logger; import org.geoserver.geofence.services.dto.ShortAdminRule; import org.springframework.context.support.ClassPathXmlApplicationContext; diff --git a/src/services/core/services-impl/src/test/java/org/geoserver/geofence/services/UserAdminServiceImplTest.java b/src/services/core/services-impl/src/test/java/org/geoserver/geofence/services/UserAdminServiceImplTest.java index 21349469..2bc10f2b 100644 --- a/src/services/core/services-impl/src/test/java/org/geoserver/geofence/services/UserAdminServiceImplTest.java +++ b/src/services/core/services-impl/src/test/java/org/geoserver/geofence/services/UserAdminServiceImplTest.java @@ -1,4 +1,4 @@ -/* (c) 2014 Open Source Geospatial Foundation - all rights reserved +/* (c) 2014 - 2017 Open Source Geospatial Foundation - all rights reserved * This code is licensed under the GPL 2.0 license, available at the root * application directory. */ @@ -49,7 +49,7 @@ public void testInsertDeleteUpdateUser() throws NotFoundServiceEx { userAdminService.insert(user); { - GSUser loaded = userAdminService.getFull(user.getId()); + GSUser loaded = userAdminService.getFull(user.getName()); assertNotNull(loaded); assertEquals(2, loaded.getGroups().size()); @@ -63,7 +63,7 @@ public void testInsertDeleteUpdateUser() throws NotFoundServiceEx { } { - GSUser loaded = userAdminService.getFull(user.getId()); + GSUser loaded = userAdminService.getFull(user.getName()); assertNotNull(loaded); assertEquals(3, loaded.getGroups().size()); @@ -77,7 +77,7 @@ public void testInsertDeleteUpdateUser() throws NotFoundServiceEx { } { - GSUser loaded = userAdminService.getFull(user.getId()); + GSUser loaded = userAdminService.getFull(user.getName()); assertNotNull(loaded); assertEquals(2, loaded.getGroups().size()); @@ -116,7 +116,7 @@ public void testUpdateUser() throws Exception { final String NEWNAME = "NEWNAME"; { - GSUser loaded = userAdminService.getFull(user.getId()); + GSUser loaded = userAdminService.getFull(user.getName()); assertNotNull(loaded); assertEquals("u1", loaded.getName()); @@ -126,24 +126,14 @@ public void testUpdateUser() throws Exception { loaded.getGroups().add(ug2); loaded.setName(NEWNAME); -// WKTReader wktReader = new WKTReader(); -// String allowedArea = "MULTIPOLYGON (((414699.55 130160.43, 414701.83 130149.9, 414729.2 130155.7, 414729.2 130155.7, 414733.25 130149.8, 414735.1 130140.9, 414743.75 130142.7, 414740.6 130158.15, 414742.15 130158.5, 414739.65 130169.25, 414728.05 130166.65, 414727.77 130167.93, 414724.52 130167.19, 414717.65 130165.63, 414717.85 130164.45, 414699.55 130160.43)))"; -// MultiPolygon the_geom = (MultiPolygon) wktReader.read(allowedArea); -// the_geom.setSRID(4326); -// loaded.setAllowedArea(the_geom); - userAdminService.update(loaded); } { - GSUser loaded = userAdminService.getFull(user.getId()); + GSUser loaded = userAdminService.getFull(NEWNAME); assertNotNull(loaded); - assertEquals(NEWNAME, loaded.getName()); + assertEquals(user.getId(), loaded.getId()); assertEquals(2, loaded.getGroups().size()); -// assertEquals("p2", loaded.getGroups().getName()); - -// assertNotNull(loaded.getAllowedArea()); -// assertEquals(4326, loaded.getAllowedArea().getSRID()); } } @@ -154,15 +144,10 @@ public void testUpdateUserGroups() throws Exception { UserGroup ug2 = createRole("g2"); UserGroup ug3 = createRole("g3"); + Long id = createUser("u1", ug1).getId(); - Long id; { - id = createUser("u1", ug1).getId(); - } - - - { - GSUser loaded = userAdminService.getFull(id); + GSUser loaded = userAdminService.getFull("u1"); assertNotNull(loaded); assertEquals("u1", loaded.getName()); @@ -174,7 +159,7 @@ public void testUpdateUserGroups() throws Exception { userAdminService.update(loaded); } { - GSUser loaded = userAdminService.getFull(id); + GSUser loaded = userAdminService.getFull("u1"); assertNotNull(loaded); assertEquals(2, loaded.getGroups().size()); @@ -185,7 +170,7 @@ public void testUpdateUserGroups() throws Exception { userAdminService.update(loaded); } { - GSUser loaded = userAdminService.getFull(id); + GSUser loaded = userAdminService.getFull("u1"); assertNotNull(loaded); assertEquals(2, loaded.getGroups().size()); @@ -194,11 +179,11 @@ public void testUpdateUserGroups() throws Exception { } protected boolean hasGroups(GSUser user, String ... groupName) { - Set names = new HashSet(); + Set names = new HashSet<>(); for (UserGroup userGroup : user.getGroups()) { names.add(userGroup.getName()); } - + return names.containsAll(Arrays.asList(groupName)); } @@ -229,7 +214,7 @@ public void testGetUsersCount() { List users = userAdminService.getList("%9",null,null); assertEquals(1, users.size()); assertEquals("u99", users.get(0).getName()); - assertEquals((Long)u99.getId(), (Long)users.get(0).getId()); + assertEquals(u99.getId(), (Long)users.get(0).getId()); } } diff --git a/src/services/core/services-impl/src/test/java/org/geoserver/test/AbstractSpringContextTest.java b/src/services/core/services-impl/src/test/java/org/geoserver/test/AbstractSpringContextTest.java index 4dc6406c..7b3d67c2 100644 --- a/src/services/core/services-impl/src/test/java/org/geoserver/test/AbstractSpringContextTest.java +++ b/src/services/core/services-impl/src/test/java/org/geoserver/test/AbstractSpringContextTest.java @@ -1,4 +1,4 @@ -/* (c) 2014 Open Source Geospatial Foundation - all rights reserved +/* (c) 2014 - 2017 Open Source Geospatial Foundation - all rights reserved * This code is licensed under the GPL 2.0 license, available at the root * application directory. */ @@ -7,8 +7,8 @@ import junit.framework.TestCase; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; +import org.apache.log4j.LogManager; +import org.apache.log4j.Logger; import org.springframework.context.support.ClassPathXmlApplicationContext; diff --git a/src/services/core/webtest/pom.xml b/src/services/core/webtest/pom.xml index e31eba69..138b66c2 100644 --- a/src/services/core/webtest/pom.xml +++ b/src/services/core/webtest/pom.xml @@ -1,6 +1,6 @@ - - + + + + log4j + log4j + + + diff --git a/src/services/core/webtest/src/main/java/org/geoserver/geofence/servicetest/MainTest.java b/src/services/core/webtest/src/main/java/org/geoserver/geofence/servicetest/MainTest.java index ecbceffc..cf6da16b 100644 --- a/src/services/core/webtest/src/main/java/org/geoserver/geofence/servicetest/MainTest.java +++ b/src/services/core/webtest/src/main/java/org/geoserver/geofence/servicetest/MainTest.java @@ -1,4 +1,4 @@ -/* (c) 2014 Open Source Geospatial Foundation - all rights reserved +/* (c) 2014 - 2017 Open Source Geospatial Foundation - all rights reserved * This code is licensed under the GPL 2.0 license, available at the root * application directory. */ @@ -26,8 +26,8 @@ import java.util.List; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; +import org.apache.log4j.LogManager; +import org.apache.log4j.Logger; import org.springframework.beans.BeansException; import org.springframework.beans.factory.InitializingBean; diff --git a/src/services/modules/ldap/pom.xml b/src/services/modules/ldap/pom.xml index ac462fd4..65a90f52 100644 --- a/src/services/modules/ldap/pom.xml +++ b/src/services/modules/ldap/pom.xml @@ -1,11 +1,9 @@ @@ -27,28 +25,53 @@ - + + + org.geoserver.geofence + geofence-model-internal + + + + org.geoserver.geofence + geofence-persistence + + + + org.geoserver.geofence + geofence-services-api + + - - org.geoserver.geofence - geofence-model-internal + + + org.springframework.ldap + spring-ldap-core + 2.2.1.RELEASE - - - org.geoserver.geofence - geofence-persistence + + + com.google.guava + guava + 20.0 - - org.springframework.ldap - spring-ldap-core - 1.3.1.RELEASE - - - org.springframework.ldap - spring-ldap-test - 1.3.1.RELEASE + + + + + + + + + + org.springframework.ldap + spring-ldap-test + 2.2.1.RELEASE test @@ -60,30 +83,59 @@ log4j - + + - org.apache.logging.log4j - log4j-slf4j-impl + org.apache.directory.server + apacheds-core + 1.5.5 test - org.apache.logging.log4j - log4j-core + org.apache.directory.server + apacheds-core-entry + 1.5.5 + test + + + org.apache.directory.server + apacheds-protocol-shared + 1.5.5 + test + + + org.apache.directory.server + apacheds-protocol-ldap + 1.5.5 + test + + + org.apache.directory.server + apacheds-server-jndi + 1.5.5 + test + + + org.apache.directory.shared + shared-ldap + 0.9.15 test - - org.geoserver.geofence - geofence-services-api + org.hibernatespatial + hibernate-spatial-h2-geodb + test - + + + log4j + log4j + + + junit junit - 4.10 test @@ -95,8 +147,8 @@ org.apache.maven.plugins maven-compiler-plugin - 1.6 - 1.6 + 1.7 + 1.7 diff --git a/src/services/modules/ldap/src/main/java/org/geoserver/geofence/dao/ldap/LdapAttributesMapper.java b/src/services/modules/ldap/src/main/java/org/geoserver/geofence/dao/ldap/LdapAttributesMapper.java deleted file mode 100644 index 054e4292..00000000 --- a/src/services/modules/ldap/src/main/java/org/geoserver/geofence/dao/ldap/LdapAttributesMapper.java +++ /dev/null @@ -1,22 +0,0 @@ -/* (c) 2014 Open Source Geospatial Foundation - all rights reserved - * This code is licensed under the GPL 2.0 license, available at the root - * application directory. - */ - -package org.geoserver.geofence.dao.ldap; - -import org.springframework.ldap.core.AttributesMapper; - -/** - * @author "Mauro Bartolomeoli - mauro.bartolomeoli@geo-solutions.it" - * - */ -public interface LdapAttributesMapper extends AttributesMapper { - /** - * Maps a DAO attribute to the LDAP one. - * - * @param attributeName - * @return - */ - public String getLdapAttribute(String attributeName); -} diff --git a/src/services/modules/ldap/src/main/java/org/geoserver/geofence/dao/utils/LdapUtils.java b/src/services/modules/ldap/src/main/java/org/geoserver/geofence/dao/utils/LdapUtils.java deleted file mode 100644 index 168ec877..00000000 --- a/src/services/modules/ldap/src/main/java/org/geoserver/geofence/dao/utils/LdapUtils.java +++ /dev/null @@ -1,63 +0,0 @@ -/* (c) 2014 Open Source Geospatial Foundation - all rights reserved - * This code is licensed under the GPL 2.0 license, available at the root - * application directory. - */ - -package org.geoserver.geofence.dao.utils; - -import org.geoserver.geofence.dao.ldap.LdapAttributesMapper; - -import java.util.List; - -import org.springframework.ldap.core.AttributesMapper; -import org.springframework.ldap.core.LdapTemplate; - -import com.googlecode.genericdao.search.Filter; - -/** - * @author "Mauro Bartolomeoli - mauro.bartolomeoli@geo-solutions.it" - * - */ -public class LdapUtils { - /** - * Creates and LDAP filter from the DAO search filter. - * Currently only "property = value" filters are supported. - * - * @param filter - * @return - */ - public static String createLdapFilter(Filter filter, AttributesMapper mapper) { - // TODO add other filter types - if(filter.getOperator() == Filter.OP_EQUAL) { - String propertyName = filter.getProperty(); - if(mapper instanceof LdapAttributesMapper) { - propertyName = ((LdapAttributesMapper) mapper) - .getLdapAttribute(propertyName); - } - return propertyName + "=" + filter.getValue().toString(); - } - return null; - } - - /** - * @param searchBase - * @param filter - * @param attributesMapper - * @return - */ - public static List search(LdapTemplate ldapTemplate, String searchBase, String filter, - AttributesMapper attributesMapper) { - return ldapTemplate.search(searchBase, filter, attributesMapper); - } - - /** - * @param searchBase - * @param filter - * @param attributesMapper - * @return - */ - public static List search(LdapTemplate ldapTemplate, String searchBase, Filter filter, - AttributesMapper attributesMapper) { - return search(ldapTemplate, searchBase, LdapUtils.createLdapFilter(filter, attributesMapper), attributesMapper); - } -} diff --git a/src/services/modules/ldap/src/main/java/org/geoserver/geofence/ldap/LdapAttributesMapper.java b/src/services/modules/ldap/src/main/java/org/geoserver/geofence/ldap/LdapAttributesMapper.java new file mode 100644 index 00000000..e0c9595a --- /dev/null +++ b/src/services/modules/ldap/src/main/java/org/geoserver/geofence/ldap/LdapAttributesMapper.java @@ -0,0 +1,21 @@ +/* (c) 2014 - 2017 Open Source Geospatial Foundation - all rights reserved + * This code is licensed under the GPL 2.0 license, available at the root + * application directory. + */ +package org.geoserver.geofence.ldap; + +import org.springframework.ldap.core.AttributesMapper; + +/** + * @author "Mauro Bartolomeoli - mauro.bartolomeoli@geo-solutions.it" + */ +public interface LdapAttributesMapper extends AttributesMapper +{ + /** + * Maps a DAO attribute to the LDAP one. + * + * @param attributeName + * @return + */ + public String getLdapAttribute(String attributeName); +} diff --git a/src/services/modules/ldap/src/main/java/org/geoserver/geofence/ldap/dao/impl/BaseAttributesMapper.java b/src/services/modules/ldap/src/main/java/org/geoserver/geofence/ldap/dao/impl/BaseAttributesMapper.java index a97209eb..7aca7035 100644 --- a/src/services/modules/ldap/src/main/java/org/geoserver/geofence/ldap/dao/impl/BaseAttributesMapper.java +++ b/src/services/modules/ldap/src/main/java/org/geoserver/geofence/ldap/dao/impl/BaseAttributesMapper.java @@ -1,11 +1,10 @@ -/* (c) 2014 Open Source Geospatial Foundation - all rights reserved +/* (c) 2014 - 2017 Open Source Geospatial Foundation - all rights reserved * This code is licensed under the GPL 2.0 license, available at the root * application directory. */ - package org.geoserver.geofence.ldap.dao.impl; -import org.geoserver.geofence.dao.ldap.LdapAttributesMapper; +import org.geoserver.geofence.ldap.LdapAttributesMapper; import java.util.Map; @@ -14,56 +13,64 @@ import javax.naming.directory.Attributes; /** - * Base class for the LDAP attribute mappers. - * Implements mappings from LDAP attributes to DAO ones. - * - * @author "Mauro Bartolomeoli - mauro.bartolomeoli@geo-solutions.it" + * Base class for the LDAP attribute mappers. Implements mappings from LDAP attributes to DAO ones. * + * @author "Mauro Bartolomeoli - mauro.bartolomeoli@geo-solutions.it" + * @author Emanuele Tajariol (etj at geo-solutions.it) */ -public abstract class BaseAttributesMapper implements LdapAttributesMapper { - protected Map ldapAttributeMappings; - - /** - * Sets mappings from ldap attributes to GSUser and UserGroup ones. - * - * @param ldapAttributeMappings the ldapAttributeMappings to set - */ - public void setLdapAttributeMappings(Map ldapAttributeMappings) { - this.ldapAttributeMappings = ldapAttributeMappings; - } - - /** - * Gets the LDAP mapping for the given DAO attribute. - * - * @param attributeName - * @return - */ - public String getLdapAttribute(String attributeName) { - return ldapAttributeMappings.get(attributeName); - } - - /** - * Gets an attribute value from the given list. - * Automatically maps the attributeName (in DAO form) to LDAP form. - * - * @param attrs - * @return - * @throws NamingException - */ - protected String getAttribute(Attributes attrs, - String attributeName) - throws javax.naming.NamingException { - Attribute attrValue = attrs.get(ldapAttributeMappings.get(attributeName)); - if(attrValue != null) { - Object value = attrValue.get(); - if (value instanceof String) { - return (String) value; - } if (value instanceof byte[]) { - return new String((byte[]) value); - } else { - return value.toString(); - } - } - return ""; - } +public abstract class BaseAttributesMapper implements LdapAttributesMapper +{ + protected Map map; + + /** + * Sets mappings from ldap attributes to GSUser and UserGroup ones. + * + * @param ldapAttributeMappings the ldapAttributeMappings to set + */ + public void setMap(Map ldapAttributeMappings) + { + this.map = ldapAttributeMappings; + } + + public Map getMap() + { + return map; + } + + /** + * Gets the LDAP mapping for the given DAO attribute. + * + * @param attributeName + * @return + */ + @Override + public String getLdapAttribute(String attributeName) + { + return map.get(attributeName); + } + + /** + * Gets an attribute value from the given list. Automatically maps the attributeName (in DAO form) to LDAP form. + * + * @param attrs + * @return + * @throws NamingException + */ + protected String getAttribute(Attributes attrs, String attributeName) + throws javax.naming.NamingException + { + Attribute attrValue = attrs.get(map.get(attributeName)); + if (attrValue != null) { + Object value = attrValue.get(); + if (value instanceof String) { + return (String) value; + } + if (value instanceof byte[]) { + return new String((byte[]) value); + } else { + return value.toString(); + } + } + return ""; + } } diff --git a/src/services/modules/ldap/src/main/java/org/geoserver/geofence/ldap/dao/impl/BaseDAO.java b/src/services/modules/ldap/src/main/java/org/geoserver/geofence/ldap/dao/impl/BaseDAO.java deleted file mode 100644 index e3a19771..00000000 --- a/src/services/modules/ldap/src/main/java/org/geoserver/geofence/ldap/dao/impl/BaseDAO.java +++ /dev/null @@ -1,256 +0,0 @@ -/* (c) 2014 Open Source Geospatial Foundation - all rights reserved - * This code is licensed under the GPL 2.0 license, available at the root - * application directory. - */ - -package org.geoserver.geofence.ldap.dao.impl; - -import org.geoserver.geofence.core.dao.RestrictedGenericDAO; -import org.geoserver.geofence.dao.utils.LdapUtils; - -import java.util.ArrayList; -import java.util.List; - -import org.springframework.ldap.core.AttributesMapper; -import org.springframework.ldap.core.LdapTemplate; - -import com.googlecode.genericdao.search.Filter; -import com.googlecode.genericdao.search.ISearch; -import com.googlecode.genericdao.search.Search; - -/** - * Base DAO Implementation using LDAP services. - * - * It uses a spring-ldap LdapTemplate to communicate with the LDAP server. - * Currently only read type operations are supported (findAll, find, search). - * - * A backup DAO can be defined. It will be used as a primary source for id lookups. - * - * @author "Mauro Bartolomeoli - mauro.bartolomeoli@geo-solutions.it" - * @param - * - */ -public abstract class BaseDAO, R> implements RestrictedGenericDAO { - - private LdapTemplate ldapTemplate; - - private String searchBase; - - private String searchFilter; - - private AttributesMapper attributesMapper; - - T dao; - - /** - * Sets the backup DAO. - * - * @param dao the dao to set - */ - public void setDao(T dao) { - this.dao = dao; - } - - /** - * Sets the base name for users in LDAP server. - * - * @param searchBase the searchBase to set - */ - public void setSearchBase(String searchBase) { - this.searchBase = searchBase; - } - - /** - * Sets the filter used to identify objects from the base name. - * - * @param searchFilter the searchFilter to set - */ - public void setSearchFilter(String searchFilter) { - this.searchFilter = searchFilter; - } - - /** - * Sets the AttributeMapper used to build objects from LDAP - * objects. - * - * @param attributesMapper the attributesMapper to set - */ - public void setAttributesMapper(AttributesMapper attributesMapper) { - this.attributesMapper = attributesMapper; - } - - /** - * Sets the LDAP communication object. - * - * @param ldapTemplate the ldapTemplate to set - */ - public void setLdapTemplate(LdapTemplate ldapTemplate) { - this.ldapTemplate = ldapTemplate; - } - - @Override - public List findAll() { - return search(searchFilter); - } - - @Override - public R find(Long id) { - // try to load the user from db, first - R object = searchOnDb(id); - if(object != null) { - return object; - } - List objects = search( new Filter("id", id) ); - if(objects == null || objects.size() == 0) { - return null; - } - return objects.get(0); - } - - @Override - public List search(ISearch search) { - List objects = new ArrayList(); - if(search.getFilters().size() == 0) { - // no filter - return findAll(); - } - for(Filter filter : search.getFilters()) { - if(filter != null) { - List filteredObjects = search(filter); - objects.addAll(filteredObjects); - } - } - return objects; - } - - @Override - public int count(ISearch search) { - return search(search).size(); - } - - @Override - public void persist(R... entities) { - // insert not implemented - } - - - @Override - public R merge(R entity) { - // update not implemented - return entity; - } - - - @Override - public boolean remove(R entity) { - // remove not implemented - return false; - } - - - @Override - public boolean removeById(Long id) { - // remove not implemented - return false; - } - - /** - * Does a direct lookup for the distinguished name given. - * - * @param dn distinguished name to lookup - * @return - */ - public R lookup(String dn) { - return (R)ldapTemplate.lookup(dn, attributesMapper); - } - - /** - * Search the given user id on the backup DAO, if defined. - * The id can be a classic id (>0) or an extId (<0). - * It's an extId if it's the id read from the LDAP server. - * - * @param id - * @return - */ - private R searchOnDb(Long id) { - if(dao != null) { - if(id < 0) { - // If negative, it's an extId (id from LDAP server) - // we must search on that attribute - Search search = new Search(); - Filter filter = new Filter("extId", id+""); - List filters = new ArrayList(); - filters.add(filter); - search.setFilters(filters); - List objects = dao.search(search); - if(objects.size() > 0) { - return objects.get(0); - } - } else { - // else it's a classic id - R object = (R) dao.find(id); - if(object != null) { - return object; - } - } - } - - return null; - } - - /** - * Search using the given filter on the LDAP server. - * Each result object is mapped with the given mapper. - * Given base and filter are used. - * - * @param base - * @param filter - * @param mapper - * @return - */ - public List search(String base, Filter filter, AttributesMapper mapper) { - return LdapUtils.search(ldapTemplate, base, filter, mapper); - } - - /** - * Search using the given filter on the LDAP server. - * Each result object is mapped with the given mapper. - * Given base and filter are used. - * - * @param base - * @param filter - * @param mapper - * @return - */ - public List search(String base, String filter, AttributesMapper mapper) { - return LdapUtils.search(ldapTemplate, base, filter, mapper); - } - - /** - * Search using the given filter on the LDAP server. - * Uses default base, filter and mapper. - * - * @param base - * @param filter - * @param mapper - * @return - */ - public List search(Filter filter) { - return search(searchBase, filter, attributesMapper); - } - - /** - * Search using the given filter on the LDAP server. - * Uses default base, filter and mapper. - * - * @param base - * @param filter - * @param mapper - * @return - */ - public List search(String filter) { - return search(searchBase, filter, attributesMapper); - } - - -} diff --git a/src/services/modules/ldap/src/main/java/org/geoserver/geofence/ldap/dao/impl/GSUserAttributesMapper.java b/src/services/modules/ldap/src/main/java/org/geoserver/geofence/ldap/dao/impl/GSUserAttributesMapper.java index 351b2f73..23b72688 100644 --- a/src/services/modules/ldap/src/main/java/org/geoserver/geofence/ldap/dao/impl/GSUserAttributesMapper.java +++ b/src/services/modules/ldap/src/main/java/org/geoserver/geofence/ldap/dao/impl/GSUserAttributesMapper.java @@ -1,39 +1,51 @@ -/* (c) 2014 Open Source Geospatial Foundation - all rights reserved +/* (c) 2014 - 2017 Open Source Geospatial Foundation - all rights reserved * This code is licensed under the GPL 2.0 license, available at the root * application directory. */ - package org.geoserver.geofence.ldap.dao.impl; +import edu.emory.mathcs.backport.java.util.Collections; import org.geoserver.geofence.core.model.GSUser; import javax.naming.NamingException; +import javax.naming.directory.Attribute; import javax.naming.directory.Attributes; +import org.apache.commons.lang.StringUtils; +import org.apache.log4j.LogManager; +import org.apache.log4j.Logger; + /** * AttributeMapper for GSUser objects. - * - * @author "Mauro Bartolomeoli - mauro.bartolomeoli@geo-solutions.it" * + * @author "Mauro Bartolomeoli - mauro.bartolomeoli@geo-solutions.it" + * @author Emanuele Tajariol (etj at geo-solutions.it) */ -public class GSUserAttributesMapper extends BaseAttributesMapper { +public class GSUserAttributesMapper extends BaseAttributesMapper +{ + private static final Logger LOGGER = LogManager.getLogger(GSUserAttributesMapper.class); - + @Override + public Object mapFromAttributes(Attributes attrs) throws NamingException + { + GSUser user = new GSUser(); + String id = getAttribute(attrs, "id"); + if(StringUtils.isBlank(id)) { + LOGGER.warn("Empty id for GSUser"); + if(LOGGER.isDebugEnabled()) { + for(Object oa: Collections.list(attrs.getAll())) { + Attribute a = (Attribute)oa; + LOGGER.debug("---> " + a); + } + } + } + user.setExtId(id); + user.setName(getAttribute(attrs, "username")); + user.setEmailAddress(getAttribute(attrs, "email")); + user.setEnabled(true); + user.setFullName(getAttribute(attrs, "name") + " " + getAttribute(attrs, "surname")); + user.setPassword(getAttribute(attrs, "password")); - @Override - public Object mapFromAttributes(Attributes attrs) throws NamingException { - GSUser user = new GSUser(); - user.setId(Long.parseLong(getAttribute(attrs, "id"))); - user.setExtId(-user.getId()+""); - user.setName(getAttribute(attrs, "username")); - user.setEmailAddress(getAttribute(attrs, "email")); - user.setEnabled(true); - user.setFullName(getAttribute(attrs, "name") + " " - + getAttribute(attrs, "surname")); - user.setPassword(getAttribute(attrs, "password")); - - return user; - } - - + return user; + } } diff --git a/src/services/modules/ldap/src/main/java/org/geoserver/geofence/ldap/dao/impl/GSUserDAOLdapImpl.java b/src/services/modules/ldap/src/main/java/org/geoserver/geofence/ldap/dao/impl/GSUserDAOLdapImpl.java index 39b85bf4..19a86fdb 100644 --- a/src/services/modules/ldap/src/main/java/org/geoserver/geofence/ldap/dao/impl/GSUserDAOLdapImpl.java +++ b/src/services/modules/ldap/src/main/java/org/geoserver/geofence/ldap/dao/impl/GSUserDAOLdapImpl.java @@ -1,8 +1,7 @@ -/* (c) 2014 Open Source Geospatial Foundation - all rights reserved +/* (c) 2014 - 2017 Open Source Geospatial Foundation - all rights reserved * This code is licensed under the GPL 2.0 license, available at the root * application directory. */ - package org.geoserver.geofence.ldap.dao.impl; import org.geoserver.geofence.core.dao.GSUserDAO; @@ -11,118 +10,97 @@ import java.util.HashSet; import java.util.List; -import java.util.Set; - -import org.springframework.ldap.core.AttributesMapper; import com.googlecode.genericdao.search.Filter; - +import com.googlecode.genericdao.search.Search; +import org.apache.commons.lang.StringUtils; /** - * GSUserDAO implementation, using an LDAP server as a primary source, and the original - * JPA based DAO as a backup. - * - * @author "Mauro Bartolomeoli - mauro.bartolomeoli@geo-solutions.it" + * GSUserDAO implementation, using an LDAP server as a primary source. * + * @author "Mauro Bartolomeoli - mauro.bartolomeoli@geo-solutions.it" + * @author Emanuele Tajariol (etj at geo-solutions.it) */ -public class GSUserDAOLdapImpl extends BaseDAO implements GSUserDAO { - - private String groupsBase = "ou=Groups"; - - private AttributesMapper groupsAttributesMapper; - String userDn = "uid=%s,ou=People"; - - - /** - * - */ - public GSUserDAOLdapImpl() { - super(); - // set default search base and filter for users - setSearchBase("ou=People"); - setSearchFilter("objectClass=inetOrgPerson"); - } - - /** - * Sets the base name for groups in LDAP server. - * Used to extract groups bounded to the user. - * - * @param groupsBase the groupsBase to set - */ - public void setGroupsBase(String groupsBase) { - this.groupsBase = groupsBase; - } - - /** - * Sets the userDn template, to quickly locate a user into an LDAP server, - * by its distinguished name. - * It's a template, filled with the user name (use %s as a placeholder for that=. - * - * @param userDn the userDn to set - */ - public void setUserDn(String userDn) { - this.userDn = userDn; - } - - - /** - * Sets the AttributeMapper used to build UserGroup objects from LDAP - * objects. - * - * @param groupsAttributesMapper the groupsAttributesMapper to set - */ - public void setGroupsAttributesMapper(AttributesMapper groupsAttributesMapper) { - this.groupsAttributesMapper = groupsAttributesMapper; - } - - - - @Override - public Set getGroups(Long id) { - GSUser user = find(id); - fillWithGroups(user); - return user.getGroups(); - } - - /** - * Gets the list of user groups from the LDAP server for the given user. - * - * @param user - * @return - */ - private Set getGroups(GSUser user) { - Set groups = new HashSet(); - Filter filter = new Filter("member", user.getName()); - List groupsList = search(groupsBase, filter, groupsAttributesMapper); - groups.addAll(groupsList); - return groups; - } - - - @Override - public GSUser getFull(Long id) { - GSUser user = find(id); - if(user != null) { - return fillWithGroups(user); - } - return null; - } - - @Override - public GSUser getFull(String name) { - return fillWithGroups(lookup(String.format(userDn, name))); - } - - - - /** - * Updates the groups list for the given user. - * - * @param gsUser - * @return - */ - private GSUser fillWithGroups(GSUser user) { - user.setGroups(getGroups(user)); - return user; - } +public class GSUserDAOLdapImpl extends LDAPBaseDAO implements GSUserDAO +{ + + private UserGroupDAOLdapImpl userGroupDAOLdapImpl; + + /** + * + */ + public GSUserDAOLdapImpl() + { + super(); + // set default search base and filter for users + setSearchBase("ou=People"); + setSearchFilter("objectClass=inetOrgPerson"); + } + + /** + * Gets the list of user groups from the LDAP server for the given user. + * + * @param user + * @return + */ + private List getGroups(GSUser user) + { + Filter filter; + + String dn = user.getExtId(); + if(StringUtils.isNotBlank(dn)) { + filter = new Filter("member", dn); + } else { + String userName = user.getName(); + LOGGER.info("User id is null, using username '"+userName+"'"); + String nameAttr = getLDAPAttribute("username"); + String exp = nameAttr + "=" + userName; + filter = new Filter("member", exp); + } + + List groups = userGroupDAOLdapImpl.search(filter); + return groups; + } + + @Override + public GSUser getFull(String name) + { + GSUser user = searchByName(name); + if(user == null) + return null; + + return fillWithGroups(user); + } + + /** + * Updates the groups list for the given user. + * + * @param gsUser + * @return + */ + private GSUser fillWithGroups(GSUser user) + { + user.setGroups(new HashSet(getGroups(user))); + return user; + } + + public GSUser searchByName(String name) { + + Search search = new Search(); + search.addFilter(new Filter("username", name)); + List users = search(search); + + if(users.isEmpty()) + return null; + else if(users.size() > 1) + throw new IllegalArgumentException("Given filter ("+name+") returns too many users ("+users.size()+")"); + GSUser user = users.get(0); + return user; + } + + public void setUserGroupDAOLdapImpl(UserGroupDAOLdapImpl userGroupDAOLdapImpl) + { + this.userGroupDAOLdapImpl = userGroupDAOLdapImpl; + } + } diff --git a/src/services/modules/ldap/src/main/java/org/geoserver/geofence/ldap/dao/impl/LDAPBaseDAO.java b/src/services/modules/ldap/src/main/java/org/geoserver/geofence/ldap/dao/impl/LDAPBaseDAO.java new file mode 100644 index 00000000..f05d78b6 --- /dev/null +++ b/src/services/modules/ldap/src/main/java/org/geoserver/geofence/ldap/dao/impl/LDAPBaseDAO.java @@ -0,0 +1,282 @@ +/* (c) 2014 - 2017 Open Source Geospatial Foundation - all rights reserved + * This code is licensed under the GPL 2.0 license, available at the root + * application directory. + */ +package org.geoserver.geofence.ldap.dao.impl; + +import java.util.List; +import java.util.ArrayList; +import java.util.Collections; +import java.util.concurrent.ExecutionException; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.atomic.AtomicLong; + +import com.google.common.cache.CacheBuilder; +import com.google.common.cache.CacheLoader; +import com.google.common.cache.LoadingCache; + +import com.google.common.util.concurrent.Futures; +import com.google.common.util.concurrent.ListenableFuture; + +import org.geoserver.geofence.core.dao.RestrictedGenericDAO; +import org.geoserver.geofence.ldap.utils.LdapUtils; + +import org.springframework.ldap.core.AttributesMapper; +import org.springframework.ldap.core.LdapTemplate; + +import com.googlecode.genericdao.search.Filter; +import com.googlecode.genericdao.search.ISearch; + +import org.apache.log4j.LogManager; +import org.apache.log4j.Logger; +import org.springframework.beans.factory.InitializingBean; + +/** + * Base DAO Implementation using LDAP services. + * + * It uses a spring-ldap LdapTemplate to communicate with the LDAP server. + * + * Currently only read type operations are supported (findAll, find, search). + * + * Search results are cached in order to avoid too many calls to the LDAP services. + * + * @author "Mauro Bartolomeoli - mauro.bartolomeoli@geo-solutions.it" + * @author Emanuele Tajariol (etj at geo-solutions.it) + */ +public abstract class LDAPBaseDAO, R> + implements RestrictedGenericDAO, InitializingBean +{ + protected static Logger LOGGER = LogManager.getLogger(LDAPBaseDAO.class); + + private LdapTemplate ldapTemplate; + private String searchBase; + private String searchFilter; + private AttributesMapper attributesMapper; + + private LoadingCache> ldapcache; + private long cachesize = 1000; + private long cacherefreshsec = 3600; + private long cacheexpiresec = 3600; + private final AtomicLong dumpCnt = new AtomicLong(0); + + public LDAPBaseDAO() + { + } + + @Override + public void afterPropertiesSet() throws Exception + { + ldapcache = getCacheBuilder().build(new LDAPLoader()); + } + + protected CacheBuilder getCacheBuilder() { + CacheBuilder builder = CacheBuilder.newBuilder() + .maximumSize(cachesize) + .refreshAfterWrite(cacherefreshsec, TimeUnit.SECONDS) // reloadable after x time + .expireAfterWrite(cacheexpiresec, TimeUnit.MILLISECONDS) // throw away entries too old + .recordStats() + ; + return builder; + } + + + protected String getLDAPAttribute(String attrName) { + return ((BaseAttributesMapper)attributesMapper).getLdapAttribute(attrName); + } + + @Override + public List findAll() + { + return search(searchFilter); + } + + @Override + public R find(Long id) + { + LOGGER.warn(getClass().getSimpleName() + ": search by id is deprecated (id="+id+")"); + return null; + } + + @Override + public List search(ISearch search) + { + List objects = new ArrayList<>(); + if (search.getFilters().isEmpty()) { + // no filter + return findAll(); + } + for (Filter filter : search.getFilters()) { + if (filter != null) { + List filteredObjects = search(filter); + objects.addAll(filteredObjects); + } + } + return objects; + } + + @Override + public int count(ISearch search) + { + return search(search).size(); + } + + @Override + public void persist(R... entities) + { + LOGGER.warn(getClass().getSimpleName() + ": persisting not allowed in LDAP"); + } + + @Override + public R merge(R entity) + { + LOGGER.warn(getClass().getSimpleName() + ": persisting not allowed in LDAP"); + return entity; + } + + @Override + public boolean remove(R entity) + { + LOGGER.warn(getClass().getSimpleName() + ": persisting not allowed in LDAP"); + return false; + } + + @Override + public boolean removeById(Long id) + { + LOGGER.warn(getClass().getSimpleName() + ": persisting not allowed in LDAP"); + return false; + } + + /** + * Does a direct lookup for the distinguished name given. + * + * @param dn distinguished name to lookup + * @return + */ + public R lookup(String dn) + { + return (R) ldapTemplate.lookup(dn, attributesMapper); + } + + /** + * Search using the given filter on the LDAP server. Uses default base, filter and mapper. + * + * @param base + * @param filter + * @param mapper + * @return + */ + public List search(Filter filter) + { + return search(LdapUtils.createLDAPFilter(filter, attributesMapper)); + } + + /** + * Search using the given filter on the LDAP server. Uses default base, filter and mapper. + * + * @param base + * @param filter + * @param mapper + * @return + */ + public List search(String filter) + { + if(LOGGER.isDebugEnabled()) + LOGGER.debug(getClass().getSimpleName() + ": searching base:'"+searchBase+"', filter: '"+filter+"'"); + + if(LOGGER.isInfoEnabled()) { + if(dumpCnt.incrementAndGet() % 10 == 0) { + LOGGER.info("LDAP Cache :"+ ldapcache.stats()); + } + } + + try { + return ldapcache.get(filter); + //return search(ldapTemplate, searchBase, filter, attributesMapper); + } catch (ExecutionException ex) { + LOGGER.warn("Error while getting LDAP info: " + ex.getMessage(), ex); + return Collections.EMPTY_LIST; + } + } + + private class LDAPLoader extends CacheLoader> + { + private Logger LOGGER = LogManager.getLogger(LDAPLoader.class); + + @Override + public List load(String filter) throws Exception { + if(LOGGER.isDebugEnabled()) + LOGGER.debug("Loading " + filter); + + return ldapTemplate.search(searchBase, filter, attributesMapper); + } + + @Override + public ListenableFuture> reload(final String filter, List accessInfo) throws Exception + { + if(LDAPBaseDAO.this.LOGGER.isDebugEnabled()) + LOGGER.debug("RELoading " + filter); + + // this is a sync implementation + List ldapObjs = ldapTemplate.search(searchBase, filter, attributesMapper); + return Futures.immediateFuture(ldapObjs); + } + } + + /** + * Sets the base name for users in LDAP server. + * + * @param searchBase the searchBase to set + */ + public void setSearchBase(String searchBase) + { + this.searchBase = searchBase; + } + + /** + * Sets the filter used to identify objects from the base name. + * + * @param searchFilter the searchFilter to set + */ + public void setSearchFilter(String searchFilter) + { + this.searchFilter = searchFilter; + } + + /** + * Sets the AttributeMapper used to build objects from LDAP objects. + * + * @param attributesMapper the attributesMapper to set + */ + public void setAttributesMapper(AttributesMapper attributesMapper) + { + this.attributesMapper = attributesMapper; + } + + /** + * Sets the LDAP communication object. + * + * @param ldapTemplate the ldapTemplate to set + */ + public void setLdapTemplate(LdapTemplate ldapTemplate) + { + this.ldapTemplate = ldapTemplate; + } + + public void setCachesize(long cachesize) + { + this.cachesize = cachesize; + } + + public void setCacherefreshsec(long cacherefreshsec) + { + this.cacherefreshsec = cacherefreshsec; + } + + public void setCacheexpiresec(long cacheexpiresec) + { + this.cacheexpiresec = cacheexpiresec; + } + + +} diff --git a/src/services/modules/ldap/src/main/java/org/geoserver/geofence/ldap/dao/impl/RuleDAOLdapImpl.java b/src/services/modules/ldap/src/main/java/org/geoserver/geofence/ldap/dao/impl/RuleDAOLdapImpl.java deleted file mode 100644 index be97432d..00000000 --- a/src/services/modules/ldap/src/main/java/org/geoserver/geofence/ldap/dao/impl/RuleDAOLdapImpl.java +++ /dev/null @@ -1,155 +0,0 @@ -/* (c) 2014 Open Source Geospatial Foundation - all rights reserved - * This code is licensed under the GPL 2.0 license, available at the root - * application directory. - */ - -package org.geoserver.geofence.ldap.dao.impl; - -import org.geoserver.geofence.core.dao.GSUserDAO; -import org.geoserver.geofence.core.dao.UserGroupDAO; -import org.geoserver.geofence.core.dao.impl.RuleDAOImpl; -import org.geoserver.geofence.core.model.GSUser; -import org.geoserver.geofence.core.model.Rule; -import org.geoserver.geofence.core.model.UserGroup; - -/** - * Implementation of RuleDAO compatible with ldap user and group daos. - * - * It persists user and groups to db when a rule is bound to a new user or group. - * - * @author "Mauro Bartolomeoli - mauro.bartolomeoli@geo-solutions.it" - * - */ -public class RuleDAOLdapImpl extends RuleDAOImpl { - - private GSUserDAO userDao; - - private UserGroupDAO userGroupDao; - - /** - * Original JPA GSUserDAO. - * Used to persist new users from ldap to db. - * - * @param userDao the userDao to set - */ - public void setUserDao(GSUserDAO userDao) { - this.userDao = userDao; - } - - - - /** - * Original JPA UserGroupDAO. - * Used to persist new groups from ldap to db. - * - * @param userGroupDao the userGroupDao to set - */ - public void setUserGroupDao(UserGroupDAO userGroupDao) { - this.userGroupDao = userGroupDao; - } - - - - @Override - public void persist(Rule... entities) { -// for(Rule rule : entities) { -// checkUserAndGroup(rule); -// } - super.persist(entities); - } - - - // This part has been removed in the refactoring of the user model. - // We probably don't need to store the user anymore when using ldap - -// /** -// * Checks a rule, to identify users or groups not persisted on db. -// * If any is found, they are persisted before the rule, to avoid -// * referential integrity issues. -// * -// * @param rule -// */ -// private void checkUserAndGroup(Rule entity) { -// if(notPersistedUser(entity)) { -// // create a new persistable user, persist it and update the rule -// GSUser user = copyUser(entity.getGsuser()); -// userDao.persist(user); -// entity.setGsuser(user); -// } -// if(notPersistedGroup(entity)) { -// // create a new persistable group, persist it and update the rule -// UserGroup group = copyGroup(entity.getUserGroup()); -// userGroupDao.persist(group); -// entity.setUserGroup(group); -// } -// } - - - -// /** -// * Checks if the rule has a group defined, and if it is persisted. -// * -// * @param rule -// * @return -// */ -// private boolean notPersistedGroup(Rule rule) { -// return rule.getRolename() != null && userGroupDao.find(rule.getUserGroup().getId()) == null; -// } - - -// -// /** -// * Checks if the rule has a user defined, and if it is persisted. -// * -// * @param rule -// * @return -// */ -// private boolean notPersistedUser(Rule rule) { -// return rule.getUsername() != null && userDao.getFull(rule.getUsername()) == null; -// } - - - - @Override - public Rule merge(Rule entity) { -// checkUserAndGroup(entity); - return super.merge(entity); - - } - -// /** -// * Creates a persistable copy of the given user. -// * -// * @param user -// */ -// private GSUser copyUser(GSUser user) -// { -// GSUser newUser = new GSUser(); -// newUser.setName(user.getName()); -// newUser.setFullName(user.getFullName()); -// newUser.setEmailAddress(user.getEmailAddress()); -// newUser.setEnabled(true); -// newUser.setAdmin(user.isAdmin()); -// newUser.setPassword(user.getPassword()); -// // set external id to negative ldap id, so that it's easily identifiable in -// // searches -// newUser.setExtId(-user.getId()+""); -// newUser.setDateCreation(user.getDateCreation()); -// return newUser; -// } -// -// /** -// * Creates a persistable copy of the given group. -// * -// * @param user -// */ -// private UserGroup copyGroup(UserGroup group) -// { -// UserGroup newGroup = new UserGroup(); -// newGroup.setName(group.getName()); -// newGroup.setExtId(-group.getId()+""); -// newGroup.setEnabled(true); -// return newGroup; -// } - -} diff --git a/src/services/modules/ldap/src/main/java/org/geoserver/geofence/ldap/dao/impl/UserGroupAttributesMapper.java b/src/services/modules/ldap/src/main/java/org/geoserver/geofence/ldap/dao/impl/UserGroupAttributesMapper.java index 5c10c3ae..69fcad95 100644 --- a/src/services/modules/ldap/src/main/java/org/geoserver/geofence/ldap/dao/impl/UserGroupAttributesMapper.java +++ b/src/services/modules/ldap/src/main/java/org/geoserver/geofence/ldap/dao/impl/UserGroupAttributesMapper.java @@ -1,36 +1,49 @@ -/* (c) 2014 Open Source Geospatial Foundation - all rights reserved +/* (c) 2014 - 2017 Open Source Geospatial Foundation - all rights reserved * This code is licensed under the GPL 2.0 license, available at the root * application directory. */ - package org.geoserver.geofence.ldap.dao.impl; +import edu.emory.mathcs.backport.java.util.Collections; import org.geoserver.geofence.core.model.UserGroup; import javax.naming.NamingException; +import javax.naming.directory.Attribute; import javax.naming.directory.Attributes; +import org.apache.commons.lang.StringUtils; +import org.apache.log4j.LogManager; +import org.apache.log4j.Logger; /** * AttributeMapper for UserGroup objects. - * - * @author "Mauro Bartolomeoli - mauro.bartolomeoli@geo-solutions.it" * + * @author "Mauro Bartolomeoli - mauro.bartolomeoli@geo-solutions.it" + * @author Emanuele Tajariol (etj at geo-solutions.it) */ -public class UserGroupAttributesMapper extends BaseAttributesMapper { +public class UserGroupAttributesMapper extends BaseAttributesMapper +{ + private static final Logger LOGGER = LogManager.getLogger(UserGroupAttributesMapper.class); + + @Override + public Object mapFromAttributes(Attributes attrs) throws NamingException + { + UserGroup group = new UserGroup(); - + String id = getAttribute(attrs, "id"); + if(StringUtils.isBlank(id)) { + LOGGER.warn("Empty id for UserGroup"); + if(LOGGER.isDebugEnabled()) { + for(Object oa: Collections.list(attrs.getAll())) { + Attribute a = (Attribute)oa; + LOGGER.debug("---> " + a); + } + } + } + group.setExtId(id); + group.setName(getAttribute(attrs, "groupname")); + group.setEnabled(true); - @Override - public Object mapFromAttributes(Attributes attrs) throws NamingException { - UserGroup group = new UserGroup(); - group.setId(Long.parseLong(getAttribute(attrs, "id"))); - group.setExtId(-group.getId()+""); - group.setName(getAttribute(attrs, "groupname")); - group.setEnabled(true); - - return group; - } - - + return group; + } } diff --git a/src/services/modules/ldap/src/main/java/org/geoserver/geofence/ldap/dao/impl/UserGroupDAOLdapImpl.java b/src/services/modules/ldap/src/main/java/org/geoserver/geofence/ldap/dao/impl/UserGroupDAOLdapImpl.java index 8f8eb5e7..3fc9714e 100644 --- a/src/services/modules/ldap/src/main/java/org/geoserver/geofence/ldap/dao/impl/UserGroupDAOLdapImpl.java +++ b/src/services/modules/ldap/src/main/java/org/geoserver/geofence/ldap/dao/impl/UserGroupDAOLdapImpl.java @@ -1,28 +1,26 @@ -/* (c) 2014 Open Source Geospatial Foundation - all rights reserved +/* (c) 2014 - 2017 Open Source Geospatial Foundation - all rights reserved * This code is licensed under the GPL 2.0 license, available at the root * application directory. */ - package org.geoserver.geofence.ldap.dao.impl; import org.geoserver.geofence.core.dao.UserGroupDAO; import org.geoserver.geofence.core.model.UserGroup; /** - * UserGroupDAO implementation, using an LDAP server as a primary source, and the original - * JPA based DAO as a backup. - * - * @author "Mauro Bartolomeoli - mauro.bartolomeoli@geo-solutions.it" + * UserGroupDAO implementation, using an LDAP server as a primary source. * + * @author "Mauro Bartolomeoli - mauro.bartolomeoli@geo-solutions.it" + * @author Emanuele Tajariol (etj at geo-solutions.it) */ -public class UserGroupDAOLdapImpl extends BaseDAO implements UserGroupDAO { - /** - * - */ - public UserGroupDAOLdapImpl() { - super(); - // set default search base and filter for groups - setSearchBase("ou=Groups"); - setSearchFilter("objectClass=posixGroup"); - } +public class UserGroupDAOLdapImpl extends LDAPBaseDAO implements UserGroupDAO +{ + + public UserGroupDAOLdapImpl() + { + super(); + // set default search base and filter for groups + setSearchBase("ou=Groups"); + setSearchFilter("objectClass=posixGroup"); + } } diff --git a/src/services/modules/ldap/src/main/java/org/geoserver/geofence/ldap/utils/LdapUtils.java b/src/services/modules/ldap/src/main/java/org/geoserver/geofence/ldap/utils/LdapUtils.java new file mode 100644 index 00000000..6a23c8de --- /dev/null +++ b/src/services/modules/ldap/src/main/java/org/geoserver/geofence/ldap/utils/LdapUtils.java @@ -0,0 +1,47 @@ +/* (c) 2014 - 2017 Open Source Geospatial Foundation - all rights reserved + * This code is licensed under the GPL 2.0 license, available at the root + * application directory. + */ +package org.geoserver.geofence.ldap.utils; + +import org.geoserver.geofence.ldap.LdapAttributesMapper; + +import org.springframework.ldap.core.AttributesMapper; + +import com.googlecode.genericdao.search.Filter; + +import org.apache.log4j.LogManager; +import org.apache.log4j.Logger; + +/** + * @author "Mauro Bartolomeoli - mauro.bartolomeoli@geo-solutions.it" + */ +public class LdapUtils +{ + private static Logger LOGGER = LogManager.getLogger(LdapUtils.class); + + + /** + * Creates and LDAP filter from the DAO search filter. Currently only "property = value" filters are supported. + * + * @param filter + * @return + */ + public static String createLDAPFilter(Filter filter, AttributesMapper mapper) + { + // TODO add other filter types + if (filter.getOperator() == Filter.OP_EQUAL) { + String propertyName = filter.getProperty(); + if (mapper instanceof LdapAttributesMapper) { + propertyName = ((LdapAttributesMapper) mapper) + .getLdapAttribute(propertyName); + } + return propertyName + "=" + filter.getValue().toString(); + } else { + LOGGER.error("MISSING IMPLEMENTATION FOR " + filter); + } + return null; + } + + +} diff --git a/src/services/modules/ldap/src/main/resources/applicationContext-geofence-ldap-datasource.xml b/src/services/modules/ldap/src/main/resources/applicationContext-geofence-ldap-datasource.xml new file mode 100644 index 00000000..cdb009d6 --- /dev/null +++ b/src/services/modules/ldap/src/main/resources/applicationContext-geofence-ldap-datasource.xml @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/services/modules/ldap/src/main/resources/applicationContext-geofenceLdapDatasource.xml b/src/services/modules/ldap/src/main/resources/applicationContext-geofenceLdapDatasource.xml deleted file mode 100644 index b24b5675..00000000 --- a/src/services/modules/ldap/src/main/resources/applicationContext-geofenceLdapDatasource.xml +++ /dev/null @@ -1,68 +0,0 @@ - - - - - - - - - - - - - - - classpath*:geofence-ldap.properties - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/services/modules/ldap/src/main/resources/applicationContext-override.xml b/src/services/modules/ldap/src/main/resources/applicationContext-override.xml deleted file mode 100644 index c660c72a..00000000 --- a/src/services/modules/ldap/src/main/resources/applicationContext-override.xml +++ /dev/null @@ -1,59 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/src/services/modules/ldap/src/main/resources/applicationContext.xml b/src/services/modules/ldap/src/main/resources/applicationContext.xml index 9e39938d..c8555acd 100644 --- a/src/services/modules/ldap/src/main/resources/applicationContext.xml +++ b/src/services/modules/ldap/src/main/resources/applicationContext.xml @@ -1,70 +1,76 @@ - - - + - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - + + + + - - - - - - - - - - - - - - - - - diff --git a/src/services/modules/ldap/src/test/java/org/geoserver/geofence/ldap/dao/impl/BaseDAOTest.java b/src/services/modules/ldap/src/test/java/org/geoserver/geofence/ldap/dao/impl/BaseDAOTest.java index fb595b40..2cf67410 100644 --- a/src/services/modules/ldap/src/test/java/org/geoserver/geofence/ldap/dao/impl/BaseDAOTest.java +++ b/src/services/modules/ldap/src/test/java/org/geoserver/geofence/ldap/dao/impl/BaseDAOTest.java @@ -1,112 +1,117 @@ -/* (c) 2014 Open Source Geospatial Foundation - all rights reserved +/* (c) 2014 - 2017 Open Source Geospatial Foundation - all rights reserved * This code is licensed under the GPL 2.0 license, available at the root * application directory. */ package org.geoserver.geofence.ldap.dao.impl; -import static org.junit.Assert.assertNotNull; +import org.springframework.context.support.ClassPathXmlApplicationContext; +import org.springframework.core.io.ClassPathResource; + +import org.springframework.ldap.core.LdapTemplate; +import org.springframework.ldap.core.support.LdapContextSource; +import org.springframework.ldap.test.LdapTestUtils; +import org.springframework.ldap.support.LdapUtils; + import org.geoserver.geofence.core.dao.GSUserDAO; import org.geoserver.geofence.core.dao.UserGroupDAO; -import javax.naming.directory.DirContext; +import org.apache.log4j.LogManager; +import org.apache.log4j.Logger; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; +import static org.junit.Assert.*; import org.junit.AfterClass; import org.junit.Before; import org.junit.BeforeClass; +import org.junit.Rule; import org.junit.Test; -import org.springframework.context.support.ClassPathXmlApplicationContext; -import org.springframework.core.io.ClassPathResource; -import org.springframework.ldap.core.DistinguishedName; -import org.springframework.ldap.core.LdapTemplate; -import org.springframework.ldap.core.support.LdapContextSource; -import org.springframework.ldap.test.LdapTestUtils; - - +import org.junit.rules.TestName; /** * * @author ETj (etj at geo-solutions.it) */ -public abstract class BaseDAOTest { +public abstract class BaseDAOTest +{ protected final Logger LOGGER; protected static GSUserDAO userDAO; protected static UserGroupDAO userGroupDAO; - + protected static ClassPathXmlApplicationContext ctx = null; - public BaseDAOTest() { + @Rule + public TestName name = new TestName(); + + public BaseDAOTest() + { LOGGER = LogManager.getLogger(getClass()); - - - synchronized(BaseDAOTest.class) { - if(ctx == null) { + synchronized (BaseDAOTest.class) { + if (ctx == null) { String[] paths = { - "applicationContext.xml" + "classpath*:applicationContext.xml", +// "applicationContext.xml", +// "applicationContext-geofence-ldap.xml" // ,"applicationContext-test.xml" }; ctx = new ClassPathXmlApplicationContext(paths); - userDAO = (GSUserDAO)ctx.getBean("gsLdapUserDAO"); - userGroupDAO = (UserGroupDAO)ctx.getBean("ldapUserGroupDAO"); + userDAO = (GSUserDAO) ctx.getBean("gsUserDAO_LDAP"); + userGroupDAO = (UserGroupDAO) ctx.getBean("userGroupDAO_LDAP"); } - + } } - - private static DirContext ldapContext = null; - - + @BeforeClass - public static void setUpClass() throws Exception { - try { - // Start an LDAP server and import test data - ldapContext = LdapTestUtils.startApacheDirectoryServer(10389, "dc=example,dc=com", "test", LdapTestUtils.DEFAULT_PRINCIPAL, LdapTestUtils.DEFAULT_PASSWORD, null); - } catch(Exception e) { - ldapContext = null; - } - + public static void setUpClass() throws Exception + { + // Start an LDAP server and import test data +// LdapTestUtils.startEmbeddedServer(10389, "", "test"); +// LdapTestUtils.startEmbeddedServer(10389, "dc=example,dc=com", "test"); + LdapTestUtils.startEmbeddedServer(10389, "dc=com", "test"); + loadData(); } - + @AfterClass - public static void tearDownClass() throws Exception { - LdapTestUtils.destroyApacheDirectoryServer(LdapTestUtils.DEFAULT_PRINCIPAL, LdapTestUtils.DEFAULT_PASSWORD); - if(ldapContext != null) { - ldapContext.close(); - ldapContext = null; - } + public static void tearDownClass() throws Exception + { + LdapTestUtils.shutdownEmbeddedServer(); } @Before - public void setUp() throws Exception { - org.junit.Assume.assumeNotNull(ldapContext); - // Bind to the directory + public void setUp() throws Exception + { + LOGGER.info("################ Setting up -- " + getClass().getSimpleName() + ":: " + name.getMethodName() ); +// loadData(); + LOGGER.info("##### Ending setup for " + getClass().getSimpleName() + " ###----------------------"); + } + + protected static void loadData() throws Exception + { + // Bind to the directory LdapContextSource contextSource = new LdapContextSource(); contextSource.setUrl("ldap://127.0.0.1:10389"); - contextSource.setUserDn(LdapTestUtils.DEFAULT_PRINCIPAL); - contextSource.setPassword(LdapTestUtils.DEFAULT_PASSWORD); + contextSource.setUserDn("uid=admin,ou=system"); + contextSource.setPassword("secret"); contextSource.setPooled(false); //contextSource.setDirObjectFactory(null); - contextSource.afterPropertiesSet(); + contextSource.afterPropertiesSet(); // Create the Sprint LDAP template LdapTemplate template = new LdapTemplate(contextSource); // Clear out any old data - and load the test data - LdapTestUtils.cleanAndSetup(template.getContextSource(), new DistinguishedName("dc=example,dc=com"), new ClassPathResource("data.ldif")); - LOGGER.info("################ Running " + getClass().getSimpleName() ); - - - LOGGER.info("##### Ending setup for " + getClass().getSimpleName() + " ###----------------------"); + LdapTestUtils.clearSubContexts(contextSource, LdapUtils.newLdapName("dc=example,dc=com")); + LdapTestUtils.loadLdif(contextSource, new ClassPathResource("data.ldif")); } @Test - public void testCheckDAOs() { - assertNotNull(userDAO); + public void testCheckDAOs() + { + assertNotNull(userDAO); + assertTrue(userDAO instanceof GSUserDAOLdapImpl); } } diff --git a/src/services/modules/ldap/src/test/java/org/geoserver/geofence/ldap/dao/impl/GSUserDAOLdapImplTest.java b/src/services/modules/ldap/src/test/java/org/geoserver/geofence/ldap/dao/impl/GSUserDAOLdapImplTest.java index 20bd0477..3abad00c 100644 --- a/src/services/modules/ldap/src/test/java/org/geoserver/geofence/ldap/dao/impl/GSUserDAOLdapImplTest.java +++ b/src/services/modules/ldap/src/test/java/org/geoserver/geofence/ldap/dao/impl/GSUserDAOLdapImplTest.java @@ -1,8 +1,7 @@ -/* (c) 2014 Open Source Geospatial Foundation - all rights reserved +/* (c) 2014 - 2017 Open Source Geospatial Foundation - all rights reserved * This code is licensed under the GPL 2.0 license, available at the root * application directory. */ - package org.geoserver.geofence.ldap.dao.impl; import static org.junit.Assert.*; @@ -14,55 +13,87 @@ import com.googlecode.genericdao.search.Filter; import com.googlecode.genericdao.search.Search; - - +import java.util.HashSet; +import java.util.Set; +import org.geoserver.geofence.core.model.UserGroup; /** * @author "Mauro Bartolomeoli - mauro.bartolomeoli@geo-solutions.it" - * + * @author Emanuele Tajariol (etj at geo-solutions.it) */ -public class GSUserDAOLdapImplTest extends BaseDAOTest { - @Test - public void testFindAll() { - List users = userDAO.findAll(); - assertTrue(users.size() > 0); - GSUser user = users.get(0); - assertTrue(user.getName().length() > 0); - } - - @Test - public void testFind() { - GSUser user = userDAO.find(1l); - assertNotNull(user); - assertEquals("admin", user.getName()); - } - - @Test - public void testGetFullByName() { - GSUser user = userDAO.getFull("admin"); - assertNotNull(user); - assertEquals("admin", user.getName()); - } - - @Test - public void testGetFullById() { - GSUser user = userDAO.getFull(1l); - assertNotNull(user); - assertEquals("admin", user.getName()); - } - - @Test - public void testCount() { - assertTrue(userDAO.count(new Search()) > 0); - } - - @Test - public void testSearch() { - Search search = new Search(); - search.addFilter(new Filter("username", "admin")); - List users = userDAO.search(search); - assertTrue(users.size() > 0); - GSUser user = users.get(0); - assertTrue(user.getName().length() > 0); - } +public class GSUserDAOLdapImplTest extends BaseDAOTest +{ + + @Test + public void testFindAll() + { + List users = userDAO.findAll(); + assertTrue(users.size() > 0); + GSUser user = users.get(0); + assertTrue(user.getName().length() > 0); + } + + @Test + public void testFind() + { + GSUser user = userDAO.find(1l); + assertNull(user); + } + + @Test + public void testGetFullByName() + { + final String USERNAME = "admin"; + GSUser user = userDAO.getFull(USERNAME); + assertNotNull(user); + LOGGER.info("Searching for '" + USERNAME + "', found " + user); + assertEquals(USERNAME, user.getName()); + } + + @Test + public void testCount() + { + assertTrue(userDAO.count(new Search()) > 0); + } + + @Test + public void testSearch_admin() + { + Search search = new Search(); + search.addFilter(new Filter("username", "admin")); + List users = userDAO.search(search); + assertTrue(users.size() > 0); + GSUser user = users.get(0); + assertTrue(user.getName().length() > 0); + } + + @Test + public void testSearch_groups() + { + Search search = new Search(); + search.addFilter(new Filter("username", "destination1")); + List users = userDAO.search(search); + assertTrue(users.size() == 1); + GSUser user = users.get(0); + assertTrue(user.getName().equals("destination1")); + } + + @Test + public void test_getFullByName_groups() + { + GSUser user = userDAO.getFull("destination2"); + assertNotNull(user); + assertEquals("destination2", user.getName()); + assertEquals(2, user.getGroups().size()); + + Set gnames = new HashSet<>(); + for (UserGroup g : user.getGroups()) { + LOGGER.debug("group : " + g.getName()); + gnames.add(g.getName()); + } + + assertTrue(gnames.contains("destination")); + assertTrue(gnames.contains("otherGroup")); + } + } diff --git a/src/services/modules/ldap/src/test/java/org/geoserver/geofence/ldap/dao/impl/UserGroupDAOLdapImplTest.java b/src/services/modules/ldap/src/test/java/org/geoserver/geofence/ldap/dao/impl/UserGroupDAOLdapImplTest.java index 1da27037..7d3cb2f6 100644 --- a/src/services/modules/ldap/src/test/java/org/geoserver/geofence/ldap/dao/impl/UserGroupDAOLdapImplTest.java +++ b/src/services/modules/ldap/src/test/java/org/geoserver/geofence/ldap/dao/impl/UserGroupDAOLdapImplTest.java @@ -1,13 +1,10 @@ -/* (c) 2014 Open Source Geospatial Foundation - all rights reserved +/* (c) 2014 - 2017 Open Source Geospatial Foundation - all rights reserved * This code is licensed under the GPL 2.0 license, available at the root * application directory. */ - package org.geoserver.geofence.ldap.dao.impl; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; +import static org.junit.Assert.*; import org.geoserver.geofence.core.model.UserGroup; import java.util.List; @@ -16,43 +13,57 @@ import com.googlecode.genericdao.search.Filter; import com.googlecode.genericdao.search.Search; - - +import edu.emory.mathcs.backport.java.util.Arrays; +import java.util.HashSet; +import java.util.Set; /** * @author "Mauro Bartolomeoli - mauro.bartolomeoli@geo-solutions.it" - * + * @author Emanuele Tajariol (etj at geo-solutions.it) */ -public class UserGroupDAOLdapImplTest extends BaseDAOTest { - @Test - public void testFindAll() { - List groups = userGroupDAO.findAll(); - assertTrue(groups.size() > 0); - UserGroup group = groups.get(0); - assertTrue(group.getName().length() > 0); - } - - @Test - public void testFind() { - UserGroup group = userGroupDAO.find(1l); - assertNotNull(group); - assertNotNull(group.getName()); - assertEquals("admin", group.getName()); - } - - @Test - public void testSearch() { - Search search = new Search(); - search.addFilter(new Filter("groupname", "admin")); - - List groups = userGroupDAO.search(search); - assertTrue(groups.size() > 0); - UserGroup group = groups.get(0); - assertTrue(group.getName().length() > 0); - } - - @Test - public void testCount() { - assertTrue(userGroupDAO.count(new Search()) > 0); - } +public class UserGroupDAOLdapImplTest extends BaseDAOTest +{ + + @Test + public void testFindAll() + { + List groups = userGroupDAO.findAll(); + assertTrue("No groups", groups.size() > 0); + UserGroup group = groups.get(0); + assertTrue("Empty group name", group.getName().length() > 0); + + + Set expected = new HashSet<>(Arrays.asList(new String[]{"adminGroup", "other", "otherGroup", "destination"})); + Set found = new HashSet<>(); + for (UserGroup g : groups) { + LOGGER.debug("Found group " + g); + found.add(g.getName()); + } + assertEquals("Bad group set found", expected, found); + } + + @Test + public void testFind() + { + UserGroup group = userGroupDAO.find(1l); + assertNull("Find by id should be disabled in LDAP", group); + } + + @Test + public void testSearch() + { + Search search = new Search(); + search.addFilter(new Filter("groupname", "adminGroup")); + + List groups = userGroupDAO.search(search); + assertTrue(groups.size() == 1); + UserGroup group = groups.get(0); + assertEquals("adminGroup", group.getName()); + } + + @Test + public void testCount() + { + assertEquals(4, userGroupDAO.count(new Search())); + } } diff --git a/src/services/modules/ldap/src/test/resources/applicationContext.xml b/src/services/modules/ldap/src/test/resources/applicationContext.xml deleted file mode 100644 index 8b4e35c1..00000000 --- a/src/services/modules/ldap/src/test/resources/applicationContext.xml +++ /dev/null @@ -1,84 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/services/modules/ldap/src/test/resources/data.ldif b/src/services/modules/ldap/src/test/resources/data.ldif index 6c5a19ac..743b3c40 100644 --- a/src/services/modules/ldap/src/test/resources/data.ldif +++ b/src/services/modules/ldap/src/test/resources/data.ldif @@ -14,60 +14,82 @@ objectClass: top objectClass: organizationalUnit ou: Groups -dn: cn=admin,ou=Groups,dc=example,dc=com +dn: cn=adminRole,ou=Groups,dc=example,dc=com objectClass: top objectClass: organizationalRole -objectClass: groupOfNames -cn: admin -member: admin -telephoneNumber: 1 +cn: adminRole +telephoneNumber: 10 +dn: cn=adminGroup,ou=Groups,dc=example,dc=com +objectClass: top +objectClass: groupOfNames +cn: adminGroup +member: cn=admin,ou=People,dc=example,dc=com -dn: uid=admin,ou=People,dc=example,dc=com +dn: cn=admin,ou=People,dc=example,dc=com objectClass: top objectClass: inetOrgPerson givenName: admin sn: admin -uid: admin cn: admin userPassword: {SHA}0DPiKuNIrrVmD8IUCuw1hQxNqZc= -telephoneNumber: 1 +telephoneNumber: 20 + dn: cn=destination,ou=Groups,dc=example,dc=com objectClass: top -objectClass: organizationalRole objectClass: groupOfNames cn: destination -member: destination -telephoneNumber: 2 +member: cn=destination1,ou=People,dc=example,dc=com +member: cn=destination2,ou=People,dc=example,dc=com +# test ldap server won't return the dn +member: cn=destination1 +member: cn=destination2 + -dn: uid=destination,ou=People,dc=example,dc=com +dn: cn=otherGroup,ou=Groups,dc=example,dc=com +objectClass: top +objectClass: groupOfNames +cn: otherGroup +member: cn=destination2,ou=People,dc=example,dc=com +member: cn=destination2 + + +dn: cn=destination1,ou=People,dc=example,dc=com objectClass: top objectClass: inetOrgPerson -givenName: destination -sn: destination -uid: destination -cn: destination +givenName: destination1 +sn: destination1 +cn: destination1 userPassword: {SHA}DPG8hLuLrKgE+QFaFY6IZC1BX/o= -mail: destination@destination.it -telephoneNumber: 2 +mail: destination1@destination.it +telephoneNumber: 41 + + +dn: cn=destination2,ou=People,dc=example,dc=com +objectClass: top +objectClass: inetOrgPerson +givenName: destination2 +sn: destination2 +cn: destination2 +userPassword: {SHA}DPG8hLuLrKgE+QFaFY6IZC1BX/o= +mail: destination2@destination.it +telephoneNumber: 42 + dn: cn=other,ou=Groups,dc=example,dc=com objectClass: top -objectClass: organizationalRole objectClass: groupOfNames cn: other -member: other -telephoneNumber: 3 +member: cn=other,ou=People,dc=example,dc=com -dn: uid=other,ou=People,dc=example,dc=com +dn: cn=other,ou=People,dc=example,dc=com objectClass: top objectClass: inetOrgPerson givenName: other sn: other -uid: other cn: other userPassword: {SHA}0JQeaNqPOBUf+Gph/Fn3xc+fyqI= -telephoneNumber: 3 +telephoneNumber: 60 diff --git a/src/services/modules/ldap/src/test/resources/geofence-datasource-ovr.properties b/src/services/modules/ldap/src/test/resources/geofence-datasource-ovr.properties new file mode 100644 index 00000000..f359a900 --- /dev/null +++ b/src/services/modules/ldap/src/test/resources/geofence-datasource-ovr.properties @@ -0,0 +1,40 @@ +# (c) 2017 Open Source Geospatial Foundation - all rights reserved +# This code is licensed under the GPL 2.0 license, available at the root application directory. + +# Some DB param overrides +geofenceEntityManagerFactory.jpaPropertyMap[hibernate.hbm2ddl.auto]=update +geofenceVendorAdapter.generateDdl=true +geofenceVendorAdapter.showSql=false + +# Switch the DAOs from DB to LDAP +geofence_dao_registry.selectedType = LDAP + +# LDAP directory connection params +geofenceLdapSource.url = ldap://localhost:10389 +geofenceLdapSource.base = dc=example,dc=com +geofenceLdapSource.userDn = uid=admin,ou=system +geofenceLdapSource.password = secret + +# User filters +gsUserDAO_LDAP.searchBase = ou=People +gsUserDAO_LDAP.searchFilter = objectClass=inetOrgPerson +#gsUserDAO_LDAP.userDn = uid=%s,ou=People +#gsUserDAO_LDAP.userDn = cn=%s +#gsUserDAO_LDAP.groupsBase = ou=Groups + +# Group filters +userGroupDAO_LDAP.searchBase = ou=Groups +userGroupDAO_LDAP.searchFilter = objectClass=groupOfNames + +# Mapping LDAP user attributes to internal +geofenceLdapUserMapper.map[id] = distinguishedName +geofenceLdapUserMapper.map[username] = cn +geofenceLdapUserMapper.map[email] = mail +geofenceLdapUserMapper.map[name] = givenName +geofenceLdapUserMapper.map[surname] = sn +geofenceLdapUserMapper.map[password] = userPassword + +# Mapping LDAP group attributes to internal +geofenceLdapGroupMapper.map[id] = distinguishedName +geofenceLdapGroupMapper.map[groupname] = cn +geofenceLdapGroupMapper.map[member] = member diff --git a/src/services/modules/ldap/src/test/resources/geofence-ldap-ovr.properties b/src/services/modules/ldap/src/test/resources/geofence-ldap-ovr.properties deleted file mode 100644 index 5b0e4b9c..00000000 --- a/src/services/modules/ldap/src/test/resources/geofence-ldap-ovr.properties +++ /dev/null @@ -1,5 +0,0 @@ -# /* (c) 2014 Open Source Geospatial Foundation - all rights reserved -# * This code is licensed under the GPL 2.0 license, available at the root -# * application directory. -# */ -# diff --git a/src/services/modules/ldap/src/test/resources/geofence-ldap.properties b/src/services/modules/ldap/src/test/resources/geofence-ldap.properties deleted file mode 100644 index 95c7a18e..00000000 --- a/src/services/modules/ldap/src/test/resources/geofence-ldap.properties +++ /dev/null @@ -1,10 +0,0 @@ -# /* (c) 2014 Open Source Geospatial Foundation - all rights reserved -# * This code is licensed under the GPL 2.0 license, available at the root -# * application directory. -# */ -# -geofenceLdapSource.url=ldap://localhost:10389 -geofenceLdapSource.base=dc=example,dc=com -geofenceLdapSource.user=uid=admin,ou=system -geofenceLdapSource.password=secret - diff --git a/src/services/modules/ldap/src/test/resources/log4j.properties b/src/services/modules/ldap/src/test/resources/log4j.properties new file mode 100644 index 00000000..e908351a --- /dev/null +++ b/src/services/modules/ldap/src/test/resources/log4j.properties @@ -0,0 +1,18 @@ +# /* (c) 2017 Open Source Geospatial Foundation - all rights reserved +# * This code is licensed under the GPL 2.0 license, available at the root +# * application directory. +# */ +# +log4j.rootLogger=INFO, consoleAppender + +log4j.appender.consoleAppender=org.apache.log4j.ConsoleAppender +log4j.appender.consoleAppender.layout=org.apache.log4j.PatternLayout +log4j.appender.consoleAppender.layout.ConversionPattern=%p %d{yyyy-MM-dd HH:mm:ss.SSS} %C{1}.%M() %-3L - %m %n + +log4j.logger.org.hibernate=WARN +log4j.logger.com.trg=INFO + +log4j.logger.org.springframework.ldap=ALL + + +log4j.logger.org.geoserver.geofence=DEBUG diff --git a/src/services/modules/login/impl/pom.xml b/src/services/modules/login/impl/pom.xml index ec608d2c..3ca647e2 100644 --- a/src/services/modules/login/impl/pom.xml +++ b/src/services/modules/login/impl/pom.xml @@ -1,6 +1,6 @@ - - - - - javassist javassist @@ -59,29 +54,11 @@ spring-beans - - - - - - org.apache.logging.log4j - log4j-api + log4j + log4j - + commons-httpclient commons-httpclient diff --git a/src/services/modules/login/impl/src/main/java/org/geoserver/geofence/login/LoginServiceImpl.java b/src/services/modules/login/impl/src/main/java/org/geoserver/geofence/login/LoginServiceImpl.java index 91670c76..57617cee 100644 --- a/src/services/modules/login/impl/src/main/java/org/geoserver/geofence/login/LoginServiceImpl.java +++ b/src/services/modules/login/impl/src/main/java/org/geoserver/geofence/login/LoginServiceImpl.java @@ -1,11 +1,10 @@ -/* (c) 2014 Open Source Geospatial Foundation - all rights reserved +/* (c) 2014 - 2017 Open Source Geospatial Foundation - all rights reserved * This code is licensed under the GPL 2.0 license, available at the root * application directory. */ package org.geoserver.geofence.login; -import org.geoserver.geofence.login.LoginService; import javax.annotation.PostConstruct; import javax.annotation.PreDestroy; @@ -16,8 +15,8 @@ import org.geoserver.geofence.login.util.GrantAll; import org.geoserver.geofence.login.util.SessionManager; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; +import org.apache.log4j.LogManager; +import org.apache.log4j.Logger; import org.springframework.beans.factory.DisposableBean; import org.springframework.beans.factory.InitializingBean; diff --git a/src/services/modules/login/impl/src/main/java/org/geoserver/geofence/login/cxf/BasicAuthInterceptor.java b/src/services/modules/login/impl/src/main/java/org/geoserver/geofence/login/cxf/BasicAuthInterceptor.java index ed6ee1d9..009df473 100644 --- a/src/services/modules/login/impl/src/main/java/org/geoserver/geofence/login/cxf/BasicAuthInterceptor.java +++ b/src/services/modules/login/impl/src/main/java/org/geoserver/geofence/login/cxf/BasicAuthInterceptor.java @@ -1,4 +1,4 @@ -/* (c) 2014-2016 Open Source Geospatial Foundation - all rights reserved +/* (c) 2014 - 2017 Open Source Geospatial Foundation - all rights reserved * This code is licensed under the GPL 2.0 license, available at the root * application directory. */ @@ -23,10 +23,8 @@ import org.apache.cxf.message.Exchange; import org.apache.cxf.message.Message; import org.apache.cxf.phase.Phase; -import org.apache.cxf.transport.Conduit; -import org.apache.cxf.ws.addressing.EndpointReferenceType; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; +import org.apache.log4j.LogManager; +import org.apache.log4j.Logger; /** diff --git a/src/services/modules/login/impl/src/main/java/org/geoserver/geofence/login/util/GrantAll.java b/src/services/modules/login/impl/src/main/java/org/geoserver/geofence/login/util/GrantAll.java index 1650ed26..5f345370 100644 --- a/src/services/modules/login/impl/src/main/java/org/geoserver/geofence/login/util/GrantAll.java +++ b/src/services/modules/login/impl/src/main/java/org/geoserver/geofence/login/util/GrantAll.java @@ -1,13 +1,10 @@ -/* (c) 2014 Open Source Geospatial Foundation - all rights reserved +/* (c) 2014 - 2017 Open Source Geospatial Foundation - all rights reserved * This code is licensed under the GPL 2.0 license, available at the root * application directory. */ package org.geoserver.geofence.login.util; -import java.io.UnsupportedEncodingException; -import java.security.MessageDigest; -import java.security.NoSuchAlgorithmException; import java.util.Arrays; import org.geoserver.geofence.api.AuthProvider; @@ -15,8 +12,8 @@ import org.geoserver.geofence.api.dto.GrantedAuths; import org.geoserver.geofence.api.exception.AuthException; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; +import org.apache.log4j.LogManager; +import org.apache.log4j.Logger; /** @@ -39,7 +36,6 @@ public GrantedAuths login(String username, String password, String pwFromDb) thr GrantedAuths ga = new GrantedAuths(); String hashedPw = MD5Util.getHash(password); -// LOGGER.info("storedPassword: " + pwFromDb); LOGGER.info("hashedPw: " + hashedPw); if (hashedPw.equals(pwFromDb)) { diff --git a/src/services/modules/login/impl/src/main/java/org/geoserver/geofence/login/util/MD5Util.java b/src/services/modules/login/impl/src/main/java/org/geoserver/geofence/login/util/MD5Util.java index 8697e4e1..d6e8e502 100644 --- a/src/services/modules/login/impl/src/main/java/org/geoserver/geofence/login/util/MD5Util.java +++ b/src/services/modules/login/impl/src/main/java/org/geoserver/geofence/login/util/MD5Util.java @@ -1,4 +1,4 @@ -/* (c) 2014, 2015 Open Source Geospatial Foundation - all rights reserved +/* (c) 2014 - 2017 Open Source Geospatial Foundation - all rights reserved * This code is licensed under the GPL 2.0 license, available at the root * application directory. */ @@ -9,8 +9,8 @@ import java.io.UnsupportedEncodingException; import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; +import org.apache.log4j.LogManager; +import org.apache.log4j.Logger; /** * diff --git a/src/services/modules/login/impl/src/main/java/org/geoserver/geofence/login/util/SessionManager.java b/src/services/modules/login/impl/src/main/java/org/geoserver/geofence/login/util/SessionManager.java index e343fb56..64fe6417 100644 --- a/src/services/modules/login/impl/src/main/java/org/geoserver/geofence/login/util/SessionManager.java +++ b/src/services/modules/login/impl/src/main/java/org/geoserver/geofence/login/util/SessionManager.java @@ -1,4 +1,4 @@ -/* (c) 2014 Open Source Geospatial Foundation - all rights reserved +/* (c) 2014 - 2017 Open Source Geospatial Foundation - all rights reserved * This code is licensed under the GPL 2.0 license, available at the root * application directory. */ @@ -11,10 +11,8 @@ import org.geoserver.geofence.api.dto.GrantedAuths; import org.geoserver.geofence.api.exception.AuthException; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; - - +import org.apache.log4j.LogManager; +import org.apache.log4j.Logger; /** * diff --git a/src/services/modules/login/impl/src/test/resources/applicationContext-test.xml b/src/services/modules/login/impl/src/test/resources/applicationContext-test.xml index 0d008a8f..f12d4e91 100644 --- a/src/services/modules/login/impl/src/test/resources/applicationContext-test.xml +++ b/src/services/modules/login/impl/src/test/resources/applicationContext-test.xml @@ -1,31 +1,18 @@ - - - - - - - - - - - diff --git a/src/services/modules/rest/api/pom.xml b/src/services/modules/rest/api/pom.xml index 9297fe1e..c5468489 100644 --- a/src/services/modules/rest/api/pom.xml +++ b/src/services/modules/rest/api/pom.xml @@ -1,6 +1,6 @@ diff --git a/src/services/modules/rest/client/src/test/java/org/geoserver/geofence/services/rest/GeoFenceClientTest.java b/src/services/modules/rest/client/src/test/java/org/geoserver/geofence/services/rest/GeoFenceClientTest.java index e7b72949..ad4bd132 100644 --- a/src/services/modules/rest/client/src/test/java/org/geoserver/geofence/services/rest/GeoFenceClientTest.java +++ b/src/services/modules/rest/client/src/test/java/org/geoserver/geofence/services/rest/GeoFenceClientTest.java @@ -1,4 +1,4 @@ -/* (c) 2014, 2015 Open Source Geospatial Foundation - all rights reserved +/* (c) 2014 - 2017 Open Source Geospatial Foundation - all rights reserved * This code is licensed under the GPL 2.0 license, available at the root * application directory. */ @@ -10,17 +10,19 @@ import org.geoserver.geofence.services.dto.ShortGroup; import org.geoserver.geofence.services.dto.ShortInstance; import org.geoserver.geofence.services.rest.model.RESTInputGroup; +import org.geoserver.geofence.services.rest.model.RESTInputInstance; import org.geoserver.geofence.services.rest.model.RESTInputRule; import org.geoserver.geofence.services.rest.model.RESTInputUser; import org.geoserver.geofence.services.rest.model.RESTOutputRule; import org.geoserver.geofence.services.rest.model.RESTOutputRuleList; +import org.geoserver.geofence.services.rest.model.RESTRulePosition; import org.geoserver.geofence.services.rest.model.RESTShortUser; import org.geoserver.geofence.services.rest.model.util.IdName; import java.net.ConnectException; import java.util.Arrays; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; -import org.geoserver.geofence.services.rest.model.RESTRulePosition; +import javax.ws.rs.core.Response; +import org.apache.log4j.LogManager; +import org.apache.log4j.Logger; import org.junit.AfterClass; import org.junit.Before; @@ -217,6 +219,57 @@ public void testReassign() { assertEquals(1, client.getUserService().get("pippo").getGroups().size()); } + @Test + public void testBaseRule() { + GeoFenceClient client = createClient(); + + String roleName = "RN0"; + String instanceName = "I0"; + String ipaddress = "10.11.12.0/24"; + String service = "S0"; + String request = "RQ0"; + String workspace = "WS0"; + String layer = "L0"; + + RESTInputInstance inputInstance = new RESTInputInstance(); + inputInstance.setName(instanceName); + inputInstance.setDescription("test instance"); + inputInstance.setBaseURL("http://localhost"); + inputInstance.setPassword("password"); + inputInstance.setUsername("username"); + + client.getGSInstanceService().insert(inputInstance); + + RESTInputRule inputRule = new RESTInputRule(); + inputRule.setRolename(roleName); + inputRule.setInstance(new IdName(instanceName)); + inputRule.setIpaddress(ipaddress); + inputRule.setService(service); + inputRule.setRequest(request); + inputRule.setWorkspace(workspace); + inputRule.setLayer(layer); + inputRule.setGrant(GrantType.ALLOW); + inputRule.setPosition(new RESTRulePosition(RESTRulePosition.RulePosition.offsetFromTop, 0)); + + Response response = client.getRuleService().insert(inputRule); + assertNotNull(response.getEntityTag()); + String id = response.getEntityTag().getValue(); + assertNotNull(id); + + RESTOutputRule outRule = client.getRuleService().get(Long.parseLong(id)); + assertNotNull(outRule); + + assertEquals(roleName, outRule.getRolename()); + assertEquals(instanceName, outRule.getInstance().getName()); + assertEquals(ipaddress, outRule.getIpaddress()); + assertEquals(service, outRule.getService()); + assertEquals(request, outRule.getRequest()); + assertEquals(workspace, outRule.getWorkspace()); + assertEquals(layer, outRule.getLayer()); + assertEquals(GrantType.ALLOW, outRule.getGrant()); + + } + protected boolean pingGeoFence(GeoFenceClient client) { try { client.getUserService().count("*"); diff --git a/src/services/modules/rest/impl/pom.xml b/src/services/modules/rest/impl/pom.xml index 8ddf9182..e9f1bb2c 100644 --- a/src/services/modules/rest/impl/pom.xml +++ b/src/services/modules/rest/impl/pom.xml @@ -1,6 +1,6 @@ + + + + + + + + GeoFence rulez + + + + + + + + + + + + + + + + + + + + + +
idpriuserroleinstanceIPservicereqworkspacelayergrantconstraints
+ + +
+ + + + + + + + + + + + + + + + + + + + + +
+
+ + + + ATTR: + + + + +
diff --git a/src/services/modules/rest/test/pom.xml b/src/services/modules/rest/test/pom.xml index 0c407d46..ceb18145 100644 --- a/src/services/modules/rest/test/pom.xml +++ b/src/services/modules/rest/test/pom.xml @@ -1,14 +1,15 @@ - - 4.0.0 + + + 4.0.0 org.geoserver.geofence @@ -95,9 +96,10 @@ dom4j dom4j
+ - org.apache.logging.log4j - log4j-api + log4j + log4j diff --git a/src/services/modules/rest/test/src/main/java/org/geoserver/geofence/services/servicetest/MainTest.java b/src/services/modules/rest/test/src/main/java/org/geoserver/geofence/services/servicetest/MainTest.java index 36f8f827..06175592 100644 --- a/src/services/modules/rest/test/src/main/java/org/geoserver/geofence/services/servicetest/MainTest.java +++ b/src/services/modules/rest/test/src/main/java/org/geoserver/geofence/services/servicetest/MainTest.java @@ -1,4 +1,4 @@ -/* (c) 2014 Open Source Geospatial Foundation - all rights reserved +/* (c) 2014 - 2017 Open Source Geospatial Foundation - all rights reserved * This code is licensed under the GPL 2.0 license, available at the root * application directory. */ @@ -27,8 +27,8 @@ import org.geoserver.geofence.services.dto.ShortGroup; import org.geoserver.geofence.services.rest.utils.InstanceCleaner; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; +import org.apache.log4j.LogManager; +import org.apache.log4j.Logger; import org.springframework.beans.factory.InitializingBean; diff --git a/src/services/pom.xml b/src/services/pom.xml index 11d2462f..7ec61b2d 100644 --- a/src/services/pom.xml +++ b/src/services/pom.xml @@ -1,11 +1,9 @@ 4.0.0 @@ -49,10 +47,10 @@ 1.3.03 2.1 - 3.6.0.Final + 3.6.0.Final 1.1.1 1.1.0 - + 1.1.1 2.3 3.2 @@ -188,7 +186,7 @@ geofence-rest-test ${geofence-version}
- + org.geoserver.geofence geofence-ldap @@ -222,6 +220,8 @@ + + + + + + log4j + log4j + 1.2.17 @@ -408,9 +410,9 @@ ${javax-mail-version} - - - + + + javax.xml.bind jaxb-api @@ -422,18 +424,9 @@ 2.2.11 - - - - - - - - + + + org.springframework spring-core @@ -616,7 +609,7 @@ javax.persistence persistence-api - + com.googlecode.genericdao @@ -808,8 +801,8 @@ maven-compiler-plugin 3.1 - 1.6 - 1.6 + 1.8 + 1.8 true UTF-8 - +