@Override public Collection<? extends AccessCheck> getAccessChecks() { final Collection<AccessCheck> checks = new ArrayList<AccessCheck>(); checks.add(new AccessCheck(AccessRequired.Util.resourceNameFromConfigBeanProxy(parentBean), "read")); if (longOpt) { try { List<ConfigBeanProxy> children = (List<ConfigBeanProxy>) targetMethod.invoke(parentBean); for (ConfigBeanProxy child : children) { if (name == null || name.equals(Dom.unwrap(child).getKey())) { checks.add(new AccessCheck(AccessRequired.Util.resourceNameFromConfigBeanProxy(child), "read")); } } } catch (Exception ex) { String msg = localStrings.getLocalString(GenericCrudCommand.class, "GenericListCommand.accesschecks", "Exception while creating access checks for generic command {0}: {1}", commandName, ex.getMessage()); LogHelper.log(logger, Level.SEVERE, ConfigApiLoggerInfo.ACCESS_CHK_CREATE_FAILED, ex, commandName); throw new RuntimeException(msg, ex); } } return checks; }
private String resourceNameFromField(final Field f, final AdminCommand command) throws IllegalArgumentException, IllegalAccessException { f.setAccessible(true); if (ConfigBeanProxy.class.isAssignableFrom(f.getType())) { return AccessRequired.Util.resourceNameFromConfigBeanProxy((ConfigBeanProxy) f.get(command)); } else if (ConfigBean.class.isAssignableFrom(f.getType())) { return AccessRequired.Util.resourceNameFromDom((ConfigBean) f.get(command)); } else { final String savedResourceName = namedResourceMgr.find(f.get(command)); if (savedResourceName != null) { return savedResourceName; } } final Object fieldValue = f.get(command); if (fieldValue == null) { throw new IllegalArgumentException(command.getClass().getName() + "." + f.getName() + "== null"); } return fieldValue.toString(); }
sb.append(AccessRequired.Util.resourceNameFromConfigBeanType( (ConfigBeanProxy) parent, arNC.collection(), (Class<? extends ConfigBeanProxy>) childType)); } else if (ConfigBean.class.isAssignableFrom(parent.getClass())) { sb.append(AccessRequired.Util.resourceNameFromConfigBeanType( (ConfigBean) parent, arNC.collection(),
public static String resourceNameFromDom(Dom d) { Dom lastDom = null; final StringBuilder path = new StringBuilder(); while (d != null) { if (path.length() > 0) { path.insert(0, '/'); } final ConfigModel m = d.model; lastDom = d; final String key = d.getKey(); final String pathSegment = m.getTagName() + (key == null ? "" : "/" + key); path.insert(0, pathSegment); d = d.parent(); } if (lastDom != null) { if (lastDom.getKey() != null) { path.insert(0, pluralize(lastDom.model.getTagName()) + '/'); } } return path.toString(); }
public static String resourceNameFromDom(Dom d) { Dom lastDom = null; final StringBuilder path = new StringBuilder(); while (d != null) { if (path.length() > 0) { path.insert(0, '/'); } final ConfigModel m = d.model; lastDom = d; final String key = d.getKey(); final String pathSegment = m.getTagName() + (key == null ? "" : "/" + key); path.insert(0, pathSegment); d = d.parent(); } if (lastDom != null) { if (lastDom.getKey() != null) { path.insert(0, pluralize(lastDom.model.getTagName()) + '/'); } } return path.toString(); }
/** * Returns the resource name, if any was set when the access check was created. * @return */ public String resourceName() { if (resource != null) { return Util.resourceNameFromConfigBeanProxy(resource); } if (parent != null) { if (childName == null) { return Util.resourceNameFromConfigBeanType(parent, null, childType); } else { return Util.resourceNameFromConfigBeanTypeAndName(parent, childType, childName); } } return resourceName; }
public static String resourceNameFromConfigBeanType( final Dom parent, String collectionName, final Class<? extends ConfigBeanProxy> childType) { final StringBuilder sb = new StringBuilder(resourceNameFromDom(parent)).append('/'); final String tagName = parent.document.buildModel(childType).getTagName(); if (collectionName != null) { if (collectionName.isEmpty()) { collectionName = pluralize(tagName); } sb.append(collectionName).append('/'); } sb.append(tagName); return sb.toString(); }
/** * Returns the resource name, if any was set when the access check was created. * @return */ public String resourceName() { if (resource != null) { return Util.resourceNameFromConfigBeanProxy(resource); } if (parent != null) { if (childName == null) { return Util.resourceNameFromConfigBeanType(parent, null, childType); } else { return Util.resourceNameFromConfigBeanTypeAndName(parent, childType, childName); } } return resourceName; }
public static String resourceNameFromConfigBeanType( final Dom parent, String collectionName, final Class<? extends ConfigBeanProxy> childType) { final StringBuilder sb = new StringBuilder(resourceNameFromDom(parent)).append('/'); final String tagName = parent.document.buildModel(childType).getTagName(); if (collectionName != null) { if (collectionName.isEmpty()) { collectionName = pluralize(tagName); } sb.append(collectionName).append('/'); } sb.append(tagName); return sb.toString(); }
public static String resourceNameFromConfigBeanProxy(ConfigBeanProxy b) { return (b == null ? null : resourceNameFromDom(Dom.unwrap(b))); }
/** * Creates a new {@code AccessCheck} (typically for an existing target child) * @param parent the parent of the config bean to be accessed * @param childType the type of the child config bean * @param childName the name of the child config bean * @param action the action on the resource */ public AccessCheck(final ConfigBeanProxy parent, final Class<? extends ConfigBeanProxy> childType, final String childName, final String action) { this(Util.resourceNameFromConfigBeanTypeAndName(parent, childType, childName), action); }
/** * Creates a new {@code AccessCheck} (typically for an existing target child) * @param parent the parent of the config bean to be accessed * @param childType the type of the child config bean * @param childName the name of the child config bean * @param action the action on the resource */ public AccessCheck(final ConfigBeanProxy parent, final Class<? extends ConfigBeanProxy> childType, final String childName, final String action) { this(Util.resourceNameFromConfigBeanTypeAndName(parent, childType, childName), action); }
static String resourceNameFromConfigBeanTypeAndName( final ConfigBeanProxy parent, final Class<? extends ConfigBeanProxy> childType, final String childName) { return resourceNameFromConfigBeanType(parent, null, childType) + (childName != null && ! childName.isEmpty() ? "/" + childName : ""); }
@Override public Collection<? extends AccessCheck> getAccessChecks() { final Collection<AccessCheck> result = new ArrayList<AccessCheck>(); result.add(new AccessCheck(AccessRequired.Util.resourceNameFromConfigBeanProxy(spb), "update")); return result; }
private static String resourceNameFromRestEndpoint(Class<? extends ConfigBeanProxy> c, final String path, final ServiceLocator locator) { ConfigBeanProxy b = locator.getService(c); String name = (b != null ? AccessRequired.Util.resourceNameFromConfigBeanProxy(b) : "?"); if (path != null) { name += '/' + path; } return name; }
@Override public Collection<? extends AccessRequired.AccessCheck> getAccessChecks() { final Collection<AccessRequired.AccessCheck> result = new ArrayList<AccessRequired.AccessCheck>(); result.add(new AccessRequired.AccessCheck(AccessRequired.Util.resourceNameFromConfigBeanProxy(spb), "update")); return result; }
private Collection<? extends AccessCheck> getAccessChecksForNonMonitoring() { final Collection<AccessCheck> accessChecks = new ArrayList<AccessCheck>(); for (Map.Entry<Dom,String> entry : matchingNodes.entrySet()) { accessChecks.add(new AccessCheck(AccessRequired.Util.resourceNameFromDom((Dom)entry.getKey()), "read")); } return accessChecks; }
public static String resourceNameFromConfigBeanProxy(ConfigBeanProxy b) { return (b == null ? null : resourceNameFromDom(Dom.unwrap(b))); }
static String resourceNameFromConfigBeanTypeAndName( final ConfigBeanProxy parent, final Class<? extends ConfigBeanProxy> childType, final String childName) { return resourceNameFromConfigBeanType(parent, null, childType) + (childName != null && ! childName.isEmpty() ? "/" + childName : ""); }
public static String resourceNameFromConfigBeanType( final ConfigBeanProxy parent, final String collectionName, final Class<? extends ConfigBeanProxy> childType) { return (parent == null ? null : resourceNameFromConfigBeanType(Dom.unwrap(parent), collectionName, childType)); }