From f38c0eb67550592ec56bca91a5e07b2a2eb100f5 Mon Sep 17 00:00:00 2001 From: Luke Taylor Date: Tue, 28 Apr 2009 06:42:57 +0000 Subject: [PATCH] Updated heavy-duty sample to be able to build it. --- sandbox/heavyduty/pom.xml | 100 ++++---- .../src/main/java/bigbank/BankDaoStub.java | 4 +- .../src/main/java/bigbank/BankService.java | 8 +- ...avyDutyAuthenticationProcessingFilter.java | 10 +- .../security/ui/HeavyDutyEntryPoint.java | 6 +- .../web/TestMultiActionController.java | 16 +- .../src/main/java/sample/TestVoter.java | 11 +- .../java/sample/dao/impl/GenericDAOImpl.java | 18 +- .../main/java/sample/service/UserService.java | 12 +- .../sample/service/impl/UserServiceImpl.java | 22 +- .../webapp/WEB-INF/appContext-security.xml | 108 ++++----- .../applicationContext-acegi-security.xml | 226 +++++++++--------- .../heavyduty/src/main/webapp/WEB-INF/web.xml | 2 +- 13 files changed, 268 insertions(+), 275 deletions(-) diff --git a/sandbox/heavyduty/pom.xml b/sandbox/heavyduty/pom.xml index 8a42fa6283..a882b5e4f5 100755 --- a/sandbox/heavyduty/pom.xml +++ b/sandbox/heavyduty/pom.xml @@ -8,24 +8,20 @@ org.springframework.security - spring-security-core + spring-security-web ${spring.security.version} org.springframework.security - spring-security-taglibs + spring-security-ldap ${spring.security.version} - org.springframework - org.springframework.core - ${spring.version} - - - org.springframework - org.springframework.context - ${spring.version} + org.springframework.security + spring-security-config + ${spring.security.version} + org.springframework org.springframework.web @@ -40,60 +36,62 @@ org.springframework org.springframework.jdbc runtime - ${spring.version} + ${spring.version} org.springframework - spring-orm + org.springframework.orm ${spring.version} - + + org.freemarker freemarker runtime 2.3.12 - - - hsqldb - hsqldb - 1.8.0.7 - compile - - - org.hibernate - hibernate-entitymanager - 3.3.2.GA - compile - - - net.sf.ehcache - ehcache - 1.3.0 - compile - - - org.aspectj - aspectjweaver - true - 1.5.4 - - - org.aspectj - aspectjrt - 1.5.4 - + + + hsqldb + hsqldb + 1.8.0.7 + compile + + + org.hibernate + hibernate-entitymanager + 3.3.2.GA + compile + + + net.sf.ehcache + ehcache + 1.4.1 + compile + javax.servlet servlet-api provided 2.4 - + javax.servlet jstl @@ -104,7 +102,7 @@ taglibs standard runtime - 1.1.2 + 1.1.2 org.apache.directory.server @@ -123,18 +121,18 @@ slf4j-log4j12 1.4.3 runtime - + org.springframework.ldap spring-ldap 1.2.1 - + log4j log4j runtime 1.2.14 - + @@ -155,7 +153,7 @@ true 2.0 - + org.mortbay.jetty maven-jetty-plugin @@ -183,8 +181,8 @@ - - 2.5.6 + + 3.0.0.M2 3.0.0.CI-SNAPSHOT diff --git a/sandbox/heavyduty/src/main/java/bigbank/BankDaoStub.java b/sandbox/heavyduty/src/main/java/bigbank/BankDaoStub.java index c675f95895..2bfbbeaa4b 100755 --- a/sandbox/heavyduty/src/main/java/bigbank/BankDaoStub.java +++ b/sandbox/heavyduty/src/main/java/bigbank/BankDaoStub.java @@ -5,8 +5,8 @@ import java.util.Map; public class BankDaoStub implements BankDao { private long id = 0; - private Map accounts = new HashMap(); - + private Map accounts = new HashMap(); + public void createOrUpdateAccount(Account account) { if (account.getId() == -1) { id++; diff --git a/sandbox/heavyduty/src/main/java/bigbank/BankService.java b/sandbox/heavyduty/src/main/java/bigbank/BankService.java index 15c5879ba6..6f99db8546 100755 --- a/sandbox/heavyduty/src/main/java/bigbank/BankService.java +++ b/sandbox/heavyduty/src/main/java/bigbank/BankService.java @@ -1,15 +1,15 @@ package bigbank; -import org.springframework.security.annotation.Secured; +import org.springframework.security.access.annotation.Secured; public interface BankService { - + @Secured("IS_AUTHENTICATED_ANONYMOUSLY") public Account readAccount(Long id); - + @Secured("IS_AUTHENTICATED_ANONYMOUSLY") public Account[] findAccounts(); - + @Secured("ROLE_TELLER") public Account post(Account account, double amount); } diff --git a/sandbox/heavyduty/src/main/java/heavyduty/security/ui/HeavyDutyAuthenticationProcessingFilter.java b/sandbox/heavyduty/src/main/java/heavyduty/security/ui/HeavyDutyAuthenticationProcessingFilter.java index 97fe1bf0c0..4e7be0180c 100755 --- a/sandbox/heavyduty/src/main/java/heavyduty/security/ui/HeavyDutyAuthenticationProcessingFilter.java +++ b/sandbox/heavyduty/src/main/java/heavyduty/security/ui/HeavyDutyAuthenticationProcessingFilter.java @@ -1,11 +1,11 @@ package heavyduty.security.ui; -import org.springframework.security.ui.webapp.AuthenticationProcessingFilter; +import org.springframework.security.web.authentication.AuthenticationProcessingFilter; public class HeavyDutyAuthenticationProcessingFilter extends AuthenticationProcessingFilter { - - - - + + + + } diff --git a/sandbox/heavyduty/src/main/java/heavyduty/security/ui/HeavyDutyEntryPoint.java b/sandbox/heavyduty/src/main/java/heavyduty/security/ui/HeavyDutyEntryPoint.java index 0e65f9ebeb..af40c3ea20 100755 --- a/sandbox/heavyduty/src/main/java/heavyduty/security/ui/HeavyDutyEntryPoint.java +++ b/sandbox/heavyduty/src/main/java/heavyduty/security/ui/HeavyDutyEntryPoint.java @@ -1,9 +1,9 @@ package heavyduty.security.ui; -import org.springframework.security.ui.webapp.AuthenticationProcessingFilterEntryPoint; +import org.springframework.security.web.authentication.AuthenticationProcessingFilterEntryPoint; public class HeavyDutyEntryPoint extends AuthenticationProcessingFilterEntryPoint { - - + + } diff --git a/sandbox/heavyduty/src/main/java/heavyduty/web/TestMultiActionController.java b/sandbox/heavyduty/src/main/java/heavyduty/web/TestMultiActionController.java index 5882a0d473..c5ec4e11d7 100644 --- a/sandbox/heavyduty/src/main/java/heavyduty/web/TestMultiActionController.java +++ b/sandbox/heavyduty/src/main/java/heavyduty/web/TestMultiActionController.java @@ -18,33 +18,33 @@ import org.springframework.web.servlet.mvc.multiaction.MultiActionController; */ public class TestMultiActionController extends MultiActionController { public static final String VIEW_NAME = "multi-action-test"; - + public String login(HttpServletRequest request, HttpServletResponse response) { return "login"; } - + public void step1(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String[] x = request.getParameterValues("x"); logger.info("x= " + (x == null ? "null" : Arrays.asList(x))); String[] y = request.getParameterValues("y"); - logger.info("y = " + (y == null ? "null" : Arrays.asList(y))); + logger.info("y = " + (y == null ? "null" : Arrays.asList(y))); request.getRequestDispatcher("/testMulti.htm?action=step1xtra&x=5&x=5").forward(request, response); } public ModelAndView step1xtra(HttpServletRequest request, HttpServletResponse response) throws ServletRequestBindingException { logger.info("x = " + Arrays.asList(request.getParameterValues("x"))); return createView("step2"); - } - + } + public ModelAndView step2(HttpServletRequest request, HttpServletResponse response) throws ServletRequestBindingException { return createView("step1"); } - + private ModelAndView createView(String name) { - Map model = new HashMap(); + Map model = new HashMap(); model.put("nextAction", name); return new ModelAndView(VIEW_NAME, model); } - + } diff --git a/sandbox/heavyduty/src/main/java/sample/TestVoter.java b/sandbox/heavyduty/src/main/java/sample/TestVoter.java index c5bd4222ae..557dfc2fdd 100644 --- a/sandbox/heavyduty/src/main/java/sample/TestVoter.java +++ b/sandbox/heavyduty/src/main/java/sample/TestVoter.java @@ -1,12 +1,11 @@ package sample; -import java.lang.annotation.Annotation; import java.util.List; import org.aopalliance.intercept.MethodInvocation; -import org.springframework.security.Authentication; -import org.springframework.security.ConfigAttribute; -import org.springframework.security.vote.AccessDecisionVoter; +import org.springframework.security.access.ConfigAttribute; +import org.springframework.security.access.vote.AccessDecisionVoter; +import org.springframework.security.core.Authentication; public class TestVoter implements AccessDecisionVoter { @@ -14,14 +13,14 @@ public class TestVoter implements AccessDecisionVoter { return true; } - public boolean supports(Class clazz) { + public boolean supports(Class clazz) { return MethodInvocation.class.isAssignableFrom(clazz); } public int vote(Authentication authentication, Object object, List config) { MethodInvocation mi = (MethodInvocation) object; - Annotation[][] annotations = mi.getMethod().getParameterAnnotations(); + mi.getMethod().getParameterAnnotations(); return ACCESS_GRANTED; diff --git a/sandbox/heavyduty/src/main/java/sample/dao/impl/GenericDAOImpl.java b/sandbox/heavyduty/src/main/java/sample/dao/impl/GenericDAOImpl.java index 01af5b984c..b775eeb3b7 100755 --- a/sandbox/heavyduty/src/main/java/sample/dao/impl/GenericDAOImpl.java +++ b/sandbox/heavyduty/src/main/java/sample/dao/impl/GenericDAOImpl.java @@ -24,7 +24,7 @@ public class GenericDAOImpl /** * Minimal constructor - * + * * @param t * type POJO hibernate */ @@ -34,12 +34,11 @@ public class GenericDAOImpl /** * read data - * + * * @param id * data id * @return data */ - @SuppressWarnings("unchecked") public T read(PK id) { if (id == null) { throw new IllegalArgumentException("Id cannot be null or empty"); @@ -54,7 +53,7 @@ public class GenericDAOImpl /** * persist data - * + * * @param transientInstance * data to persist * @see sido.common.dao.GenericDAO#persist(T) @@ -68,9 +67,9 @@ public class GenericDAOImpl } /** - * + * * attach clean - * + * * @param instance * data to attach * @see sido.common.dao.GenericDAO#refresh(T) @@ -85,7 +84,7 @@ public class GenericDAOImpl /** * delete - * + * * @param persistentInstance * data to delete * @see sido.common.dao.GenericDAO#delete(T) @@ -100,13 +99,12 @@ public class GenericDAOImpl /** * merge - * + * * @param detachedInstance * data to merge * @return the merged data * @see sido.common.dao.GenericDAO#merge(T) */ - @SuppressWarnings("unchecked") public T merge(T detachedInstance) { if (LOG.isDebugEnabled()) { LOG.debug("merging instance of " @@ -123,4 +121,4 @@ public class GenericDAOImpl } -} \ No newline at end of file +} diff --git a/sandbox/heavyduty/src/main/java/sample/service/UserService.java b/sandbox/heavyduty/src/main/java/sample/service/UserService.java index a81c6e91c9..bd5c18b40b 100755 --- a/sandbox/heavyduty/src/main/java/sample/service/UserService.java +++ b/sandbox/heavyduty/src/main/java/sample/service/UserService.java @@ -1,16 +1,16 @@ package sample.service; -import org.springframework.security.userdetails.UserDetails; -import org.springframework.security.userdetails.UserDetailsService; +import org.springframework.security.core.userdetails.UserDetails; +import org.springframework.security.core.userdetails.UserDetailsService; public interface UserService extends UserDetailsService { - + /** * Register a new User in database * @param username */ public UserDetails register(String username, String password); - - - + + + } diff --git a/sandbox/heavyduty/src/main/java/sample/service/impl/UserServiceImpl.java b/sandbox/heavyduty/src/main/java/sample/service/impl/UserServiceImpl.java index eb92fb845c..0152cc4e7d 100755 --- a/sandbox/heavyduty/src/main/java/sample/service/impl/UserServiceImpl.java +++ b/sandbox/heavyduty/src/main/java/sample/service/impl/UserServiceImpl.java @@ -1,18 +1,16 @@ /** - * + * */ package sample.service.impl; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.security.AuthenticationException; -import org.springframework.security.GrantedAuthority; -import org.springframework.security.GrantedAuthorityImpl; -import org.springframework.security.userdetails.UserDetails; -import org.springframework.security.userdetails.UsernameNotFoundException; +import org.springframework.security.core.AuthenticationException; +import org.springframework.security.core.authority.AuthorityUtils; +import org.springframework.security.core.userdetails.UserDetails; +import org.springframework.security.core.userdetails.UsernameNotFoundException; import org.springframework.stereotype.Component; -import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import sample.dao.UserDAO; @@ -21,7 +19,7 @@ import sample.service.UserService; /** * @author A207119 - * + * */ @Component @Transactional @@ -39,9 +37,9 @@ public class UserServiceImpl implements UserService { try { User user = userDAO.findByUsername(username); - return new org.springframework.security.userdetails.User(user + return new org.springframework.security.core.userdetails.User(user .getUsername(), user.getPassword(), true, true, true, true, - new GrantedAuthority[] { new GrantedAuthorityImpl("ROLE_USER") }); + AuthorityUtils.createAuthorityList("ROLE_USER")); } catch (Exception e) { LOG.error(e.getMessage(), e); throw new UsernameNotFoundException("No matching account", e); @@ -51,9 +49,9 @@ public class UserServiceImpl implements UserService { public UserDetails register(String username, String password) { User user = new User(username, password); userDAO.persist(user); - return new org.springframework.security.userdetails.User(user + return new org.springframework.security.core.userdetails.User(user .getUsername(), user.getPassword(), true, true, true, true, - new GrantedAuthority[] { new GrantedAuthorityImpl("ROLE_USER") }); + AuthorityUtils.createAuthorityList("ROLE_USER")); } diff --git a/sandbox/heavyduty/src/main/webapp/WEB-INF/appContext-security.xml b/sandbox/heavyduty/src/main/webapp/WEB-INF/appContext-security.xml index c7cc0c6d9b..4a85ec7f05 100755 --- a/sandbox/heavyduty/src/main/webapp/WEB-INF/appContext-security.xml +++ b/sandbox/heavyduty/src/main/webapp/WEB-INF/appContext-security.xml @@ -12,33 +12,33 @@ xmlns:aop="http://www.springframework.org/schema/aop" 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/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd + http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-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/security http://www.springframework.org/schema/security/spring-security-2.0.2.xsd"> - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + - - @@ -57,25 +57,25 @@ - + - - - + + + - - + --> + - + - - - - + + + + - + - - - - + + + + - - - - - - - - - - - - - - + + + + + + + + + + + + + - \ No newline at end of file + + diff --git a/sandbox/heavyduty/src/main/webapp/WEB-INF/applicationContext-acegi-security.xml b/sandbox/heavyduty/src/main/webapp/WEB-INF/applicationContext-acegi-security.xml index edd0759a43..3057ccc8ee 100755 --- a/sandbox/heavyduty/src/main/webapp/WEB-INF/applicationContext-acegi-security.xml +++ b/sandbox/heavyduty/src/main/webapp/WEB-INF/applicationContext-acegi-security.xml @@ -18,35 +18,35 @@ - - - - - + + + + + - + - - - - - - - - - + + + + + + + + + - - - - - - - + + + + + + + @@ -57,105 +57,105 @@ My Realm - + - - - - + + + + - - - - + + + + - - - - - - - - - - - - - + + + + + + + + + + + + + - - - - - - - - - + + + + + + + + + - - - - - - - + + + + + + + - - - - + + + + - - - - - - - - - - - - - + + + + + + + + + + + + + - - - + + + - - - - - - - - + + + + + + + + - - + + - + - + - - - + + + - - - - - - - + + + + + + + - \ No newline at end of file + diff --git a/sandbox/heavyduty/src/main/webapp/WEB-INF/web.xml b/sandbox/heavyduty/src/main/webapp/WEB-INF/web.xml index 1d6f237482..9a678c7c27 100755 --- a/sandbox/heavyduty/src/main/webapp/WEB-INF/web.xml +++ b/sandbox/heavyduty/src/main/webapp/WEB-INF/web.xml @@ -62,7 +62,7 @@ - context. Optional unless concurrent session control is being used. --> - org.springframework.security.ui.session.HttpSessionEventPublisher + org.springframework.security.web.session.HttpSessionEventPublisher