Source Code Cross Referenced for BaseMemoryRealmAction.java in  » J2EE » JOnAS-4.8.6 » org » objectweb » jonas » webapp » jonasadmin » security » 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 » J2EE » JOnAS 4.8.6 » org.objectweb.jonas.webapp.jonasadmin.security 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * JOnAS: Java(TM) Open Application Server
003:         * Copyright (C) 1999 Bull S.A.
004:         * Contact: jonas-team@objectweb.org
005:         *
006:         * This library is free software; you can redistribute it and/or
007:         * modify it under the terms of the GNU Lesser General Public
008:         * License as published by the Free Software Foundation; either
009:         * version 2.1 of the License, or any later version.
010:         *
011:         * This library is distributed in the hope that it will be useful,
012:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
013:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
014:         * Lesser General Public License for more details.
015:         *
016:         * You should have received a copy of the GNU Lesser General Public
017:         * License along with this library; if not, write to the Free Software
018:         * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
019:         * USA
020:         *
021:         * Initial developer(s): Michel-Ange ANTON
022:         * --------------------------------------------------------------------------
023:         * $Id: BaseMemoryRealmAction.java 9680 2006-10-06 12:08:33Z danesa $
024:         * --------------------------------------------------------------------------
025:         */
026:
027:        package org.objectweb.jonas.webapp.jonasadmin.security;
028:
029:        import java.util.ArrayList;
030:        import java.util.Arrays;
031:        import java.util.Collections;
032:
033:        import javax.management.ObjectName;
034:        import javax.servlet.http.HttpServletRequest;
035:
036:        import org.apache.struts.action.ActionMapping;
037:        import org.objectweb.jonas.jmx.JonasManagementRepr;
038:        import org.objectweb.jonas.jmx.JonasObjectName;
039:        import org.objectweb.jonas.webapp.jonasadmin.Jlists;
040:
041:        /**
042:         *
043:         */
044:
045:        abstract public class BaseMemoryRealmAction extends BaseSecurityAction {
046:
047:            // --------------------------------------------------------- Public Methods
048:
049:            // --------------------------------------------------------- Protected Methods
050:            protected MemoryRealmForm getForm(ActionMapping p_Mapping,
051:                    HttpServletRequest p_Request) {
052:                // Form used
053:                MemoryRealmForm oForm = null;
054:                // Memory realm to edit
055:                String sResource = p_Request.getParameter("resource");
056:
057:                // Build a new form
058:                if (sResource != null) {
059:                    oForm = new MemoryRealmForm();
060:                    m_Session.setAttribute("memoryRealmForm", oForm);
061:                    oForm.reset(p_Mapping, p_Request);
062:                    oForm.setResource(sResource);
063:                    // free old items of session
064:                    m_Session.removeAttribute("userMemoryRealmForm");
065:                    m_Session.removeAttribute("roleMemoryRealmForm");
066:                    m_Session.removeAttribute("groupMemoryRealmForm");
067:                    m_Session.removeAttribute("itemsMemoryRealmForm");
068:                } else {
069:                    oForm = (MemoryRealmForm) m_Session
070:                            .getAttribute("memoryRealmForm");
071:                }
072:                return oForm;
073:            }
074:
075:            /**
076:             * Remove of session the <code>ItemsMemoryRealmForm</code> instance
077:             * if the given type is different of the current type.
078:             *
079:             * @param p_Type Current type (user, role, group)
080:             */
081:            protected void removeItemsMemoryRealmForm(String p_Type) {
082:                ItemsMemoryRealmForm oForm = (ItemsMemoryRealmForm) m_Session
083:                        .getAttribute("itemsMemoryRealmForm");
084:                if (oForm != null) {
085:                    if ((oForm.getType() != null)
086:                            && (oForm.getType().equals(p_Type) == false)) {
087:                        m_Session.removeAttribute("itemsMemoryRealmForm");
088:                    }
089:                }
090:            }
091:
092:            /**
093:             * Populate the <code>UserMemoryRealmForm</code> with MBeans.
094:             * If the user name is null, the User MBean is not called to populate the form.
095:             *
096:             * @param p_RealmForm Used for the resource name
097:             * @param p_UserForm Form to populate
098:             * @param p_UserName The user (Can be null)
099:             * @throws Exception
100:             */
101:            protected void populateUserForm(MemoryRealmForm p_RealmForm,
102:                    UserMemoryRealmForm p_UserForm, String p_UserName,
103:                    String jonasServerName) throws Exception {
104:
105:                if (p_UserName != null) {
106:                    // Populate with Mbean 'user'
107:                    ObjectName oObjectName = JonasObjectName.user(p_RealmForm
108:                            .getResource(), p_UserName);
109:                    p_UserForm.setUser(getStringAttribute(oObjectName, "Name"));
110:
111:                    p_UserForm.setListGroupsUser(new ArrayList(Arrays
112:                            .asList((String[]) JonasManagementRepr
113:                                    .getAttribute(oObjectName, "ArrayGroups",
114:                                            jonasServerName))));
115:                    p_UserForm.setListGroupsUsed(new ArrayList(p_UserForm
116:                            .getListGroupsUser()));
117:
118:                    p_UserForm.setListRolesUser(new ArrayList(Arrays
119:                            .asList((String[]) JonasManagementRepr
120:                                    .getAttribute(oObjectName, "ArrayRoles",
121:                                            jonasServerName))));
122:                    p_UserForm.setListRolesUsed(new ArrayList(p_UserForm
123:                            .getListRolesUser()));
124:                }
125:                // Populate with Mbean 'realm'
126:                ObjectName oObjectName = JonasObjectName
127:                        .securityMemoryFactory(p_RealmForm.getResource());
128:                p_UserForm.setListGroupsRealm(new ArrayList(Arrays
129:                        .asList((String[]) JonasManagementRepr.invoke(
130:                                oObjectName, "listGroups", null, null,
131:                                jonasServerName))));
132:                p_UserForm.setListRolesRealm(new ArrayList(Arrays
133:                        .asList((String[]) JonasManagementRepr.invoke(
134:                                oObjectName, "listRoles", null, null,
135:                                jonasServerName))));
136:
137:                // Calculate Unused
138:                ArrayList alUnused = new ArrayList(p_UserForm
139:                        .getListGroupsRealm());
140:                alUnused.removeAll(p_UserForm.getListGroupsUser());
141:                Collections.sort(alUnused);
142:                p_UserForm.setListGroupsNotused(alUnused);
143:
144:                alUnused = new ArrayList(p_UserForm.getListRolesRealm());
145:                alUnused.removeAll(p_UserForm.getListRolesUser());
146:                Collections.sort(alUnused);
147:                p_UserForm.setListRolesNotused(alUnused);
148:
149:                // Format list to string
150:                p_UserForm.setGroupsUsed(Jlists.getString(p_UserForm
151:                        .getListGroupsUsed(), Jlists.SEPARATOR));
152:                p_UserForm.setGroupsNotused(Jlists.getString(p_UserForm
153:                        .getListGroupsNotused(), Jlists.SEPARATOR));
154:                p_UserForm.setRolesUsed(Jlists.getString(p_UserForm
155:                        .getListRolesUsed(), Jlists.SEPARATOR));
156:                p_UserForm.setRolesNotused(Jlists.getString(p_UserForm
157:                        .getListRolesNotused(), Jlists.SEPARATOR));
158:            }
159:
160:            /**
161:             * Encrypt a password with MBean security service method.
162:             *
163:             * @param p_Password Password to encrypt
164:             * @param p_EncrypMethod MD5 or SHA string
165:             * @return The encrypted password
166:             * @throws Exception
167:             */
168:            protected String encryptPassword(String p_Password,
169:                    String p_EncrypMethod, String jonasServerName)
170:                    throws Exception {
171:                ObjectName onSecurityService = JonasObjectName
172:                        .securityService();
173:                String[] asParam = { p_Password, p_EncrypMethod };
174:                String[] asSignature = { "java.lang.String", "java.lang.String" };
175:                return (String) JonasManagementRepr.invoke(onSecurityService,
176:                        "encryptPassword", asParam, asSignature,
177:                        jonasServerName);
178:            }
179:
180:            /**
181:             * Populate the <code>RoleMemoryRealmForm</code> with MBeans.
182:             * If the Role name is null, the Role MBean is not called to populate the form.
183:             *
184:             * @param p_RealmForm Used for the resource name
185:             * @param p_RoleForm Form to populate
186:             * @param p_RoleName The user (Can be null)
187:             * @throws Exception
188:             */
189:            protected void populateRoleForm(MemoryRealmForm p_RealmForm,
190:                    RoleMemoryRealmForm p_RoleForm, String p_RoleName)
191:                    throws Exception {
192:
193:                if (p_RoleName != null) {
194:                    // Populate with Mbean 'Role'
195:                    ObjectName oObjectName = JonasObjectName.role(p_RealmForm
196:                            .getResource(), p_RoleName);
197:                    p_RoleForm.setRole(getStringAttribute(oObjectName, "Name"));
198:                    p_RoleForm.setDescription(getStringAttribute(oObjectName,
199:                            "Description"));
200:                }
201:            }
202:
203:            /**
204:             * Populate the <code>GroupMemoryRealmForm</code> with MBeans.
205:             * If the user name is null, the Group MBean is not called to populate the form.
206:             *
207:             * @param p_RealmForm Used for the resource name
208:             * @param p_GroupForm Form to populate
209:             * @param p_GroupName The user (Can be null)
210:             * @throws Exception
211:             */
212:            protected void populateGroupForm(MemoryRealmForm p_RealmForm,
213:                    GroupMemoryRealmForm p_GroupForm, String p_GroupName,
214:                    String jonasServerName) throws Exception {
215:
216:                if (p_GroupName != null) {
217:                    // Populate with Mbean 'group'
218:                    ObjectName oObjectName = JonasObjectName.group(p_RealmForm
219:                            .getResource(), p_GroupName);
220:                    p_GroupForm
221:                            .setGroup(getStringAttribute(oObjectName, "Name"));
222:                    p_GroupForm.setDescription(getStringAttribute(oObjectName,
223:                            "Description"));
224:
225:                    p_GroupForm.setListRolesGroup(new ArrayList(Arrays
226:                            .asList((String[]) JonasManagementRepr
227:                                    .getAttribute(oObjectName, "ArrayRoles",
228:                                            jonasServerName))));
229:                    p_GroupForm.setListRolesUsed(new ArrayList(p_GroupForm
230:                            .getListRolesGroup()));
231:                }
232:                // Populate with Mbean 'realm'
233:                ObjectName oObjectName = JonasObjectName
234:                        .securityMemoryFactory(p_RealmForm.getResource());
235:                p_GroupForm.setListRolesRealm(new ArrayList(Arrays
236:                        .asList((String[]) JonasManagementRepr.invoke(
237:                                oObjectName, "listRoles", null, null,
238:                                jonasServerName))));
239:
240:                // Calculate Unused
241:                ArrayList alUnused = new ArrayList(p_GroupForm
242:                        .getListRolesRealm());
243:                alUnused.removeAll(p_GroupForm.getListRolesGroup());
244:                Collections.sort(alUnused);
245:                p_GroupForm.setListRolesNotused(alUnused);
246:
247:                // Format list to string
248:                p_GroupForm.setRolesUsed(Jlists.getString(p_GroupForm
249:                        .getListRolesUsed(), Jlists.SEPARATOR));
250:                p_GroupForm.setRolesNotused(Jlists.getString(p_GroupForm
251:                        .getListRolesNotused(), Jlists.SEPARATOR));
252:            }
253:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.