01: /*
02: * Copyright 2007 Pentaho Corporation. All rights reserved.
03: * This software was developed by Pentaho Corporation and is provided under the terms
04: * of the Mozilla Public License, Version 1.1, or any later version. You may not use
05: * this file except in compliance with the license. If you need a copy of the license,
06: * please go to http://www.mozilla.org/MPL/MPL-1.1.txt. The Original Code is the Pentaho
07: * BI Platform. The Initial Developer is Pentaho Corporation.
08: *
09: * Software distributed under the Mozilla Public License is distributed on an "AS IS"
10: * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. Please refer to
11: * the license for the specific language governing your rights and limitations.
12: */
13: package com.pentaho.security.memory;
14:
15: import org.acegisecurity.userdetails.memory.UserMap;
16: import org.acegisecurity.userdetails.memory.UserMapEditor;
17: import org.springframework.beans.factory.FactoryBean;
18:
19: /**
20: * Takes as input the string that defines a <code>UserMap</code>. When
21: * Spring instantiates this bean, it outputs a
22: * <code>UserMap</code>.
23: *
24: * <p>This class allows a string that defines a <code>UserMap</code> to be defined once in
25: * Spring beans XML, then used by multiple client beans that need access to user to role mappings.</p>
26: *
27: * <p>This class is necessary
28: * since <code>UserMap</code> does not define a constructor or setter
29: * necessary to populate a <code>UserMap</code> bean, nor does it provide any
30: * way to extract its mappings once created.</p>
31: *
32: * <p>Example usage:</p>
33: *
34: * <pre>
35: * <bean id="userMap" class="java.lang.String">
36: * <constructor-arg type="java.lang.String">
37: * <value>
38: * <![CDATA[
39: * joe=password,Admin,ceo,Authenticated
40: * ...
41: * ]]>
42: * </value>
43: * </constructor-arg>
44: * </bean>
45: *
46: * <bean id="userMapFactoryBean"
47: * class="com.pentaho.security.UserMapFactoryBean">
48: * <property name="userMap" ref="userMap" />
49: * </bean>
50: *
51: * <bean id="memoryAuthenticationDao"
52: * class="org.acegisecurity.userdetails.memory.InMemoryDaoImpl">
53: * <property name="userMap" ref="userMapFactoryBean" />
54: * </bean>
55: * </pre>
56: *
57: * @author mlowery
58: * @see UserRoleListEnhancedUserMapFactoryBean
59: */
60: public class UserMapFactoryBean implements FactoryBean {
61: /*
62: * The user map text which will be processed by property editor.
63: */
64: private String userMap;
65:
66: public Object getObject() throws Exception {
67: UserMapEditor userMapEditor = new UserMapEditor();
68: userMapEditor.setAsText(userMap);
69: return userMapEditor.getValue();
70: }
71:
72: public Class getObjectType() {
73: return UserMap.class;
74: }
75:
76: public boolean isSingleton() {
77: return true;
78: }
79:
80: public void setUserMap(final String userMap) {
81: this.userMap = userMap;
82: }
83:
84: }
|