From 9b898e84c41041cc80817259e41659e1d77b6c25 Mon Sep 17 00:00:00 2001 From: "Mark St. Godard" Date: Sun, 25 Sep 2005 05:58:49 +0000 Subject: [PATCH] Added Java 5 Annotations version of Contacts sample (contacts-tiger). Note: I have added a pre goal to add the source dir of the original Contacts example. I also added an exclude on the main project.properties for the attributes sample, as the Commons Attributes plugin causes issues with Java 5 source compilation. The Annotations version will eventually replace the Commons Attributes approach, for now those users will need to manually build the attributes example. --- .classpath | 1 + doc/xdocs/changes.xml | 1 + project.properties | 4 + project.xml | 5 + samples/contacts-tiger/.cvsignore | 6 + samples/contacts-tiger/maven.xml | 57 ++++ samples/contacts-tiger/project.properties | 26 ++ samples/contacts-tiger/project.xml | 46 +++ .../annotation/ContactManagerBackend.java | 205 ++++++++++++ .../src/main/resources/log4j.properties | 37 +++ .../src/main/resources/messages.properties | 2 + .../src/main/webapp/common/WEB-INF/.cvsignore | 2 + ...pplicationContext-common-authorization.xml | 163 +++++++++ .../applicationContext-common-business.xml | 72 ++++ .../common/WEB-INF/contacts-servlet.xml | 87 +++++ .../main/webapp/common/WEB-INF/jsp/add.jsp | 40 +++ .../common/WEB-INF/jsp/addPermission.jsp | 55 ++++ .../common/WEB-INF/jsp/adminPermission.jsp | 39 +++ .../common/WEB-INF/jsp/deletePermission.jsp | 18 + .../webapp/common/WEB-INF/jsp/deleted.jsp | 13 + .../main/webapp/common/WEB-INF/jsp/hello.jsp | 51 +++ .../webapp/common/WEB-INF/jsp/include.jsp | 5 + .../main/webapp/common/WEB-INF/jsp/index.jsp | 32 ++ .../common/WEB-INF/remoting-servlet.xml | 54 +++ .../src/main/webapp/common/WEB-INF/spring.tld | 311 ++++++++++++++++++ .../src/main/webapp/common/index.jsp | 4 + .../src/main/webapp/common/logoff.jsp | 9 + .../src/main/webapp/common/secure/debug.jsp | 28 ++ .../applicationContext-acegi-security.xml | 183 +++++++++++ .../applicationContext-annotations.xml | 184 +++++++++++ .../WEB-INF/applicationContext-business.xml | 48 +++ .../src/main/webapp/filter/WEB-INF/web.xml | 107 ++++++ .../src/main/webapp/filter/acegilogin.jsp | 48 +++ .../src/main/webapp/filter/error.html | 5 + .../src/main/webapp/filter/exitUser.jsp | 45 +++ .../src/main/webapp/filter/switchUser.jsp | 43 +++ 36 files changed, 2036 insertions(+) create mode 100644 samples/contacts-tiger/.cvsignore create mode 100644 samples/contacts-tiger/maven.xml create mode 100644 samples/contacts-tiger/project.properties create mode 100644 samples/contacts-tiger/project.xml create mode 100644 samples/contacts-tiger/src/main/java/sample/contact/annotation/ContactManagerBackend.java create mode 100644 samples/contacts-tiger/src/main/resources/log4j.properties create mode 100644 samples/contacts-tiger/src/main/resources/messages.properties create mode 100644 samples/contacts-tiger/src/main/webapp/common/WEB-INF/.cvsignore create mode 100644 samples/contacts-tiger/src/main/webapp/common/WEB-INF/applicationContext-common-authorization.xml create mode 100644 samples/contacts-tiger/src/main/webapp/common/WEB-INF/applicationContext-common-business.xml create mode 100644 samples/contacts-tiger/src/main/webapp/common/WEB-INF/contacts-servlet.xml create mode 100644 samples/contacts-tiger/src/main/webapp/common/WEB-INF/jsp/add.jsp create mode 100644 samples/contacts-tiger/src/main/webapp/common/WEB-INF/jsp/addPermission.jsp create mode 100644 samples/contacts-tiger/src/main/webapp/common/WEB-INF/jsp/adminPermission.jsp create mode 100644 samples/contacts-tiger/src/main/webapp/common/WEB-INF/jsp/deletePermission.jsp create mode 100644 samples/contacts-tiger/src/main/webapp/common/WEB-INF/jsp/deleted.jsp create mode 100644 samples/contacts-tiger/src/main/webapp/common/WEB-INF/jsp/hello.jsp create mode 100644 samples/contacts-tiger/src/main/webapp/common/WEB-INF/jsp/include.jsp create mode 100644 samples/contacts-tiger/src/main/webapp/common/WEB-INF/jsp/index.jsp create mode 100644 samples/contacts-tiger/src/main/webapp/common/WEB-INF/remoting-servlet.xml create mode 100644 samples/contacts-tiger/src/main/webapp/common/WEB-INF/spring.tld create mode 100644 samples/contacts-tiger/src/main/webapp/common/index.jsp create mode 100644 samples/contacts-tiger/src/main/webapp/common/logoff.jsp create mode 100644 samples/contacts-tiger/src/main/webapp/common/secure/debug.jsp create mode 100644 samples/contacts-tiger/src/main/webapp/filter/WEB-INF/applicationContext-acegi-security.xml create mode 100644 samples/contacts-tiger/src/main/webapp/filter/WEB-INF/applicationContext-annotations.xml create mode 100644 samples/contacts-tiger/src/main/webapp/filter/WEB-INF/applicationContext-business.xml create mode 100644 samples/contacts-tiger/src/main/webapp/filter/WEB-INF/web.xml create mode 100644 samples/contacts-tiger/src/main/webapp/filter/acegilogin.jsp create mode 100644 samples/contacts-tiger/src/main/webapp/filter/error.html create mode 100644 samples/contacts-tiger/src/main/webapp/filter/exitUser.jsp create mode 100644 samples/contacts-tiger/src/main/webapp/filter/switchUser.jsp diff --git a/.classpath b/.classpath index 5719d5cda4..22e1d4526b 100644 --- a/.classpath +++ b/.classpath @@ -62,5 +62,6 @@ + diff --git a/doc/xdocs/changes.xml b/doc/xdocs/changes.xml index d66fd60a1d..a647d35de7 100644 --- a/doc/xdocs/changes.xml +++ b/doc/xdocs/changes.xml @@ -26,6 +26,7 @@ + Added Contacts (Java 5) sample uses @Transactional and @Secured annotations SwitchUserProcessingFilter to provide user security context switching Java 1.5 annotation support BasicAuthenticationProcessingFilter no longer creates HttpSession via WebAuthenticationDetails call diff --git a/project.properties b/project.properties index a1965fd6f6..e9167f7a5f 100644 --- a/project.properties +++ b/project.properties @@ -65,6 +65,10 @@ maven.license.licenseFile=${rootdir}/LICENSE.txt maven.multiproject.basedir=${rootdir} maven.multiproject.includes=core/project.xml,adapters/*/project.xml,samples/*/project.xml,domain/project.xml,core-tiger/project.xml +# excluding the attributes project since the Commons Attributes plugin causes +# problems with java 5 source code compilation +maven.multiproject.excludes=samples/attributes/project.xml + # multichanges maven.multichanges.basedir=${maven.multiproject.basedir} maven.multichanges.includes=${maven.multiproject.includes} diff --git a/project.xml b/project.xml index 35fac8a88e..3f5e41bc82 100644 --- a/project.xml +++ b/project.xml @@ -102,6 +102,11 @@ robertsanders robertsanders at users.sourceforge.net + + Mark St.Godard + markstg + markstg at users.sourceforge.net + diff --git a/samples/contacts-tiger/.cvsignore b/samples/contacts-tiger/.cvsignore new file mode 100644 index 0000000000..2471891f5e --- /dev/null +++ b/samples/contacts-tiger/.cvsignore @@ -0,0 +1,6 @@ +classes +dist +api +build.properties +temporary +target diff --git a/samples/contacts-tiger/maven.xml b/samples/contacts-tiger/maven.xml new file mode 100644 index 0000000000..3e11e6696f --- /dev/null +++ b/samples/contacts-tiger/maven.xml @@ -0,0 +1,57 @@ + + + + + + + + + + + + The "war" goal is deprecated. Use "multiwar:multiwar" instead. + + + + + + + + + + + + + + + + + + + + + + + + multiproject:install doesn't install Contacts Samples WARs to local repo + + + + + + + + + + + diff --git a/samples/contacts-tiger/project.properties b/samples/contacts-tiger/project.properties new file mode 100644 index 0000000000..57bf00899c --- /dev/null +++ b/samples/contacts-tiger/project.properties @@ -0,0 +1,26 @@ +# Ant properties for building the Contacts (Java 5) sample application. +# $Id$ + +name.filter=filter +src.dir=src +war.dir=war +lib.dir=${basedir}/../../lib +dist.lib.dir=${basedir}/../../dist +build.dir=classes +dist.dir=dist +javadocs.dir=api +jalopy.xml=${basedir}/../../jalopy.xml +tmp.dir=temporary +etc.dir=etc +client.dir=client + + +maven.war.src=${maven.src.dir}/main/webapp/common + +maven.multiproject.type=multiwar + +maven.xdoc.distributionType=war +maven.xdoc.distributionUrl=http://acegisecurity.sourceforge.net/maven/acegisecurity/wars + +maven.compile.target=1.5 +maven.compile.source=1.5 diff --git a/samples/contacts-tiger/project.xml b/samples/contacts-tiger/project.xml new file mode 100644 index 0000000000..3a33af2201 --- /dev/null +++ b/samples/contacts-tiger/project.xml @@ -0,0 +1,46 @@ + + + ${basedir}/../project.xml + 3 + acegi-security-sample-contacts-tiger + Acegi Security System for Spring - Contacts sample (Java 5) + acegisecurity + /home/groups/a/ac/acegisecurity/htdocs/multiproject/acegi-security-sample-contacts-tiger + + scm:cvs:pserver:anonymous@cvs.sourceforge.net:/cvsroot/acegisecurity:acegisecurity + scm:cvs:ext:${maven.username}@cvs.sourceforge.net:/cvsroot/acegisecurity:acegisecurity + http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/acegisecurity/acegisecurity/samples/contacts-tiger/ + + + + hessian + hessian + 3.0.1 + jar + http://www.caucho.com + + true + + + + burlap + burlap + 2.1.7 + jar + http://www.caucho.com + + true + + + + acegisecurity + acegi-security-tiger + 0.9.0-SNAPSHOT + jar + + true + + + + + diff --git a/samples/contacts-tiger/src/main/java/sample/contact/annotation/ContactManagerBackend.java b/samples/contacts-tiger/src/main/java/sample/contact/annotation/ContactManagerBackend.java new file mode 100644 index 0000000000..3e1ff7a8e2 --- /dev/null +++ b/samples/contacts-tiger/src/main/java/sample/contact/annotation/ContactManagerBackend.java @@ -0,0 +1,205 @@ +/* Copyright 2004, 2005 Acegi Technology Pty Limited + * + * Licensed 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 sample.contact.annotation; + +import java.util.List; +import java.util.Random; + +import net.sf.acegisecurity.Authentication; +import net.sf.acegisecurity.UserDetails; +import net.sf.acegisecurity.acl.basic.AclObjectIdentity; +import net.sf.acegisecurity.acl.basic.BasicAclExtendedDao; +import net.sf.acegisecurity.acl.basic.NamedEntityObjectIdentity; +import net.sf.acegisecurity.acl.basic.SimpleAclEntry; +import net.sf.acegisecurity.annotation.Secured; +import net.sf.acegisecurity.context.SecurityContextHolder; + +import org.springframework.beans.factory.InitializingBean; +import org.springframework.context.support.ApplicationObjectSupport; +import org.springframework.transaction.annotation.Transactional; +import org.springframework.util.Assert; + +import sample.contact.Contact; +import sample.contact.ContactDao; +import sample.contact.ContactManager; + + +/** + * Concrete implementation of Java 5 Annotated {@link ContactManager}. + * + * @author Mark St.Godard + * @version $Id$ + */ +@Transactional +public class ContactManagerBackend extends ApplicationObjectSupport + implements ContactManager, InitializingBean { + //~ Instance fields ======================================================== + + private BasicAclExtendedDao basicAclExtendedDao; + private ContactDao contactDao; + private int counter = 100; + + //~ Methods ================================================================ + + @Secured ({"ROLE_USER","AFTER_ACL_COLLECTION_READ"}) + @Transactional(readOnly=true) + public List getAll() { + if (logger.isDebugEnabled()) { + logger.debug("Returning all contacts"); + } + + return contactDao.findAll(); + } + + @Secured ({"ROLE_USER"}) + @Transactional(readOnly=true) + public List getAllRecipients() { + if (logger.isDebugEnabled()) { + logger.debug("Returning all recipients"); + } + + List list = contactDao.findAllPrincipals(); + list.addAll(contactDao.findAllRoles()); + + return list; + } + + public void setBasicAclExtendedDao(BasicAclExtendedDao basicAclExtendedDao) { + this.basicAclExtendedDao = basicAclExtendedDao; + } + + public BasicAclExtendedDao getBasicAclExtendedDao() { + return basicAclExtendedDao; + } + + @Secured ({"ROLE_USER","AFTER_ACL_READ"}) + @Transactional(readOnly=true) + public Contact getById(Integer id) { + if (logger.isDebugEnabled()) { + logger.debug("Returning contact with id: " + id); + } + + return contactDao.getById(id); + } + + public void setContactDao(ContactDao contactDao) { + this.contactDao = contactDao; + } + + public ContactDao getContactDao() { + return contactDao; + } + + /** + * This is a public method. + * + * @return DOCUMENT ME! + */ + public Contact getRandomContact() { + if (logger.isDebugEnabled()) { + logger.debug("Returning random contact"); + } + + Random rnd = new Random(); + List contacts = contactDao.findAll(); + int getNumber = rnd.nextInt(contacts.size()); + + return (Contact) contacts.get(getNumber); + } + + @Secured ({"ACL_CONTACT_ADMIN"}) + public void addPermission(Contact contact, String recipient, + Integer permission) { + SimpleAclEntry simpleAclEntry = new SimpleAclEntry(); + simpleAclEntry.setAclObjectIdentity(makeObjectIdentity(contact)); + simpleAclEntry.setMask(permission.intValue()); + simpleAclEntry.setRecipient(recipient); + basicAclExtendedDao.create(simpleAclEntry); + + if (logger.isDebugEnabled()) { + logger.debug("Added permission " + permission + " for recipient " + + recipient + " contact " + contact); + } + } + + public void afterPropertiesSet() throws Exception { + Assert.notNull(contactDao, "contactDao required"); + Assert.notNull(basicAclExtendedDao, "basicAclExtendedDao required"); + } + + @Secured ({"ROLE_USER"}) + public void create(Contact contact) { + // Create the Contact itself + contact.setId(new Integer(counter++)); + contactDao.create(contact); + + // Grant the current principal access to the contact + addPermission(contact, getUsername(), + new Integer(SimpleAclEntry.ADMINISTRATION)); + + if (logger.isDebugEnabled()) { + logger.debug("Created contact " + contact + + " and granted admin permission to recipient " + getUsername()); + } + } + + @Secured ({"ACL_CONTACT_DELETE"}) + public void delete(Contact contact) { + contactDao.delete(contact.getId()); + + // Delete the ACL information as well + basicAclExtendedDao.delete(makeObjectIdentity(contact)); + + if (logger.isDebugEnabled()) { + logger.debug("Deleted contact " + contact + + " including ACL permissions"); + } + } + + @Secured ({"ACL_CONTACT_ADMIN"}) + public void deletePermission(Contact contact, String recipient) { + basicAclExtendedDao.delete(makeObjectIdentity(contact), recipient); + + if (logger.isDebugEnabled()) { + logger.debug("Deleted contact " + contact + + " ACL permissions for recipient " + recipient); + } + } + + public void update(Contact contact) { + contactDao.update(contact); + + if (logger.isDebugEnabled()) { + logger.debug("Updated contact " + contact); + } + } + + protected String getUsername() { + Authentication auth = SecurityContextHolder.getContext() + .getAuthentication(); + + if (auth.getPrincipal() instanceof UserDetails) { + return ((UserDetails) auth.getPrincipal()).getUsername(); + } else { + return auth.getPrincipal().toString(); + } + } + + private AclObjectIdentity makeObjectIdentity(Contact contact) { + return new NamedEntityObjectIdentity(contact.getClass().getName(), + contact.getId().toString()); + } +} diff --git a/samples/contacts-tiger/src/main/resources/log4j.properties b/samples/contacts-tiger/src/main/resources/log4j.properties new file mode 100644 index 0000000000..a16a75a136 --- /dev/null +++ b/samples/contacts-tiger/src/main/resources/log4j.properties @@ -0,0 +1,37 @@ +# Global logging configuration +log4j.rootLogger=WARN, stdout, fileout + +#log4j.logger.org.springframework.aop.framework.autoproxy=DEBUG, stdout, fileout +#log4j.logger.org.springframework.aop.framework.autoproxy.metadata=DEBUG, stdout, fileout +#log4j.logger.org.springframework.aop.framework.autoproxy.target=DEBUG, stdout, fileout +#log4j.logger.org.springframework.transaction.interceptor=DEBUG, stdout, fileout +#log4j.logger.net.sf.acegisecurity.intercept=DEBUG, stdout, fileout +#log4j.logger.net.sf.acegisecurity.intercept.method=DEBUG, stdout, fileout +#log4j.logger.net.sf.acegisecurity.intercept.web=DEBUG, stdout, fileout +#log4j.logger.net.sf.acegisecurity.afterinvocation=DEBUG, stdout, fileout +#log4j.logger.net.sf.acegisecurity.acl=DEBUG, stdout, fileout +#log4j.logger.net.sf.acegisecurity.acl.basic=DEBUG, stdout, fileout +#log4j.logger.net.sf.acegisecurity.taglibs.authz=DEBUG, stdout, fileout +#log4j.logger.net.sf.acegisecurity.ui.basicauth=DEBUG, stdout, fileout +#log4j.logger.net.sf.acegisecurity.ui.rememberme=DEBUG, stdout, fileout +#log4j.logger.net.sf.acegisecurity.ui=DEBUG, stdout, fileout +#log4j.logger.net.sf.acegisecurity.afterinvocation=DEBUG, stdout, fileout +#log4j.logger.net.sf.acegisecurity.ui.rmi=DEBUG, stdout, fileout +#log4j.logger.net.sf.acegisecurity.ui.httpinvoker=DEBUG, stdout, fileout +#log4j.logger.net.sf.acegisecurity.util=DEBUG, stdout, fileout +#log4j.logger.net.sf.acegisecurity.providers.dao=DEBUG, stdout, fileout +log4j.logger.sample.contact=DEBUG, stdout, fileout + +# Console output... +log4j.appender.stdout=org.apache.log4j.ConsoleAppender +log4j.appender.stdout.layout=org.apache.log4j.PatternLayout +log4j.appender.stdout.layout.conversionPattern=[%p,%c{1},%t] %m%n + +# Rolling log file output... +log4j.appender.fileout=org.apache.log4j.RollingFileAppender +log4j.appender.fileout.File=contacts.log +#log4j.appender.fileout.File=${webapp.root}/WEB-INF/log4j.log +log4j.appender.fileout.MaxFileSize=1024KB +log4j.appender.fileout.MaxBackupIndex=1 +log4j.appender.fileout.layout=org.apache.log4j.PatternLayout +log4j.appender.fileout.layout.conversionPattern=%d{ABSOLUTE} %5p %c{1},%t:%L - %m%n diff --git a/samples/contacts-tiger/src/main/resources/messages.properties b/samples/contacts-tiger/src/main/resources/messages.properties new file mode 100644 index 0000000000..d869ef70b5 --- /dev/null +++ b/samples/contacts-tiger/src/main/resources/messages.properties @@ -0,0 +1,2 @@ +err.name.webContact.name=Name 3-50 characters is required. +err.name.webContact.email=Email 3-50 characters is required. diff --git a/samples/contacts-tiger/src/main/webapp/common/WEB-INF/.cvsignore b/samples/contacts-tiger/src/main/webapp/common/WEB-INF/.cvsignore new file mode 100644 index 0000000000..86e9501ee1 --- /dev/null +++ b/samples/contacts-tiger/src/main/webapp/common/WEB-INF/.cvsignore @@ -0,0 +1,2 @@ +lib + diff --git a/samples/contacts-tiger/src/main/webapp/common/WEB-INF/applicationContext-common-authorization.xml b/samples/contacts-tiger/src/main/webapp/common/WEB-INF/applicationContext-common-authorization.xml new file mode 100644 index 0000000000..57c4d3b318 --- /dev/null +++ b/samples/contacts-tiger/src/main/webapp/common/WEB-INF/applicationContext-common-authorization.xml @@ -0,0 +1,163 @@ + + + + + + + + + + + + net.sf.acegisecurity.acl.basic.SimpleAclEntry.ADMINISTRATION + + + net.sf.acegisecurity.acl.basic.SimpleAclEntry.READ + + + net.sf.acegisecurity.acl.basic.SimpleAclEntry.DELETE + + + + + + + + + ACL_CONTACT_READ + sample.contact.Contact + + + + + + + + + + + + ACL_CONTACT_DELETE + sample.contact.Contact + + + + + + + + + + + + ACL_CONTACT_ADMIN + sample.contact.Contact + + + + + + + + + + + false + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + sample.contact.ContactManager.create=ROLE_USER + sample.contact.ContactManager.getAllRecipients=ROLE_USER + sample.contact.ContactManager.getAll=ROLE_USER,AFTER_ACL_COLLECTION_READ + sample.contact.ContactManager.getById=ROLE_USER,AFTER_ACL_READ + sample.contact.ContactManager.delete=ACL_CONTACT_DELETE + sample.contact.ContactManager.deletePermission=ACL_CONTACT_ADMIN + sample.contact.ContactManager.addPermission=ACL_CONTACT_ADMIN + + + + + diff --git a/samples/contacts-tiger/src/main/webapp/common/WEB-INF/applicationContext-common-business.xml b/samples/contacts-tiger/src/main/webapp/common/WEB-INF/applicationContext-common-business.xml new file mode 100644 index 0000000000..6666a49cee --- /dev/null +++ b/samples/contacts-tiger/src/main/webapp/common/WEB-INF/applicationContext-common-business.xml @@ -0,0 +1,72 @@ + + + + + + + + + + org.hsqldb.jdbcDriver + + + jdbc:hsqldb:mem:contacts + + + sa + + + + + + + + + + + + + + + sample.contact.ContactManager.create=PROPAGATION_REQUIRED + sample.contact.ContactManager.getAllRecipients=PROPAGATION_REQUIRED,readOnly + sample.contact.ContactManager.getAll=PROPAGATION_REQUIRED,readOnly + sample.contact.ContactManager.getById=PROPAGATION_REQUIRED,readOnly + sample.contact.ContactManager.delete=PROPAGATION_REQUIRED + sample.contact.ContactManager.deletePermission=PROPAGATION_REQUIRED + sample.contact.ContactManager.addPermission=PROPAGATION_REQUIRED + + + + + + + + + + + + + + sample.contact.ContactManager + + + + + + + + + + + + + + + diff --git a/samples/contacts-tiger/src/main/webapp/common/WEB-INF/contacts-servlet.xml b/samples/contacts-tiger/src/main/webapp/common/WEB-INF/contacts-servlet.xml new file mode 100644 index 0000000000..a796a6b16b --- /dev/null +++ b/samples/contacts-tiger/src/main/webapp/common/WEB-INF/contacts-servlet.xml @@ -0,0 +1,87 @@ + + + + + + + + + + + messages + + + + + + + + + + + + + + + + + + + + + + + + + + + + publicIndexController + secureAddForm + secureIndexController + secureDeleteController + adminPermissionController + deletePermissionController + addPermissionForm + + + + + + + + + + true + webContact + sample.contact.WebContact + + add + index.htm + + + + + + + true + addPermission + sample.contact.AddPermission + + addPermission + index.htm + + + + + + + /WEB-INF/jsp/ + .jsp + + + diff --git a/samples/contacts-tiger/src/main/webapp/common/WEB-INF/jsp/add.jsp b/samples/contacts-tiger/src/main/webapp/common/WEB-INF/jsp/add.jsp new file mode 100644 index 0000000000..5b14a52275 --- /dev/null +++ b/samples/contacts-tiger/src/main/webapp/common/WEB-INF/jsp/add.jsp @@ -0,0 +1,40 @@ +<%@ include file="/WEB-INF/jsp/include.jsp" %> + +Add New Contact + +

