/** * write the descriptor class to a DOM tree and return it * * @param parent node for the DOM tree * @param node name for * @param the descriptor to write * @return the DOM tree top node */ public Node writeDescriptor( Node parent, String nodeName, PrincipalNameDescriptor descriptor) { //principal-name Element principal = (Element) appendTextChild( parent, RuntimeTagNames.PRINCIPAL_NAME, descriptor.getName()); // class-name setAttribute(principal, RuntimeTagNames.CLASS_NAME, descriptor.getClassName()); return principal; } }
@Override protected PrincipalNameDescriptor createDescriptor() { return new PrincipalNameDescriptor(); }
@Override public void addDescriptor(Object newDescriptor) { if (newDescriptor instanceof SecurityRoleMapping) { SecurityRoleMapping roleMap = (SecurityRoleMapping)newDescriptor; descriptor.addSecurityRoleMapping(roleMap); Application app = descriptor.getApplication(); if (app!=null) { Role role = new Role(roleMap.getRoleName()); SecurityRoleMapper rm = app.getRoleMapper(); if (rm != null) { List<PrincipalNameDescriptor> principals = roleMap.getPrincipalNames(); for (int i = 0; i < principals.size(); i++) { rm.assignRole(principals.get(i).getPrincipal(), role, descriptor); } List<String> groups = roleMap.getGroupNames(); for (int i = 0; i < groups.size(); i++) { rm.assignRole(new Group(groups.get(i)), role, descriptor); } } } } }
/** * receives notiification of the value for a particular tag * * @param element the xml element * @param value it's associated value */ public void setElementValue(XMLElement element, String value) { PrincipalNameDescriptor principal = (PrincipalNameDescriptor) getDescriptor(); if (RuntimeTagNames.PRINCIPAL_NAME.equals(element.getQName())) { principal.setName(value); Object rootDesc = getParentNode().getParentNode().getDescriptor(); if (rootDesc instanceof RootDeploymentDescriptor) { principal.setClassLoader(((RootDeploymentDescriptor)rootDesc).getClassLoader()); } } else super.setElementValue(element, value); }
public String toString() { return "principal-name " + principalName + "; className " + getClassName(); } }
/** *@deprecated *This method needs to be removed once the custom principal is fully *supported. We keep it for now for backward compatiblity in API. Note *that this method only returns the name of the principals, not their *class-names. Use with caution! */ public String[] getPrincipalName() { String[] names = new String[principals.size()]; for (int i = 0; i < principals.size(); i++) { names[i] = principals.get(i).getName(); } return names; } }
/** * parsed an attribute of an element * * @param the element name * @param the attribute name * @param the attribute value * @return true if the attribute was processed */ protected boolean setAttributeValue( XMLElement element, XMLElement attribute, String value) { PrincipalNameDescriptor principal = (PrincipalNameDescriptor) getDescriptor(); if (attribute.getQName().equals(RuntimeTagNames.CLASS_NAME)) { principal.setClassName(value); return true; } return false; }
/** * Adds a new DOL descriptor instance to the descriptor instance associated with * this XMLNode * * @param mewDescriptor the new descriptor */ public void addDescriptor(Object newDescriptor) { if (newDescriptor instanceof SecurityRoleMapping) { SecurityRoleMapping roleMap = (SecurityRoleMapping) newDescriptor; descriptor.addSecurityRoleMapping(roleMap); if (descriptor!=null && !descriptor.isVirtual()) { Role role = new Role(roleMap.getRoleName()); SecurityRoleMapper rm = descriptor.getRoleMapper(); if (rm != null) { List<PrincipalNameDescriptor> principals = roleMap.getPrincipalNames(); for (int i = 0; i < principals.size(); i++) { rm.assignRole(principals.get(i).getPrincipal(), role, descriptor); } List<String> groups = roleMap.getGroupNames(); for (int i = 0; i < groups.size(); i++) { rm.assignRole(new Group(groups.get(i)), role, descriptor); } } } } }
/** * receives notiification of the value for a particular tag * * @param element the xml element * @param value it's associated value */ public void setElementValue(XMLElement element, String value) { PrincipalNameDescriptor principal = (PrincipalNameDescriptor) getDescriptor(); if (RuntimeTagNames.PRINCIPAL_NAME.equals(element.getQName())) { principal.setName(value); Object rootDesc = getParentNode().getParentNode().getDescriptor(); if (rootDesc instanceof RootDeploymentDescriptor) { principal.setClassLoader(((RootDeploymentDescriptor)rootDesc).getClassLoader()); } } else super.setElementValue(element, value); }
public String toString() { return "principal-name " + principalName + "; className " + getClassName(); } }
/** *@deprecated *This method needs to be removed once the custom principal is fully *supported. We keep it for now for backward compatiblity in API. Note *that this method only returns the name of the principals, not their *class-names. Use with caution! */ public String[] getPrincipalName() { String[] names = new String[principals.size()]; for (int i = 0; i < principals.size(); i++) { names[i] = new String(principals.get(i).getName()); } return names; } }
/** * parsed an attribute of an element * * @param the element name * @param the attribute name * @param the attribute value * @return true if the attribute was processed */ protected boolean setAttributeValue( XMLElement element, XMLElement attribute, String value) { PrincipalNameDescriptor principal = (PrincipalNameDescriptor) getDescriptor(); if (attribute.getQName().equals(RuntimeTagNames.CLASS_NAME)) { principal.setClassName(value); return true; } return false; }
/** * Adds a new DOL descriptor instance to the descriptor instance associated with * this XMLNode * * @param descriptor the new descriptor */ public void addDescriptor(Object newDescriptor) { if (newDescriptor instanceof SecurityRoleMapping) { SecurityRoleMapping roleMap = (SecurityRoleMapping)newDescriptor; descriptor.addSecurityRoleMapping(roleMap); Application app = descriptor.getApplication(); if (app!=null) { Role role = new Role(roleMap.getRoleName()); SecurityRoleMapper rm = app.getRoleMapper(); if (rm != null) { List<PrincipalNameDescriptor> principals = roleMap.getPrincipalNames(); for (int i = 0; i < principals.size(); i++) { rm.assignRole(principals.get(i).getPrincipal(), role, descriptor); } List<String> groups = roleMap.getGroupNames(); for (int i = 0; i < groups.size(); i++) { rm.assignRole(new Group(groups.get(i)), role, descriptor); } } } } }
/** * write the descriptor class to a DOM tree and return it * * @param parent node for the DOM tree * @param node name for * @param the descriptor to write * @return the DOM tree top node */ public Node writeDescriptor( Node parent, String nodeName, PrincipalNameDescriptor descriptor) { //principal-name Element principal = (Element) appendTextChild( parent, RuntimeTagNames.PRINCIPAL_NAME, descriptor.getName()); // class-name setAttribute(principal, RuntimeTagNames.CLASS_NAME, descriptor.getClassName()); return principal; } }
public Principal getPrincipal() { try { if (cLoader == null) { cLoader = Thread.currentThread().getContextClassLoader(); } Class clazz = Class.forName(getClassName(), true, cLoader); Constructor constructor = clazz.getConstructor(new Class[]{String.class}); Object o = constructor.newInstance(new Object[]{principalName}); return (Principal) o; } catch(Exception ex) { RuntimeException e = new RuntimeException(); e.initCause(ex); throw e; } }
/** * Adds a new DOL descriptor instance to the descriptor instance associated with * this XMLNode * * @param newDescriptor the new descriptor */ public void addDescriptor(Object newDescriptor) { if (newDescriptor instanceof SecurityRoleMapping) { SecurityRoleMapping roleMap = (SecurityRoleMapping) newDescriptor; if (descriptor!=null && !descriptor.isVirtual()) { descriptor.addSecurityRoleMapping(roleMap); Role role = new Role(roleMap.getRoleName()); SecurityRoleMapper rm = descriptor.getRoleMapper(); if (rm != null) { List<PrincipalNameDescriptor> principals = roleMap.getPrincipalNames(); for (int i = 0; i < principals.size(); i++) { rm.assignRole(principals.get(i).getPrincipal(), role, descriptor); } List<String> groups = roleMap.getGroupNames(); for (int i = 0; i < groups.size(); i++) { rm.assignRole(new Group(groups.get(i)), role, descriptor); } } } } }
public Principal getPrincipal() { try { if (cLoader == null) { cLoader = Thread.currentThread().getContextClassLoader(); } Class clazz = Class.forName(getClassName(), true, cLoader); Constructor constructor = clazz.getConstructor(new Class[]{String.class}); Object o = constructor.newInstance(new Object[]{principalName}); return (Principal) o; } catch(Exception ex) { RuntimeException e = new RuntimeException(); e.initCause(ex); throw e; } }
List<PrincipalNameDescriptor> principals = srm.getPrincipalNames(); for (int i = 0; i < principals.size(); i++) { rm.assignRole(principals.get(i).getPrincipal(), role, descriptor);