You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@syncope.apache.org by gi...@apache.org on 2015/12/24 16:07:57 UTC

syncope git commit: [SYNCOPE-719] Self registration and password reset are visible only if enabled

Repository: syncope
Updated Branches:
  refs/heads/master 851fead53 -> accc6fe7b


[SYNCOPE-719] Self registration and password reset are visible only if enabled


Project: http://git-wip-us.apache.org/repos/asf/syncope/repo
Commit: http://git-wip-us.apache.org/repos/asf/syncope/commit/accc6fe7
Tree: http://git-wip-us.apache.org/repos/asf/syncope/tree/accc6fe7
Diff: http://git-wip-us.apache.org/repos/asf/syncope/diff/accc6fe7

Branch: refs/heads/master
Commit: accc6fe7ba153df130167fa12cbf6c4243600d4f
Parents: 851fead
Author: giacomolm <gi...@hotmail.it>
Authored: Thu Dec 24 16:06:44 2015 +0100
Committer: giacomolm <gi...@hotmail.it>
Committed: Thu Dec 24 16:06:44 2015 +0100

----------------------------------------------------------------------
 .../enduser/SyncopeEnduserApplication.java      | 11 +++
 .../enduser/adapters/SyncopeTOAdapter.java      | 41 ++++++++++++
 .../client/enduser/model/SyncopeTORequest.java  | 70 ++++++++++++++++++++
 .../client/enduser/resources/InfoResource.java  | 64 ++++++++++++++++++
 .../resources/META-INF/resources/app/index.html |  1 +
 .../resources/META-INF/resources/app/js/app.js  |  4 +-
 .../app/js/controllers/LoginController.js       | 30 ++++++++-
 .../resources/app/js/services/infoService.js    | 42 ++++++++++++
 .../META-INF/resources/app/views/self.html      | 10 ++-
 9 files changed, 268 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/syncope/blob/accc6fe7/client/enduser/src/main/java/org/apache/syncope/client/enduser/SyncopeEnduserApplication.java
----------------------------------------------------------------------
diff --git a/client/enduser/src/main/java/org/apache/syncope/client/enduser/SyncopeEnduserApplication.java b/client/enduser/src/main/java/org/apache/syncope/client/enduser/SyncopeEnduserApplication.java
index c708502..23ee026 100644
--- a/client/enduser/src/main/java/org/apache/syncope/client/enduser/SyncopeEnduserApplication.java
+++ b/client/enduser/src/main/java/org/apache/syncope/client/enduser/SyncopeEnduserApplication.java
@@ -27,6 +27,7 @@ import java.util.List;
 import java.util.Locale;
 import java.util.Properties;
 import org.apache.commons.io.FileUtils;
+import org.apache.syncope.client.enduser.resources.InfoResource;
 import org.apache.syncope.client.enduser.resources.LoginResource;
 import org.apache.syncope.client.enduser.resources.LogoutResource;
 import org.apache.syncope.client.enduser.resources.SchemaResource;
@@ -189,6 +190,16 @@ public class SyncopeEnduserApplication extends WebApplication implements Seriali
             }
         });
 