Add Contact

+
+ + + + + + + + + + + + + + + +
Name: + "> + + +
Email: + "> + + +
+
+ + Please fix all errors! + +

+ +
+">Home + + diff --git a/samples/contacts-tiger/src/main/webapp/common/WEB-INF/jsp/addPermission.jsp b/samples/contacts-tiger/src/main/webapp/common/WEB-INF/jsp/addPermission.jsp new file mode 100644 index 0000000000..52c05365ec --- /dev/null +++ b/samples/contacts-tiger/src/main/webapp/common/WEB-INF/jsp/addPermission.jsp @@ -0,0 +1,55 @@ +<%@ include file="/WEB-INF/jsp/include.jsp" %> + +Add Permission + +

Add Permission

+
+ + + + + + + + + + + + + + + + + + + +
Contact:
Recipient: + + + +
Permission: + + + +
+
+ + Please fix all errors! + +

+ +
+

+">Admin Permission ">Manage + + diff --git a/samples/contacts-tiger/src/main/webapp/common/WEB-INF/jsp/adminPermission.jsp b/samples/contacts-tiger/src/main/webapp/common/WEB-INF/jsp/adminPermission.jsp new file mode 100644 index 0000000000..d27ade53e0 --- /dev/null +++ b/samples/contacts-tiger/src/main/webapp/common/WEB-INF/jsp/adminPermission.jsp @@ -0,0 +1,39 @@ +<%@ page import="net.sf.acegisecurity.acl.basic.SimpleAclEntry" %> +<%@ include file="/WEB-INF/jsp/include.jsp" %> + + +Administer Permissions + +

