1 26 27 package org.objectweb.jonas.webapp.jonasadmin.security; 28 29 import java.util.ArrayList ; 30 import java.util.Arrays ; 31 import java.util.Collections ; 32 33 import javax.management.ObjectName ; 34 import javax.servlet.http.HttpServletRequest ; 35 36 import org.apache.struts.action.ActionMapping; 37 import org.objectweb.jonas.jmx.JonasManagementRepr; 38 import org.objectweb.jonas.jmx.JonasObjectName; 39 import org.objectweb.jonas.webapp.jonasadmin.Jlists; 40 41 44 45 abstract public class BaseMemoryRealmAction extends BaseSecurityAction { 46 47 49 protected MemoryRealmForm getForm(ActionMapping p_Mapping, HttpServletRequest p_Request) { 51 MemoryRealmForm oForm = null; 53 String sResource = p_Request.getParameter("resource"); 55 56 if (sResource != null) { 58 oForm = new MemoryRealmForm(); 59 m_Session.setAttribute("memoryRealmForm", oForm); 60 oForm.reset(p_Mapping, p_Request); 61 oForm.setResource(sResource); 62 m_Session.removeAttribute("userMemoryRealmForm"); 64 m_Session.removeAttribute("roleMemoryRealmForm"); 65 m_Session.removeAttribute("groupMemoryRealmForm"); 66 m_Session.removeAttribute("itemsMemoryRealmForm"); 67 } 68 else { 69 oForm = (MemoryRealmForm) m_Session.getAttribute("memoryRealmForm"); 70 } 71 return oForm; 72 } 73 74 80 protected void removeItemsMemoryRealmForm(String p_Type) { 81 ItemsMemoryRealmForm oForm = (ItemsMemoryRealmForm) m_Session.getAttribute( 82 "itemsMemoryRealmForm"); 83 if (oForm != null) { 84 if ((oForm.getType() != null) && (oForm.getType().equals(p_Type) == false)) { 85 m_Session.removeAttribute("itemsMemoryRealmForm"); 86 } 87 } 88 } 89 90 99 protected void populateUserForm(MemoryRealmForm p_RealmForm, UserMemoryRealmForm p_UserForm 100 , String p_UserName) 101 throws Exception { 102 103 if (p_UserName != null) { 104 ObjectName oObjectName = JonasObjectName.user(p_RealmForm.getResource(), p_UserName); 106 p_UserForm.setUser(getStringAttribute(oObjectName, "Name")); 107 108 p_UserForm.setListGroupsUser(new ArrayList (Arrays.asList((String []) JonasManagementRepr. 109 getAttribute(oObjectName, "ArrayGroups")))); 110 p_UserForm.setListGroupsUsed(new ArrayList (p_UserForm.getListGroupsUser())); 111 112 p_UserForm.setListRolesUser(new ArrayList (Arrays.asList((String []) JonasManagementRepr. 113 getAttribute(oObjectName, "ArrayRoles")))); 114 p_UserForm.setListRolesUsed(new ArrayList (p_UserForm.getListRolesUser())); 115 } 116 ObjectName oObjectName = JonasObjectName.securityMemoryFactory(p_RealmForm.getResource()); 118 p_UserForm.setListGroupsRealm(new ArrayList (Arrays.asList((String []) JonasManagementRepr. 119 invoke(oObjectName, "listGroups", null, null)))); 120 p_UserForm.setListRolesRealm(new ArrayList (Arrays.asList((String []) JonasManagementRepr. 121 invoke(oObjectName, "listRoles", null, null)))); 122 123 ArrayList alUnused = new ArrayList (p_UserForm.getListGroupsRealm()); 125 alUnused.removeAll(p_UserForm.getListGroupsUser()); 126 Collections.sort(alUnused); 127 p_UserForm.setListGroupsNotused(alUnused); 128 129 alUnused = new ArrayList (p_UserForm.getListRolesRealm()); 130 alUnused.removeAll(p_UserForm.getListRolesUser()); 131 Collections.sort(alUnused); 132 p_UserForm.setListRolesNotused(alUnused); 133 134 p_UserForm.setGroupsUsed(Jlists.getString(p_UserForm.getListGroupsUsed(), Jlists.SEPARATOR)); 136 p_UserForm.setGroupsNotused(Jlists.getString(p_UserForm.getListGroupsNotused() 137 , Jlists.SEPARATOR)); 138 p_UserForm.setRolesUsed(Jlists.getString(p_UserForm.getListRolesUsed(), Jlists.SEPARATOR)); 139 p_UserForm.setRolesNotused(Jlists.getString(p_UserForm.getListRolesNotused() 140 , Jlists.SEPARATOR)); 141 } 142 143 151 protected String encryptPassword(String p_Password, String p_EncrypMethod) 152 throws Exception { 153 ObjectName onSecurityService = JonasObjectName.securityService(); 154 String [] asParam = { 155 p_Password, p_EncrypMethod}; 156 String [] asSignature = { 157 "java.lang.String", "java.lang.String"}; 158 return (String ) JonasManagementRepr.invoke(onSecurityService, "encryptPassword", asParam 159 , asSignature); 160 } 161 162 171 protected void populateRoleForm(MemoryRealmForm p_RealmForm, RoleMemoryRealmForm p_RoleForm 172 , String p_RoleName) 173 throws Exception { 174 175 if (p_RoleName != null) { 176 ObjectName oObjectName = JonasObjectName.role(p_RealmForm.getResource(), p_RoleName); 178 p_RoleForm.setRole(getStringAttribute(oObjectName, "Name")); 179 p_RoleForm.setDescription(getStringAttribute(oObjectName, "Description")); 180 } 181 } 182 183 192 protected void populateGroupForm(MemoryRealmForm p_RealmForm, GroupMemoryRealmForm p_GroupForm 193 , String p_GroupName) 194 throws Exception { 195 196 if (p_GroupName != null) { 197 ObjectName oObjectName = JonasObjectName.group(p_RealmForm.getResource(), p_GroupName); 199 p_GroupForm.setGroup(getStringAttribute(oObjectName, "Name")); 200 p_GroupForm.setDescription(getStringAttribute(oObjectName, "Description")); 201 202 p_GroupForm.setListRolesGroup(new ArrayList (Arrays.asList((String []) 203 JonasManagementRepr.getAttribute(oObjectName, "ArrayRoles")))); 204 p_GroupForm.setListRolesUsed(new ArrayList (p_GroupForm.getListRolesGroup())); 205 } 206 ObjectName oObjectName = JonasObjectName.securityMemoryFactory(p_RealmForm.getResource()); 208 p_GroupForm.setListRolesRealm(new ArrayList (Arrays.asList((String []) JonasManagementRepr. 209 invoke(oObjectName, "listRoles", null, null)))); 210 211 ArrayList alUnused = new ArrayList (p_GroupForm.getListRolesRealm()); 213 alUnused.removeAll(p_GroupForm.getListRolesGroup()); 214 Collections.sort(alUnused); 215 p_GroupForm.setListRolesNotused(alUnused); 216 217 p_GroupForm.setRolesUsed(Jlists.getString(p_GroupForm.getListRolesUsed(), Jlists.SEPARATOR)); 219 p_GroupForm.setRolesNotused(Jlists.getString(p_GroupForm.getListRolesNotused() 220 , Jlists.SEPARATOR)); 221 } 222 } 223 | Popular Tags |