/** * Parsers permissionDescription and instantiates the permission using * the ClassLoader of this class. * * @param permissionDescription * @return */ public static Permission getPermission(String permissionDescription) { return getPermission(permissionDescription, PermissionParser.class.getClassLoader()); }
private static PermissionInfo parse(String permissionDescription) { StringReader reader = new StringReader(permissionDescription); try { return parse(reader); } catch (IOException ex) { throw new RuntimeException(ex); } }
private static void parseFromClassName(StringReader StringReader, PermissionInfo result) throws IOException { PushbackReader reader = new PushbackReader(StringReader, 1); result.className = readSection(reader); result.name = readSection(reader); result.actions = readSection(reader); byte closingBracketsCount = 0; for (int ch = reader.read(); ch != -1; ch = reader.read()) { if (ch == ' ') { continue; } if (ch == ')') { closingBracketsCount++; if (closingBracketsCount > 1) { throw new IllegalArgumentException("more than 1 closing bracket"); } continue; } else { throw new IllegalArgumentException("illegal character at this position: "+ch); } } }
private static String readSectionWithNoHeadingSpace(PushbackReader reader) throws IOException { StringBuilder sectionWriter = new StringBuilder(); for (int ch = reader.read(); ch != -1; ch = reader.read()) { if (ch == '"') { if (sectionWriter.length() > 0) { throw new IllegalArgumentException("Quote at wrong position, characters before quote: "+sectionWriter.toString()); } sectionWriter = null; return readTillQuote(reader); } if (ch == ' ') { return sectionWriter.toString(); } if (ch == ')') { reader.unread(ch); return sectionWriter.toString(); } sectionWriter.append((char)ch); } throw new IllegalArgumentException("missing closing bracket (')')"); }
private static String readSection(PushbackReader reader) throws IOException { for (int ch = reader.read(); ch != -1; ch = reader.read()) { if (ch == ' ') { continue; } else { reader.unread(ch); return readSectionWithNoHeadingSpace(reader); } } return null; }
private static PermissionInfo parse(StringReader reader) throws IOException { PermissionInfo result = new PermissionInfo(); for (int ch = reader.read(); ch != -1; ch = reader.read()) { if (ch == ' ') { continue; } if (ch =='(') { parseFromClassName(reader, result); break; } else { throw new IllegalArgumentException("Permission description does not start with '('"); } } for (int ch = reader.read(); ch != -1; ch = reader.read()) { if (ch != ' ') { throw new IllegalArgumentException("Unparsable characters after closing ')'"); } } return result; }
/** * Get the set of permissions required for read-write access to the * triple-collection, the set may be empty meaning that the default * TCPermission is required. * * @param GraphUri * @return the collection of permissions */ public Collection<Permission> getRequiredReadWritePermissions(IRI GraphUri) { Collection<Permission> result = readWritePermissionCache.get(GraphUri); if (result == null) { result = new ArrayList<Permission>(); Collection<String> permissionStrings = getRequiredReadWritePermissionStrings(GraphUri); for (String string : permissionStrings) { result.add(PermissionParser.getPermission(string, getClass().getClassLoader())); } readWritePermissionCache.put(GraphUri, result); } return result; }
PermissionInfo permissionInfo = parse(permissionDescription); try { Class clazz = classLoader.loadClass(permissionInfo.className);
/** * Get the set of permissions required for read access to the * triple-collection, the set may be empty meaning that the default * TCPermission is required. * * @param GraphUri * @return the collection of permissions */ public Collection<Permission> getRequiredReadPermissions(IRI GraphUri) { Collection<Permission> result = readPermissionCache.get(GraphUri); if (result == null) { result = new ArrayList<Permission>(); Collection<String> permissionStrings = getRequiredReadPermissionStrings(GraphUri); for (String string : permissionStrings) { result.add(PermissionParser.getPermission(string, getClass().getClassLoader())); } readPermissionCache.put(GraphUri, result); } return result; }
/** * Get the set of permissions required for read access to the * triple-collection, the set may be empty meaning that the default * TCPermission is required. * * @param GraphUri * @return the collection of permissions */ public Collection<Permission> getRequiredReadPermissions(IRI GraphUri) { Collection<Permission> result = readPermissionCache.get(GraphUri); if (result == null) { result = new ArrayList<Permission>(); Collection<String> permissionStrings = getRequiredReadPermissionStrings(GraphUri); for (String string : permissionStrings) { result.add(PermissionParser.getPermission(string, getClass().getClassLoader())); } readPermissionCache.put(GraphUri, result); } return result; }
/** * Get the set of permissions required for read-write access to the * triple-collection, the set may be empty meaning that the default * TCPermission is required. * * @param GraphUri * @return the collection of permissions */ public Collection<Permission> getRequiredReadWritePermissions(IRI GraphUri) { Collection<Permission> result = readWritePermissionCache.get(GraphUri); if (result == null) { result = new ArrayList<Permission>(); Collection<String> permissionStrings = getRequiredReadWritePermissionStrings(GraphUri); for (String string : permissionStrings) { result.add(PermissionParser.getPermission(string, getClass().getClassLoader())); } readWritePermissionCache.put(GraphUri, result); } return result; }
@Override public Object run() { logger.debug("Get permissions for user " + user.getName()); List<String> permissions = getAllPermissionsOfAUserByName(user .getName()); for (String permissionStr : permissions) { logger.debug("Add permission {}", permissionStr); Permission perm = permissionMap.get(permissionStr); // make new permission, if the required // <code>Permission</code> object is not in the map. if (perm == null) { try { perm = PermissionParser.getPermission(permissionStr, getClass().getClassLoader()); } catch (IllegalArgumentException e) { logger.error("parsing "+permissionStr,e); continue; } catch (RuntimeException e) { logger.error("instantiating "+permissionStr,e); continue; } } result.add(perm); } return null; } });
@Override public Object run() { logger.debug("Get permissions for user " + user.getName()); List<String> permissions = getAllPermissionsOfAUserByName(user .getName()); for (String permissionStr : permissions) { logger.debug("Add permission {}", permissionStr); Permission perm = permissionMap.get(permissionStr); // make new permission, if the required // <code>Permission</code> object is not in the map. if (perm == null) { try { perm = PermissionParser.getPermission(permissionStr, getClass().getClassLoader()); } catch (IllegalArgumentException e) { logger.error("parsing "+permissionStr,e); continue; } catch (RuntimeException e) { logger.error("instantiating "+permissionStr,e); continue; } } result.add(perm); } return null; } });
@Override public Object run() { logger.debug("Get permissions for user " + user.getName()); List<String> permissions = getAllPermissionsOfAUserByName(user .getName()); for (String permissionStr : permissions) { logger.debug("Add permission {}", permissionStr); Permission perm = permissionMap.get(permissionStr); // make new permission, if the required // <code>Permission</code> object is not in the map. if (perm == null) { try { perm = PermissionParser.getPermission(permissionStr, getClass().getClassLoader()); } catch (IllegalArgumentException e) { logger.error("parsing "+permissionStr,e); continue; } catch (RuntimeException e) { logger.error("instantiating "+permissionStr,e); continue; } } result.add(perm); } return null; } });