From db692ab010200203fb73cc3c3ba9206ff59d2bca Mon Sep 17 00:00:00 2001 From: Manuel Rego Casasnovas Date: Wed, 16 May 2012 10:36:05 +0200 Subject: [PATCH] Configure a custom URL target resolver in order to define the proper URL for bound users Bound users will be redirected to user dashboard after login. FEA: ItEr76S28UserDashboard --- .../services/CustomTargetUrlResolver.java | 65 +++++++++++++++++++ ...ibreplan-webapp-spring-security-config.xml | 11 +++- 2 files changed, 75 insertions(+), 1 deletion(-) create mode 100644 libreplan-webapp/src/main/java/org/libreplan/web/users/services/CustomTargetUrlResolver.java diff --git a/libreplan-webapp/src/main/java/org/libreplan/web/users/services/CustomTargetUrlResolver.java b/libreplan-webapp/src/main/java/org/libreplan/web/users/services/CustomTargetUrlResolver.java new file mode 100644 index 000000000..2f83495c0 --- /dev/null +++ b/libreplan-webapp/src/main/java/org/libreplan/web/users/services/CustomTargetUrlResolver.java @@ -0,0 +1,65 @@ +/* + * This file is part of LibrePlan + * + * Copyright (C) 2012 Igalia, S.L. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +package org.libreplan.web.users.services; + +import javax.servlet.http.HttpServletRequest; + +import org.libreplan.business.common.exceptions.InstanceNotFoundException; +import org.libreplan.business.users.daos.IUserDAO; +import org.libreplan.business.users.entities.User; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.security.Authentication; +import org.springframework.security.ui.TargetUrlResolverImpl; +import org.springframework.security.ui.savedrequest.SavedRequest; +import org.springframework.security.userdetails.UserDetails; + +/** + * Determines the URL for authenticated users depending on if user is bound or + * not to any resource.
+ * + * If the user is bound to a resource then the target URL will be the user + * dashboard. + * + * @author Manuel Rego Casasnovas + */ +public class CustomTargetUrlResolver extends TargetUrlResolverImpl { + + private final static String USER_DASHBOARD_URL = "/myaccount/userDashboard.zul"; + + @Autowired + private IUserDAO userDAO; + + @Override + public String determineTargetUrl(SavedRequest savedRequest, + HttpServletRequest currentRequest, Authentication auth) { + UserDetails userDetails = (UserDetails) auth.getPrincipal(); + + try { + User user = userDAO.findByLoginName(userDetails.getUsername()); + if (user.isBound()) { + return USER_DASHBOARD_URL; + } + } catch (InstanceNotFoundException e) { + throw new RuntimeException(e); + } + + return super.determineTargetUrl(savedRequest, currentRequest, auth); + } +} diff --git a/libreplan-webapp/src/main/resources/libreplan-webapp-spring-security-config.xml b/libreplan-webapp/src/main/resources/libreplan-webapp-spring-security-config.xml index 302d817d5..8701861b6 100644 --- a/libreplan-webapp/src/main/resources/libreplan-webapp-spring-security-config.xml +++ b/libreplan-webapp/src/main/resources/libreplan-webapp-spring-security-config.xml @@ -57,6 +57,9 @@ + @@ -121,7 +124,9 @@ - + + + +