Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id DFEF7200ACC for ; Mon, 2 May 2016 17:33:51 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id DEB5E1609B1; Mon, 2 May 2016 17:33:51 +0200 (CEST) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 7838A1609B0 for ; Mon, 2 May 2016 17:33:50 +0200 (CEST) Received: (qmail 94424 invoked by uid 500); 2 May 2016 15:33:49 -0000 Mailing-List: contact commits-help@syncope.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@syncope.apache.org Delivered-To: mailing list commits@syncope.apache.org Received: (qmail 94234 invoked by uid 99); 2 May 2016 15:33:49 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 02 May 2016 15:33:49 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 310FFDFC77; Mon, 2 May 2016 15:33:49 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: ilgrosso@apache.org To: commits@syncope.apache.org Message-Id: <9d941c2b0bbf4e818540d5cc650da8c3@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: syncope git commit: SYNCOPE-798 now cancel does logout plus refactoring authorization Date: Mon, 2 May 2016 15:33:49 +0000 (UTC) archived-at: Mon, 02 May 2016 15:33:52 -0000 Repository: syncope Updated Branches: refs/heads/master a637694af -> edb0cb33d SYNCOPE-798 now cancel does logout plus refactoring authorization Project: http://git-wip-us.apache.org/repos/asf/syncope/repo Commit: http://git-wip-us.apache.org/repos/asf/syncope/commit/edb0cb33 Tree: http://git-wip-us.apache.org/repos/asf/syncope/tree/edb0cb33 Diff: http://git-wip-us.apache.org/repos/asf/syncope/diff/edb0cb33 Branch: refs/heads/master Commit: edb0cb33d4ca6ac6b993dfc2f8ee536752f17e02 Parents: a637694 Author: Matteo Di Carlo Authored: Tue Apr 26 12:17:55 2016 +0200 Committer: Francesco Chicchiriccò Committed: Mon May 2 17:33:21 2016 +0200 ---------------------------------------------------------------------- .../enduser/SyncopeEnduserApplication.java | 11 ++ .../enduser/resources/AbstractBaseResource.java | 2 +- .../enduser/resources/UserSelfIsLogged.java | 66 ++++++++++ .../resources/META-INF/resources/app/js/app.js | 125 +++++++++++-------- .../app/js/controllers/HomeController.js | 16 --- .../app/js/controllers/LoginController.js | 13 +- .../resources/app/js/services/authService.js | 36 ++---- .../META-INF/resources/app/views/self.html | 6 +- .../resources/app/views/user-credentials.html | 2 +- .../app/views/user-derived-schemas.html | 2 +- .../resources/app/views/user-form-finish.html | 2 +- .../resources/app/views/user-groups.html | 2 +- .../resources/app/views/user-plain-schemas.html | 2 +- .../resources/app/views/user-resources.html | 2 +- .../app/views/user-virtual-schemas.html | 2 +- 15 files changed, 180 insertions(+), 109 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/syncope/blob/edb0cb33/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 9a3e32e..75f758d 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 @@ -18,6 +18,7 @@ */ package org.apache.syncope.client.enduser; +import org.apache.syncope.client.enduser.resources.UserSelfIsLogged; import java.io.File; import java.io.Serializable; import org.apache.syncope.client.enduser.pages.HomePage; @@ -155,6 +156,16 @@ public class SyncopeEnduserApplication extends WebApplication implements Seriali } }); + mountResource("/api/self/islogged", new ResourceReference("userSelfIsLogged") { + + private static final long serialVersionUID = -128426276529456602L; + + @Override + public IResource getResource() { + return new UserSelfIsLogged(); + } + }); + // resource to retrieve info about logged user mountResource("/api/self/read", new ResourceReference("userSelfRead") { http://git-wip-us.apache.org/repos/asf/syncope/blob/edb0cb33/client/enduser/src/main/java/org/apache/syncope/client/enduser/resources/AbstractBaseResource.java ---------------------------------------------------------------------- diff --git a/client/enduser/src/main/java/org/apache/syncope/client/enduser/resources/AbstractBaseResource.java b/client/enduser/src/main/java/org/apache/syncope/client/enduser/resources/AbstractBaseResource.java index a364841..6f38d0d 100644 --- a/client/enduser/src/main/java/org/apache/syncope/client/enduser/resources/AbstractBaseResource.java +++ b/client/enduser/src/main/java/org/apache/syncope/client/enduser/resources/AbstractBaseResource.java @@ -33,7 +33,7 @@ public abstract class AbstractBaseResource extends AbstractResource { private static final long serialVersionUID = -7875801358718612782L; - private static final Logger LOG = LoggerFactory.getLogger(AbstractBaseResource.class); + protected static final Logger LOG = LoggerFactory.getLogger(AbstractBaseResource.class); protected static final ObjectMapper MAPPER = new ObjectMapper(); http://git-wip-us.apache.org/repos/asf/syncope/blob/edb0cb33/client/enduser/src/main/java/org/apache/syncope/client/enduser/resources/UserSelfIsLogged.java ---------------------------------------------------------------------- diff --git a/client/enduser/src/main/java/org/apache/syncope/client/enduser/resources/UserSelfIsLogged.java b/client/enduser/src/main/java/org/apache/syncope/client/enduser/resources/UserSelfIsLogged.java new file mode 100644 index 0000000..d1f0c7a --- /dev/null +++ b/client/enduser/src/main/java/org/apache/syncope/client/enduser/resources/UserSelfIsLogged.java @@ -0,0 +1,66 @@ +/* + * 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 javax.servlet.http.HttpServletRequest; +import javax.ws.rs.core.Response; +import org.apache.syncope.client.enduser.SyncopeEnduserSession; +import org.apache.wicket.request.resource.IResource; + +public class UserSelfIsLogged extends AbstractBaseResource { + + private static final long serialVersionUID = 1L; + + @Override + protected ResourceResponse newResourceResponse(final Attributes attributes) { + + ResourceResponse response = new ResourceResponse(); + + LOG.debug("Checking if user is authenticated"); + + try { + HttpServletRequest request = (HttpServletRequest) attributes.getRequest().getContainerRequest(); + if (!xsrfCheck(request)) { + LOG.error("XSRF TOKEN does not match"); + response.setError(Response.Status.BAD_REQUEST.getStatusCode(), "XSRF TOKEN does not match"); + return response; + } + + response.setWriteCallback(new WriteCallback() { + + @Override + public void writeData(final IResource.Attributes attributes) throws IOException { + attributes.getResponse().write( + Boolean.toString(SyncopeEnduserSession.get().isAuthenticated())); + } + }); + response.setStatusCode(Response.Status.OK.getStatusCode()); + + } catch (Exception e) { + LOG.error("Could not read credentials from request", e); + response.setError(Response.Status.BAD_REQUEST.getStatusCode(), new StringBuilder() + .append("ErrorMessage{{ ") + .append(e.getMessage()) + .append(" }}") + .toString()); + } + return response; + } +} http://git-wip-us.apache.org/repos/asf/syncope/blob/edb0cb33/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 8217dc8..17e0816 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 @@ -61,9 +61,10 @@ app.config(['$stateProvider', '$urlRouterProvider', '$httpProvider', templateUrl: 'views/home.html', controller: 'HomeController', resolve: { - 'authenticated': function (AuthenticationHelper) { - return AuthenticationHelper.authenticated(); - } + 'authenticated': ['AuthService', + function (AuthService) { + return AuthService.islogged() + }] } }) .state('create', { @@ -105,9 +106,10 @@ app.config(['$stateProvider', '$urlRouterProvider', '$httpProvider', url: '/self/update', templateUrl: 'views/editUser.html', resolve: { - 'authenticated': function (AuthenticationHelper) { - return AuthenticationHelper.authenticated(); - } + 'authenticated': ['AuthService', + function (AuthService) { + return AuthService.islogged(); + }] } }) // nested states @@ -117,63 +119,70 @@ app.config(['$stateProvider', '$urlRouterProvider', '$httpProvider', url: '/credentials', templateUrl: 'views/user-credentials.html', resolve: { - 'authenticated': function (AuthenticationHelper) { - return AuthenticationHelper.authenticated(); - } + 'authenticated': ['AuthService', + function (AuthService) { + return AuthService.islogged(); + }] } }) .state('update.plainSchemas', { url: '/plainSchemas', templateUrl: 'views/user-plain-schemas.html', resolve: { - 'authenticated': function (AuthenticationHelper) { - return AuthenticationHelper.authenticated(); - } + 'authenticated': ['AuthService', + function (AuthService) { + return AuthService.islogged(); + }] } }) .state('update.derivedSchemas', { url: '/derivedSchemas', templateUrl: 'views/user-derived-schemas.html', resolve: { - 'authenticated': function (AuthenticationHelper) { - return AuthenticationHelper.authenticated(); - } + 'authenticated': ['AuthService', + function (AuthService) { + return AuthService.islogged(); + }] } }) .state('update.virtualSchemas', { url: '/virtualSchemas', templateUrl: 'views/user-virtual-schemas.html', resolve: { - 'authenticated': function (AuthenticationHelper) { - return AuthenticationHelper.authenticated(); - } + 'authenticated': ['AuthService', + function (AuthService) { + return AuthService.islogged(); + }] } }) .state('update.groups', { url: '/groups', templateUrl: 'views/user-groups.html', resolve: { - 'authenticated': function (AuthenticationHelper) { - return AuthenticationHelper.authenticated(); - } + 'authenticated': ['AuthService', + function (AuthService) { + return AuthService.islogged(); + }] } }) .state('update.resources', { url: '/resources', templateUrl: 'views/user-resources.html', resolve: { - 'authenticated': function (AuthenticationHelper) { - return AuthenticationHelper.authenticated(); - } + 'authenticated': ['AuthService', + function (AuthService) { + return AuthService.islogged(); + }] } }) .state('update.finish', { url: '/finish', templateUrl: 'views/user-form-finish.html', resolve: { - 'authenticated': function (AuthenticationHelper) { - return AuthenticationHelper.authenticated(); - } + 'authenticated': ['AuthService', + function (AuthService) { + return AuthService.islogged(); + }] } }) .state('passwordreset', { @@ -197,7 +206,7 @@ app.config(['$stateProvider', '$urlRouterProvider', '$httpProvider', $httpProvider.defaults.withCredentials = true; $httpProvider.defaults.xsrfCookieName = 'XSRF-TOKEN'; $httpProvider.defaults.xsrfHeaderName = 'X-XSRF-TOKEN'; - + //SYNCOPE-780 $httpProvider.defaults.headers.common["If-Modified-Since"] = "0"; @@ -238,12 +247,10 @@ app.config(['$stateProvider', '$urlRouterProvider', '$httpProvider', }]); -app.run(['$rootScope', '$location', '$cookies', '$state', - function ($rootScope, $location, $cookies, $state) { +app.run(['$rootScope', '$location', '$cookies', '$state', 'AuthService', + function ($rootScope, $location, $cookies, $state, AuthService) { // main program // keep user logged in after page refresh - // check if user is logged or not - $rootScope.currentUser = $cookies.get('currentUser') || null; //If the route change failed due to authentication error, redirect them out $rootScope.$on('$routeChangeError', function (event, current, previous, rejection) { if (rejection === 'Not Authenticated') { @@ -254,10 +261,38 @@ app.run(['$rootScope', '$location', '$cookies', '$state', $rootScope.$on('$stateChangeSuccess', function (event, toState) { if (toState.name === 'create') { $state.go('create.credentials'); + } else if (toState.name === 'update') { $state.go('update.credentials'); - } - else { + + } else if (toState.name.indexOf("update") > -1) { + AuthService.islogged().then(function (response) { + if (response === "true") { + $state.go(toState); + } else { + $state.go('self'); + } + }, function (response) { + console.log("not logged"); + $state.go('self'); + } + ); + + } else if (toState.name === 'home' || toState.name === 'self') { + AuthService.islogged().then(function (response) { + console.log("User logged (change): ", response) + console.log("User logged (change): ", AuthService.islogged()) + if (response === "true") { + $state.go('update.credentials'); + } else { + $state.go('self'); + } + }, function (response) { + console.log("not logged"); + $state.go('self'); + } + ); + } else { $state.go(toState); } }); @@ -361,8 +396,7 @@ app.controller('ApplicationController', ['$scope', '$rootScope', 'InfoService', } }); }, timer); - } - else { + } else { pendingNotifications.each(function (idx, element) { var popup = $(element).data("kendoPopup"); if (popup) { @@ -387,7 +421,6 @@ app.controller('ApplicationController', ['$scope', '$rootScope', 'InfoService', $scope.$on('hideErrorMessage', function (event, popupMessage) { $scope.hideError(popupMessage, $scope.notification); }); - //wizard active element $scope.wizard = { "credentials": {url: "/credentials", templateUrl: "views/user-credentials.html"}, @@ -398,23 +431,5 @@ app.controller('ApplicationController', ['$scope', '$rootScope', 'InfoService', "resources": {url: "/resources", templateUrl: "views/user-resources.html"}, "finish": {url: "/finish", templateUrl: "views/user-form-finish.html"} }; - - } }]); -app.factory('AuthenticationHelper', ['$q', '$rootScope', - function ($q, $rootScope) { - return { - authenticated: function () { - - var currentUser = $rootScope.currentUser; - console.log("AuthenticationHelper, currentUser: ", currentUser); - if (angular.isDefined(currentUser) && currentUser) { - return true; - } else { - console.log("NOT AUTHENTICATED, REDIRECT TO LOGIN PAGE"); - return $q.reject('Not Authenticated'); - } - } - }; - }]); http://git-wip-us.apache.org/repos/asf/syncope/blob/edb0cb33/client/enduser/src/main/resources/META-INF/resources/app/js/controllers/HomeController.js ---------------------------------------------------------------------- diff --git a/client/enduser/src/main/resources/META-INF/resources/app/js/controllers/HomeController.js b/client/enduser/src/main/resources/META-INF/resources/app/js/controllers/HomeController.js index bf86413..0470587 100644 --- a/client/enduser/src/main/resources/META-INF/resources/app/js/controllers/HomeController.js +++ b/client/enduser/src/main/resources/META-INF/resources/app/js/controllers/HomeController.js @@ -20,20 +20,4 @@ 'use strict'; angular.module("home").controller("HomeController", ['$scope', '$http', '$location', function ($scope, $http, $location) { - $scope.title = 'Hello world!'; - $scope.subtitle = 'Hello world SUBTITLE!'; - $scope.name = ""; - -// check if user is logged or not, check session variables: if user isn't logged redirect to login page - - console.log("SONO IN HomeController"); - -// var isLogged = false; -// if (!isLogged) { -// console.log("REDIRECT TO LOGIN PAGE"); -//// window.location = "./self.html"; -// $location.path("/self"); -// } - - }]); \ No newline at end of file http://git-wip-us.apache.org/repos/asf/syncope/blob/edb0cb33/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 c1c563c..a166784 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 @@ -45,7 +45,7 @@ angular.module("login").controller("LoginController", ['$scope', '$rootScope', ' errorMessage = errorMessage.split("}}")[0]; } $scope.credentials.errorMessage = "Login failed: " + errorMessage; - $scope.showError($scope.credentials.errorMessage, $scope.notification); + $scope.showError($scope.credentials.errorMessage, $scope.notification); }); }; @@ -57,8 +57,13 @@ angular.module("login").controller("LoginController", ['$scope', '$rootScope', ' }); }; - $scope.isLogged = function () { - return angular.isDefined($rootScope.currentUser) && $rootScope.currentUser; + $scope.islogged = function () { + AuthService.islogged().then(function (response) { + console.log("user login status detected", response); + return response.data === true; + }, function (response) { + console.log("error retrieving user login status", response); + }); }; $scope.selfCreate = function () { @@ -66,7 +71,7 @@ angular.module("login").controller("LoginController", ['$scope', '$rootScope', ' }; $scope.passwordReset = function () { - $location.path("/passwordreset"); + $location.path("/passwordreset"); }; $scope.errorAPI = function () { http://git-wip-us.apache.org/repos/asf/syncope/blob/edb0cb33/client/enduser/src/main/resources/META-INF/resources/app/js/services/authService.js ---------------------------------------------------------------------- diff --git a/client/enduser/src/main/resources/META-INF/resources/app/js/services/authService.js b/client/enduser/src/main/resources/META-INF/resources/app/js/services/authService.js index 3c3f7af..56a5e36 100644 --- a/client/enduser/src/main/resources/META-INF/resources/app/js/services/authService.js +++ b/client/enduser/src/main/resources/META-INF/resources/app/js/services/authService.js @@ -25,21 +25,12 @@ angular.module('login') var authService = {}; - var clearUserCookie = function () { - $rootScope.currentUser = null; - $cookies.remove('currentUser'); - }; - authService.login = function (credentials) { return $http .post('/syncope-enduser/api/login', credentials) .then(function (response) { - var username = response.data; - $cookies.put('currentUser', username); - $rootScope.currentUser = username; - return username; + return response.data; }, function (response) { - clearUserCookie(); console.log("Something went wrong during login, exit with status: ", response); return $q.reject(response.data || response.statusText); }); @@ -49,26 +40,25 @@ angular.module('login') return $http .get('/syncope-enduser/api/logout') .then(function (response) { - clearUserCookie(); return response; }, function (response) { - clearUserCookie(); console.log("Something went wrong during logout, exit with status: ", response); }); }; - return authService; -// return { -// login: $resource('/syncope-enduser/api/login', {}, { -// do: {method: 'POST', params: {}, isArray: false} -// }) -// }; -// return { -// logout: $resource('/cradleDashboard/api/logout', {}, { -// query: {method: 'GET', params: {}, isArray: false} -// }) -// }; + authService.islogged = function () { + return $http + .get('/syncope-enduser/api/self/islogged') + .then(function (response) { + console.log("user logged: (authServ)" + response.data); + return response.data; + }, function (response) { + console.log("error retrieving user login status"); + }); + }; + + return authService; }]); http://git-wip-us.apache.org/repos/asf/syncope/blob/edb0cb33/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 43a539d..482fedd 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 @@ -52,7 +52,7 @@ under the License.
-