Source code: org/acegisecurity/intercept/method/MethodDefinitionSourceEditor.java
1 /* Copyright 2004 Acegi Technology Pty Limited
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 package org.acegisecurity.intercept.method;
17
18 import org.acegisecurity.ConfigAttributeDefinition;
19 import org.acegisecurity.ConfigAttributeEditor;
20
21 import org.apache.commons.logging.Log;
22 import org.apache.commons.logging.LogFactory;
23
24 import org.springframework.beans.propertyeditors.PropertiesEditor;
25
26 import java.beans.PropertyEditorSupport;
27
28 import java.util.Iterator;
29 import java.util.Properties;
30
31
32 /**
33 * Property editor to assist with the setup of a {@link
34 * MethodDefinitionSource}.
35 *
36 * <p>
37 * The class creates and populates a {@link MethodDefinitionMap}.
38 * </p>
39 *
40 * @author Ben Alex
41 * @version $Id: MethodDefinitionSourceEditor.java,v 1.2 2005/11/17 00:56:09 benalex Exp $
42 */
43 public class MethodDefinitionSourceEditor extends PropertyEditorSupport {
44 //~ Static fields/initializers =============================================
45
46 private static final Log logger = LogFactory.getLog(MethodDefinitionSourceEditor.class);
47
48 //~ Methods ================================================================
49
50 public void setAsText(String s) throws IllegalArgumentException {
51 MethodDefinitionMap source = new MethodDefinitionMap();
52
53 if ((s == null) || "".equals(s)) {
54 // Leave value in property editor null
55 } else {
56 // Use properties editor to tokenize the string
57 PropertiesEditor propertiesEditor = new PropertiesEditor();
58 propertiesEditor.setAsText(s);
59
60 Properties props = (Properties) propertiesEditor.getValue();
61
62 // Now we have properties, process each one individually
63 ConfigAttributeEditor configAttribEd = new ConfigAttributeEditor();
64
65 for (Iterator iter = props.keySet().iterator(); iter.hasNext();) {
66 String name = (String) iter.next();
67 String value = props.getProperty(name);
68
69 // Convert value to series of security configuration attributes
70 configAttribEd.setAsText(value);
71
72 ConfigAttributeDefinition attr = (ConfigAttributeDefinition) configAttribEd
73 .getValue();
74
75 // Register name and attribute
76 source.addSecureMethod(name, attr);
77 }
78 }
79
80 setValue(source);
81 }
82 }