SEC-97: Format Acegi Security source code in accordance with latest Jalopy configuration.
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
/* Copyright 2004 Acegi Technology Pty Limited
|
||||
/* Copyright 2004, 2005, 2006 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.
|
||||
@@ -25,35 +25,35 @@ import org.acegisecurity.acl.basic.SimpleAclEntry;
|
||||
* @version $Id$
|
||||
*/
|
||||
public class AddPermission {
|
||||
//~ Instance fields ========================================================
|
||||
//~ Instance fields ================================================================================================
|
||||
|
||||
public Contact contact;
|
||||
public Integer permission = new Integer(SimpleAclEntry.NOTHING);
|
||||
public String recipient;
|
||||
|
||||
//~ Methods ================================================================
|
||||
|
||||
public void setContact(Contact contact) {
|
||||
this.contact = contact;
|
||||
}
|
||||
//~ Methods ========================================================================================================
|
||||
|
||||
public Contact getContact() {
|
||||
return contact;
|
||||
}
|
||||
|
||||
public void setPermission(Integer permission) {
|
||||
this.permission = permission;
|
||||
}
|
||||
|
||||
public Integer getPermission() {
|
||||
return permission;
|
||||
}
|
||||
|
||||
public void setRecipient(String recipient) {
|
||||
this.recipient = recipient;
|
||||
}
|
||||
|
||||
public String getRecipient() {
|
||||
return recipient;
|
||||
}
|
||||
|
||||
public void setContact(Contact contact) {
|
||||
this.contact = contact;
|
||||
}
|
||||
|
||||
public void setPermission(Integer permission) {
|
||||
this.permission = permission;
|
||||
}
|
||||
|
||||
public void setRecipient(String recipient) {
|
||||
this.recipient = recipient;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/* Copyright 2004, 2005 Acegi Technology Pty Limited
|
||||
/* Copyright 2004, 2005, 2006 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.
|
||||
@@ -45,42 +45,28 @@ import javax.servlet.http.HttpServletResponse;
|
||||
* @author Ben Alex
|
||||
* @version $Id$
|
||||
*/
|
||||
public class AddPermissionController extends SimpleFormController
|
||||
implements InitializingBean {
|
||||
//~ Instance fields ========================================================
|
||||
public class AddPermissionController extends SimpleFormController implements InitializingBean {
|
||||
//~ Instance fields ================================================================================================
|
||||
|
||||
private ContactManager contactManager;
|
||||
|
||||
//~ Methods ================================================================
|
||||
|
||||
public void setContactManager(ContactManager contact) {
|
||||
this.contactManager = contact;
|
||||
}
|
||||
|
||||
public ContactManager getContactManager() {
|
||||
return contactManager;
|
||||
}
|
||||
//~ Methods ========================================================================================================
|
||||
|
||||
public void afterPropertiesSet() throws Exception {
|
||||
Assert.notNull(contactManager,
|
||||
"A ContactManager implementation is required");
|
||||
Assert.notNull(contactManager, "A ContactManager implementation is required");
|
||||
}
|
||||
|
||||
protected ModelAndView disallowDuplicateFormSubmission(
|
||||
HttpServletRequest request, HttpServletResponse response)
|
||||
protected ModelAndView disallowDuplicateFormSubmission(HttpServletRequest request, HttpServletResponse response)
|
||||
throws Exception {
|
||||
BindException errors = new BindException(formBackingObject(request),
|
||||
getCommandName());
|
||||
errors.reject("err.duplicateFormSubmission",
|
||||
"Duplicate form submission.");
|
||||
BindException errors = new BindException(formBackingObject(request), getCommandName());
|
||||
errors.reject("err.duplicateFormSubmission", "Duplicate form submission.");
|
||||
|
||||
return showForm(request, response, errors);
|
||||
}
|
||||
|
||||
protected Object formBackingObject(HttpServletRequest request)
|
||||
throws Exception {
|
||||
int contactId = RequestUtils.getRequiredIntParameter(request,
|
||||
"contactId");
|
||||
int contactId = RequestUtils.getRequiredIntParameter(request, "contactId");
|
||||
|
||||
Contact contact = contactManager.getById(new Long(contactId));
|
||||
|
||||
@@ -90,19 +76,53 @@ public class AddPermissionController extends SimpleFormController
|
||||
return addPermission;
|
||||
}
|
||||
|
||||
protected ModelAndView handleInvalidSubmit(HttpServletRequest request,
|
||||
HttpServletResponse response) throws Exception {
|
||||
public ContactManager getContactManager() {
|
||||
return contactManager;
|
||||
}
|
||||
|
||||
protected ModelAndView handleInvalidSubmit(HttpServletRequest request, HttpServletResponse response)
|
||||
throws Exception {
|
||||
return disallowDuplicateFormSubmission(request, response);
|
||||
}
|
||||
|
||||
protected ModelAndView onSubmit(HttpServletRequest request,
|
||||
HttpServletResponse response, Object command, BindException errors)
|
||||
throws Exception {
|
||||
private Map listPermissions(HttpServletRequest request) {
|
||||
Map map = new LinkedHashMap();
|
||||
map.put(new Integer(SimpleAclEntry.NOTHING),
|
||||
getApplicationContext().getMessage("select.none", null, "None", request.getLocale()));
|
||||
map.put(new Integer(SimpleAclEntry.ADMINISTRATION),
|
||||
getApplicationContext().getMessage("select.administer", null, "Administer", request.getLocale()));
|
||||
map.put(new Integer(SimpleAclEntry.READ),
|
||||
getApplicationContext().getMessage("select.read", null, "Read", request.getLocale()));
|
||||
map.put(new Integer(SimpleAclEntry.DELETE),
|
||||
getApplicationContext().getMessage("select.delete", null, "Delete", request.getLocale()));
|
||||
map.put(new Integer(SimpleAclEntry.READ_WRITE_DELETE),
|
||||
getApplicationContext().getMessage("select.readWriteDelete", null, "Read+Write+Delete", request.getLocale()));
|
||||
|
||||
return map;
|
||||
}
|
||||
|
||||
private Map listRecipients(HttpServletRequest request) {
|
||||
Map map = new LinkedHashMap();
|
||||
map.put("",
|
||||
getApplicationContext().getMessage("select.pleaseSelect", null, "-- please select --", request.getLocale()));
|
||||
|
||||
Iterator recipientsIter = contactManager.getAllRecipients().iterator();
|
||||
|
||||
while (recipientsIter.hasNext()) {
|
||||
String recipient = (String) recipientsIter.next();
|
||||
map.put(recipient, recipient);
|
||||
}
|
||||
|
||||
return map;
|
||||
}
|
||||
|
||||
protected ModelAndView onSubmit(HttpServletRequest request, HttpServletResponse response, Object command,
|
||||
BindException errors) throws Exception {
|
||||
AddPermission addPermission = (AddPermission) command;
|
||||
|
||||
try {
|
||||
contactManager.addPermission(addPermission.getContact(),
|
||||
addPermission.getRecipient(), addPermission.getPermission());
|
||||
contactManager.addPermission(addPermission.getContact(), addPermission.getRecipient(),
|
||||
addPermission.getPermission());
|
||||
} catch (DataAccessException existingPermission) {
|
||||
existingPermission.printStackTrace();
|
||||
errors.rejectValue("recipient", "err.recipientExistsForContact",
|
||||
@@ -123,40 +143,7 @@ public class AddPermissionController extends SimpleFormController
|
||||
return model;
|
||||
}
|
||||
|
||||
private Map listPermissions(HttpServletRequest request) {
|
||||
Map map = new LinkedHashMap();
|
||||
map.put(new Integer(SimpleAclEntry.NOTHING),
|
||||
getApplicationContext().getMessage("select.none", null, "None",
|
||||
request.getLocale()));
|
||||
map.put(new Integer(SimpleAclEntry.ADMINISTRATION),
|
||||
getApplicationContext().getMessage("select.administer", null,
|
||||
"Administer", request.getLocale()));
|
||||
map.put(new Integer(SimpleAclEntry.READ),
|
||||
getApplicationContext().getMessage("select.read", null, "Read",
|
||||
request.getLocale()));
|
||||
map.put(new Integer(SimpleAclEntry.DELETE),
|
||||
getApplicationContext().getMessage("select.delete", null, "Delete",
|
||||
request.getLocale()));
|
||||
map.put(new Integer(SimpleAclEntry.READ_WRITE_DELETE),
|
||||
getApplicationContext().getMessage("select.readWriteDelete", null,
|
||||
"Read+Write+Delete", request.getLocale()));
|
||||
|
||||
return map;
|
||||
}
|
||||
|
||||
private Map listRecipients(HttpServletRequest request) {
|
||||
Map map = new LinkedHashMap();
|
||||
map.put("",
|
||||
getApplicationContext().getMessage("select.pleaseSelect", null,
|
||||
"-- please select --", request.getLocale()));
|
||||
|
||||
Iterator recipientsIter = contactManager.getAllRecipients().iterator();
|
||||
|
||||
while (recipientsIter.hasNext()) {
|
||||
String recipient = (String) recipientsIter.next();
|
||||
map.put(recipient, recipient);
|
||||
}
|
||||
|
||||
return map;
|
||||
public void setContactManager(ContactManager contact) {
|
||||
this.contactManager = contact;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/* Copyright 2004 Acegi Technology Pty Limited
|
||||
/* Copyright 2004, 2005, 2006 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.
|
||||
@@ -29,7 +29,7 @@ import org.springframework.validation.Validator;
|
||||
* @version $Id$
|
||||
*/
|
||||
public class AddPermissionValidator implements Validator {
|
||||
//~ Methods ================================================================
|
||||
//~ Methods ========================================================================================================
|
||||
|
||||
public boolean supports(Class clazz) {
|
||||
return clazz.equals(AddPermission.class);
|
||||
@@ -38,21 +38,16 @@ public class AddPermissionValidator implements Validator {
|
||||
public void validate(Object obj, Errors errors) {
|
||||
AddPermission addPermission = (AddPermission) obj;
|
||||
|
||||
ValidationUtils.rejectIfEmptyOrWhitespace(errors, "permission",
|
||||
"err.permission", "Permission is required");
|
||||
ValidationUtils.rejectIfEmptyOrWhitespace(errors, "recipient",
|
||||
"err.recipient", "Recipient is required");
|
||||
ValidationUtils.rejectIfEmptyOrWhitespace(errors, "permission", "err.permission", "Permission is required");
|
||||
ValidationUtils.rejectIfEmptyOrWhitespace(errors, "recipient", "err.recipient", "Recipient is required");
|
||||
|
||||
if (addPermission.getPermission() != null) {
|
||||
int permission = addPermission.getPermission().intValue();
|
||||
|
||||
if ((permission != SimpleAclEntry.NOTHING)
|
||||
&& (permission != SimpleAclEntry.ADMINISTRATION)
|
||||
&& (permission != SimpleAclEntry.READ)
|
||||
&& (permission != SimpleAclEntry.DELETE)
|
||||
if ((permission != SimpleAclEntry.NOTHING) && (permission != SimpleAclEntry.ADMINISTRATION)
|
||||
&& (permission != SimpleAclEntry.READ) && (permission != SimpleAclEntry.DELETE)
|
||||
&& (permission != SimpleAclEntry.READ_WRITE_DELETE)) {
|
||||
errors.rejectValue("permission", "err.permission.invalid",
|
||||
"The indicated permission is invalid.");
|
||||
errors.rejectValue("permission", "err.permission.invalid", "The indicated permission is invalid.");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/* Copyright 2004, 2005 Acegi Technology Pty Limited
|
||||
/* Copyright 2004, 2005, 2006 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.
|
||||
@@ -43,37 +43,28 @@ import javax.servlet.http.HttpServletResponse;
|
||||
* @version $Id$
|
||||
*/
|
||||
public class AdminPermissionController implements Controller, InitializingBean {
|
||||
//~ Instance fields ========================================================
|
||||
//~ Instance fields ================================================================================================
|
||||
|
||||
private AclManager aclManager;
|
||||
private ContactManager contactManager;
|
||||
|
||||
//~ Methods ================================================================
|
||||
//~ Methods ========================================================================================================
|
||||
|
||||
public void setAclManager(AclManager aclManager) {
|
||||
this.aclManager = aclManager;
|
||||
public void afterPropertiesSet() throws Exception {
|
||||
Assert.notNull(contactManager, "A ContactManager implementation is required");
|
||||
Assert.notNull(aclManager, "An aclManager implementation is required");
|
||||
}
|
||||
|
||||
public AclManager getAclManager() {
|
||||
return aclManager;
|
||||
}
|
||||
|
||||
public void setContactManager(ContactManager contact) {
|
||||
this.contactManager = contact;
|
||||
}
|
||||
|
||||
public ContactManager getContactManager() {
|
||||
return contactManager;
|
||||
}
|
||||
|
||||
public void afterPropertiesSet() throws Exception {
|
||||
Assert.notNull(contactManager,
|
||||
"A ContactManager implementation is required");
|
||||
Assert.notNull(aclManager, "An aclManager implementation is required");
|
||||
}
|
||||
|
||||
public ModelAndView handleRequest(HttpServletRequest request,
|
||||
HttpServletResponse response) throws ServletException, IOException {
|
||||
public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response)
|
||||
throws ServletException, IOException {
|
||||
int id = RequestUtils.getRequiredIntParameter(request, "contactId");
|
||||
|
||||
Contact contact = contactManager.getById(new Long(id));
|
||||
@@ -85,4 +76,12 @@ public class AdminPermissionController implements Controller, InitializingBean {
|
||||
|
||||
return new ModelAndView("adminPermission", "model", model);
|
||||
}
|
||||
|
||||
public void setAclManager(AclManager aclManager) {
|
||||
this.aclManager = aclManager;
|
||||
}
|
||||
|
||||
public void setContactManager(ContactManager contact) {
|
||||
this.contactManager = contact;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -36,33 +36,27 @@ import java.util.Map;
|
||||
|
||||
|
||||
/**
|
||||
* Demonstrates accessing the {@link ContactManager} via remoting protocols.
|
||||
*
|
||||
* <P>
|
||||
* Based on Spring's JPetStore sample, written by Juergen Hoeller.
|
||||
* </p>
|
||||
* Demonstrates accessing the {@link ContactManager} via remoting protocols.<P>Based on Spring's JPetStore sample,
|
||||
* written by Juergen Hoeller.</p>
|
||||
*
|
||||
* @author Ben Alex
|
||||
*/
|
||||
public class ClientApplication {
|
||||
//~ Instance fields ========================================================
|
||||
//~ Instance fields ================================================================================================
|
||||
|
||||
private final ListableBeanFactory beanFactory;
|
||||
|
||||
//~ Constructors ===========================================================
|
||||
//~ Constructors ===================================================================================================
|
||||
|
||||
public ClientApplication(ListableBeanFactory beanFactory) {
|
||||
this.beanFactory = beanFactory;
|
||||
}
|
||||
|
||||
//~ Methods ================================================================
|
||||
//~ Methods ========================================================================================================
|
||||
|
||||
public void invokeContactManager(Authentication authentication,
|
||||
int nrOfCalls) {
|
||||
StopWatch stopWatch = new StopWatch(nrOfCalls
|
||||
+ " ContactManager call(s)");
|
||||
Map contactServices = this.beanFactory.getBeansOfType(ContactManager.class,
|
||||
true, true);
|
||||
public void invokeContactManager(Authentication authentication, int nrOfCalls) {
|
||||
StopWatch stopWatch = new StopWatch(nrOfCalls + " ContactManager call(s)");
|
||||
Map contactServices = this.beanFactory.getBeansOfType(ContactManager.class, true, true);
|
||||
|
||||
SecurityContextHolder.getContext().setAuthentication(authentication);
|
||||
|
||||
@@ -72,20 +66,13 @@ public class ClientApplication {
|
||||
Object object = this.beanFactory.getBean("&" + beanName);
|
||||
|
||||
try {
|
||||
System.out.println(
|
||||
"Trying to find setUsername(String) method on: "
|
||||
+ object.getClass().getName());
|
||||
System.out.println("Trying to find setUsername(String) method on: " + object.getClass().getName());
|
||||
|
||||
Method method = object.getClass()
|
||||
.getMethod("setUsername",
|
||||
new Class[] {String.class});
|
||||
System.out.println("Found; Trying to setUsername(String) to "
|
||||
+ authentication.getPrincipal());
|
||||
method.invoke(object,
|
||||
new Object[] {authentication.getPrincipal()});
|
||||
Method method = object.getClass().getMethod("setUsername", new Class[] {String.class});
|
||||
System.out.println("Found; Trying to setUsername(String) to " + authentication.getPrincipal());
|
||||
method.invoke(object, new Object[] {authentication.getPrincipal()});
|
||||
} catch (NoSuchMethodException ignored) {
|
||||
System.out.println(
|
||||
"This client proxy factory does not have a setUsername(String) method");
|
||||
System.out.println("This client proxy factory does not have a setUsername(String) method");
|
||||
} catch (IllegalAccessException ignored) {
|
||||
ignored.printStackTrace();
|
||||
} catch (InvocationTargetException ignored) {
|
||||
@@ -93,25 +80,17 @@ public class ClientApplication {
|
||||
}
|
||||
|
||||
try {
|
||||
System.out.println(
|
||||
"Trying to find setPassword(String) method on: "
|
||||
+ object.getClass().getName());
|
||||
System.out.println("Trying to find setPassword(String) method on: " + object.getClass().getName());
|
||||
|
||||
Method method = object.getClass()
|
||||
.getMethod("setPassword",
|
||||
new Class[] {String.class});
|
||||
method.invoke(object,
|
||||
new Object[] {authentication.getCredentials()});
|
||||
System.out.println("Found; Trying to setPassword(String) to "
|
||||
+ authentication.getCredentials());
|
||||
Method method = object.getClass().getMethod("setPassword", new Class[] {String.class});
|
||||
method.invoke(object, new Object[] {authentication.getCredentials()});
|
||||
System.out.println("Found; Trying to setPassword(String) to " + authentication.getCredentials());
|
||||
} catch (NoSuchMethodException ignored) {
|
||||
System.out.println(
|
||||
"This client proxy factory does not have a setPassword(String) method");
|
||||
System.out.println("This client proxy factory does not have a setPassword(String) method");
|
||||
} catch (IllegalAccessException ignored) {}
|
||||
catch (InvocationTargetException ignored) {}
|
||||
|
||||
ContactManager remoteContactManager = (ContactManager) contactServices
|
||||
.get(beanName);
|
||||
ContactManager remoteContactManager = (ContactManager) contactServices.get(beanName);
|
||||
System.out.println("Calling ContactManager '" + beanName + "'");
|
||||
|
||||
stopWatch.start(beanName);
|
||||
@@ -132,8 +111,7 @@ public class ClientApplication {
|
||||
System.out.println("Contact: " + contact.toString());
|
||||
}
|
||||
} else {
|
||||
System.out.println(
|
||||
"No contacts found which this user has permission to");
|
||||
System.out.println("No contacts found which this user has permission to");
|
||||
}
|
||||
|
||||
System.out.println();
|
||||
@@ -162,12 +140,10 @@ public class ClientApplication {
|
||||
nrOfCalls = Integer.parseInt(nrOfCallsString);
|
||||
}
|
||||
|
||||
ListableBeanFactory beanFactory = new FileSystemXmlApplicationContext(
|
||||
"clientContext.xml");
|
||||
ListableBeanFactory beanFactory = new FileSystemXmlApplicationContext("clientContext.xml");
|
||||
ClientApplication client = new ClientApplication(beanFactory);
|
||||
|
||||
client.invokeContactManager(new UsernamePasswordAuthenticationToken(
|
||||
username, password), nrOfCalls);
|
||||
client.invokeContactManager(new UsernamePasswordAuthenticationToken(username, password), nrOfCalls);
|
||||
System.exit(0);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/* Copyright 2004, 2005 Acegi Technology Pty Limited
|
||||
/* Copyright 2004, 2005, 2006 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.
|
||||
@@ -25,13 +25,13 @@ import java.io.Serializable;
|
||||
* @version $Id$
|
||||
*/
|
||||
public class Contact implements Serializable {
|
||||
//~ Instance fields ========================================================
|
||||
//~ Instance fields ================================================================================================
|
||||
|
||||
private Long id;
|
||||
private String email;
|
||||
private String name;
|
||||
|
||||
//~ Constructors ===========================================================
|
||||
//~ Constructors ===================================================================================================
|
||||
|
||||
public Contact(String name, String email) {
|
||||
this.name = name;
|
||||
@@ -40,16 +40,7 @@ public class Contact implements Serializable {
|
||||
|
||||
public Contact() {}
|
||||
|
||||
//~ Methods ================================================================
|
||||
|
||||
/**
|
||||
* DOCUMENT ME!
|
||||
*
|
||||
* @param email The email to set.
|
||||
*/
|
||||
public void setEmail(String email) {
|
||||
this.email = email;
|
||||
}
|
||||
//~ Methods ========================================================================================================
|
||||
|
||||
/**
|
||||
* DOCUMENT ME!
|
||||
@@ -60,10 +51,6 @@ public class Contact implements Serializable {
|
||||
return email;
|
||||
}
|
||||
|
||||
public void setId(Long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
/**
|
||||
* DOCUMENT ME!
|
||||
*
|
||||
@@ -76,19 +63,32 @@ public class Contact implements Serializable {
|
||||
/**
|
||||
* DOCUMENT ME!
|
||||
*
|
||||
* @param name The name to set.
|
||||
* @return Returns the name.
|
||||
*/
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
/**
|
||||
* DOCUMENT ME!
|
||||
*
|
||||
* @return Returns the name.
|
||||
* @param email The email to set.
|
||||
*/
|
||||
public String getName() {
|
||||
return name;
|
||||
public void setEmail(String email) {
|
||||
this.email = email;
|
||||
}
|
||||
|
||||
public void setId(Long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
/**
|
||||
* DOCUMENT ME!
|
||||
*
|
||||
* @param name The name to set.
|
||||
*/
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/* Copyright 2004, 2005 Acegi Technology Pty Limited
|
||||
/* Copyright 2004, 2005, 2006 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.
|
||||
@@ -25,9 +25,7 @@ import java.util.List;
|
||||
* @version $Id$
|
||||
*/
|
||||
public interface ContactDao {
|
||||
//~ Methods ================================================================
|
||||
|
||||
public Contact getById(Long id);
|
||||
//~ Methods ========================================================================================================
|
||||
|
||||
public void create(Contact contact);
|
||||
|
||||
@@ -39,5 +37,7 @@ public interface ContactDao {
|
||||
|
||||
public List findAllRoles();
|
||||
|
||||
public Contact getById(Long id);
|
||||
|
||||
public void update(Contact contact);
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/* Copyright 2004, 2005 Acegi Technology Pty Limited
|
||||
/* Copyright 2004, 2005, 2006 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.
|
||||
@@ -36,7 +36,7 @@ import javax.sql.DataSource;
|
||||
* @version $Id$
|
||||
*/
|
||||
public class ContactDaoSpring extends JdbcDaoSupport implements ContactDao {
|
||||
//~ Instance fields ========================================================
|
||||
//~ Instance fields ================================================================================================
|
||||
|
||||
private ContactDelete contactDelete;
|
||||
private ContactInsert contactInsert;
|
||||
@@ -46,21 +46,10 @@ public class ContactDaoSpring extends JdbcDaoSupport implements ContactDao {
|
||||
private PrincipalsAllQuery principalsAllQuery;
|
||||
private RolesAllQuery rolesAllQuery;
|
||||
|
||||
//~ Methods ================================================================
|
||||
|
||||
public Contact getById(Long id) {
|
||||
List list = contactsByIdQuery.execute(id.longValue());
|
||||
|
||||
if (list.size() == 0) {
|
||||
return null;
|
||||
} else {
|
||||
return (Contact) list.get(0);
|
||||
}
|
||||
}
|
||||
//~ Methods ========================================================================================================
|
||||
|
||||
public void create(Contact contact) {
|
||||
System.out.println("creating contact w/ id " + contact.getId() + " "
|
||||
+ contact.getEmail());
|
||||
System.out.println("creating contact w/ id " + contact.getId() + " " + contact.getEmail());
|
||||
contactInsert.insert(contact);
|
||||
}
|
||||
|
||||
@@ -80,8 +69,14 @@ public class ContactDaoSpring extends JdbcDaoSupport implements ContactDao {
|
||||
return rolesAllQuery.execute();
|
||||
}
|
||||
|
||||
public void update(Contact contact) {
|
||||
contactUpdate.update(contact);
|
||||
public Contact getById(Long id) {
|
||||
List list = contactsByIdQuery.execute(id.longValue());
|
||||
|
||||
if (list.size() == 0) {
|
||||
return null;
|
||||
} else {
|
||||
return (Contact) list.get(0);
|
||||
}
|
||||
}
|
||||
|
||||
protected void initDao() throws Exception {
|
||||
@@ -98,13 +93,15 @@ public class ContactDaoSpring extends JdbcDaoSupport implements ContactDao {
|
||||
return contact.getClass().getName() + ":" + contact.getId();
|
||||
}
|
||||
|
||||
//~ Inner Classes ==========================================================
|
||||
public void update(Contact contact) {
|
||||
contactUpdate.update(contact);
|
||||
}
|
||||
|
||||
protected class AclObjectIdentityByObjectIdentityQuery
|
||||
extends MappingSqlQuery {
|
||||
//~ Inner Classes ==================================================================================================
|
||||
|
||||
protected class AclObjectIdentityByObjectIdentityQuery extends MappingSqlQuery {
|
||||
protected AclObjectIdentityByObjectIdentityQuery(DataSource ds) {
|
||||
super(ds,
|
||||
"SELECT id FROM acl_object_identity WHERE object_identity = ?");
|
||||
super(ds, "SELECT id FROM acl_object_identity WHERE object_identity = ?");
|
||||
declareParameter(new SqlParameter(Types.VARCHAR));
|
||||
compile();
|
||||
}
|
||||
@@ -125,8 +122,7 @@ public class ContactDaoSpring extends JdbcDaoSupport implements ContactDao {
|
||||
compile();
|
||||
}
|
||||
|
||||
protected int insert(String objectIdentity,
|
||||
Long parentAclObjectIdentity, String aclClass) {
|
||||
protected int insert(String objectIdentity, Long parentAclObjectIdentity, String aclClass) {
|
||||
Object[] objs = new Object[] {null, objectIdentity, parentAclObjectIdentity, aclClass};
|
||||
super.update(objs);
|
||||
|
||||
@@ -156,16 +152,14 @@ public class ContactDaoSpring extends JdbcDaoSupport implements ContactDao {
|
||||
}
|
||||
|
||||
protected void insert(Contact contact) {
|
||||
Object[] objs = new Object[] {contact.getId(), contact.getName(), contact
|
||||
.getEmail()};
|
||||
Object[] objs = new Object[] {contact.getId(), contact.getName(), contact.getEmail()};
|
||||
super.update(objs);
|
||||
}
|
||||
}
|
||||
|
||||
protected class ContactUpdate extends SqlUpdate {
|
||||
protected ContactUpdate(DataSource ds) {
|
||||
super(ds,
|
||||
"UPDATE contacts SET contact_name = ?, address = ? WHERE id = ?");
|
||||
super(ds, "UPDATE contacts SET contact_name = ?, address = ? WHERE id = ?");
|
||||
declareParameter(new SqlParameter(Types.VARCHAR));
|
||||
declareParameter(new SqlParameter(Types.VARCHAR));
|
||||
declareParameter(new SqlParameter(Types.BIGINT));
|
||||
@@ -173,8 +167,7 @@ public class ContactDaoSpring extends JdbcDaoSupport implements ContactDao {
|
||||
}
|
||||
|
||||
protected void update(Contact contact) {
|
||||
Object[] objs = new Object[] {contact.getName(), contact.getEmail(), contact
|
||||
.getId()};
|
||||
Object[] objs = new Object[] {contact.getName(), contact.getEmail(), contact.getId()};
|
||||
super.update(objs);
|
||||
}
|
||||
}
|
||||
@@ -198,8 +191,7 @@ public class ContactDaoSpring extends JdbcDaoSupport implements ContactDao {
|
||||
|
||||
protected class ContactsByIdQuery extends MappingSqlQuery {
|
||||
protected ContactsByIdQuery(DataSource ds) {
|
||||
super(ds,
|
||||
"SELECT id, contact_name, email FROM contacts WHERE id = ? ORDER BY id");
|
||||
super(ds, "SELECT id, contact_name, email FROM contacts WHERE id = ? ORDER BY id");
|
||||
declareParameter(new SqlParameter(Types.BIGINT));
|
||||
compile();
|
||||
}
|
||||
@@ -217,8 +209,7 @@ public class ContactDaoSpring extends JdbcDaoSupport implements ContactDao {
|
||||
|
||||
protected class PermissionDelete extends SqlUpdate {
|
||||
protected PermissionDelete(DataSource ds) {
|
||||
super(ds,
|
||||
"DELETE FROM acl_permission WHERE ACL_OBJECT_IDENTITY = ? AND RECIPIENT = ?");
|
||||
super(ds, "DELETE FROM acl_permission WHERE ACL_OBJECT_IDENTITY = ? AND RECIPIENT = ?");
|
||||
declareParameter(new SqlParameter(Types.BIGINT));
|
||||
declareParameter(new SqlParameter(Types.VARCHAR));
|
||||
compile();
|
||||
@@ -239,8 +230,7 @@ public class ContactDaoSpring extends JdbcDaoSupport implements ContactDao {
|
||||
compile();
|
||||
}
|
||||
|
||||
protected int insert(Long aclObjectIdentity, String recipient,
|
||||
Integer mask) {
|
||||
protected int insert(Long aclObjectIdentity, String recipient, Integer mask) {
|
||||
Object[] objs = new Object[] {null, aclObjectIdentity, recipient, mask};
|
||||
super.update(objs);
|
||||
|
||||
@@ -262,8 +252,7 @@ public class ContactDaoSpring extends JdbcDaoSupport implements ContactDao {
|
||||
|
||||
protected class RolesAllQuery extends MappingSqlQuery {
|
||||
protected RolesAllQuery(DataSource ds) {
|
||||
super(ds,
|
||||
"SELECT DISTINCT authority FROM authorities ORDER BY authority");
|
||||
super(ds, "SELECT DISTINCT authority FROM authorities ORDER BY authority");
|
||||
compile();
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/* Copyright 2004, 2005 Acegi Technology Pty Limited
|
||||
/* Copyright 2004, 2005, 2006 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.
|
||||
@@ -25,7 +25,15 @@ import java.util.List;
|
||||
* @version $Id$
|
||||
*/
|
||||
public interface ContactManager {
|
||||
//~ Methods ================================================================
|
||||
//~ Methods ========================================================================================================
|
||||
|
||||
public void addPermission(Contact contact, String recipient, Integer permission);
|
||||
|
||||
public void create(Contact contact);
|
||||
|
||||
public void delete(Contact contact);
|
||||
|
||||
public void deletePermission(Contact contact, String recipient);
|
||||
|
||||
public List getAll();
|
||||
|
||||
@@ -34,13 +42,4 @@ public interface ContactManager {
|
||||
public Contact getById(Long id);
|
||||
|
||||
public Contact getRandomContact();
|
||||
|
||||
public void addPermission(Contact contact, String recipient,
|
||||
Integer permission);
|
||||
|
||||
public void create(Contact contact);
|
||||
|
||||
public void delete(Contact contact);
|
||||
|
||||
public void deletePermission(Contact contact, String recipient);
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/* Copyright 2004, 2005 Acegi Technology Pty Limited
|
||||
/* Copyright 2004, 2005, 2006 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.
|
||||
@@ -16,11 +16,14 @@
|
||||
package sample.contact;
|
||||
|
||||
import org.acegisecurity.Authentication;
|
||||
|
||||
import org.acegisecurity.acl.basic.AclObjectIdentity;
|
||||
import org.acegisecurity.acl.basic.BasicAclExtendedDao;
|
||||
import org.acegisecurity.acl.basic.NamedEntityObjectIdentity;
|
||||
import org.acegisecurity.acl.basic.SimpleAclEntry;
|
||||
|
||||
import org.acegisecurity.context.SecurityContextHolder;
|
||||
|
||||
import org.acegisecurity.userdetails.UserDetails;
|
||||
|
||||
import org.springframework.beans.factory.InitializingBean;
|
||||
@@ -39,15 +42,63 @@ import java.util.Random;
|
||||
* @author Ben Alex
|
||||
* @version $Id$
|
||||
*/
|
||||
public class ContactManagerBackend extends ApplicationObjectSupport
|
||||
implements ContactManager, InitializingBean {
|
||||
//~ Instance fields ========================================================
|
||||
public class ContactManagerBackend extends ApplicationObjectSupport implements ContactManager, InitializingBean {
|
||||
//~ Instance fields ================================================================================================
|
||||
|
||||
private BasicAclExtendedDao basicAclExtendedDao;
|
||||
private ContactDao contactDao;
|
||||
private int counter = 1000;
|
||||
|
||||
//~ Methods ================================================================
|
||||
//~ Methods ========================================================================================================
|
||||
|
||||
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");
|
||||
}
|
||||
|
||||
public void create(Contact contact) {
|
||||
// Create the Contact itself
|
||||
contact.setId(new Long(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());
|
||||
}
|
||||
}
|
||||
|
||||
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");
|
||||
}
|
||||
}
|
||||
|
||||
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 List getAll() {
|
||||
if (logger.isDebugEnabled()) {
|
||||
@@ -68,10 +119,6 @@ public class ContactManagerBackend extends ApplicationObjectSupport
|
||||
return list;
|
||||
}
|
||||
|
||||
public void setBasicAclExtendedDao(BasicAclExtendedDao basicAclExtendedDao) {
|
||||
this.basicAclExtendedDao = basicAclExtendedDao;
|
||||
}
|
||||
|
||||
public BasicAclExtendedDao getBasicAclExtendedDao() {
|
||||
return basicAclExtendedDao;
|
||||
}
|
||||
@@ -84,10 +131,6 @@ public class ContactManagerBackend extends ApplicationObjectSupport
|
||||
return contactDao.getById(id);
|
||||
}
|
||||
|
||||
public void setContactDao(ContactDao contactDao) {
|
||||
this.contactDao = contactDao;
|
||||
}
|
||||
|
||||
public ContactDao getContactDao() {
|
||||
return contactDao;
|
||||
}
|
||||
@@ -109,72 +152,8 @@ public class ContactManagerBackend extends ApplicationObjectSupport
|
||||
return (Contact) contacts.get(getNumber);
|
||||
}
|
||||
|
||||
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");
|
||||
}
|
||||
|
||||
public void create(Contact contact) {
|
||||
// Create the Contact itself
|
||||
contact.setId(new Long(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());
|
||||
}
|
||||
}
|
||||
|
||||
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");
|
||||
}
|
||||
}
|
||||
|
||||
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();
|
||||
Authentication auth = SecurityContextHolder.getContext().getAuthentication();
|
||||
|
||||
if (auth.getPrincipal() instanceof UserDetails) {
|
||||
return ((UserDetails) auth.getPrincipal()).getUsername();
|
||||
@@ -184,7 +163,22 @@ public class ContactManagerBackend extends ApplicationObjectSupport
|
||||
}
|
||||
|
||||
private AclObjectIdentity makeObjectIdentity(Contact contact) {
|
||||
return new NamedEntityObjectIdentity(contact.getClass().getName(),
|
||||
contact.getId().toString());
|
||||
return new NamedEntityObjectIdentity(contact.getClass().getName(), contact.getId().toString());
|
||||
}
|
||||
|
||||
public void setBasicAclExtendedDao(BasicAclExtendedDao basicAclExtendedDao) {
|
||||
this.basicAclExtendedDao = basicAclExtendedDao;
|
||||
}
|
||||
|
||||
public void setContactDao(ContactDao contactDao) {
|
||||
this.contactDao = contactDao;
|
||||
}
|
||||
|
||||
public void update(Contact contact) {
|
||||
contactDao.update(contact);
|
||||
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("Updated contact " + contact);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/* Copyright 2004, 2005 Acegi Technology Pty Limited
|
||||
/* Copyright 2004, 2005, 2006 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.
|
||||
@@ -33,31 +33,23 @@ import javax.sql.DataSource;
|
||||
* @version $Id$
|
||||
*/
|
||||
public class DataSourcePopulator implements InitializingBean {
|
||||
//~ Instance fields ========================================================
|
||||
//~ Instance fields ================================================================================================
|
||||
|
||||
Random rnd = new Random();
|
||||
String[] firstNames = {"Bob", "Mary", "James", "Jane", "Kristy", "Kirsty", "Kate", "Jeni", "Angela", "Melanie", "Kent", "William", "Geoff", "Jeff", "Adrian", "Amanda", "Lisa", "Elizabeth", "Prue", "Richard", "Darin", "Phillip", "Michael", "Belinda", "Samantha", "Brian", "Greg", "Matthew"};
|
||||
String[] lastNames = {"Smith", "Williams", "Jackson", "Rictor", "Nelson", "Fitzgerald", "McAlpine", "Sutherland", "Abbott", "Hall", "Edwards", "Gates", "Black", "Brown", "Gray", "Marwell", "Booch", "Johnson", "McTaggart", "Parklin", "Findlay", "Robinson", "Giugni", "Lang", "Chi", "Carmichael"};
|
||||
private DataSource dataSource;
|
||||
Random rnd = new Random();
|
||||
String[] firstNames = {
|
||||
"Bob", "Mary", "James", "Jane", "Kristy", "Kirsty", "Kate", "Jeni", "Angela", "Melanie", "Kent", "William",
|
||||
"Geoff", "Jeff", "Adrian", "Amanda", "Lisa", "Elizabeth", "Prue", "Richard", "Darin", "Phillip", "Michael",
|
||||
"Belinda", "Samantha", "Brian", "Greg", "Matthew"
|
||||
};
|
||||
String[] lastNames = {
|
||||
"Smith", "Williams", "Jackson", "Rictor", "Nelson", "Fitzgerald", "McAlpine", "Sutherland", "Abbott", "Hall",
|
||||
"Edwards", "Gates", "Black", "Brown", "Gray", "Marwell", "Booch", "Johnson", "McTaggart", "Parklin",
|
||||
"Findlay", "Robinson", "Giugni", "Lang", "Chi", "Carmichael"
|
||||
};
|
||||
private int createEntities = 1000;
|
||||
|
||||
//~ Methods ================================================================
|
||||
|
||||
public void setCreateEntities(int createEntities) {
|
||||
this.createEntities = createEntities;
|
||||
}
|
||||
|
||||
public int getCreateEntities() {
|
||||
return createEntities;
|
||||
}
|
||||
|
||||
public void setDataSource(DataSource dataSource) {
|
||||
this.dataSource = dataSource;
|
||||
}
|
||||
|
||||
public DataSource getDataSource() {
|
||||
return dataSource;
|
||||
}
|
||||
//~ Methods ========================================================================================================
|
||||
|
||||
public void afterPropertiesSet() throws Exception {
|
||||
Assert.notNull(dataSource, "dataSource required");
|
||||
@@ -66,30 +58,20 @@ public class DataSourcePopulator implements InitializingBean {
|
||||
|
||||
template.execute(
|
||||
"CREATE TABLE CONTACTS(ID BIGINT NOT NULL PRIMARY KEY, CONTACT_NAME VARCHAR_IGNORECASE(50) NOT NULL, EMAIL VARCHAR_IGNORECASE(50) NOT NULL)");
|
||||
template.execute(
|
||||
"INSERT INTO contacts VALUES (1, 'John Smith', 'john@somewhere.com');"); // marissa
|
||||
template.execute(
|
||||
"INSERT INTO contacts VALUES (2, 'Michael Citizen', 'michael@xyz.com');"); // marissa
|
||||
template.execute(
|
||||
"INSERT INTO contacts VALUES (3, 'Joe Bloggs', 'joe@demo.com');"); // marissa
|
||||
template.execute(
|
||||
"INSERT INTO contacts VALUES (4, 'Karen Sutherland', 'karen@sutherland.com');"); // marissa + dianne + scott
|
||||
template.execute(
|
||||
"INSERT INTO contacts VALUES (5, 'Mitchell Howard', 'mitchell@abcdef.com');"); // dianne
|
||||
template.execute(
|
||||
"INSERT INTO contacts VALUES (6, 'Rose Costas', 'rose@xyz.com');"); // dianne + scott
|
||||
template.execute(
|
||||
"INSERT INTO contacts VALUES (7, 'Amanda Smith', 'amanda@abcdef.com');"); // scott
|
||||
template.execute(
|
||||
"INSERT INTO contacts VALUES (8, 'Cindy Smith', 'cindy@smith.com');"); // dianne + scott
|
||||
template.execute(
|
||||
"INSERT INTO contacts VALUES (9, 'Jonathan Citizen', 'jonathan@xyz.com');"); // scott
|
||||
template.execute("INSERT INTO contacts VALUES (1, 'John Smith', 'john@somewhere.com');"); // marissa
|
||||
template.execute("INSERT INTO contacts VALUES (2, 'Michael Citizen', 'michael@xyz.com');"); // marissa
|
||||
template.execute("INSERT INTO contacts VALUES (3, 'Joe Bloggs', 'joe@demo.com');"); // marissa
|
||||
template.execute("INSERT INTO contacts VALUES (4, 'Karen Sutherland', 'karen@sutherland.com');"); // marissa + dianne + scott
|
||||
template.execute("INSERT INTO contacts VALUES (5, 'Mitchell Howard', 'mitchell@abcdef.com');"); // dianne
|
||||
template.execute("INSERT INTO contacts VALUES (6, 'Rose Costas', 'rose@xyz.com');"); // dianne + scott
|
||||
template.execute("INSERT INTO contacts VALUES (7, 'Amanda Smith', 'amanda@abcdef.com');"); // scott
|
||||
template.execute("INSERT INTO contacts VALUES (8, 'Cindy Smith', 'cindy@smith.com');"); // dianne + scott
|
||||
template.execute("INSERT INTO contacts VALUES (9, 'Jonathan Citizen', 'jonathan@xyz.com');"); // scott
|
||||
|
||||
for (int i = 10; i < createEntities; i++) {
|
||||
String[] person = selectPerson();
|
||||
template.execute("INSERT INTO contacts VALUES (" + i + ", '"
|
||||
+ person[2] + "', '" + person[0].toLowerCase() + "@"
|
||||
+ person[1].toLowerCase() + ".com');");
|
||||
template.execute("INSERT INTO contacts VALUES (" + i + ", '" + person[2] + "', '" + person[0].toLowerCase()
|
||||
+ "@" + person[1].toLowerCase() + ".com');");
|
||||
}
|
||||
|
||||
template.execute(
|
||||
@@ -114,39 +96,25 @@ public class DataSourcePopulator implements InitializingBean {
|
||||
"INSERT INTO acl_object_identity VALUES (9, 'sample.contact.Contact:9', null, 'org.acegisecurity.acl.basic.SimpleAclEntry');");
|
||||
|
||||
for (int i = 10; i < createEntities; i++) {
|
||||
template.execute("INSERT INTO acl_object_identity VALUES (" + i
|
||||
+ ", 'sample.contact.Contact:" + i
|
||||
template.execute("INSERT INTO acl_object_identity VALUES (" + i + ", 'sample.contact.Contact:" + i
|
||||
+ "', null, 'org.acegisecurity.acl.basic.SimpleAclEntry');");
|
||||
}
|
||||
|
||||
template.execute(
|
||||
"CREATE TABLE ACL_PERMISSION(ID BIGINT GENERATED BY DEFAULT AS IDENTITY(START WITH 100) NOT NULL PRIMARY KEY,ACL_OBJECT_IDENTITY BIGINT NOT NULL,RECIPIENT VARCHAR_IGNORECASE(100) NOT NULL,MASK INTEGER NOT NULL,CONSTRAINT UNIQUE_RECIPIENT UNIQUE(ACL_OBJECT_IDENTITY,RECIPIENT),CONSTRAINT SYS_FK_7 FOREIGN KEY(ACL_OBJECT_IDENTITY) REFERENCES ACL_OBJECT_IDENTITY(ID))");
|
||||
template.execute(
|
||||
"INSERT INTO acl_permission VALUES (null, 1, 'marissa', 1);"); // administer
|
||||
template.execute(
|
||||
"INSERT INTO acl_permission VALUES (null, 2, 'marissa', 2);"); // read
|
||||
template.execute(
|
||||
"INSERT INTO acl_permission VALUES (null, 3, 'marissa', 22);"); // read+write+delete
|
||||
template.execute(
|
||||
"INSERT INTO acl_permission VALUES (null, 4, 'marissa', 1);"); // administer
|
||||
template.execute(
|
||||
"INSERT INTO acl_permission VALUES (null, 4, 'dianne', 1);"); // administer
|
||||
template.execute(
|
||||
"INSERT INTO acl_permission VALUES (null, 4, 'scott', 2);"); // read
|
||||
template.execute(
|
||||
"INSERT INTO acl_permission VALUES (null, 5, 'dianne', 2);"); // read
|
||||
template.execute(
|
||||
"INSERT INTO acl_permission VALUES (null, 6, 'dianne', 22);"); // read+write+delete
|
||||
template.execute(
|
||||
"INSERT INTO acl_permission VALUES (null, 6, 'scott', 2);"); // read
|
||||
template.execute(
|
||||
"INSERT INTO acl_permission VALUES (null, 7, 'scott', 1);"); // administer
|
||||
template.execute(
|
||||
"INSERT INTO acl_permission VALUES (null, 8, 'dianne', 2);"); // read
|
||||
template.execute(
|
||||
"INSERT INTO acl_permission VALUES (null, 8, 'scott', 2);"); // read
|
||||
template.execute(
|
||||
"INSERT INTO acl_permission VALUES (null, 9, 'scott', 22);"); // read+write+delete
|
||||
template.execute("INSERT INTO acl_permission VALUES (null, 1, 'marissa', 1);"); // administer
|
||||
template.execute("INSERT INTO acl_permission VALUES (null, 2, 'marissa', 2);"); // read
|
||||
template.execute("INSERT INTO acl_permission VALUES (null, 3, 'marissa', 22);"); // read+write+delete
|
||||
template.execute("INSERT INTO acl_permission VALUES (null, 4, 'marissa', 1);"); // administer
|
||||
template.execute("INSERT INTO acl_permission VALUES (null, 4, 'dianne', 1);"); // administer
|
||||
template.execute("INSERT INTO acl_permission VALUES (null, 4, 'scott', 2);"); // read
|
||||
template.execute("INSERT INTO acl_permission VALUES (null, 5, 'dianne', 2);"); // read
|
||||
template.execute("INSERT INTO acl_permission VALUES (null, 6, 'dianne', 22);"); // read+write+delete
|
||||
template.execute("INSERT INTO acl_permission VALUES (null, 6, 'scott', 2);"); // read
|
||||
template.execute("INSERT INTO acl_permission VALUES (null, 7, 'scott', 1);"); // administer
|
||||
template.execute("INSERT INTO acl_permission VALUES (null, 8, 'dianne', 2);"); // read
|
||||
template.execute("INSERT INTO acl_permission VALUES (null, 8, 'scott', 2);"); // read
|
||||
template.execute("INSERT INTO acl_permission VALUES (null, 9, 'scott', 22);"); // read+write+delete
|
||||
|
||||
String[] users = {"bill", "bob", "jane"}; // don't want to mess around with consistent sample data
|
||||
int[] permissions = {1, 2, 22};
|
||||
@@ -154,15 +122,14 @@ public class DataSourcePopulator implements InitializingBean {
|
||||
for (int i = 10; i < createEntities; i++) {
|
||||
String user = users[rnd.nextInt(users.length)];
|
||||
int permission = permissions[rnd.nextInt(permissions.length)];
|
||||
template.execute("INSERT INTO acl_permission VALUES (null, " + i
|
||||
+ ", '" + user + "', " + permission + ");");
|
||||
template.execute("INSERT INTO acl_permission VALUES (null, " + i + ", '" + user + "', " + permission + ");");
|
||||
|
||||
String user2 = users[rnd.nextInt(users.length)];
|
||||
int permission2 = permissions[rnd.nextInt(permissions.length)];
|
||||
|
||||
if (!user2.equals(user)) {
|
||||
template.execute("INSERT INTO acl_permission VALUES (null, "
|
||||
+ i + ", '" + user2 + "', " + permission2 + ");");
|
||||
template.execute("INSERT INTO acl_permission VALUES (null, " + i + ", '" + user2 + "', " + permission2
|
||||
+ ");");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -170,8 +137,7 @@ public class DataSourcePopulator implements InitializingBean {
|
||||
"CREATE TABLE USERS(USERNAME VARCHAR_IGNORECASE(50) NOT NULL PRIMARY KEY,PASSWORD VARCHAR_IGNORECASE(50) NOT NULL,ENABLED BOOLEAN NOT NULL);");
|
||||
template.execute(
|
||||
"CREATE TABLE AUTHORITIES(USERNAME VARCHAR_IGNORECASE(50) NOT NULL,AUTHORITY VARCHAR_IGNORECASE(50) NOT NULL,CONSTRAINT FK_AUTHORITIES_USERS FOREIGN KEY(USERNAME) REFERENCES USERS(USERNAME));");
|
||||
template.execute(
|
||||
"CREATE UNIQUE INDEX IX_AUTH_USERNAME ON AUTHORITIES(USERNAME,AUTHORITY);");
|
||||
template.execute("CREATE UNIQUE INDEX IX_AUTH_USERNAME ON AUTHORITIES(USERNAME,AUTHORITY);");
|
||||
|
||||
/*
|
||||
Passwords encoded using MD5, NOT in Base64 format, with null as salt
|
||||
@@ -184,26 +150,16 @@ public class DataSourcePopulator implements InitializingBean {
|
||||
Encoded password for jane is "wombat"
|
||||
|
||||
*/
|
||||
template.execute(
|
||||
"INSERT INTO USERS VALUES('marissa','a564de63c2d0da68cf47586ee05984d7',TRUE);");
|
||||
template.execute(
|
||||
"INSERT INTO USERS VALUES('dianne','65d15fe9156f9c4bbffd98085992a44e',TRUE);");
|
||||
template.execute(
|
||||
"INSERT INTO USERS VALUES('scott','2b58af6dddbd072ed27ffc86725d7d3a',TRUE);");
|
||||
template.execute(
|
||||
"INSERT INTO USERS VALUES('peter','22b5c9accc6e1ba628cedc63a72d57f8',FALSE);");
|
||||
template.execute(
|
||||
"INSERT INTO USERS VALUES('bill','2b58af6dddbd072ed27ffc86725d7d3a',TRUE);");
|
||||
template.execute(
|
||||
"INSERT INTO USERS VALUES('bob','2b58af6dddbd072ed27ffc86725d7d3a',TRUE);");
|
||||
template.execute(
|
||||
"INSERT INTO USERS VALUES('jane','2b58af6dddbd072ed27ffc86725d7d3a',TRUE);");
|
||||
template.execute(
|
||||
"INSERT INTO AUTHORITIES VALUES('marissa','ROLE_USER');");
|
||||
template.execute(
|
||||
"INSERT INTO AUTHORITIES VALUES('marissa','ROLE_SUPERVISOR');");
|
||||
template.execute(
|
||||
"INSERT INTO AUTHORITIES VALUES('dianne','ROLE_USER');");
|
||||
template.execute("INSERT INTO USERS VALUES('marissa','a564de63c2d0da68cf47586ee05984d7',TRUE);");
|
||||
template.execute("INSERT INTO USERS VALUES('dianne','65d15fe9156f9c4bbffd98085992a44e',TRUE);");
|
||||
template.execute("INSERT INTO USERS VALUES('scott','2b58af6dddbd072ed27ffc86725d7d3a',TRUE);");
|
||||
template.execute("INSERT INTO USERS VALUES('peter','22b5c9accc6e1ba628cedc63a72d57f8',FALSE);");
|
||||
template.execute("INSERT INTO USERS VALUES('bill','2b58af6dddbd072ed27ffc86725d7d3a',TRUE);");
|
||||
template.execute("INSERT INTO USERS VALUES('bob','2b58af6dddbd072ed27ffc86725d7d3a',TRUE);");
|
||||
template.execute("INSERT INTO USERS VALUES('jane','2b58af6dddbd072ed27ffc86725d7d3a',TRUE);");
|
||||
template.execute("INSERT INTO AUTHORITIES VALUES('marissa','ROLE_USER');");
|
||||
template.execute("INSERT INTO AUTHORITIES VALUES('marissa','ROLE_SUPERVISOR');");
|
||||
template.execute("INSERT INTO AUTHORITIES VALUES('dianne','ROLE_USER');");
|
||||
template.execute("INSERT INTO AUTHORITIES VALUES('scott','ROLE_USER');");
|
||||
template.execute("INSERT INTO AUTHORITIES VALUES('peter','ROLE_USER');");
|
||||
template.execute("INSERT INTO AUTHORITIES VALUES('bill','ROLE_USER');");
|
||||
@@ -211,10 +167,26 @@ public class DataSourcePopulator implements InitializingBean {
|
||||
template.execute("INSERT INTO AUTHORITIES VALUES('jane','ROLE_USER');");
|
||||
}
|
||||
|
||||
public int getCreateEntities() {
|
||||
return createEntities;
|
||||
}
|
||||
|
||||
public DataSource getDataSource() {
|
||||
return dataSource;
|
||||
}
|
||||
|
||||
private String[] selectPerson() {
|
||||
String firstName = firstNames[rnd.nextInt(firstNames.length)];
|
||||
String lastName = lastNames[rnd.nextInt(lastNames.length)];
|
||||
|
||||
return new String[] {firstName, lastName, firstName + " " + lastName};
|
||||
}
|
||||
|
||||
public void setCreateEntities(int createEntities) {
|
||||
this.createEntities = createEntities;
|
||||
}
|
||||
|
||||
public void setDataSource(DataSource dataSource) {
|
||||
this.dataSource = dataSource;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/* Copyright 2004, 2005 Acegi Technology Pty Limited
|
||||
/* Copyright 2004, 2005, 2006 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.
|
||||
@@ -37,31 +37,30 @@ import javax.servlet.http.HttpServletResponse;
|
||||
* @version $Id$
|
||||
*/
|
||||
public class DeleteController implements Controller, InitializingBean {
|
||||
//~ Instance fields ========================================================
|
||||
//~ Instance fields ================================================================================================
|
||||
|
||||
private ContactManager contactManager;
|
||||
|
||||
//~ Methods ================================================================
|
||||
//~ Methods ========================================================================================================
|
||||
|
||||
public void setContactManager(ContactManager contact) {
|
||||
this.contactManager = contact;
|
||||
public void afterPropertiesSet() throws Exception {
|
||||
Assert.notNull(contactManager, "A ContactManager implementation is required");
|
||||
}
|
||||
|
||||
public ContactManager getContactManager() {
|
||||
return contactManager;
|
||||
}
|
||||
|
||||
public void afterPropertiesSet() throws Exception {
|
||||
Assert.notNull(contactManager,
|
||||
"A ContactManager implementation is required");
|
||||
}
|
||||
|
||||
public ModelAndView handleRequest(HttpServletRequest request,
|
||||
HttpServletResponse response) throws ServletException, IOException {
|
||||
public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response)
|
||||
throws ServletException, IOException {
|
||||
int id = RequestUtils.getRequiredIntParameter(request, "contactId");
|
||||
Contact contact = contactManager.getById(new Long(id));
|
||||
contactManager.delete(contact);
|
||||
|
||||
return new ModelAndView("deleted", "contact", contact);
|
||||
}
|
||||
|
||||
public void setContactManager(ContactManager contact) {
|
||||
this.contactManager = contact;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/* Copyright 2004, 2005 Acegi Technology Pty Limited
|
||||
/* Copyright 2004, 2005, 2006 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.
|
||||
@@ -42,41 +42,30 @@ import javax.servlet.http.HttpServletResponse;
|
||||
* @version $Id$
|
||||
*/
|
||||
public class DeletePermissionController implements Controller, InitializingBean {
|
||||
//~ Instance fields ========================================================
|
||||
//~ Instance fields ================================================================================================
|
||||
|
||||
private AclManager aclManager;
|
||||
private ContactManager contactManager;
|
||||
|
||||
//~ Methods ================================================================
|
||||
//~ Methods ========================================================================================================
|
||||
|
||||
public void setAclManager(AclManager aclManager) {
|
||||
this.aclManager = aclManager;
|
||||
public void afterPropertiesSet() throws Exception {
|
||||
Assert.notNull(contactManager, "A ContactManager implementation is required");
|
||||
Assert.notNull(aclManager, "An aclManager implementation is required");
|
||||
}
|
||||
|
||||
public AclManager getAclManager() {
|
||||
return aclManager;
|
||||
}
|
||||
|
||||
public void setContactManager(ContactManager contact) {
|
||||
this.contactManager = contact;
|
||||
}
|
||||
|
||||
public ContactManager getContactManager() {
|
||||
return contactManager;
|
||||
}
|
||||
|
||||
public void afterPropertiesSet() throws Exception {
|
||||
Assert.notNull(contactManager,
|
||||
"A ContactManager implementation is required");
|
||||
Assert.notNull(aclManager, "An aclManager implementation is required");
|
||||
}
|
||||
|
||||
public ModelAndView handleRequest(HttpServletRequest request,
|
||||
HttpServletResponse response) throws ServletException, IOException {
|
||||
int contactId = RequestUtils.getRequiredIntParameter(request,
|
||||
"contactId");
|
||||
String recipient = RequestUtils.getRequiredStringParameter(request,
|
||||
"recipient");
|
||||
public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response)
|
||||
throws ServletException, IOException {
|
||||
int contactId = RequestUtils.getRequiredIntParameter(request, "contactId");
|
||||
String recipient = RequestUtils.getRequiredStringParameter(request, "recipient");
|
||||
|
||||
Contact contact = contactManager.getById(new Long(contactId));
|
||||
|
||||
@@ -88,4 +77,12 @@ public class DeletePermissionController implements Controller, InitializingBean
|
||||
|
||||
return new ModelAndView("deletePermission", "model", model);
|
||||
}
|
||||
|
||||
public void setAclManager(AclManager aclManager) {
|
||||
this.aclManager = aclManager;
|
||||
}
|
||||
|
||||
public void setContactManager(ContactManager contact) {
|
||||
this.contactManager = contact;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/* Copyright 2004 Acegi Technology Pty Limited
|
||||
/* Copyright 2004, 2005, 2006 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.
|
||||
@@ -17,9 +17,10 @@ package sample.contact;
|
||||
|
||||
import org.springframework.beans.factory.InitializingBean;
|
||||
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
import org.springframework.web.servlet.ModelAndView;
|
||||
import org.springframework.web.servlet.mvc.Controller;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
@@ -35,28 +36,28 @@ import javax.servlet.http.HttpServletResponse;
|
||||
* @version $Id$
|
||||
*/
|
||||
public class PublicIndexController implements Controller, InitializingBean {
|
||||
//~ Instance fields ========================================================
|
||||
//~ Instance fields ================================================================================================
|
||||
|
||||
private ContactManager contactManager;
|
||||
|
||||
//~ Methods ================================================================
|
||||
//~ Methods ========================================================================================================
|
||||
|
||||
public void setContactManager(ContactManager contact) {
|
||||
this.contactManager = contact;
|
||||
public void afterPropertiesSet() throws Exception {
|
||||
Assert.notNull(contactManager, "A ContactManager implementation is required");
|
||||
}
|
||||
|
||||
public ContactManager getContactManager() {
|
||||
return contactManager;
|
||||
}
|
||||
|
||||
public void afterPropertiesSet() throws Exception {
|
||||
Assert.notNull(contactManager, "A ContactManager implementation is required");
|
||||
}
|
||||
|
||||
public ModelAndView handleRequest(HttpServletRequest request,
|
||||
HttpServletResponse response) throws ServletException, IOException {
|
||||
public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response)
|
||||
throws ServletException, IOException {
|
||||
Contact rnd = contactManager.getRandomContact();
|
||||
|
||||
return new ModelAndView("hello", "contact", rnd);
|
||||
}
|
||||
|
||||
public void setContactManager(ContactManager contact) {
|
||||
this.contactManager = contact;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/* Copyright 2004 Acegi Technology Pty Limited
|
||||
/* Copyright 2004, 2005, 2006 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.
|
||||
@@ -17,9 +17,10 @@ package sample.contact;
|
||||
|
||||
import org.springframework.beans.factory.InitializingBean;
|
||||
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
import org.springframework.web.servlet.ModelAndView;
|
||||
import org.springframework.web.servlet.mvc.Controller;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
@@ -39,26 +40,22 @@ import javax.servlet.http.HttpServletResponse;
|
||||
* @version $Id$
|
||||
*/
|
||||
public class SecureIndexController implements Controller, InitializingBean {
|
||||
//~ Instance fields ========================================================
|
||||
//~ Instance fields ================================================================================================
|
||||
|
||||
private ContactManager contactManager;
|
||||
|
||||
//~ Methods ================================================================
|
||||
//~ Methods ========================================================================================================
|
||||
|
||||
public void setContactManager(ContactManager contact) {
|
||||
this.contactManager = contact;
|
||||
public void afterPropertiesSet() throws Exception {
|
||||
Assert.notNull(contactManager, "A ContactManager implementation is required");
|
||||
}
|
||||
|
||||
public ContactManager getContactManager() {
|
||||
return contactManager;
|
||||
}
|
||||
|
||||
public void afterPropertiesSet() throws Exception {
|
||||
Assert.notNull(contactManager, "A ContactManager implementation is required");
|
||||
}
|
||||
|
||||
public ModelAndView handleRequest(HttpServletRequest request,
|
||||
HttpServletResponse response) throws ServletException, IOException {
|
||||
public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response)
|
||||
throws ServletException, IOException {
|
||||
List myContactsList = contactManager.getAll();
|
||||
Contact[] myContacts;
|
||||
|
||||
@@ -73,4 +70,8 @@ public class SecureIndexController implements Controller, InitializingBean {
|
||||
|
||||
return new ModelAndView("index", "model", model);
|
||||
}
|
||||
|
||||
public void setContactManager(ContactManager contact) {
|
||||
this.contactManager = contact;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/* Copyright 2004 Acegi Technology Pty Limited
|
||||
/* Copyright 2004, 2005, 2006 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.
|
||||
@@ -22,26 +22,26 @@ package sample.contact;
|
||||
* @version $Id$
|
||||
*/
|
||||
public class WebContact {
|
||||
//~ Instance fields ========================================================
|
||||
//~ Instance fields ================================================================================================
|
||||
|
||||
private String email;
|
||||
private String name;
|
||||
|
||||
//~ Methods ================================================================
|
||||
|
||||
public void setEmail(String email) {
|
||||
this.email = email;
|
||||
}
|
||||
//~ Methods ========================================================================================================
|
||||
|
||||
public String getEmail() {
|
||||
return email;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setEmail(String email) {
|
||||
this.email = email;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/* Copyright 2004 Acegi Technology Pty Limited
|
||||
/* Copyright 2004, 2005, 2006 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.
|
||||
@@ -30,14 +30,17 @@ import javax.servlet.http.HttpServletRequest;
|
||||
* @version $Id$
|
||||
*/
|
||||
public class WebContactAddController extends SimpleFormController {
|
||||
//~ Instance fields ========================================================
|
||||
//~ Instance fields ================================================================================================
|
||||
|
||||
private ContactManager contactManager;
|
||||
|
||||
//~ Methods ================================================================
|
||||
//~ Methods ========================================================================================================
|
||||
|
||||
public void setContactManager(ContactManager contactManager) {
|
||||
this.contactManager = contactManager;
|
||||
protected Object formBackingObject(HttpServletRequest request)
|
||||
throws ServletException {
|
||||
WebContact wc = new WebContact();
|
||||
|
||||
return wc;
|
||||
}
|
||||
|
||||
public ContactManager getContactManager() {
|
||||
@@ -54,10 +57,7 @@ public class WebContactAddController extends SimpleFormController {
|
||||
return new ModelAndView(new RedirectView(getSuccessView()));
|
||||
}
|
||||
|
||||
protected Object formBackingObject(HttpServletRequest request)
|
||||
throws ServletException {
|
||||
WebContact wc = new WebContact();
|
||||
|
||||
return wc;
|
||||
public void setContactManager(ContactManager contactManager) {
|
||||
this.contactManager = contactManager;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/* Copyright 2004 Acegi Technology Pty Limited
|
||||
/* Copyright 2004, 2005, 2006 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.
|
||||
@@ -26,7 +26,7 @@ import org.springframework.validation.Validator;
|
||||
* @version $Id$
|
||||
*/
|
||||
public class WebContactValidator implements Validator {
|
||||
//~ Methods ================================================================
|
||||
//~ Methods ========================================================================================================
|
||||
|
||||
public boolean supports(Class clazz) {
|
||||
return clazz.equals(WebContact.class);
|
||||
@@ -35,16 +35,12 @@ public class WebContactValidator implements Validator {
|
||||
public void validate(Object obj, Errors errors) {
|
||||
WebContact wc = (WebContact) obj;
|
||||
|
||||
if ((wc.getName() == null) || (wc.getName().length() < 3)
|
||||
|| (wc.getName().length() > 50)) {
|
||||
errors.rejectValue("name", "err.name",
|
||||
"Name 3-50 characters is required.");
|
||||
if ((wc.getName() == null) || (wc.getName().length() < 3) || (wc.getName().length() > 50)) {
|
||||
errors.rejectValue("name", "err.name", "Name 3-50 characters is required.");
|
||||
}
|
||||
|
||||
if ((wc.getEmail() == null) || (wc.getEmail().length() < 3)
|
||||
|| (wc.getEmail().length() > 50)) {
|
||||
errors.rejectValue("email", "err.email",
|
||||
"Email 3-50 characters is required.");
|
||||
if ((wc.getEmail() == null) || (wc.getEmail().length() < 3) || (wc.getEmail().length() > 50)) {
|
||||
errors.rejectValue("email", "err.email", "Email 3-50 characters is required.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user