SEC-97: Format Acegi Security source code in accordance with latest Jalopy configuration.
This commit is contained in:
@@ -24,6 +24,7 @@ import org.springframework.util.Assert;
|
||||
/**
|
||||
* A utility to translate a web.xml file into a set of acegi security spring beans.
|
||||
*
|
||||
* <p>
|
||||
* Also produces a new "acegified" web.xml file with the necessary filters installed
|
||||
* and the security elements defined by the servlet DTD removed.
|
||||
*
|
||||
|
||||
@@ -1,50 +1,89 @@
|
||||
/* 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.
|
||||
* 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 acegifier.web;
|
||||
|
||||
import acegifier.WebXmlConverter;
|
||||
|
||||
import org.acegisecurity.util.FilterChainProxy;
|
||||
import org.acegisecurity.util.InMemoryResource;
|
||||
|
||||
import org.dom4j.Document;
|
||||
import org.dom4j.DocumentException;
|
||||
|
||||
import org.dom4j.io.OutputFormat;
|
||||
import org.dom4j.io.XMLWriter;
|
||||
|
||||
import org.springframework.beans.BeansException;
|
||||
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
|
||||
import org.springframework.beans.factory.xml.XmlBeanDefinitionReader;
|
||||
|
||||
import org.springframework.validation.BindException;
|
||||
import org.springframework.validation.Errors;
|
||||
|
||||
import org.springframework.web.servlet.ModelAndView;
|
||||
import org.springframework.web.servlet.mvc.SimpleFormController;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import javax.xml.transform.TransformerException;
|
||||
|
||||
import org.acegisecurity.util.FilterChainProxy;
|
||||
import org.acegisecurity.util.InMemoryResource;
|
||||
import org.dom4j.Document;
|
||||
import org.dom4j.DocumentException;
|
||||
import org.dom4j.io.OutputFormat;
|
||||
import org.dom4j.io.XMLWriter;
|
||||
import org.springframework.beans.BeansException;
|
||||
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
|
||||
import org.springframework.beans.factory.xml.XmlBeanDefinitionReader;
|
||||
import org.springframework.validation.BindException;
|
||||
import org.springframework.validation.Errors;
|
||||
import org.springframework.web.servlet.ModelAndView;
|
||||
import org.springframework.web.servlet.mvc.SimpleFormController;
|
||||
|
||||
import acegifier.WebXmlConverter;
|
||||
|
||||
/**
|
||||
* Takes a submitted web.xml, applies the transformer to it and returns the resulting
|
||||
* modified web.xml and acegi-app-context.xml file contents.
|
||||
* Takes a submitted web.xml, applies the transformer to it and returns the resulting modified web.xml and
|
||||
* acegi-app-context.xml file contents.
|
||||
*
|
||||
* @author Luke Taylor
|
||||
* @version $Id$
|
||||
*/
|
||||
public class AcegifierController extends SimpleFormController {
|
||||
//~ Constructors ===================================================================================================
|
||||
|
||||
public AcegifierController() {
|
||||
public AcegifierController() {}
|
||||
|
||||
//~ Methods ========================================================================================================
|
||||
|
||||
/**
|
||||
* Creates a BeanFactory from the spring beans XML document
|
||||
*
|
||||
* @param beans DOCUMENT ME!
|
||||
*
|
||||
* @return DOCUMENT ME!
|
||||
*/
|
||||
private DefaultListableBeanFactory createBeanFactory(Document beans) {
|
||||
DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
|
||||
XmlBeanDefinitionReader beanReader = new XmlBeanDefinitionReader(bf);
|
||||
beanReader.loadBeanDefinitions(new InMemoryResource(beans.asXML().getBytes()));
|
||||
|
||||
return bf;
|
||||
}
|
||||
|
||||
public ModelAndView onSubmit(
|
||||
HttpServletRequest request, HttpServletResponse response, Object command, BindException errors)
|
||||
throws Exception {
|
||||
|
||||
AcegifierForm conversion = (AcegifierForm)command;
|
||||
public ModelAndView onSubmit(HttpServletRequest request, HttpServletResponse response, Object command,
|
||||
BindException errors) throws Exception {
|
||||
AcegifierForm conversion = (AcegifierForm) command;
|
||||
WebXmlConverter converter = new WebXmlConverter();
|
||||
int nBeans = 0;
|
||||
Document newWebXml = null, acegiBeans = null;
|
||||
Document newWebXml = null;
|
||||
Document acegiBeans = null;
|
||||
|
||||
try {
|
||||
converter.setInput(conversion.getWebXml());
|
||||
@@ -53,12 +92,13 @@ public class AcegifierController extends SimpleFormController {
|
||||
acegiBeans = converter.getAcegiBeans();
|
||||
nBeans = validateAcegiBeans(conversion, acegiBeans, errors);
|
||||
} catch (DocumentException de) {
|
||||
errors.rejectValue("webXml","webXmlDocError","There was a problem with your web.xml: " + de.getMessage());
|
||||
errors.rejectValue("webXml", "webXmlDocError", "There was a problem with your web.xml: " + de.getMessage());
|
||||
} catch (TransformerException te) {
|
||||
errors.rejectValue("webXml","transFailure","There was an error during the XSL transformation: " + te.getMessage());
|
||||
errors.rejectValue("webXml", "transFailure",
|
||||
"There was an error during the XSL transformation: " + te.getMessage());
|
||||
}
|
||||
|
||||
if(errors.hasErrors()) {
|
||||
if (errors.hasErrors()) {
|
||||
return showForm(request, response, errors);
|
||||
}
|
||||
|
||||
@@ -70,42 +110,49 @@ public class AcegifierController extends SimpleFormController {
|
||||
return new ModelAndView("acegificationResults", model);
|
||||
}
|
||||
|
||||
/** Creates a formatted XML string from the supplied document */
|
||||
/**
|
||||
* Creates a formatted XML string from the supplied document
|
||||
*
|
||||
* @param document DOCUMENT ME!
|
||||
*
|
||||
* @return DOCUMENT ME!
|
||||
*
|
||||
* @throws IOException DOCUMENT ME!
|
||||
*/
|
||||
private String prettyPrint(Document document) throws IOException {
|
||||
ByteArrayOutputStream output = new ByteArrayOutputStream();
|
||||
OutputFormat format = OutputFormat.createPrettyPrint();
|
||||
format.setTrimText(false);
|
||||
|
||||
XMLWriter writer = new XMLWriter(output, format);
|
||||
writer.write(document);
|
||||
writer.flush();
|
||||
writer.close();
|
||||
|
||||
return output.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Validates the acegi beans, based on the input form data, and returns the number
|
||||
* of spring beans defined in the document.
|
||||
* Validates the acegi beans, based on the input form data, and returns the number of spring beans defined
|
||||
* in the document.
|
||||
*
|
||||
* @param conversion DOCUMENT ME!
|
||||
* @param beans DOCUMENT ME!
|
||||
* @param errors DOCUMENT ME!
|
||||
*
|
||||
* @return DOCUMENT ME!
|
||||
*/
|
||||
private int validateAcegiBeans(AcegifierForm conversion, Document beans, Errors errors) {
|
||||
DefaultListableBeanFactory bf = createBeanFactory(beans);
|
||||
|
||||
//TODO: actually do some proper validation!
|
||||
|
||||
try {
|
||||
bf.getBean("filterChainProxy", FilterChainProxy.class);
|
||||
} catch (BeansException be) {
|
||||
errors.rejectValue("webXml","beansInvalid","There was an error creating or accessing the bean factory " + be.getMessage());
|
||||
errors.rejectValue("webXml", "beansInvalid",
|
||||
"There was an error creating or accessing the bean factory " + be.getMessage());
|
||||
}
|
||||
|
||||
return bf.getBeanDefinitionCount();
|
||||
}
|
||||
|
||||
/** Creates a BeanFactory from the spring beans XML document */
|
||||
private DefaultListableBeanFactory createBeanFactory(Document beans) {
|
||||
DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
|
||||
XmlBeanDefinitionReader beanReader = new XmlBeanDefinitionReader(bf);
|
||||
beanReader.loadBeanDefinitions(new InMemoryResource(beans.asXML().getBytes()));
|
||||
|
||||
return bf;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,3 +1,18 @@
|
||||
/* 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.
|
||||
* 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 acegifier.web;
|
||||
|
||||
/**
|
||||
@@ -7,8 +22,12 @@ package acegifier.web;
|
||||
* @version $Id$
|
||||
*/
|
||||
public class AcegifierForm {
|
||||
//~ Instance fields ================================================================================================
|
||||
|
||||
private String webXml;
|
||||
|
||||
//~ Methods ========================================================================================================
|
||||
|
||||
public String getWebXml() {
|
||||
return webXml;
|
||||
}
|
||||
|
||||
@@ -1,25 +1,28 @@
|
||||
/* 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.
|
||||
* 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 acegifier;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
import javax.xml.transform.TransformerFactoryConfigurationError;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.acegisecurity.providers.ProviderManager;
|
||||
import org.acegisecurity.providers.dao.DaoAuthenticationProvider;
|
||||
import org.acegisecurity.ui.ExceptionTranslationFilter;
|
||||
import org.acegisecurity.userdetails.UserDetails;
|
||||
import org.acegisecurity.userdetails.memory.InMemoryDaoImpl;
|
||||
import org.acegisecurity.util.InMemoryResource;
|
||||
import org.dom4j.Document;
|
||||
import org.dom4j.io.OutputFormat;
|
||||
import org.dom4j.io.XMLWriter;
|
||||
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
|
||||
import org.springframework.beans.factory.xml.XmlBeanDefinitionReader;
|
||||
import org.springframework.core.io.ClassPathResource;
|
||||
import org.springframework.core.io.Resource;
|
||||
|
||||
/**
|
||||
* Tests the WebXmlConverter by applying it to a sample web.xml file.
|
||||
|
||||
@@ -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.
|
||||
@@ -17,6 +17,7 @@ package sample.annotations;
|
||||
|
||||
import org.acegisecurity.annotation.Secured;
|
||||
|
||||
|
||||
/**
|
||||
* <code>BankService</code> sample using Java 5 Annotations.
|
||||
*
|
||||
@@ -25,10 +26,9 @@ import org.acegisecurity.annotation.Secured;
|
||||
*
|
||||
* @see org.acegisecurity.annotation.Secured
|
||||
*/
|
||||
|
||||
@Secured({"ROLE_TELLER" })
|
||||
@Secured({"ROLE_TELLER"})
|
||||
public interface BankService {
|
||||
//~ Methods ================================================================
|
||||
//~ Methods ========================================================================================================
|
||||
|
||||
/**
|
||||
* Get the account balance.
|
||||
@@ -37,8 +37,7 @@ public interface BankService {
|
||||
*
|
||||
* @return The balance
|
||||
*/
|
||||
|
||||
@Secured({"ROLE_PERMISSION_BALANCE" })
|
||||
@Secured({"ROLE_PERMISSION_BALANCE"})
|
||||
public float balance(String accountNumber);
|
||||
|
||||
/**
|
||||
@@ -46,7 +45,6 @@ public interface BankService {
|
||||
*
|
||||
* @return The list of accounts
|
||||
*/
|
||||
|
||||
@Secured({"ROLE_PERMISSION_LIST" })
|
||||
@Secured({"ROLE_PERMISSION_LIST"})
|
||||
public String[] listAccounts();
|
||||
}
|
||||
|
||||
@@ -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.
|
||||
@@ -17,12 +17,12 @@ package sample.annotations;
|
||||
|
||||
/**
|
||||
* <code>BankService</code> sample implementation.
|
||||
*
|
||||
*
|
||||
* @author Mark St.Godard
|
||||
* @version $Id$
|
||||
*/
|
||||
public class BankServiceImpl implements BankService {
|
||||
//~ Methods ================================================================
|
||||
//~ Methods ========================================================================================================
|
||||
|
||||
public float balance(String accountNumber) {
|
||||
return 42000000;
|
||||
|
||||
@@ -1,11 +1,27 @@
|
||||
package sample.annotations;
|
||||
/* 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.
|
||||
* 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.annotations;
|
||||
|
||||
import org.acegisecurity.AccessDeniedException;
|
||||
import org.acegisecurity.GrantedAuthority;
|
||||
import org.acegisecurity.GrantedAuthorityImpl;
|
||||
|
||||
import org.acegisecurity.context.SecurityContextHolder;
|
||||
import org.acegisecurity.context.SecurityContextImpl;
|
||||
|
||||
import org.acegisecurity.providers.TestingAuthenticationToken;
|
||||
|
||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
@@ -13,11 +29,29 @@ import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
|
||||
/**
|
||||
*
|
||||
DOCUMENT ME!
|
||||
*
|
||||
* @author Mark St.Godard
|
||||
* @version $Id$
|
||||
*/
|
||||
public class Main {
|
||||
//~ Methods ================================================================
|
||||
//~ Methods ========================================================================================================
|
||||
|
||||
/**
|
||||
* This can be done in a web app by using a filter or <code>SpringMvcIntegrationInterceptor</code>.
|
||||
*/
|
||||
private static void createSecureContext() {
|
||||
TestingAuthenticationToken auth = new TestingAuthenticationToken("test", "test",
|
||||
new GrantedAuthority[] {
|
||||
new GrantedAuthorityImpl("ROLE_TELLER"), new GrantedAuthorityImpl("ROLE_PERMISSION_LIST")
|
||||
});
|
||||
|
||||
SecurityContextHolder.getContext().setAuthentication(auth);
|
||||
}
|
||||
|
||||
private static void destroySecureContext() {
|
||||
SecurityContextHolder.setContext(new SecurityContextImpl());
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
createSecureContext();
|
||||
@@ -40,21 +74,4 @@ public class Main {
|
||||
|
||||
destroySecureContext();
|
||||
}
|
||||
|
||||
/**
|
||||
* This can be done in a web app by using a filter or
|
||||
* <code>SpringMvcIntegrationInterceptor</code>.
|
||||
*/
|
||||
private static void createSecureContext() {
|
||||
TestingAuthenticationToken auth = new TestingAuthenticationToken("test",
|
||||
"test",
|
||||
new GrantedAuthority[] {new GrantedAuthorityImpl("ROLE_TELLER"), new GrantedAuthorityImpl(
|
||||
"ROLE_PERMISSION_LIST")});
|
||||
|
||||
SecurityContextHolder.getContext().setAuthentication(auth);
|
||||
}
|
||||
|
||||
private static void destroySecureContext() {
|
||||
SecurityContextHolder.setContext(new SecurityContextImpl());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,11 +1,29 @@
|
||||
/* 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.
|
||||
* 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 samples.annotations;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.acegisecurity.AccessDeniedException;
|
||||
import org.acegisecurity.GrantedAuthority;
|
||||
import org.acegisecurity.GrantedAuthorityImpl;
|
||||
|
||||
import org.acegisecurity.context.SecurityContextHolder;
|
||||
import org.acegisecurity.context.SecurityContextImpl;
|
||||
|
||||
import org.acegisecurity.providers.TestingAuthenticationToken;
|
||||
|
||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
@@ -14,69 +32,68 @@ import sample.annotations.BankService;
|
||||
|
||||
|
||||
/**
|
||||
* Tests security objects.
|
||||
*
|
||||
* @author Ben Alex
|
||||
* @version $Id$
|
||||
*/
|
||||
* Tests security objects.
|
||||
*
|
||||
* @author Ben Alex
|
||||
* @version $Id$
|
||||
*/
|
||||
public class BankTests extends TestCase {
|
||||
//~ Instance fields ========================================================
|
||||
//~ Instance fields ================================================================================================
|
||||
|
||||
private BankService service;
|
||||
private ClassPathXmlApplicationContext ctx;
|
||||
private BankService service;
|
||||
private ClassPathXmlApplicationContext ctx;
|
||||
|
||||
//~ Constructors ===========================================================
|
||||
//~ Constructors ===================================================================================================
|
||||
|
||||
public BankTests() {
|
||||
super();
|
||||
}
|
||||
public BankTests() {
|
||||
super();
|
||||
}
|
||||
|
||||
public BankTests(String arg0) {
|
||||
super(arg0);
|
||||
}
|
||||
public BankTests(String arg0) {
|
||||
super(arg0);
|
||||
}
|
||||
|
||||
//~ Methods ================================================================
|
||||
//~ Methods ========================================================================================================
|
||||
|
||||
public final void setUp() throws Exception {
|
||||
super.setUp();
|
||||
ctx = new ClassPathXmlApplicationContext("applicationContext-annotations.xml");
|
||||
service = (BankService) ctx.getBean("bankService");
|
||||
}
|
||||
private static void createSecureContext() {
|
||||
TestingAuthenticationToken auth = new TestingAuthenticationToken("test", "test",
|
||||
new GrantedAuthority[] {
|
||||
new GrantedAuthorityImpl("ROLE_TELLER"), new GrantedAuthorityImpl("ROLE_PERMISSION_LIST")
|
||||
});
|
||||
|
||||
public static void main(String[] args) {
|
||||
junit.textui.TestRunner.run(BankTests.class);
|
||||
}
|
||||
SecurityContextHolder.getContext().setAuthentication(auth);
|
||||
}
|
||||
|
||||
public void testDeniedAccess() throws Exception {
|
||||
createSecureContext();
|
||||
private static void destroySecureContext() {
|
||||
SecurityContextHolder.setContext(new SecurityContextImpl());
|
||||
}
|
||||
|
||||
try {
|
||||
service.balance("1");
|
||||
fail("Should have thrown AccessDeniedException");
|
||||
} catch (AccessDeniedException expected) {
|
||||
assertTrue(true);
|
||||
}
|
||||
public static void main(String[] args) {
|
||||
junit.textui.TestRunner.run(BankTests.class);
|
||||
}
|
||||
|
||||
destroySecureContext();
|
||||
}
|
||||
public final void setUp() throws Exception {
|
||||
super.setUp();
|
||||
ctx = new ClassPathXmlApplicationContext("applicationContext-annotations.xml");
|
||||
service = (BankService) ctx.getBean("bankService");
|
||||
}
|
||||
|
||||
public void testListAccounts() throws Exception {
|
||||
createSecureContext();
|
||||
service.listAccounts();
|
||||
destroySecureContext();
|
||||
}
|
||||
public void testDeniedAccess() throws Exception {
|
||||
createSecureContext();
|
||||
|
||||
private static void createSecureContext() {
|
||||
TestingAuthenticationToken auth = new TestingAuthenticationToken("test",
|
||||
"test",
|
||||
new GrantedAuthority[] {new GrantedAuthorityImpl("ROLE_TELLER"), new GrantedAuthorityImpl(
|
||||
"ROLE_PERMISSION_LIST")});
|
||||
try {
|
||||
service.balance("1");
|
||||
fail("Should have thrown AccessDeniedException");
|
||||
} catch (AccessDeniedException expected) {
|
||||
assertTrue(true);
|
||||
}
|
||||
|
||||
SecurityContextHolder.getContext().setAuthentication(auth);
|
||||
}
|
||||
destroySecureContext();
|
||||
}
|
||||
|
||||
private static void destroySecureContext() {
|
||||
SecurityContextHolder.setContext(new SecurityContextImpl());
|
||||
}
|
||||
public void testListAccounts() throws Exception {
|
||||
createSecureContext();
|
||||
service.listAccounts();
|
||||
destroySecureContext();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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,7 +22,6 @@ package sample.attributes;
|
||||
* @author Ben Alex
|
||||
* @version $Id$
|
||||
*
|
||||
* @@net.sf.acegisecurity.SecurityConfig("ROLE_TELLER")
|
||||
*/
|
||||
public interface BankService {
|
||||
//~ Methods ================================================================
|
||||
|
||||
@@ -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.
|
||||
@@ -23,7 +23,7 @@ package sample.attributes;
|
||||
* @version $Id$
|
||||
*/
|
||||
public class BankServiceImpl implements BankService {
|
||||
//~ Methods ================================================================
|
||||
//~ Methods ========================================================================================================
|
||||
|
||||
public float balance(String accountNumber) {
|
||||
return 42000000;
|
||||
|
||||
@@ -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.
|
||||
@@ -18,8 +18,10 @@ package sample.attributes;
|
||||
import org.acegisecurity.AccessDeniedException;
|
||||
import org.acegisecurity.GrantedAuthority;
|
||||
import org.acegisecurity.GrantedAuthorityImpl;
|
||||
|
||||
import org.acegisecurity.context.SecurityContextHolder;
|
||||
import org.acegisecurity.context.SecurityContextImpl;
|
||||
|
||||
import org.acegisecurity.providers.TestingAuthenticationToken;
|
||||
|
||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
@@ -33,13 +35,28 @@ import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
* @version $Id$
|
||||
*/
|
||||
public class Main {
|
||||
//~ Methods ================================================================
|
||||
//~ Methods ========================================================================================================
|
||||
|
||||
/**
|
||||
* This can be done in a web app by using a filter or <code>SpringMvcIntegrationInterceptor</code>.
|
||||
*/
|
||||
private static void createSecureContext() {
|
||||
TestingAuthenticationToken auth = new TestingAuthenticationToken("test", "test",
|
||||
new GrantedAuthority[] {
|
||||
new GrantedAuthorityImpl("ROLE_TELLER"), new GrantedAuthorityImpl("ROLE_PERMISSION_LIST")
|
||||
});
|
||||
|
||||
SecurityContextHolder.getContext().setAuthentication(auth);
|
||||
}
|
||||
|
||||
private static void destroySecureContext() {
|
||||
SecurityContextHolder.setContext(new SecurityContextImpl());
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
createSecureContext();
|
||||
|
||||
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
|
||||
"applicationContext.xml");
|
||||
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");
|
||||
BankService service = (BankService) context.getBean("bankService");
|
||||
|
||||
// will succeed
|
||||
@@ -56,21 +73,4 @@ public class Main {
|
||||
|
||||
destroySecureContext();
|
||||
}
|
||||
|
||||
/**
|
||||
* This can be done in a web app by using a filter or
|
||||
* <code>SpringMvcIntegrationInterceptor</code>.
|
||||
*/
|
||||
private static void createSecureContext() {
|
||||
TestingAuthenticationToken auth = new TestingAuthenticationToken("test",
|
||||
"test",
|
||||
new GrantedAuthority[] {new GrantedAuthorityImpl("ROLE_TELLER"), new GrantedAuthorityImpl(
|
||||
"ROLE_PERMISSION_LIST")});
|
||||
|
||||
SecurityContextHolder.getContext().setAuthentication(auth);
|
||||
}
|
||||
|
||||
private static void destroySecureContext() {
|
||||
SecurityContextHolder.setContext(new SecurityContextImpl());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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.
|
||||
@@ -20,8 +20,10 @@ import junit.framework.TestCase;
|
||||
import org.acegisecurity.AccessDeniedException;
|
||||
import org.acegisecurity.GrantedAuthority;
|
||||
import org.acegisecurity.GrantedAuthorityImpl;
|
||||
|
||||
import org.acegisecurity.context.SecurityContextHolder;
|
||||
import org.acegisecurity.context.SecurityContextImpl;
|
||||
|
||||
import org.acegisecurity.providers.TestingAuthenticationToken;
|
||||
|
||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
@@ -34,12 +36,12 @@ import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
* @version $Id$
|
||||
*/
|
||||
public class BankTests extends TestCase {
|
||||
//~ Instance fields ========================================================
|
||||
//~ Instance fields ================================================================================================
|
||||
|
||||
private BankService service;
|
||||
private ClassPathXmlApplicationContext ctx;
|
||||
|
||||
//~ Constructors ===========================================================
|
||||
//~ Constructors ===================================================================================================
|
||||
|
||||
public BankTests() {
|
||||
super();
|
||||
@@ -49,7 +51,24 @@ public class BankTests extends TestCase {
|
||||
super(arg0);
|
||||
}
|
||||
|
||||
//~ Methods ================================================================
|
||||
//~ Methods ========================================================================================================
|
||||
|
||||
private static void createSecureContext() {
|
||||
TestingAuthenticationToken auth = new TestingAuthenticationToken("test", "test",
|
||||
new GrantedAuthority[] {
|
||||
new GrantedAuthorityImpl("ROLE_TELLER"), new GrantedAuthorityImpl("ROLE_PERMISSION_LIST")
|
||||
});
|
||||
|
||||
SecurityContextHolder.getContext().setAuthentication(auth);
|
||||
}
|
||||
|
||||
private static void destroySecureContext() {
|
||||
SecurityContextHolder.setContext(new SecurityContextImpl());
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
junit.textui.TestRunner.run(BankTests.class);
|
||||
}
|
||||
|
||||
public final void setUp() throws Exception {
|
||||
super.setUp();
|
||||
@@ -57,10 +76,6 @@ public class BankTests extends TestCase {
|
||||
service = (BankService) ctx.getBean("bankService");
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
junit.textui.TestRunner.run(BankTests.class);
|
||||
}
|
||||
|
||||
public void testDeniedAccess() throws Exception {
|
||||
createSecureContext();
|
||||
|
||||
@@ -79,17 +94,4 @@ public class BankTests extends TestCase {
|
||||
service.listAccounts();
|
||||
destroySecureContext();
|
||||
}
|
||||
|
||||
private static void createSecureContext() {
|
||||
TestingAuthenticationToken auth = new TestingAuthenticationToken("test",
|
||||
"test",
|
||||
new GrantedAuthority[] {new GrantedAuthorityImpl("ROLE_TELLER"), new GrantedAuthorityImpl(
|
||||
"ROLE_PERMISSION_LIST")});
|
||||
|
||||
SecurityContextHolder.getContext().setAuthentication(auth);
|
||||
}
|
||||
|
||||
private static void destroySecureContext() {
|
||||
SecurityContextHolder.setContext(new SecurityContextImpl());
|
||||
}
|
||||
}
|
||||
|
||||
+91
-93
@@ -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.
|
||||
@@ -15,27 +15,34 @@
|
||||
|
||||
package sample.contact.annotation;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
|
||||
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.annotation.Secured;
|
||||
|
||||
import org.acegisecurity.context.SecurityContextHolder;
|
||||
|
||||
import org.acegisecurity.userdetails.UserDetails;
|
||||
|
||||
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;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
|
||||
|
||||
/**
|
||||
* Concrete implementation of Java 5 Annotated {@link ContactManager}.
|
||||
@@ -44,18 +51,70 @@ import sample.contact.ContactManager;
|
||||
* @version $Id$
|
||||
*/
|
||||
@Transactional
|
||||
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 = 100;
|
||||
|
||||
//~ Methods ================================================================
|
||||
//~ Methods ========================================================================================================
|
||||
|
||||
@Secured ({"ROLE_USER","AFTER_ACL_COLLECTION_READ"})
|
||||
@Transactional(readOnly=true)
|
||||
@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 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());
|
||||
}
|
||||
}
|
||||
|
||||
@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);
|
||||
}
|
||||
}
|
||||
|
||||
@Secured({"ROLE_USER", "AFTER_ACL_COLLECTION_READ"})
|
||||
@Transactional(readOnly = true)
|
||||
public List getAll() {
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("Returning all contacts");
|
||||
@@ -64,8 +123,8 @@ public class ContactManagerBackend extends ApplicationObjectSupport
|
||||
return contactDao.findAll();
|
||||
}
|
||||
|
||||
@Secured ({"ROLE_USER"})
|
||||
@Transactional(readOnly=true)
|
||||
@Secured({"ROLE_USER"})
|
||||
@Transactional(readOnly = true)
|
||||
public List getAllRecipients() {
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("Returning all recipients");
|
||||
@@ -77,16 +136,12 @@ public class ContactManagerBackend extends ApplicationObjectSupport
|
||||
return list;
|
||||
}
|
||||
|
||||
public void setBasicAclExtendedDao(BasicAclExtendedDao basicAclExtendedDao) {
|
||||
this.basicAclExtendedDao = basicAclExtendedDao;
|
||||
}
|
||||
|
||||
public BasicAclExtendedDao getBasicAclExtendedDao() {
|
||||
return basicAclExtendedDao;
|
||||
}
|
||||
|
||||
@Secured ({"ROLE_USER","AFTER_ACL_READ"})
|
||||
@Transactional(readOnly=true)
|
||||
@Secured({"ROLE_USER", "AFTER_ACL_READ"})
|
||||
@Transactional(readOnly = true)
|
||||
public Contact getById(Long id) {
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("Returning contact with id: " + id);
|
||||
@@ -95,10 +150,6 @@ public class ContactManagerBackend extends ApplicationObjectSupport
|
||||
return contactDao.getById(id);
|
||||
}
|
||||
|
||||
public void setContactDao(ContactDao contactDao) {
|
||||
this.contactDao = contactDao;
|
||||
}
|
||||
|
||||
public ContactDao getContactDao() {
|
||||
return contactDao;
|
||||
}
|
||||
@@ -120,76 +171,8 @@ public class ContactManagerBackend extends ApplicationObjectSupport
|
||||
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 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());
|
||||
}
|
||||
}
|
||||
|
||||
@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();
|
||||
Authentication auth = SecurityContextHolder.getContext().getAuthentication();
|
||||
|
||||
if (auth.getPrincipal() instanceof UserDetails) {
|
||||
return ((UserDetails) auth.getPrincipal()).getUsername();
|
||||
@@ -199,7 +182,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 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