Administer Permissions

+

+ + + +

+ + + + + + + + + +
+ + <% + SimpleAclEntry simpleAcl = ((SimpleAclEntry) pageContext.getAttribute("acl")); + String permissionBlock = simpleAcl.printPermissionsBlock(); + %> + <%= permissionBlock %> + [] + + + + + ">Del +
+

">Add Permission ">Manage + + diff --git a/samples/contacts-tiger/src/main/webapp/common/WEB-INF/jsp/deletePermission.jsp b/samples/contacts-tiger/src/main/webapp/common/WEB-INF/jsp/deletePermission.jsp new file mode 100644 index 0000000000..70e69c35b6 --- /dev/null +++ b/samples/contacts-tiger/src/main/webapp/common/WEB-INF/jsp/deletePermission.jsp @@ -0,0 +1,18 @@ +<%@ page import="net.sf.acegisecurity.acl.basic.SimpleAclEntry" %> +<%@ include file="/WEB-INF/jsp/include.jsp" %> + + +Permission Deleted + +

Permission Deleted

+

+ + + +

+ + + +

">Manage + + diff --git a/samples/contacts-tiger/src/main/webapp/common/WEB-INF/jsp/deleted.jsp b/samples/contacts-tiger/src/main/webapp/common/WEB-INF/jsp/deleted.jsp new file mode 100644 index 0000000000..8fed87c4fd --- /dev/null +++ b/samples/contacts-tiger/src/main/webapp/common/WEB-INF/jsp/deleted.jsp @@ -0,0 +1,13 @@ +<%@ include file="/WEB-INF/jsp/include.jsp" %> + + +Deletion completed + +

