Source Code Cross Referenced for FileUser.java in  » Content-Management-System » apache-lenya-2.0 » org » apache » lenya » ac » file » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Content Management System » apache lenya 2.0 » org.apache.lenya.ac.file 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Licensed to the Apache Software Foundation (ASF) under one or more
003:         *  contributor license agreements.  See the NOTICE file distributed with
004:         *  this work for additional information regarding copyright ownership.
005:         *  The ASF licenses this file to You under the Apache License, Version 2.0
006:         *  (the "License"); you may not use this file except in compliance with
007:         *  the License.  You may obtain a copy of the License at
008:         *
009:         *      http://www.apache.org/licenses/LICENSE-2.0
010:         *
011:         *  Unless required by applicable law or agreed to in writing, software
012:         *  distributed under the License is distributed on an "AS IS" BASIS,
013:         *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014:         *  See the License for the specific language governing permissions and
015:         *  limitations under the License.
016:         *
017:         */
018:
019:        package org.apache.lenya.ac.file;
020:
021:        import java.io.File;
022:        import java.io.Serializable;
023:
024:        import org.apache.avalon.framework.configuration.Configuration;
025:        import org.apache.avalon.framework.configuration.ConfigurationException;
026:        import org.apache.avalon.framework.configuration.DefaultConfiguration;
027:        import org.apache.avalon.framework.configuration.DefaultConfigurationSerializer;
028:        import org.apache.avalon.framework.logger.Logger;
029:        import org.apache.lenya.ac.AccessControlException;
030:        import org.apache.lenya.ac.Group;
031:        import org.apache.lenya.ac.GroupManager;
032:        import org.apache.lenya.ac.Item;
033:        import org.apache.lenya.ac.ItemManager;
034:        import org.apache.lenya.ac.impl.AbstractUser;
035:        import org.apache.lenya.ac.impl.ItemConfiguration;
036:
037:        /**
038:         * File-based user implementation.
039:         * @version $Id: FileUser.java 485769 2006-12-11 17:41:23Z andreas $
040:         */
041:        public class FileUser extends AbstractUser implements  Item,
042:                Serializable {
043:
044:            /**
045:             * 
046:             */
047:            private static final long serialVersionUID = 1L;
048:            protected static final String ID = "identity";
049:            protected static final String EMAIL = "email";
050:            protected static final String MENU_LOCALE = "default-menu-locale";
051:            protected static final String DOCUMENT_LOCALE = "default-document-locale";
052:            protected static final String PASSWORD = "password";
053:            protected static final String GROUPS = "groups";
054:            protected static final String GROUP = "group";
055:            protected static final String PASSWORD_ATTRIBUTE = "type";
056:
057:            /**
058:             * Creates a new FileUser object.
059:             * @param itemManager The item manager.
060:             * @param logger The logger.
061:             */
062:            public FileUser(ItemManager itemManager, Logger logger) {
063:                super (itemManager, logger);
064:                FileItemManager fileItemManager = (FileItemManager) itemManager;
065:                setConfigurationDirectory(fileItemManager
066:                        .getConfigurationDirectory());
067:            }
068:
069:            /**
070:             * Create a FileUser
071:             * @param itemManager The item manager.
072:             * @param logger The logger.
073:             * @param id the user id
074:             * @param fullName the full name of the user
075:             * @param email the users email address
076:             * @param password the users password
077:             */
078:            public FileUser(ItemManager itemManager, Logger logger, String id,
079:                    String fullName, String email, String password) {
080:                super (itemManager, logger, id, fullName, email, password);
081:                FileItemManager fileItemManager = (FileItemManager) itemManager;
082:                setConfigurationDirectory(fileItemManager
083:                        .getConfigurationDirectory());
084:            }
085:
086:            /**
087:             * Configure this FileUser.
088:             * @param config where the user details are specified
089:             * @throws ConfigurationException if the necessary details aren't specified
090:             *         in the config
091:             */
092:            public void configure(Configuration config)
093:                    throws ConfigurationException {
094:                new ItemConfiguration().configure(this , config);
095:                setEmail(config.getChild(EMAIL).getValue(""));
096:                setDefaultMenuLocale(config.getChild(MENU_LOCALE).getValue(""));
097:                setDefaultDocumentLocale(config.getChild(DOCUMENT_LOCALE)
098:                        .getValue(""));
099:                setEncryptedPassword(config.getChild(PASSWORD).getValue(null));
100:
101:                removeFromAllGroups();
102:                Configuration[] groups = config.getChildren(GROUPS);
103:
104:                if (groups.length == 1) {
105:                    groups = groups[0].getChildren(GROUP);
106:
107:                    GroupManager manager;
108:                    try {
109:                        manager = getAccreditableManager().getGroupManager();
110:                    } catch (AccessControlException e) {
111:                        throw new ConfigurationException(
112:                                "configuration failed: ", e);
113:                    }
114:
115:                    for (int i = 0; i < groups.length; i++) {
116:                        String groupId = groups[i].getValue();
117:                        Group group = manager.getGroup(groupId);
118:
119:                        if (group == null) {
120:                            throw new ConfigurationException(
121:                                    "Couldn't find Group for group name ["
122:                                            + groupId + "]");
123:                        }
124:
125:                        if (!group.contains(this )) {
126:                            group.add(this );
127:                        }
128:
129:                    }
130:                } else {
131:                    // strange, it should have groups
132:                    getLogger().error(
133:                            "User " + getId()
134:                                    + " doesn't seem to have any groups");
135:                }
136:            }
137:
138:            /**
139:             * Create a configuration from the current user details. Can be used for
140:             * saving.
141:             * @return a <code>Configuration</code>
142:             */
143:            protected Configuration createConfiguration() {
144:                DefaultConfiguration config = new DefaultConfiguration(ID);
145:                new ItemConfiguration().save(this , config);
146:
147:                DefaultConfiguration child = null;
148:
149:                // add email node
150:                child = new DefaultConfiguration(EMAIL);
151:                child.setValue(getEmail());
152:                config.addChild(child);
153:
154:                // add defaultMenuLocale node
155:                child = new DefaultConfiguration(MENU_LOCALE);
156:                child.setValue(getDefaultMenuLocale());
157:                config.addChild(child);
158:
159:                // add defaultDocumentLocale node
160:                child = new DefaultConfiguration(DOCUMENT_LOCALE);
161:                child.setValue(getDefaultDocumentLocale());
162:                config.addChild(child);
163:
164:                // add password node
165:                child = new DefaultConfiguration(PASSWORD);
166:                child.setValue(getEncryptedPassword());
167:                child.setAttribute(PASSWORD_ATTRIBUTE, "md5");
168:                config.addChild(child);
169:
170:                // add group nodes
171:                child = new DefaultConfiguration(GROUPS);
172:                config.addChild(child);
173:
174:                Group[] groups = getGroups();
175:
176:                for (int i = 0; i < groups.length; i++) {
177:                    DefaultConfiguration groupNode = new DefaultConfiguration(
178:                            GROUP);
179:                    groupNode.setValue(groups[i].getId());
180:                    child.addChild(groupNode);
181:                }
182:
183:                return config;
184:            }
185:
186:            /**
187:             * @see org.apache.lenya.ac.User#save()
188:             */
189:            public void save() throws AccessControlException {
190:                DefaultConfigurationSerializer serializer = new DefaultConfigurationSerializer();
191:                Configuration config = createConfiguration();
192:
193:                try {
194:                    serializer.serializeToFile(getFile(), config);
195:                } catch (Exception e) {
196:                    throw new AccessControlException(e);
197:                }
198:            }
199:
200:            /**
201:             * @see org.apache.lenya.ac.User#delete()
202:             */
203:            public void delete() throws AccessControlException {
204:                super .delete();
205:                getFile().delete();
206:            }
207:
208:            /**
209:             * Returns the configuration file.
210:             * @return A file object.
211:             */
212:            protected File getFile() {
213:                File xmlPath = getConfigurationDirectory();
214:                File xmlFile = new File(xmlPath, getId()
215:                        + FileUserManager.SUFFIX);
216:                return xmlFile;
217:            }
218:
219:            private File configurationDirectory;
220:
221:            /**
222:             * Returns the configuration directory.
223:             * @return A file object.
224:             */
225:            protected File getConfigurationDirectory() {
226:                return this .configurationDirectory;
227:            }
228:
229:            protected void setConfigurationDirectory(
230:                    File _configurationDirectory) {
231:                assert (_configurationDirectory != null)
232:                        && _configurationDirectory.isDirectory();
233:                this.configurationDirectory = _configurationDirectory;
234:            }
235:
236:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.