00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 package org.objectweb.jonas.webapp.jonasadmin.security;
00028
00029 import java.util.ArrayList;
00030 import java.util.Arrays;
00031 import java.util.Collections;
00032
00033 import javax.management.ObjectName;
00034 import javax.servlet.http.HttpServletRequest;
00035
00036 import org.apache.struts.action.ActionMapping;
00037 import org.objectweb.jonas.jmx.JonasManagementRepr;
00038 import org.objectweb.jonas.jmx.JonasObjectName;
00039 import org.objectweb.jonas.webapp.jonasadmin.Jlists;
00040
00045 abstract public class BaseMemoryRealmAction extends BaseSecurityAction {
00046
00047
00048
00049
00050 protected MemoryRealmForm getForm(ActionMapping p_Mapping, HttpServletRequest p_Request) {
00051
00052 MemoryRealmForm oForm = null;
00053
00054 String sResource = p_Request.getParameter("resource");
00055
00056
00057 if (sResource != null) {
00058 oForm = new MemoryRealmForm();
00059 m_Session.setAttribute("memoryRealmForm", oForm);
00060 oForm.reset(p_Mapping, p_Request);
00061 oForm.setResource(sResource);
00062
00063 m_Session.removeAttribute("userMemoryRealmForm");
00064 m_Session.removeAttribute("roleMemoryRealmForm");
00065 m_Session.removeAttribute("groupMemoryRealmForm");
00066 m_Session.removeAttribute("itemsMemoryRealmForm");
00067 }
00068 else {
00069 oForm = (MemoryRealmForm) m_Session.getAttribute("memoryRealmForm");
00070 }
00071 return oForm;
00072 }
00073
00080 protected void removeItemsMemoryRealmForm(String p_Type) {
00081 ItemsMemoryRealmForm oForm = (ItemsMemoryRealmForm) m_Session.getAttribute(
00082 "itemsMemoryRealmForm");
00083 if (oForm != null) {
00084 if ((oForm.getType() != null) && (oForm.getType().equals(p_Type) == false)) {
00085 m_Session.removeAttribute("itemsMemoryRealmForm");
00086 }
00087 }
00088 }
00089
00099 protected void populateUserForm(MemoryRealmForm p_RealmForm, UserMemoryRealmForm p_UserForm
00100 , String p_UserName)
00101 throws Exception {
00102
00103 if (p_UserName != null) {
00104
00105 ObjectName oObjectName = JonasObjectName.user(p_RealmForm.getResource(), p_UserName);
00106 p_UserForm.setUser(getStringAttribute(oObjectName, "Name"));
00107
00108 p_UserForm.setListGroupsUser(new ArrayList(Arrays.asList((String[]) JonasManagementRepr.
00109 getAttribute(oObjectName, "ArrayGroups"))));
00110 p_UserForm.setListGroupsUsed(new ArrayList(p_UserForm.getListGroupsUser()));
00111
00112 p_UserForm.setListRolesUser(new ArrayList(Arrays.asList((String[]) JonasManagementRepr.
00113 getAttribute(oObjectName, "ArrayRoles"))));
00114 p_UserForm.setListRolesUsed(new ArrayList(p_UserForm.getListRolesUser()));
00115 }
00116
00117 ObjectName oObjectName = JonasObjectName.securityMemoryFactory(p_RealmForm.getResource());
00118 p_UserForm.setListGroupsRealm(new ArrayList(Arrays.asList((String[]) JonasManagementRepr.
00119 invoke(oObjectName, "listGroups", null, null))));
00120 p_UserForm.setListRolesRealm(new ArrayList(Arrays.asList((String[]) JonasManagementRepr.
00121 invoke(oObjectName, "listRoles", null, null))));
00122
00123
00124 ArrayList alUnused = new ArrayList(p_UserForm.getListGroupsRealm());
00125 alUnused.removeAll(p_UserForm.getListGroupsUser());
00126 Collections.sort(alUnused);
00127 p_UserForm.setListGroupsNotused(alUnused);
00128
00129 alUnused = new ArrayList(p_UserForm.getListRolesRealm());
00130 alUnused.removeAll(p_UserForm.getListRolesUser());
00131 Collections.sort(alUnused);
00132 p_UserForm.setListRolesNotused(alUnused);
00133
00134
00135 p_UserForm.setGroupsUsed(Jlists.getString(p_UserForm.getListGroupsUsed(), Jlists.SEPARATOR));
00136 p_UserForm.setGroupsNotused(Jlists.getString(p_UserForm.getListGroupsNotused()
00137 , Jlists.SEPARATOR));
00138 p_UserForm.setRolesUsed(Jlists.getString(p_UserForm.getListRolesUsed(), Jlists.SEPARATOR));
00139 p_UserForm.setRolesNotused(Jlists.getString(p_UserForm.getListRolesNotused()
00140 , Jlists.SEPARATOR));
00141 }
00142
00151 protected String encryptPassword(String p_Password, String p_EncrypMethod)
00152 throws Exception {
00153 ObjectName onSecurityService = JonasObjectName.securityService();
00154 String[] asParam = {
00155 p_Password, p_EncrypMethod};
00156 String[] asSignature = {
00157 "java.lang.String", "java.lang.String"};
00158 return (String) JonasManagementRepr.invoke(onSecurityService, "encryptPassword", asParam
00159 , asSignature);
00160 }
00161
00171 protected void populateRoleForm(MemoryRealmForm p_RealmForm, RoleMemoryRealmForm p_RoleForm
00172 , String p_RoleName)
00173 throws Exception {
00174
00175 if (p_RoleName != null) {
00176
00177 ObjectName oObjectName = JonasObjectName.role(p_RealmForm.getResource(), p_RoleName);
00178 p_RoleForm.setRole(getStringAttribute(oObjectName, "Name"));
00179 p_RoleForm.setDescription(getStringAttribute(oObjectName, "Description"));
00180 }
00181 }
00182
00192 protected void populateGroupForm(MemoryRealmForm p_RealmForm, GroupMemoryRealmForm p_GroupForm
00193 , String p_GroupName)
00194 throws Exception {
00195
00196 if (p_GroupName != null) {
00197
00198 ObjectName oObjectName = JonasObjectName.group(p_RealmForm.getResource(), p_GroupName);
00199 p_GroupForm.setGroup(getStringAttribute(oObjectName, "Name"));
00200 p_GroupForm.setDescription(getStringAttribute(oObjectName, "Description"));
00201
00202 p_GroupForm.setListRolesGroup(new ArrayList(Arrays.asList((String[])
00203 JonasManagementRepr.getAttribute(oObjectName, "ArrayRoles"))));
00204 p_GroupForm.setListRolesUsed(new ArrayList(p_GroupForm.getListRolesGroup()));
00205 }
00206
00207 ObjectName oObjectName = JonasObjectName.securityMemoryFactory(p_RealmForm.getResource());
00208 p_GroupForm.setListRolesRealm(new ArrayList(Arrays.asList((String[]) JonasManagementRepr.
00209 invoke(oObjectName, "listRoles", null, null))));
00210
00211
00212 ArrayList alUnused = new ArrayList(p_GroupForm.getListRolesRealm());
00213 alUnused.removeAll(p_GroupForm.getListRolesGroup());
00214 Collections.sort(alUnused);
00215 p_GroupForm.setListRolesNotused(alUnused);
00216
00217
00218 p_GroupForm.setRolesUsed(Jlists.getString(p_GroupForm.getListRolesUsed(), Jlists.SEPARATOR));
00219 p_GroupForm.setRolesNotused(Jlists.getString(p_GroupForm.getListRolesNotused()
00220 , Jlists.SEPARATOR));
00221 }
00222 }