Deleted

+

+ + + +

">Manage + + diff --git a/samples/contacts-tiger/src/main/webapp/common/WEB-INF/jsp/hello.jsp b/samples/contacts-tiger/src/main/webapp/common/WEB-INF/jsp/hello.jsp new file mode 100644 index 0000000000..2a40c618f9 --- /dev/null +++ b/samples/contacts-tiger/src/main/webapp/common/WEB-INF/jsp/hello.jsp @@ -0,0 +1,51 @@ +<%@ include file="/WEB-INF/jsp/include.jsp" %> + + +Contacts Security Demo + +

Contacts Security Demo

+

Contacts demonstrates the following central Acegi Security capabilities: +

    +
  • Role-based security. Each principal is a member of certain roles, + which are used to restrict access to certain secure objects.
  • +
  • Domain object instance security. The Contact, the + main domain object in the application, has an access control list (ACL) + that indicates who is allowed read, administer and delete the object.
  • +
  • Method invocation security. The ContactManager service + layer bean has a number of secured (protected) and public (unprotected) + methods.
  • +
  • Web request security. The /secure URI path is protected + by Acegi Security from principals not holding the + ROLE_USER granted authority.
  • +
  • Security unaware application objects. None of the objects + are aware of the security being implemented by Acegi Security. *
  • +
  • Security taglib usage. All of the JSPs use Acegi Security's + taglib to evaluate security information. *
  • +
  • Fully declarative security. Every capability is configured in + the application context using standard Acegi Security classes. *
  • +
  • Database-sourced security data. All of the user, role and ACL + information is obtained from an in-memory JDBC-compliant database.
  • +
  • Integrated form-based and BASIC authentication. Any BASIC + authentication header is detected and used for authentication. Normal + interactive form-based authentication is used by default.
  • +
  • Remember-me services. Acegi Security's pluggable remember-me + strategy is demonstrated, with a corresponding checkbox on the login form.
  • +
