/** * Attempt to match a given permission to what is defined in the UI. * @param id String of the form "Title/Permission" (Look in the UI) for a particular permission * @return a matched permission ID */ @CheckForNull public static String findPermissionId(String id) { List<PermissionGroup> pgs = PermissionGroup.getAll(); Matcher m = PERMISSION_PATTERN.matcher(id); if(m.matches()) { String owner = m.group(1); String name = m.group(2); for(PermissionGroup pg : pgs) { if(pg.owner.equals(Permission.class)) { continue; } //TODO: Support PermissionGroupIDs (JENKINS-51598) //How do we do this properly, we want to mimic the UI as best as possible. So the logic conclusion is //That when you want admin to be Overall/Administer you put that in. Overall being the group title... //Name being the Permission you want to set in the matrix. if(pg.title.toString(Locale.US).equals(owner)) { return pg.owner.getName() + "." + name; } } } return null; } }
/** * Convert the ID representation into {@link Permission} object. * * @return * null if the conversion failed. * @see #getId() */ public static @CheckForNull Permission fromId(@Nonnull String id) { int idx = id.lastIndexOf('.'); if(idx<0) return null; try { // force the initialization so that it will put all its permissions into the list. Class cl = Class.forName(id.substring(0,idx),true, Jenkins.getInstance().getPluginManager().uberClassLoader); PermissionGroup g = PermissionGroup.get(cl); if(g ==null) return null; return g.find(id.substring(idx+1)); } catch (ClassNotFoundException e) { return null; } }
this.id = owner.getName() + '.' + name; group.add(this); ALL.add(this);
public int compareTo(PermissionGroup that) { // first, sort by the 'compare order' number. This is so that // we can put Hudson.PERMISSIONS first. int r= this.compareOrder()-that.compareOrder(); if(r!=0) return r; // among the permissions of the same group, just sort by their names // so that the sort order is consistent regardless of classloading order. return getOwnerClassName().compareTo(that.getOwnerClassName()); }
private List<Permission> findAllPermissions() { List<Permission> perms = new ArrayList<Permission>(); for (PermissionGroup group : PermissionGroup.getAll()) { perms.addAll(group.getPermissions()); } return perms; } }
public Iterator<Permission> iterator() { return getPermissions().iterator(); }
public int compareTo(PermissionGroup that) { // first, sort by the 'compare order' number. This is so that // we can put Hudson.PERMISSIONS first. int r = this.compareOrder() - that.compareOrder(); if (r != 0) { return r; } // among the permissions of the same group, just sort by their names // so that the sort order is consistent regardless of classloading order. return this.owner.getName().compareTo(that.owner.getName()); }
public int compareTo(PermissionGroup that) { // first, sort by the 'compare order' number. This is so that // we can put Hudson.PERMISSIONS first. int r= this.compareOrder()-that.compareOrder(); if(r!=0) return r; // among the permissions of the same group, just sort by their names // so that the sort order is consistent regardless of classloading order. return id().compareTo(that.id()); }
public Iterator<Permission> iterator() { return getPermissions().iterator(); }
public int compareTo(PermissionGroup that) { // first, sort by the 'compare order' number. This is so that // we can put Hudson.PERMISSIONS first. int r= this.compareOrder()-that.compareOrder(); if(r!=0) return r; // among the permissions of the same group, just sort by their names // so that the sort order is consistent regardless of classloading order. return this.owner.getName().compareTo(that.owner.getName()); }
/** * Convert the ID representation into {@link Permission} object. * * @return * null if the conversion failed. * @see #getId() */ public static @CheckForNull Permission fromId(@Nonnull String id) { int idx = id.lastIndexOf('.'); if(idx<0) return null; try { // force the initialization so that it will put all its permissions into the list. Class cl = Class.forName(id.substring(0,idx),true, Jenkins.getInstance().getPluginManager().uberClassLoader); PermissionGroup g = PermissionGroup.get(cl); if(g ==null) return null; return g.find(id.substring(idx+1)); } catch (ClassNotFoundException e) { return null; } }
/** * Attempt to match a given permission to what is defined in the UI. * @param id String of the form "Title/Permission" (Look in the UI) for a particular permission * @return a matched permission ID */ @CheckForNull public static String findPermissionId(String id) { List<PermissionGroup> pgs = PermissionGroup.getAll(); Matcher m = PERMISSION_PATTERN.matcher(id); if(m.matches()) { String owner = m.group(1); String name = m.group(2); for(PermissionGroup pg : pgs) { if(pg.owner.equals(Permission.class)) { continue; } //TODO: Support PermissionGroupIDs (JENKINS-51598) //How do we do this properly, we want to mimic the UI as best as possible. So the logic conclusion is //That when you want admin to be Overall/Administer you put that in. Overall being the group title... //Name being the Permission you want to set in the matrix. if(pg.title.toString(Locale.US).equals(owner)) { return pg.owner.getName() + "." + name; } } } return null; } }
this.scopes = ImmutableSet.copyOf(scopes); group.add(this); ALL.add(this);
@Override public final Collection<Permission> getItemsOfGroup(PermissionGroup group) { LinkedList<Permission> res = new LinkedList<>(); for (Permission p : group.getPermissions()) { if (p.getEnabled()) { res.add(p); } } return res; }