From bc675c73328397ac345e92627f524a7f94a81dd6 Mon Sep 17 00:00:00 2001 From: Oscar Gonzalez Fernandez Date: Mon, 28 Apr 2014 01:01:24 +0200 Subject: [PATCH] Upgrade Spring version --- libreplan-business/pom.xml | 57 +-- .../common/LibrePlanClassValidator.java | 6 +- .../orders/entities/SchedulingStateTest.java | 14 +- .../test/planner/daos/TaskElementDAOTest.java | 8 +- .../entities/DayAssignmentMatchers.java | 7 +- .../business/util/deepcopy/DeepCopyTest.java | 25 +- .../libreplan-business-spring-config-test.xml | 6 +- libreplan-webapp/pom.xml | 66 +-- .../org/libreplan/web/print/CutyPrint.java | 4 +- .../libreplan/web/security/SecurityUtils.java | 4 +- ...uthenticationProviderLoggingDecorator.java | 6 +- .../services/CustomTargetUrlResolver.java | 92 ++-- .../web/users/services/CustomUser.java | 9 +- .../services/DBPasswordEncoderService.java | 15 +- .../users/services/DBUserDetailsService.java | 26 +- .../LDAPCustomAuthenticationProvider.java | 15 +- .../services/LDAPUserDetailsService.java | 25 +- ...ibreplan-webapp-spring-security-config.xml | 35 +- .../src/main/webapp/WEB-INF/zk.xml | 2 +- .../CurrentUserScenarioAwareManagerTest.java | 6 +- .../services/DBUserDetailsServiceTest.java | 6 +- .../services/LDAPUserDetailsServiceTest.java | 6 +- ...lan-webapp-spring-security-config-test.xml | 4 +- pom.xml | 439 +++++------------- 24 files changed, 365 insertions(+), 518 deletions(-) diff --git a/libreplan-business/pom.xml b/libreplan-business/pom.xml index 4e12400ad..8d8a460f1 100644 --- a/libreplan-business/pom.xml +++ b/libreplan-business/pom.xml @@ -22,11 +22,6 @@ ${jdbcDriver.groupId} ${jdbcDriver.artifactId} - - - org.hibernate - hibernate - junit @@ -40,7 +35,7 @@ org.springframework - spring + spring-context-support org.apache.geronimo.specs @@ -50,16 +45,34 @@ org.springframework spring-test - org.springframework - spring-aop + spring-orm org.aspectj - aspectjtools + aspectjrt + + + org.aspectj + aspectjweaver + + + org.hibernate + hibernate-core + + + javassist + javassist + + + org.hibernate + hibernate-annotations + + + org.hibernate + hibernate-validator - org.easymock easymock @@ -70,14 +83,6 @@ easymockclassextension test - - org.hibernate - hibernate-validator - - - org.hibernate - hibernate-annotations - net.sf.json-lib json-lib @@ -92,6 +97,14 @@ commons-math commons-math + + commons-logging + commons-logging + + + org.slf4j + slf4j-log4j12 + joda-time @@ -105,14 +118,6 @@ org.dbunit dbunit - - log4j - log4j - - - org.slf4j - slf4j-simple - net.sf.ehcache ehcache diff --git a/libreplan-business/src/main/java/org/libreplan/business/common/LibrePlanClassValidator.java b/libreplan-business/src/main/java/org/libreplan/business/common/LibrePlanClassValidator.java index f63fff7ad..e8fc3c959 100644 --- a/libreplan-business/src/main/java/org/libreplan/business/common/LibrePlanClassValidator.java +++ b/libreplan-business/src/main/java/org/libreplan/business/common/LibrePlanClassValidator.java @@ -65,7 +65,7 @@ import org.hibernate.validator.Valid; import org.hibernate.validator.Validator; import org.hibernate.validator.ValidatorClass; import org.hibernate.validator.Version; -import org.hibernate.validator.interpolator.DefaultMessageInterpolatorAggerator; +import org.hibernate.validator.interpolator.DefaultMessageInterpolatorAggregator; /** @@ -113,7 +113,7 @@ public class LibrePlanClassValidator implements Serializable { private transient List memberValidators; private transient List memberGetters; private transient List childGetters; - private transient DefaultMessageInterpolatorAggerator defaultInterpolator; + private transient DefaultMessageInterpolatorAggregator defaultInterpolator; private transient MessageInterpolator userInterpolator; private static final Filter GET_ALL_FILTER = new Filter() { public boolean returnStatic() { @@ -230,7 +230,7 @@ public class LibrePlanClassValidator implements Serializable { memberValidators = new ArrayList(); memberGetters = new ArrayList(); childGetters = new ArrayList(); - defaultInterpolator = new DefaultMessageInterpolatorAggerator(); + defaultInterpolator = new DefaultMessageInterpolatorAggregator(); defaultInterpolator.initialize( messageBundle, defaultMessageBundle ); //build the class hierarchy to look for members in diff --git a/libreplan-business/src/test/java/org/libreplan/business/test/orders/entities/SchedulingStateTest.java b/libreplan-business/src/test/java/org/libreplan/business/test/orders/entities/SchedulingStateTest.java index 146d1ebae..25535fee3 100644 --- a/libreplan-business/src/test/java/org/libreplan/business/test/orders/entities/SchedulingStateTest.java +++ b/libreplan-business/src/test/java/org/libreplan/business/test/orders/entities/SchedulingStateTest.java @@ -21,6 +21,7 @@ package org.libreplan.business.test.orders.entities; import static org.hamcrest.CoreMatchers.equalTo; +import static org.hamcrest.CoreMatchers.everyItem; import static org.hamcrest.CoreMatchers.not; import static org.hamcrest.CoreMatchers.nullValue; import static org.junit.Assert.assertFalse; @@ -28,7 +29,6 @@ import static org.junit.Assert.assertNull; import static org.junit.Assert.assertThat; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; -import static org.junit.matchers.JUnitMatchers.each; import java.util.Arrays; import java.util.List; @@ -148,13 +148,13 @@ public class SchedulingStateTest { public void whenSchedulingAElementItTurnsAllItsDescendantsIntoScheduledSubelements() { root.schedule(); assertThat(allRootDescendants(), - each(hasType(Type.SCHEDULED_SUBELEMENT))); + everyItem(hasType(Type.SCHEDULED_SUBELEMENT))); } @Test public void aScheduledElementIsCompletelyScheduled() { root.schedule(); - assertThat(all(), each(completelyScheduled())); + assertThat(all(), everyItem(completelyScheduled())); } @Test @@ -179,12 +179,12 @@ public class SchedulingStateTest { @Test public void scheduledSubelementsCantBeScheduled() { root.schedule(); - assertThat(allRootDescendants(), each(not(canBeScheduled()))); + assertThat(allRootDescendants(), everyItem(not(canBeScheduled()))); } @Test public void aNoScheduledElementCanBeScheduled() { - assertThat(all(), each(canBeScheduled())); + assertThat(all(), everyItem(canBeScheduled())); } @Test @@ -269,14 +269,14 @@ public class SchedulingStateTest { @Test public void scheduledSubelementsCantBeUnScheduled() { root.schedule(); - assertThat(allRootDescendants(), each(not(canBeUnsheduled()))); + assertThat(allRootDescendants(), everyItem(not(canBeUnsheduled()))); } @Test public void afterUnschedulingAllDescendantsAreNoScheduled() { root.schedule(); root.unschedule(); - assertThat(allRootDescendants(), each(hasType(Type.NO_SCHEDULED))); + assertThat(allRootDescendants(), everyItem(hasType(Type.NO_SCHEDULED))); } @Test diff --git a/libreplan-business/src/test/java/org/libreplan/business/test/planner/daos/TaskElementDAOTest.java b/libreplan-business/src/test/java/org/libreplan/business/test/planner/daos/TaskElementDAOTest.java index a2b88a30c..c204fa85a 100644 --- a/libreplan-business/src/test/java/org/libreplan/business/test/planner/daos/TaskElementDAOTest.java +++ b/libreplan-business/src/test/java/org/libreplan/business/test/planner/daos/TaskElementDAOTest.java @@ -22,7 +22,7 @@ package org.libreplan.business.test.planner.daos; import static org.hamcrest.CoreMatchers.equalTo; -import static org.hamcrest.CoreMatchers.is; +import static org.hamcrest.CoreMatchers.instanceOf; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertThat; @@ -253,7 +253,7 @@ public class TaskElementDAOTest { throw new RuntimeException(e); } assertThat(fromDB.getId(), equalTo(task.getId())); - assertThat(fromDB, is(Task.class)); + assertThat(fromDB, instanceOf(Task.class)); checkProperties(task, fromDB); HoursGroup reloaded = ((Task) fromDB).getHoursGroup(); assertThat(reloaded.getId(), equalTo(reloaded.getId())); @@ -271,7 +271,7 @@ public class TaskElementDAOTest { throw new RuntimeException(e); } assertThat(fromDB.getId(), equalTo(milestone.getId())); - assertThat(fromDB, is(TaskMilestone.class)); + assertThat(fromDB, instanceOf(TaskMilestone.class)); } @Test @@ -295,7 +295,7 @@ public class TaskElementDAOTest { throw new RuntimeException(e); } assertThat(reloaded.getId(), equalTo(taskGroup.getId())); - assertThat(reloaded, is(TaskGroup.class)); + assertThat(reloaded, instanceOf(TaskGroup.class)); checkProperties(taskGroup, reloaded); } diff --git a/libreplan-business/src/test/java/org/libreplan/business/test/planner/entities/DayAssignmentMatchers.java b/libreplan-business/src/test/java/org/libreplan/business/test/planner/entities/DayAssignmentMatchers.java index 9eaa69b75..97b158d18 100644 --- a/libreplan-business/src/test/java/org/libreplan/business/test/planner/entities/DayAssignmentMatchers.java +++ b/libreplan-business/src/test/java/org/libreplan/business/test/planner/entities/DayAssignmentMatchers.java @@ -21,6 +21,8 @@ package org.libreplan.business.test.planner.entities; +import static org.hamcrest.CoreMatchers.both; + import java.util.ArrayList; import java.util.Arrays; import java.util.List; @@ -28,9 +30,8 @@ import java.util.List; import org.hamcrest.BaseMatcher; import org.hamcrest.Description; import org.hamcrest.Matcher; +import org.hamcrest.core.CombinableMatcher; import org.joda.time.LocalDate; -import org.junit.matchers.CombinableMatcher; -import org.junit.matchers.JUnitMatchers; import org.libreplan.business.planner.entities.DayAssignment; import org.libreplan.business.planner.entities.GenericDayAssignment; import org.libreplan.business.planner.entities.ResourceAllocation; @@ -75,7 +76,7 @@ public class DayAssignmentMatchers { public CombinableMatcher> consecutiveDays( int days) { - return JUnitMatchers.both(this).and( + return both(this).and( DayAssignmentMatchers.consecutiveDays(days)); } diff --git a/libreplan-business/src/test/java/org/libreplan/business/util/deepcopy/DeepCopyTest.java b/libreplan-business/src/test/java/org/libreplan/business/util/deepcopy/DeepCopyTest.java index 5147de4ce..c16fab46d 100644 --- a/libreplan-business/src/test/java/org/libreplan/business/util/deepcopy/DeepCopyTest.java +++ b/libreplan-business/src/test/java/org/libreplan/business/util/deepcopy/DeepCopyTest.java @@ -20,15 +20,16 @@ */ package org.libreplan.business.util.deepcopy; +import static java.util.Arrays.asList; import static org.hamcrest.CoreMatchers.equalTo; -import static org.hamcrest.CoreMatchers.is; +import static org.hamcrest.CoreMatchers.everyItem; +import static org.hamcrest.CoreMatchers.instanceOf; import static org.hamcrest.CoreMatchers.nullValue; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotSame; import static org.junit.Assert.assertSame; import static org.junit.Assert.assertThat; import static org.junit.Assert.assertTrue; -import static org.junit.matchers.Each.each; import java.math.BigDecimal; import java.util.ArrayList; @@ -110,7 +111,7 @@ public class DeepCopyTest { Integer.class, Short.class, Byte.class, Character.class, LocalDate.class, Boolean.class, DateTime.class, double.class, float.class, int.class, short.class, byte.class, char.class); - assertThat(immutableTypes, each(immutable())); + assertThat(immutableTypes, everyItem(immutable())); } private Matcher> immutable() { @@ -149,7 +150,7 @@ public class DeepCopyTest { @Test public void setsAreCopied() { EntityA entityA = new EntityA(); - HashSet originalSet = new HashSet(Arrays.asList("test", + HashSet originalSet = new HashSet(asList("test", 2, 3, new Date())); entityA.setSetProperty(originalSet); EntityA copy = new DeepCopy().copy(entityA); @@ -160,19 +161,19 @@ public class DeepCopyTest { @Test public void theSetImplementationClassIsPreservedIfPossible() { EntityA entityA = new EntityA(); - Set originalSet = new LinkedHashSet(Arrays.asList( - "test", 2, 3, new Date())); + Set originalSet = new LinkedHashSet(asList("test", 2, + 3, new Date())); entityA.setSetProperty(originalSet); EntityA copy = new DeepCopy().copy(entityA); - assertThat(copy.getSetProperty(), is(LinkedHashSet.class)); + assertThat(copy.getSetProperty(), instanceOf(LinkedHashSet.class)); } @Test public void setsInsideSetsAreRecursivelyCopiedWithoutProblem() { EntityA entityA = new EntityA(); - HashSet innerSet = new HashSet(Arrays.asList("bla", 3)); - HashSet originalSet = new HashSet(Arrays.asList("test", - 2, 3, new Date(), innerSet)); + HashSet innerSet = new HashSet(asList("bla", 3)); + HashSet originalSet = new HashSet(asList("test", 2, 3, + new Date(), innerSet)); entityA.setSetProperty(originalSet); EntityA copy = new DeepCopy().copy(entityA); assertEquals(originalSet, copy.getSetProperty()); @@ -197,7 +198,7 @@ public class DeepCopyTest { mapProperty.put("ab", "abc"); entityA.setMapProperty(mapProperty); EntityA copy = new DeepCopy().copy(entityA); - assertThat(copy.getMapProperty(), is(LinkedHashMap.class)); + assertThat(copy.getMapProperty(), instanceOf(LinkedHashMap.class)); } @Test @@ -220,7 +221,7 @@ public class DeepCopyTest { originalList.add(2); entityA.setListProperty(originalList); EntityA copy = new DeepCopy().copy(entityA); - assertThat(copy.getListProperty(), is(LinkedList.class)); + assertThat(copy.getListProperty(), instanceOf(LinkedList.class)); } @Test diff --git a/libreplan-business/src/test/resources/libreplan-business-spring-config-test.xml b/libreplan-business/src/test/resources/libreplan-business-spring-config-test.xml index a28faa52a..a0d0ca70d 100644 --- a/libreplan-business/src/test/resources/libreplan-business-spring-config-test.xml +++ b/libreplan-business/src/test/resources/libreplan-business-spring-config-test.xml @@ -3,9 +3,9 @@ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p" xmlns:tx="http://www.springframework.org/schema/tx" xmlns:context="http://www.springframework.org/schema/context" xsi:schemaLocation=" - http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd - http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd - http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd"> + http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd + http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd + http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd"> ${jdbcDriver.groupId} ${jdbcDriver.artifactId} - - - org.hibernate - hibernate - org.springframework - spring + spring-context-support + + org.springframework + spring-web + + + org.springframework.security + spring-security-config + + + org.springframework.security + spring-security-acl + + + + org.springframework.security + spring-security-ldap + org.apache.geronimo.specs geronimo-jta_1.0.1B_spec @@ -330,50 +342,22 @@ org.springframework spring-test - - - org.springframework - spring-context-support - org.springframework.security - spring-security-core + spring-security-web org.springframework.security spring-security-acl - - org.springframework.security - spring-security-core-tiger - + - org.springframework.ldap - spring-ldap-core - - - org.springframework.ldap - spring-ldap-core-tiger - - - org.springframework.ldap - spring-ldap-odm - - - org.springframework.ldap - spring-ldap-ldif-core - - - org.springframework.ldap - spring-ldap-ldif-batch - - - - org.aspectj - aspectjrt + org.springframework.security + spring-security-ldap + org.beanshell bsh @@ -432,10 +416,6 @@ com.jolbox bonecp - - org.hibernate - hibernate-validator - javax.servlet servlet-api diff --git a/libreplan-webapp/src/main/java/org/libreplan/web/print/CutyPrint.java b/libreplan-webapp/src/main/java/org/libreplan/web/print/CutyPrint.java index 5dc4cabfc..5ec803bf2 100644 --- a/libreplan-webapp/src/main/java/org/libreplan/web/print/CutyPrint.java +++ b/libreplan-webapp/src/main/java/org/libreplan/web/print/CutyPrint.java @@ -46,8 +46,8 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.libreplan.business.orders.entities.Order; import org.libreplan.web.common.entrypoints.EntryPointsHandler; -import org.springframework.security.context.SecurityContext; -import org.springframework.security.context.SecurityContextHolder; +import org.springframework.security.core.context.SecurityContext; +import org.springframework.security.core.context.SecurityContextHolder; import org.zkoss.ganttz.Planner; import org.zkoss.ganttz.servlets.CallbackServlet; import org.zkoss.ganttz.servlets.CallbackServlet.IServletRequestHandler; diff --git a/libreplan-webapp/src/main/java/org/libreplan/web/security/SecurityUtils.java b/libreplan-webapp/src/main/java/org/libreplan/web/security/SecurityUtils.java index 59dae51b4..f6a7377a4 100644 --- a/libreplan-webapp/src/main/java/org/libreplan/web/security/SecurityUtils.java +++ b/libreplan-webapp/src/main/java/org/libreplan/web/security/SecurityUtils.java @@ -36,8 +36,8 @@ import org.libreplan.business.users.entities.OrderAuthorizationType; import org.libreplan.business.users.entities.User; import org.libreplan.business.users.entities.UserRole; import org.libreplan.web.users.services.CustomUser; -import org.springframework.security.Authentication; -import org.springframework.security.context.SecurityContextHolder; +import org.springframework.security.core.Authentication; +import org.springframework.security.core.context.SecurityContextHolder; import org.zkoss.zk.ui.Executions; /** diff --git a/libreplan-webapp/src/main/java/org/libreplan/web/users/services/AuthenticationProviderLoggingDecorator.java b/libreplan-webapp/src/main/java/org/libreplan/web/users/services/AuthenticationProviderLoggingDecorator.java index 4d7c20ad2..719a39e77 100644 --- a/libreplan-webapp/src/main/java/org/libreplan/web/users/services/AuthenticationProviderLoggingDecorator.java +++ b/libreplan-webapp/src/main/java/org/libreplan/web/users/services/AuthenticationProviderLoggingDecorator.java @@ -21,9 +21,9 @@ package org.libreplan.web.users.services; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.springframework.security.Authentication; -import org.springframework.security.AuthenticationException; -import org.springframework.security.providers.AuthenticationProvider; +import org.springframework.security.authentication.AuthenticationProvider; +import org.springframework.security.core.Authentication; +import org.springframework.security.core.AuthenticationException; public class AuthenticationProviderLoggingDecorator implements AuthenticationProvider { 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 index a70659c9d..7237e39e9 100644 --- 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 @@ -19,7 +19,13 @@ package org.libreplan.web.users.services; +import java.io.IOException; +import java.util.HashSet; +import java.util.Set; + +import javax.servlet.ServletException; import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; import org.libreplan.business.common.IAdHocTransactionService; import org.libreplan.business.common.IOnTransaction; @@ -29,10 +35,10 @@ import org.libreplan.business.users.daos.IUserDAO; import org.libreplan.business.users.entities.User; import org.libreplan.business.users.entities.UserRole; 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; +import org.springframework.security.core.Authentication; +import org.springframework.security.core.GrantedAuthority; +import org.springframework.security.core.userdetails.UserDetails; +import org.springframework.security.web.authentication.SavedRequestAwareAuthenticationSuccessHandler; /** * Determines the URL for authenticated users depending on if user is bound or @@ -43,7 +49,8 @@ import org.springframework.security.userdetails.UserDetails; * * @author Manuel Rego Casasnovas */ -public class CustomTargetUrlResolver extends TargetUrlResolverImpl { +public class CustomTargetUrlResolver extends + SavedRequestAwareAuthenticationSuccessHandler { public final static String USER_DASHBOARD_URL = "/myaccount/userDashboard.zul"; @@ -60,22 +67,52 @@ public class CustomTargetUrlResolver extends TargetUrlResolverImpl { @Autowired private IAdHocTransactionService transactionServiceDAO; - @Override - public String determineTargetUrl(SavedRequest savedRequest, - HttpServletRequest currentRequest, final Authentication auth) { - if (isUserInRole(auth, UserRole.ROLE_SUPERUSER.name())) { - return super.determineTargetUrl(savedRequest, currentRequest, auth); - } + private ThreadLocal currentAuth = new ThreadLocal(); - if (isUserInRole(auth, UserRole.ROLE_BOUND_USER.name())) { + @Override + public void onAuthenticationSuccess(HttpServletRequest request, + HttpServletResponse response, Authentication auth) + throws ServletException, IOException { + + try { + currentAuth.set(auth); + super.onAuthenticationSuccess(request, response, auth); + } finally { + currentAuth.remove(); + } + } + + @Override + protected String determineTargetUrl(HttpServletRequest request, + HttpServletResponse response) { + + String targetURL = super.determineTargetUrl(request, response); + // if using default URL, we may want to use one based on the current + // user + if (targetURL.equals(getDefaultTargetUrl())) { + return calculatePreferedForUser(currentAuth.get()); + } + return targetURL; + } + + private String calculatePreferedForUser(final Authentication auth) { + if (isUserInSomeRole(auth, roles(UserRole.ROLE_BOUND_USER))) { return USER_DASHBOARD_URL; } - if (isUserInRole(auth, UserRole.ROLE_PLANNING.name())) { - return PLANNING_URL; + if (isUserInSomeRole(auth, + roles(UserRole.ROLE_SUPERUSER, UserRole.ROLE_PLANNING))) { + return getDefaultTargetUrl(); } - boolean userOrItsProfilesHaveAnyAuthorization = transactionServiceDAO + if (!hasAnyAuthorization(auth)) { + return SETTINGS_URL; + } + return getDefaultTargetUrl(); + } + + private boolean hasAnyAuthorization(final Authentication auth) { + return transactionServiceDAO .runOnReadOnlyTransaction(new IOnTransaction() { @Override public Boolean execute() { @@ -83,33 +120,34 @@ public class CustomTargetUrlResolver extends TargetUrlResolverImpl { UserDetails userDetails = (UserDetails) auth.getPrincipal(); User user = userDAO.findByLoginName(userDetails.getUsername()); user.getProfiles().size(); - return orderAuthorizationDAO - .userOrItsProfilesHaveAnyAuthorization(user); + return orderAuthorizationDAO.userOrItsProfilesHaveAnyAuthorization(user); } catch (InstanceNotFoundException e) { throw new RuntimeException(e); } - } }); - if (userOrItsProfilesHaveAnyAuthorization) { - return PLANNING_URL; - } - - return SETTINGS_URL; } - private boolean isUserInRole(Authentication auth, String role) { + private static Set roles(UserRole... roles) { + Set result = new HashSet(); + for (UserRole each : roles) { + result.add(each.name()); + } + return result; + } + + private boolean isUserInSomeRole(Authentication auth, Set roles) { if ((auth == null) || (auth.getPrincipal() == null) || (auth.getAuthorities() == null)) { return false; } - for (int i = 0; i < auth.getAuthorities().length; i++) { - if (role.equals(auth.getAuthorities()[i].getAuthority())) { + for (GrantedAuthority authority : auth.getAuthorities()) { + if (roles.contains(authority.getAuthority())) { return true; } - } + } return false; } } diff --git a/libreplan-webapp/src/main/java/org/libreplan/web/users/services/CustomUser.java b/libreplan-webapp/src/main/java/org/libreplan/web/users/services/CustomUser.java index 8acb500b6..e106ddcf5 100644 --- a/libreplan-webapp/src/main/java/org/libreplan/web/users/services/CustomUser.java +++ b/libreplan-webapp/src/main/java/org/libreplan/web/users/services/CustomUser.java @@ -21,10 +21,12 @@ package org.libreplan.web.users.services; +import java.util.Collection; + import org.apache.commons.lang.Validate; import org.libreplan.business.scenarios.entities.Scenario; -import org.springframework.security.GrantedAuthority; -import org.springframework.security.userdetails.User; +import org.springframework.security.core.GrantedAuthority; +import org.springframework.security.core.userdetails.User; /** * Extended {@link User} class in order to add information about the current @@ -38,7 +40,8 @@ public class CustomUser extends User { public CustomUser(String username, String password, boolean enabled, boolean accountNonExpired, boolean credentialsNonExpired, - boolean accountNonLocked, GrantedAuthority[] authorities, + boolean accountNonLocked, + Collection authorities, Scenario scenario) throws IllegalArgumentException { super(username, password, enabled, accountNonExpired, credentialsNonExpired, accountNonLocked, authorities); diff --git a/libreplan-webapp/src/main/java/org/libreplan/web/users/services/DBPasswordEncoderService.java b/libreplan-webapp/src/main/java/org/libreplan/web/users/services/DBPasswordEncoderService.java index 792c80ce6..49a3e5c05 100644 --- a/libreplan-webapp/src/main/java/org/libreplan/web/users/services/DBPasswordEncoderService.java +++ b/libreplan-webapp/src/main/java/org/libreplan/web/users/services/DBPasswordEncoderService.java @@ -21,11 +21,14 @@ package org.libreplan.web.users.services; -import org.springframework.security.GrantedAuthority; -import org.springframework.security.providers.dao.SaltSource; -import org.springframework.security.providers.encoding.PasswordEncoder; -import org.springframework.security.userdetails.User; -import org.springframework.security.userdetails.UserDetails; +import java.util.Collection; +import java.util.Collections; + +import org.springframework.security.authentication.dao.SaltSource; +import org.springframework.security.authentication.encoding.PasswordEncoder; +import org.springframework.security.core.GrantedAuthority; +import org.springframework.security.core.userdetails.User; +import org.springframework.security.core.userdetails.UserDetails; /** * For maximum flexibility, the implementation uses the password encoder and @@ -66,7 +69,7 @@ public class DBPasswordEncoderService implements IDBPasswordEncoderService { * the "user" passed as a parameter to "saltSource.getSalt". */ UserDetails userDetails = new User(loginName, clearPassword, true, - true, true, true, new GrantedAuthority[0]); + true, true, true, Collections.emptyList()); Object salt = null; diff --git a/libreplan-webapp/src/main/java/org/libreplan/web/users/services/DBUserDetailsService.java b/libreplan-webapp/src/main/java/org/libreplan/web/users/services/DBUserDetailsService.java index 34a4b3930..651848477 100644 --- a/libreplan-webapp/src/main/java/org/libreplan/web/users/services/DBUserDetailsService.java +++ b/libreplan-webapp/src/main/java/org/libreplan/web/users/services/DBUserDetailsService.java @@ -22,6 +22,8 @@ package org.libreplan.web.users.services; import java.text.MessageFormat; +import java.util.ArrayList; +import java.util.List; import java.util.Set; import org.libreplan.business.common.exceptions.InstanceNotFoundException; @@ -32,11 +34,11 @@ import org.libreplan.business.users.entities.User; import org.libreplan.business.users.entities.UserRole; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.dao.DataAccessException; -import org.springframework.security.GrantedAuthority; -import org.springframework.security.GrantedAuthorityImpl; -import org.springframework.security.userdetails.UserDetails; -import org.springframework.security.userdetails.UserDetailsService; -import org.springframework.security.userdetails.UsernameNotFoundException; +import org.springframework.security.core.GrantedAuthority; +import org.springframework.security.core.authority.GrantedAuthorityImpl; +import org.springframework.security.core.userdetails.UserDetails; +import org.springframework.security.core.userdetails.UserDetailsService; +import org.springframework.security.core.userdetails.UsernameNotFoundException; import org.springframework.transaction.annotation.Transactional; /** @@ -82,18 +84,12 @@ public class DBUserDetailsService implements UserDetailsService { scenario); } - private GrantedAuthority[] getGrantedAuthorities(Set roles) { - - GrantedAuthority[] grantedAuthorities = - new GrantedAuthority[roles.size()]; - int i = 0; - + private List getGrantedAuthorities(Set roles) { + List result = new ArrayList(); for (UserRole r : roles) { - grantedAuthorities[i++] = new GrantedAuthorityImpl(r.name()); + result.add(new GrantedAuthorityImpl(r.name())); } - - return grantedAuthorities; - + return result; } } diff --git a/libreplan-webapp/src/main/java/org/libreplan/web/users/services/LDAPCustomAuthenticationProvider.java b/libreplan-webapp/src/main/java/org/libreplan/web/users/services/LDAPCustomAuthenticationProvider.java index f30d5851f..4b6cc82e3 100644 --- a/libreplan-webapp/src/main/java/org/libreplan/web/users/services/LDAPCustomAuthenticationProvider.java +++ b/libreplan-webapp/src/main/java/org/libreplan/web/users/services/LDAPCustomAuthenticationProvider.java @@ -45,13 +45,13 @@ import org.springframework.ldap.core.DirContextAdapter; import org.springframework.ldap.core.DistinguishedName; import org.springframework.ldap.core.LdapTemplate; import org.springframework.ldap.filter.EqualsFilter; -import org.springframework.security.AuthenticationException; -import org.springframework.security.BadCredentialsException; -import org.springframework.security.providers.AuthenticationProvider; -import org.springframework.security.providers.UsernamePasswordAuthenticationToken; -import org.springframework.security.providers.dao.AbstractUserDetailsAuthenticationProvider; -import org.springframework.security.userdetails.UserDetails; -import org.springframework.security.userdetails.UserDetailsService; +import org.springframework.security.authentication.AuthenticationProvider; +import org.springframework.security.authentication.BadCredentialsException; +import org.springframework.security.authentication.UsernamePasswordAuthenticationToken; +import org.springframework.security.authentication.dao.AbstractUserDetailsAuthenticationProvider; +import org.springframework.security.core.AuthenticationException; +import org.springframework.security.core.userdetails.UserDetails; +import org.springframework.security.core.userdetails.UserDetailsService; import org.springframework.transaction.annotation.Transactional; /** @@ -110,7 +110,6 @@ public class LDAPCustomAuthenticationProvider extends // No needed at this time } - @SuppressWarnings({ "unchecked", "rawtypes" }) @Transactional(readOnly = true) @Override public UserDetails retrieveUser(String username, diff --git a/libreplan-webapp/src/main/java/org/libreplan/web/users/services/LDAPUserDetailsService.java b/libreplan-webapp/src/main/java/org/libreplan/web/users/services/LDAPUserDetailsService.java index 782a81674..63719c38f 100644 --- a/libreplan-webapp/src/main/java/org/libreplan/web/users/services/LDAPUserDetailsService.java +++ b/libreplan-webapp/src/main/java/org/libreplan/web/users/services/LDAPUserDetailsService.java @@ -19,6 +19,8 @@ package org.libreplan.web.users.services; import java.text.MessageFormat; +import java.util.ArrayList; +import java.util.List; import java.util.Set; import org.libreplan.business.common.exceptions.InstanceNotFoundException; @@ -29,11 +31,11 @@ import org.libreplan.business.users.entities.User; import org.libreplan.business.users.entities.UserRole; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.dao.DataAccessException; -import org.springframework.security.GrantedAuthority; -import org.springframework.security.GrantedAuthorityImpl; -import org.springframework.security.userdetails.UserDetails; -import org.springframework.security.userdetails.UserDetailsService; -import org.springframework.security.userdetails.UsernameNotFoundException; +import org.springframework.security.core.GrantedAuthority; +import org.springframework.security.core.authority.GrantedAuthorityImpl; +import org.springframework.security.core.userdetails.UserDetails; +import org.springframework.security.core.userdetails.UserDetailsService; +import org.springframework.security.core.userdetails.UsernameNotFoundException; import org.springframework.transaction.annotation.Transactional; /** @@ -80,16 +82,11 @@ public class LDAPUserDetailsService implements UserDetailsService { getGrantedAuthorities(user.getAllRoles()), scenario); } - private GrantedAuthority[] getGrantedAuthorities(Set roles) { - - GrantedAuthority[] grantedAuthorities = new GrantedAuthority[roles - .size()]; - int i = 0; - + private List getGrantedAuthorities(Set roles) { + List result = new ArrayList(); for (UserRole r : roles) { - grantedAuthorities[i++] = new GrantedAuthorityImpl(r.name()); + result.add(new GrantedAuthorityImpl(r.name())); } - - return grantedAuthorities; + return result; } } 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 cb4a03d30..d3bfef2cb 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 @@ -4,7 +4,7 @@ xmlns:beans="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd - http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-2.0.1.xsd"> + http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-3.0.3.xsd"> @@ -12,6 +12,8 @@ + + + + + + + class="org.springframework.security.authentication.encoding.ShaPasswordEncoder"> - + + + - + class="org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter" > - - + - + - - + + + class="org.libreplan.web.users.services.CustomTargetUrlResolver" > + + diff --git a/libreplan-webapp/src/main/webapp/WEB-INF/zk.xml b/libreplan-webapp/src/main/webapp/WEB-INF/zk.xml index e04d8fb34..82d325baa 100644 --- a/libreplan-webapp/src/main/webapp/WEB-INF/zk.xml +++ b/libreplan-webapp/src/main/webapp/WEB-INF/zk.xml @@ -29,7 +29,7 @@ ThreadLocal - org.springframework.security.context.ThreadLocalSecurityContextHolderStrategy=contextHolder + org.springframework.security.core.context.ThreadLocalSecurityContextHolderStrategy=contextHolder diff --git a/libreplan-webapp/src/test/java/org/libreplan/web/scenarios/CurrentUserScenarioAwareManagerTest.java b/libreplan-webapp/src/test/java/org/libreplan/web/scenarios/CurrentUserScenarioAwareManagerTest.java index 67fb66fe2..a955e6a82 100644 --- a/libreplan-webapp/src/test/java/org/libreplan/web/scenarios/CurrentUserScenarioAwareManagerTest.java +++ b/libreplan-webapp/src/test/java/org/libreplan/web/scenarios/CurrentUserScenarioAwareManagerTest.java @@ -40,9 +40,9 @@ import org.libreplan.business.scenarios.bootstrap.PredefinedScenarios; import org.libreplan.business.scenarios.entities.Scenario; import org.libreplan.web.users.services.CustomUser; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.security.Authentication; -import org.springframework.security.context.SecurityContext; -import org.springframework.security.context.SecurityContextHolder; +import org.springframework.security.core.Authentication; +import org.springframework.security.core.context.SecurityContext; +import org.springframework.security.core.context.SecurityContextHolder; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.springframework.transaction.annotation.Transactional; diff --git a/libreplan-webapp/src/test/java/org/libreplan/web/test/users/services/DBUserDetailsServiceTest.java b/libreplan-webapp/src/test/java/org/libreplan/web/test/users/services/DBUserDetailsServiceTest.java index d08e07642..7f5b58867 100644 --- a/libreplan-webapp/src/test/java/org/libreplan/web/test/users/services/DBUserDetailsServiceTest.java +++ b/libreplan-webapp/src/test/java/org/libreplan/web/test/users/services/DBUserDetailsServiceTest.java @@ -44,9 +44,9 @@ import org.libreplan.business.users.entities.UserRole; import org.libreplan.web.users.bootstrap.IUsersBootstrapInDB; import org.libreplan.web.users.bootstrap.PredefinedUsers; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.security.GrantedAuthority; -import org.springframework.security.userdetails.UserDetails; -import org.springframework.security.userdetails.UserDetailsService; +import org.springframework.security.core.GrantedAuthority; +import org.springframework.security.core.userdetails.UserDetails; +import org.springframework.security.core.userdetails.UserDetailsService; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.springframework.transaction.annotation.Transactional; diff --git a/libreplan-webapp/src/test/java/org/libreplan/web/test/users/services/LDAPUserDetailsServiceTest.java b/libreplan-webapp/src/test/java/org/libreplan/web/test/users/services/LDAPUserDetailsServiceTest.java index d037966a2..1330883f4 100644 --- a/libreplan-webapp/src/test/java/org/libreplan/web/test/users/services/LDAPUserDetailsServiceTest.java +++ b/libreplan-webapp/src/test/java/org/libreplan/web/test/users/services/LDAPUserDetailsServiceTest.java @@ -42,9 +42,9 @@ import org.libreplan.business.users.entities.UserRole; import org.libreplan.web.users.bootstrap.IUsersBootstrapInDB; import org.libreplan.web.users.bootstrap.PredefinedUsers; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.security.GrantedAuthority; -import org.springframework.security.userdetails.UserDetails; -import org.springframework.security.userdetails.UserDetailsService; +import org.springframework.security.core.GrantedAuthority; +import org.springframework.security.core.userdetails.UserDetails; +import org.springframework.security.core.userdetails.UserDetailsService; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.springframework.transaction.annotation.Transactional; diff --git a/libreplan-webapp/src/test/resources/libreplan-webapp-spring-security-config-test.xml b/libreplan-webapp/src/test/resources/libreplan-webapp-spring-security-config-test.xml index 11130ab16..acc82c676 100644 --- a/libreplan-webapp/src/test/resources/libreplan-webapp-spring-security-config-test.xml +++ b/libreplan-webapp/src/test/resources/libreplan-webapp-spring-security-config-test.xml @@ -5,12 +5,12 @@ xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd"> + class="org.springframework.security.authentication.encoding.ShaPasswordEncoder"> gettext-commons 0.9.6 + + + + org.springframework + spring-orm + 3.0.7.RELEASE + + + + org.hibernate + hibernate-core + 3.3.1.GA + + + org.hibernate + hibernate-annotations + 3.3.1.GA + + + + org.hibernate + hibernate-validator + 3.1.0.GA + + + + joda-time + joda-time-hibernate + 1.1 + + + cglib + cglib-full + + + ehcache + ehcache + + + + ${jdbcDriver.groupId} @@ -225,52 +270,94 @@ ${jdbcDriver.version} test - - - org.hibernate - hibernate - 3.2.7.ga - - - javax.transaction - jta - - - org.apache.geronimo.specs geronimo-jta_1.0.1B_spec 1.1.1 + - org.hibernate - hibernate-annotations - 3.3.1.GA + org.springframework + spring-web + 3.0.7.RELEASE - - org.hibernate - hibernate-validator - 3.0.0.ga - - + + org.springframework + spring-context-support + 3.0.7.RELEASE + + + + + org.aspectj + aspectjrt + 1.6.11 + + + org.aspectj + aspectjweaver + 1.6.11 + + + + javassist + javassist + 3.4.GA + + + + + + org.springframework.security + spring-security-web + 3.0.8.RELEASE + + + org.springframework.security + spring-security-config + 3.0.8.RELEASE + + + org.springframework.security + spring-security-acl + 3.0.8.RELEASE + + + + org.springframework.security + spring-security-ldap + 3.0.8.RELEASE + + + junit junit - 4.4 + 4.11 test com.jolbox bonecp - 0.7.1.RELEASE + 0.8.0.RELEASE test + + org.springframework + spring-test + 3.0.7.RELEASE + test + + org.easymock @@ -286,273 +373,13 @@ test - - - org.springframework - spring - 2.5.6 - - - org.springframework - spring-test - 2.5.6 - test - - - - org.springframework - spring-context-support - 2.5.6 - - - - org.springframework.security - spring-security-core - 2.0.5.RELEASE - - - org.springframework - spring-core - - - org.springframework - spring-beans - - - org.springframework - spring-context - - - org.springframework - spring-aop - - - org.springframework - spring-support - - - - - org.springframework.security - spring-security-acl - 2.0.5.RELEASE - - - org.springframework - spring-core - - - org.springframework - spring-beans - - - org.springframework - spring-context - - - org.springframework - spring-dao - - - org.springframework - spring-jdbc - - - - - org.springframework.security - spring-security-core-tiger - 2.0.5.RELEASE - - - - org.springframework.ldap - spring-ldap-core - 1.3.1.RELEASE - - - org.springframework - spring-core - - - org.springframework - spring-beans - - - org.springframework - spring-context - - - org.springframework - spring-aop - - - org.springframework - spring-support - - - org.springframework - spring-tx - - - - - org.springframework.ldap - spring-ldap-core-tiger - 1.3.1.RELEASE - - - org.springframework - spring-core - - - org.springframework - spring-beans - - - org.springframework - spring-context - - - org.springframework - spring-aop - - - org.springframework - spring-support - - - org.springframework - spring-tx - - - - - org.springframework.ldap - spring-ldap-odm - 1.3.1.RELEASE - - - org.springframework - spring-core - - - org.springframework - spring-beans - - - org.springframework - spring-context - - - org.springframework - spring-aop - - - org.springframework - spring-support - - - org.springframework - spring-tx - - - - - org.springframework.ldap - spring-ldap-ldif-core - 1.3.1.RELEASE - - - org.springframework - spring-core - - - org.springframework - spring-beans - - - org.springframework - spring-context - - - org.springframework - spring-aop - - - org.springframework - spring-support - - - org.springframework - spring-tx - - - - - org.springframework.ldap - spring-ldap-ldif-batch - 1.3.1.RELEASE - - - org.springframework - spring-core - - - org.springframework - spring-beans - - - org.springframework - spring-context - - - org.springframework - spring-aop - - - org.springframework - spring-support - - - org.springframework - spring-tx - - - - - - org.springframework - spring-aop - 2.5.6 - - - org.springframework - spring-beans - - - - - - - org.aspectj - aspectjtools - 1.7.1 - - - - - org.aspectj - aspectjrt - 1.7.1 - net.sf.json-lib json-lib 2.2.3 jdk15 - + commons-collections commons-collections 3.2 @@ -580,6 +407,11 @@ commons-logging 1.0.4 + + org.slf4j + slf4j-log4j12 + 1.7.2 + org.beanshell @@ -639,21 +471,6 @@ joda-time 1.6 - - joda-time - joda-time-hibernate - 1.1 - - - cglib - cglib-full - - - ehcache - ehcache - - - org.libreplan @@ -671,16 +488,6 @@ dbunit 2.4.6 - - log4j - log4j - 1.2.14 - - - org.slf4j - slf4j-simple - 1.5.5 - javax.servlet servlet-api @@ -804,6 +611,16 @@ org.quartz-scheduler quartz 1.8.0 + + + org.slf4j + slf4j-api + + + org.slf4j + slf4j-log4j12 + +