+ +* As the application provides an "ACL Administration" use case, those +classes are necessarily aware of security. But no business use cases are. + +

Please excuse the lack of look 'n' feel polish in this application. +It is about security, after all! :-) + +

To demonstrate a public method on ContactManager, +here's a random Contact: +

+ + + +

Get started by clicking "Manage"... +

">Manage +">Debug + + diff --git a/samples/contacts-tiger/src/main/webapp/common/WEB-INF/jsp/include.jsp b/samples/contacts-tiger/src/main/webapp/common/WEB-INF/jsp/include.jsp new file mode 100644 index 0000000000..96a45ec08f --- /dev/null +++ b/samples/contacts-tiger/src/main/webapp/common/WEB-INF/jsp/include.jsp @@ -0,0 +1,5 @@ +<%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %> +<%@ taglib prefix="authz" uri="http://acegisecurity.sf.net/authz" %> + +<%@ taglib prefix="c" uri="http://java.sun.com/jstl/core" %> +<%@ taglib prefix="fmt" uri="http://java.sun.com/jstl/fmt" %> diff --git a/samples/contacts-tiger/src/main/webapp/common/WEB-INF/jsp/index.jsp b/samples/contacts-tiger/src/main/webapp/common/WEB-INF/jsp/index.jsp new file mode 100644 index 0000000000..12a96138ed --- /dev/null +++ b/samples/contacts-tiger/src/main/webapp/common/WEB-INF/jsp/index.jsp @@ -0,0 +1,32 @@ +<%@ include file="/WEB-INF/jsp/include.jsp" %> + + +Your Contacts + +