+        mountResource("/api/info", new ResourceReference("info") {
+
+            private static final long serialVersionUID = -128426276529456602L;
+
+            @Override
+            public IResource getResource() {
+                return new InfoResource();
+            }
+        });
+
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/syncope/blob/accc6fe7/client/enduser/src/main/java/org/apache/syncope/client/enduser/adapters/SyncopeTOAdapter.java
----------------------------------------------------------------------
diff --git a/client/enduser/src/main/java/org/apache/syncope/client/enduser/adapters/SyncopeTOAdapter.java b/client/enduser/src/main/java/org/apache/syncope/client/enduser/adapters/SyncopeTOAdapter.java
new file mode 100644
index 0000000..f6103e2
--- /dev/null
+++ b/client/enduser/src/main/java/org/apache/syncope/client/enduser/adapters/SyncopeTOAdapter.java
@@ -0,0 +1,41 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.syncope.client.enduser.adapters;
+
+import org.apache.syncope.client.enduser.model.SyncopeTORequest;
+import org.apache.syncope.common.lib.to.SyncopeTO;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class SyncopeTOAdapter {
+
+    private static final Logger LOG = LoggerFactory.getLogger(SyncopeTOAdapter.class);
+
+    public SyncopeTORequest toSyncopeTORequest(final SyncopeTO syncopeTO) {
+
+        final SyncopeTORequest syncopeTORequest = new SyncopeTORequest();
+        syncopeTORequest.setPwdResetAllowed(syncopeTO.isPwdResetAllowed());
+        syncopeTORequest.setSelfRegAllowed(syncopeTO.isSelfRegAllowed());
+        syncopeTORequest.setPwdResetRequiringSecurityQuestions(syncopeTO.isPwdResetRequiringSecurityQuestions());
+        syncopeTORequest.setVersion(syncopeTO.getVersion());
+
+        return syncopeTORequest;
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/syncope/blob/accc6fe7/client/enduser/src/main/java/org/apache/syncope/client/enduser/model/SyncopeTORequest.java
----------------------------------------------------------------------
diff --git a/client/enduser/src/main/java/org/apache/syncope/client/enduser/model/SyncopeTORequest.java b/client/enduser/src/main/java/org/apache/syncope/client/enduser/model/SyncopeTORequest.java
new file mode 100644
index 0000000..0b3dbff
--- /dev/null
+++ b/client/enduser/src/main/java/org/apache/syncope/client/enduser/model/SyncopeTORequest.java
@@ -0,0 +1,70 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.syncope.client.enduser.model;
+
+import java.io.Serializable;
+
+public class SyncopeTORequest implements Serializable {
+
+    private static final long serialVersionUID = -6763020920564016374L;
+
+    private String version;
+
+    private boolean selfRegAllowed;
+
+    private boolean pwdResetAllowed;
+
+    private boolean pwdResetRequiringSecurityQuestions;
+
+    public SyncopeTORequest() {
+    }
+
+    public String getVersion() {
+        return version;
+    }
+
+    public boolean isSelfRegAllowed() {
+        return selfRegAllowed;
+    }
+
+    public boolean isPwdResetAllowed() {
+        return pwdResetAllowed;
+    }
+
+    public boolean isPwdResetRequiringSecurityQuestions() {
+        return pwdResetRequiringSecurityQuestions;
+    }
+
+    public void setVersion(final String version) {
+        this.version = version;
+    }
+
+    public void setSelfRegAllowed(final boolean selfRegAllowed) {
+        this.selfRegAllowed = selfRegAllowed;
+    }
+
+    public void setPwdResetAllowed(final boolean pwdResetAllowed) {
+        this.pwdResetAllowed = pwdResetAllowed;
+    }
+
+    public void setPwdResetRequiringSecurityQuestions(final boolean pwdResetRequiringSecurityQuestions) {
+        this.pwdResetRequiringSecurityQuestions = pwdResetRequiringSecurityQuestions;
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/syncope/blob/accc6fe7/client/enduser/src/main/java/org/apache/syncope/client/enduser/resources/InfoResource.java
----------------------------------------------------------------------
diff --git a/client/enduser/src/main/java/org/apache/syncope/client/enduser/resources/InfoResource.java b/client/enduser/src/main/java/org/apache/syncope/client/enduser/resources/InfoResource.java
new file mode 100644
index 0000000..46c3aeb
--- /dev/null
+++ b/client/enduser/src/main/java/org/apache/syncope/client/enduser/resources/InfoResource.java
@@ -0,0 +1,64 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.syncope.client.enduser.resources;
+
+import java.io.IOException;
+import org.apache.syncope.client.enduser.SyncopeEnduserSession;
+import org.apache.syncope.client.enduser.adapters.SyncopeTOAdapter;
+import org.apache.syncope.core.misc.serialization.POJOHelper;
+import org.apache.wicket.request.resource.IResource;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class InfoResource extends AbstractBaseResource {
+
+    private static final Logger LOG = LoggerFactory.getLogger(InfoResource.class);
+
+    private static final long serialVersionUID = 6453101466981543020L;
+
+    private final SyncopeTOAdapter syncopeTOAdapter;
+
+    public InfoResource() {
+        syncopeTOAdapter = new SyncopeTOAdapter();
+    }
+
+    @Override
+    protected ResourceResponse newResourceResponse(final IResource.Attributes attributes) {
+
+        ResourceResponse response = new ResourceResponse();
+        int responseStatus = 200;
+
+        try {
+            response.setWriteCallback(new WriteCallback() {
+
+                @Override
+                public void writeData(final IResource.Attributes attributes) throws IOException {
+                    attributes.getResponse().write(POJOHelper.serialize(syncopeTOAdapter.toSyncopeTORequest(
+                            SyncopeEnduserSession.get().getSyncopeTO())));
+                }
+            });
+        } catch (Exception e) {
+            LOG.error("Error retrieving syncope info", e);
+            responseStatus = 500;
+        }
+
+        response.setStatusCode(responseStatus);
+        return response;
+    }
+}

http://git-wip-us.apache.org/repos/asf/syncope/blob/accc6fe7/client/enduser/src/main/resources/META-INF/resources/app/index.html
----------------------------------------------------------------------
diff --git a/client/enduser/src/main/resources/META-INF/resources/app/index.html b/client/enduser/src/main/resources/META-INF/resources/app/index.html
index 6cb7ae6..94ff7bf 100644
--- a/client/enduser/src/main/resources/META-INF/resources/app/index.html
+++ b/client/enduser/src/main/resources/META-INF/resources/app/index.html
@@ -81,6 +81,7 @@ under the License.
     <script src="js/services/schemaService.js"></script>
     <script src="js/services/realmService.js"></script>
     <script src="js/services/securityQuestionService.js"></script>
+    <script src="js/services/infoService.js"></script>
     <!--controllers-->
     <script src="js/controllers/HomeController.js"></script>
     <script src="js/controllers/LoginController.js"></script>

http://git-wip-us.apache.org/repos/asf/syncope/blob/accc6fe7/client/enduser/src/main/resources/META-INF/resources/app/js/app.js
----------------------------------------------------------------------
diff --git a/client/enduser/src/main/resources/META-INF/resources/app/js/app.js b/client/enduser/src/main/resources/META-INF/resources/app/js/app.js
index d747689..387115c 100644
--- a/client/enduser/src/main/resources/META-INF/resources/app/js/app.js
+++ b/client/enduser/src/main/resources/META-INF/resources/app/js/app.js
@@ -23,6 +23,7 @@ angular.module('home', []);
 angular.module('login', []);
 angular.module('language', []);
 angular.module('self', []);
+angular.module('info', []);
 
 // Declare app level module which depends on views, and components
 var app = angular.module('SyncopeEnduserApp', [
@@ -37,7 +38,8 @@ var app = angular.module('SyncopeEnduserApp', [
   'home',
   'login',
   'language',
-  'self'
+  'self',
+  'info'
 ]);
 
 app.config(['$stateProvider', '$urlRouterProvider', '$httpProvider', 'growlProvider',

http://git-wip-us.apache.org/repos/asf/syncope/blob/accc6fe7/client/enduser/src/main/resources/META-INF/resources/app/js/controllers/LoginController.js
----------------------------------------------------------------------
diff --git a/client/enduser/src/main/resources/META-INF/resources/app/js/controllers/LoginController.js b/client/enduser/src/main/resources/META-INF/resources/app/js/controllers/LoginController.js
index c962571..9256668 100644
--- a/client/enduser/src/main/resources/META-INF/resources/app/js/controllers/LoginController.js
+++ b/client/enduser/src/main/resources/META-INF/resources/app/js/controllers/LoginController.js
@@ -20,7 +20,8 @@
 'use strict';
 
 angular.module("login").controller("LoginController", ['$scope', '$rootScope', '$http', '$location', '$cookies',
-  'AuthService', 'growl', function ($scope, $rootScope, $http, $location, $cookies, AuthService, growl) {
+  'AuthService', 'growl', 'InfoService', function ($scope, $rootScope, $http, $location, $cookies, AuthService, growl,
+          InfoService) {
 
     $scope.credentials = {
       username: '',
@@ -90,4 +91,31 @@ angular.module("login").controller("LoginController", ['$scope', '$rootScope', '
       });
     };
 
+    $scope.selfRegAllowed = false;
+    $scope.pwdResetAllowed = false;
+    $scope.version = "";
+    
+    //info settings are initialized every time an user open the login page
+    InfoService.getInfo().then(
+            function (response) {
+              $scope.pwdResetAllowed = response.pwdResetAllowed;              
+              $scope.selfRegAllowed = response.selfRegAllowed;
+              $scope.version = response.version;
+            },
+            function () {
+              console.log("Something went wrong while accessing info resource", response);
+            });
+            
+    $scope.isSelfRegAllowed = function () {
+      return $scope.selfRegAllowed == true;
+    };
+    
+    $scope.isPwdResetAllowed = function () {
+      return $scope.pwdResetAllowed == true;
+    };
+
+    $scope.getVersion = function () {
+      return $scope.version;
+    };
+
   }]);

http://git-wip-us.apache.org/repos/asf/syncope/blob/accc6fe7/client/enduser/src/main/resources/META-INF/resources/app/js/services/infoService.js
----------------------------------------------------------------------
diff --git a/client/enduser/src/main/resources/META-INF/resources/app/js/services/infoService.js b/client/enduser/src/main/resources/META-INF/resources/app/js/services/infoService.js
new file mode 100644
index 0000000..1f71e27
--- /dev/null
+++ b/client/enduser/src/main/resources/META-INF/resources/app/js/services/infoService.js
@@ -0,0 +1,42 @@
+/* 
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+'use strict';
+
+angular.module('info')
+        .factory('InfoService', ['$resource', '$q', '$http',
+          function ($resource, $q, $http) {
+
+            var infoService = {};
+
+            infoService.getInfo = function () {
+              return $http
+                      .get('/syncope-enduser/api/info')
+                      .then(function (response) {
+                        return response.data;
+                      }, function (response) {
+                        console.log("Something went wrong while retrieving info resource", response);
+                      });
+            };
+
+            return infoService;
+
+          }]);
+
+

http://git-wip-us.apache.org/repos/asf/syncope/blob/accc6fe7/client/enduser/src/main/resources/META-INF/resources/app/views/self.html
----------------------------------------------------------------------
diff --git a/client/enduser/src/main/resources/META-INF/resources/app/views/self.html b/client/enduser/src/main/resources/META-INF/resources/app/views/self.html
index bfd2fa3..1a87c46 100644
--- a/client/enduser/src/main/resources/META-INF/resources/app/views/self.html
+++ b/client/enduser/src/main/resources/META-INF/resources/app/views/self.html
@@ -83,13 +83,17 @@ under the License.
           </div>
 
         </div>
-        <div class="text-center" ng-show="!isLogged()">
+        <div class="text-center" ng-show="!isLogged() && isSelfRegAllowed()">
           <a href="javascript:void(0);" class="btn btn-link" ng-click="selfCreate()">Self Registration</a>
-          <!--<a href="javascript:void(0);" class="btn btn-link" ng-click="passwordReset()">Password Reset</a>-->
+
           <!--      <div id="initialLoaderDiv">
                   <img src="img/busy.gif" class="ajax-loader"/>
                 </div>-->
-        </div> <!-- /#login-container -->
+        </div>
+        <div class="text-center" ng-show="!isLogged() && isPwdResetAllowed()">
+          <a href="javascript:void(0);" class="btn btn-link" ng-click="passwordReset()">Password Reset</a>
+        </div>
+        <!-- /#login-container -->
       </div> <!-- /#login -->
     </div>