's Contacts

+

+ + + + + + + + + + + + + + + +
idNameEmail
+ + + + + + ">Del">Admin Permission
+

">Add

">Logoff (also clears any remember-me cookie) + + diff --git a/samples/contacts-tiger/src/main/webapp/common/WEB-INF/remoting-servlet.xml b/samples/contacts-tiger/src/main/webapp/common/WEB-INF/remoting-servlet.xml new file mode 100644 index 0000000000..cdc2ec7171 --- /dev/null +++ b/samples/contacts-tiger/src/main/webapp/common/WEB-INF/remoting-servlet.xml @@ -0,0 +1,54 @@ + + + + + + + + + + + + + + + + sample.contact.ContactManager + + + + + + + + + sample.contact.ContactManager + + + + + + + + + sample.contact.ContactManager + + + + diff --git a/samples/contacts-tiger/src/main/webapp/common/WEB-INF/spring.tld b/samples/contacts-tiger/src/main/webapp/common/WEB-INF/spring.tld new file mode 100644 index 0000000000..a6f7bffac6 --- /dev/null +++ b/samples/contacts-tiger/src/main/webapp/common/WEB-INF/spring.tld @@ -0,0 +1,311 @@ + + + + + + 1.1.1 + + 1.2 + + Spring + + http://www.springframework.org/tags + + Spring Framework JSP Tag Library. Authors: Rod Johnson, Juergen Hoeller + + + + + htmlEscape + org.springframework.web.servlet.tags.HtmlEscapeTag + JSP + + + Sets default HTML escape value for the current page. + Overrides a "defaultHtmlEscape" context-param in web.xml, if any. + + + + defaultHtmlEscape + true + true + + + + + + + + escapeBody + org.springframework.web.servlet.tags.EscapeBodyTag + JSP + + + Escapes its enclosed body content, applying HTML escaping and/or JavaScript escaping. + The HTML escaping flag participates in a page-wide or application-wide setting + (i.e. by HtmlEscapeTag or a "defaultHtmlEscape" context-param in web.xml). + + + + htmlEscape + false + true + + + + javaScriptEscape + false + true + + + + + + + + message + org.springframework.web.servlet.tags.MessageTag + JSP + + + Retrieves the message with the given code, or text if code isn't resolvable. + The HTML escaping flag participates in a page-wide or application-wide setting + (i.e. by HtmlEscapeTag or a "defaultHtmlEscape" context-param in web.xml). + + + + code + false + true + + + + arguments + false + true + + + + text + false + true + + + + var + false + true + + + + scope + false + true + + + + htmlEscape + false + true + + + + javaScriptEscape + false + true + + + + + + + + theme + org.springframework.web.servlet.tags.ThemeTag + JSP + + + Retrieves the theme message with the given code, or text if code isn't resolvable. + The HTML escaping flag participates in a page-wide or application-wide setting + (i.e. by HtmlEscapeTag or a "defaultHtmlEscape" context-param in web.xml). + + + + code + false + true + + + + arguments + false + true + + + + text + false + true + + + + var + false + true + + + + scope + false + true + + + + htmlEscape + false + true + + + + javaScriptEscape + false + true + + + + + + + + hasBindErrors + org.springframework.web.servlet.tags.BindErrorsTag + JSP + + + Provides Errors instance in case of bind errors. + The HTML escaping flag participates in a page-wide or application-wide setting + (i.e. by HtmlEscapeTag or a "defaultHtmlEscape" context-param in web.xml). + + + + errors + org.springframework.validation.Errors + + + + name + true + true + + + + htmlEscape + false + true + + + + + + + + nestedPath + org.springframework.web.servlet.tags.NestedPathTag + JSP + + + Sets a nested path to be used by the bind tag's path. + + + + nestedPath + java.lang.String + + + + path + true + true + + + + + + + + bind + org.springframework.web.servlet.tags.BindTag + JSP + + + Provides BindStatus object for the given bind path. + The HTML escaping flag participates in a page-wide or application-wide setting + (i.e. by HtmlEscapeTag or a "defaultHtmlEscape" context-param in web.xml). + + + + status + org.springframework.web.servlet.support.BindStatus + + + + path + true + true + + + + ignoreNestedPath + false + true + + + + htmlEscape + false + true + + + + + + + + transform + org.springframework.web.servlet.tags.TransformTag + JSP + + + Provides transformation of variables to Strings, using an appropriate + custom PropertyEditor from BindTag (can only be used inside BindTag). + The HTML escaping flag participates in a page-wide or application-wide setting + (i.e. by HtmlEscapeTag or a "defaultHtmlEscape" context-param in web.xml). + + + + value + true + true + + + + var + false + true + + + + scope + false + true + + + + htmlEscape + false + true + + + + + diff --git a/samples/contacts-tiger/src/main/webapp/common/index.jsp b/samples/contacts-tiger/src/main/webapp/common/index.jsp new file mode 100644 index 0000000000..4c86e33093 --- /dev/null +++ b/samples/contacts-tiger/src/main/webapp/common/index.jsp @@ -0,0 +1,4 @@ +<%@ include file="/WEB-INF/jsp/include.jsp" %> + +<%-- Redirected because we can't set the welcome page to a virtual URL. --%> + diff --git a/samples/contacts-tiger/src/main/webapp/common/logoff.jsp b/samples/contacts-tiger/src/main/webapp/common/logoff.jsp new file mode 100644 index 0000000000..1b291a5bab --- /dev/null +++ b/samples/contacts-tiger/src/main/webapp/common/logoff.jsp @@ -0,0 +1,9 @@ +<%@ page import="javax.servlet.http.Cookie" %> +<%@ page import="net.sf.acegisecurity.ui.rememberme.TokenBasedRememberMeServices" %> +<% +session.invalidate(); +Cookie terminate = new Cookie(TokenBasedRememberMeServices.ACEGI_SECURITY_HASHED_REMEMBER_ME_COOKIE_KEY, null); +terminate.setMaxAge(0); +response.addCookie(terminate); +response.sendRedirect("index.jsp"); +%> \ No newline at end of file diff --git a/samples/contacts-tiger/src/main/webapp/common/secure/debug.jsp b/samples/contacts-tiger/src/main/webapp/common/secure/debug.jsp new file mode 100644 index 0000000000..50433fab66 --- /dev/null +++ b/samples/contacts-tiger/src/main/webapp/common/secure/debug.jsp @@ -0,0 +1,28 @@ +<%@ page import="net.sf.acegisecurity.context.SecurityContextHolder" %> +<%@ page import="net.sf.acegisecurity.Authentication" %> +<%@ page import="net.sf.acegisecurity.GrantedAuthority" %> +<%@ page import="net.sf.acegisecurity.adapters.AuthByAdapter" %> + +<% + Authentication auth = SecurityContextHolder.getContext().getAuthentication(); + if (auth != null) { %> + Authentication object is of type: <%= auth.getClass().getName() %>

+ Authentication object as a String: <%= auth.toString() %>

+ + Authentication object holds the following granted authorities:

+<% GrantedAuthority[] granted = auth.getAuthorities(); + for (int i = 0; i < granted.length; i++) { %> + <%= granted[i].toString() %> (getAuthority(): <%= granted[i].getAuthority() %>)
+<% } + + if (auth instanceof AuthByAdapter) { %> +
SUCCESS! Your container adapter appears to be properly configured!

+<% } else { %> +
SUCCESS! Your web filters appear to be properly configured!
+<% } + + } else { %> + Authentication object is null.
+ This is an error and your Acegi Security application will not operate properly until corrected.

+<% } +%> diff --git a/samples/contacts-tiger/src/main/webapp/filter/WEB-INF/applicationContext-acegi-security.xml b/samples/contacts-tiger/src/main/webapp/filter/WEB-INF/applicationContext-acegi-security.xml new file mode 100644 index 0000000000..9bcbf0d711 --- /dev/null +++ b/samples/contacts-tiger/src/main/webapp/filter/WEB-INF/applicationContext-acegi-security.xml @@ -0,0 +1,183 @@ + + + + + + + + + + + + + + CONVERT_URL_TO_LOWERCASE_BEFORE_COMPARISON + PATTERN_TYPE_APACHE_ANT + /**=httpSessionContextIntegrationFilter,authenticationProcessingFilter,basicProcessingFilter,rememberMeProcessingFilter,anonymousProcessingFilter,securityEnforcementFilter + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + userCache + + + + + + + + + + + + + + + + + Contacts Realm + + + + foobar + anonymousUser,ROLE_ANONYMOUS + + + + foobar + + + + + + + + + + + + springRocks + + + + springRocks + + + + + + + + + + + CONVERT_URL_TO_LOWERCASE_BEFORE_COMPARISON + \A/secure/.*\Z=REQUIRES_SECURE_CHANNEL + \A/acegilogin.jsp.*\Z=REQUIRES_SECURE_CHANNEL + \A/j_acegi_security_check.*\Z=REQUIRES_SECURE_CHANNEL + \A.*\Z=REQUIRES_INSECURE_CHANNEL + + + + + + + + + + + + + + + + + + + + + + + + + + /acegilogin.jsp?login_error=1 + / + /j_acegi_security_check + + + + + /acegilogin.jsp + false + + + + false + + + + + + + + + + + + + + CONVERT_URL_TO_LOWERCASE_BEFORE_COMPARISON + PATTERN_TYPE_APACHE_ANT + /index.jsp=ROLE_ANONYMOUS,ROLE_USER + /hello.htm=ROLE_ANONYMOUS,ROLE_USER + /logoff.jsp=ROLE_ANONYMOUS,ROLE_USER + /acegilogin.jsp*=ROLE_ANONYMOUS,ROLE_USER + /**=ROLE_USER + + + + + diff --git a/samples/contacts-tiger/src/main/webapp/filter/WEB-INF/applicationContext-annotations.xml b/samples/contacts-tiger/src/main/webapp/filter/WEB-INF/applicationContext-annotations.xml new file mode 100644 index 0000000000..1bac89db5e --- /dev/null +++ b/samples/contacts-tiger/src/main/webapp/filter/WEB-INF/applicationContext-annotations.xml @@ -0,0 +1,184 @@ + + + + + + + + + + + + net.sf.acegisecurity.acl.basic.SimpleAclEntry.ADMINISTRATION + + + net.sf.acegisecurity.acl.basic.SimpleAclEntry.READ + + + net.sf.acegisecurity.acl.basic.SimpleAclEntry.DELETE + + + + + + + + + ACL_CONTACT_READ + sample.contact.Contact + + + + + + + + + + + + ACL_CONTACT_DELETE + sample.contact.Contact + + + + + + + + + + + + ACL_CONTACT_ADMIN + sample.contact.Contact + + + + + + + + + + + false + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + false + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/samples/contacts-tiger/src/main/webapp/filter/WEB-INF/applicationContext-business.xml b/samples/contacts-tiger/src/main/webapp/filter/WEB-INF/applicationContext-business.xml new file mode 100644 index 0000000000..5469acf88a --- /dev/null +++ b/samples/contacts-tiger/src/main/webapp/filter/WEB-INF/applicationContext-business.xml @@ -0,0 +1,48 @@ + + + + + + + + + + org.hsqldb.jdbcDriver + + + jdbc:hsqldb:mem:contacts + + + sa + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/samples/contacts-tiger/src/main/webapp/filter/WEB-INF/web.xml b/samples/contacts-tiger/src/main/webapp/filter/WEB-INF/web.xml new file mode 100644 index 0000000000..7b067cd65f --- /dev/null +++ b/samples/contacts-tiger/src/main/webapp/filter/WEB-INF/web.xml @@ -0,0 +1,107 @@ + + + + + + + + Contacts Sample Application + + + + contextConfigLocation + + /WEB-INF/applicationContext-acegi-security.xml + /WEB-INF/applicationContext-business.xml + /WEB-INF/applicationContext-annotations.xml + + + + + log4jConfigLocation + /WEB-INF/classes/log4j.properties + + + + Acegi Filter Chain Proxy + net.sf.acegisecurity.util.FilterToBeanProxy + + targetClass + net.sf.acegisecurity.util.FilterChainProxy + + + + + Acegi Filter Chain Proxy + /* + + + + + org.springframework.web.context.ContextLoaderListener + + + + org.springframework.web.util.Log4jConfigListener + + + + + net.sf.acegisecurity.ui.session.HttpSessionEventPublisher + + + + + contacts + org.springframework.web.servlet.DispatcherServlet + 1 + + + + + remoting + org.springframework.web.servlet.DispatcherServlet + 2 + + + + contacts + *.htm + + + + remoting + /remoting/* + + + + index.jsp + + + + /spring + /WEB-INF/spring.tld + + + diff --git a/samples/contacts-tiger/src/main/webapp/filter/acegilogin.jsp b/samples/contacts-tiger/src/main/webapp/filter/acegilogin.jsp new file mode 100644 index 0000000000..322375f8cc --- /dev/null +++ b/samples/contacts-tiger/src/main/webapp/filter/acegilogin.jsp @@ -0,0 +1,48 @@ +<%@ taglib prefix='c' uri='http://java.sun.com/jstl/core' %> +<%@ page import="net.sf.acegisecurity.ui.AbstractProcessingFilter" %> +<%@ page import="net.sf.acegisecurity.ui.webapp.AuthenticationProcessingFilter" %> +<%@ page import="net.sf.acegisecurity.AuthenticationException" %> + + + + Login + + + +

Login

+ +

Valid users: +

+

username marissa, password koala +

username dianne, password emu +

username scott, password wombat +

username peter, password opal (user disabled) +

username bill, password wombat +

username bob, password wombat +

username jane, password wombat +

+ + <%-- this form-login-page form is also used as the + form-error-page to ask for a login again. + --%> + + + Your login attempt was not successful, try again.

+ Reason: <%= ((AuthenticationException) session.getAttribute(AbstractProcessingFilter.ACEGI_SECURITY_LAST_EXCEPTION_KEY)).getMessage() %> +
+
+ +

+ + + + + + + +
User:value='<%= session.getAttribute(AuthenticationProcessingFilter.ACEGI_SECURITY_LAST_USERNAME_KEY) %>'>
Password:
Don't ask for my password for two weeks
+ +
+ + + diff --git a/samples/contacts-tiger/src/main/webapp/filter/error.html b/samples/contacts-tiger/src/main/webapp/filter/error.html new file mode 100644 index 0000000000..5d461b5a25 --- /dev/null +++ b/samples/contacts-tiger/src/main/webapp/filter/error.html @@ -0,0 +1,5 @@ + + Access denied! +

Access Denied

+ We're sorry, but you are not authorized to perform the requested operation. + \ No newline at end of file diff --git a/samples/contacts-tiger/src/main/webapp/filter/exitUser.jsp b/samples/contacts-tiger/src/main/webapp/filter/exitUser.jsp new file mode 100644 index 0000000000..52298bd469 --- /dev/null +++ b/samples/contacts-tiger/src/main/webapp/filter/exitUser.jsp @@ -0,0 +1,45 @@ +<%@ taglib prefix='c' uri='http://java.sun.com/jstl/core' %> + +<%@ page import="net.sf.acegisecurity.context.SecurityContextHolder" %> +<%@ page import="net.sf.acegisecurity.Authentication" %> +<%@ page import="net.sf.acegisecurity.ui.AbstractProcessingFilter" %> +<%@ page import="net.sf.acegisecurity.ui.webapp.AuthenticationProcessingFilter" %> +<%@ page import="net.sf.acegisecurity.AuthenticationException" %> + + + + Exit User + + + +

Exit User

+ + + + Your 'Exit User' attempt was not successful, try again.

+ Reason: <%= ((AuthenticationException) session.getAttribute(AbstractProcessingFilter.ACEGI_SECURITY_LAST_EXCEPTION_KEY)).getMessage() %> +
+
+ +
+ + + +
Current User: + + <% + Authentication auth = SecurityContextHolder.getContext().getAuthentication(); + if (auth != null) { %> + + <%= auth.getPrincipal().toString() %> + + <% } %> + + + +
+ +
+ + + diff --git a/samples/contacts-tiger/src/main/webapp/filter/switchUser.jsp b/samples/contacts-tiger/src/main/webapp/filter/switchUser.jsp new file mode 100644 index 0000000000..28388869e8 --- /dev/null +++ b/samples/contacts-tiger/src/main/webapp/filter/switchUser.jsp @@ -0,0 +1,43 @@ +<%@ taglib prefix='c' uri='http://java.sun.com/jstl/core' %> +<%@ page import="net.sf.acegisecurity.ui.AbstractProcessingFilter" %> +<%@ page import="net.sf.acegisecurity.ui.webapp.AuthenticationProcessingFilter" %> +<%@ page import="net.sf.acegisecurity.AuthenticationException" %> + + + + Switch User + + + +

Switch to User

+ +

Valid users: +

+

username marissa, password koala +

username dianne, password emu +

username scott, password wombat +

username bill, password wombat +

username bob, password wombat +

username jane, password wombat +

+ + <%-- this form-login-page form is also used as the + form-error-page to ask for a login again. + --%> + + + Your 'su' attempt was not successful, try again.

+ Reason: <%= ((AuthenticationException) session.getAttribute(AbstractProcessingFilter.ACEGI_SECURITY_LAST_EXCEPTION_KEY)).getMessage() %> +
+
+ +

+ + + +
User:
+ +
+ + +