/** * 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 */ @CheckForNull public static Permission findPermission(String id) { final String resolvedId = findPermissionId(id); return resolvedId != null ? Permission.fromId(resolvedId) : null; }
@Override public Object decode(Class targetClass, Object fromDBObject, MappedField optionalExtraInfo) { if (fromDBObject == null) return null; return Permission.fromId((String) fromDBObject); }
/** * Works like {@link #add(Permission, String)} but takes both parameters * from a single string of the form <tt>PERMISSIONID:sid</tt> */ private void add(String shortForm) { int idx = shortForm.indexOf(':'); Permission p = Permission.fromId(shortForm.substring(0, idx)); if (p==null) throw new IllegalArgumentException("Failed to parse '"+shortForm+"' --- no such permission"); add(p, shortForm.substring(idx + 1)); }
/** * 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 */ @CheckForNull public static Permission findPermission(String id) { final String resolvedId = findPermissionId(id); return resolvedId != null ? Permission.fromId(resolvedId) : null; }
/** * Works like {@link #add(Permission, String)} but takes both parameters * from a single string of the form <tt>PERMISSIONID:sid</tt> */ private void add(String shortForm) { int idx = shortForm.indexOf(':'); Permission p = Permission.fromId(shortForm.substring(0, idx)); if (p==null) throw new IllegalArgumentException("Failed to parse '"+shortForm+"' --- no such permission"); add(p,shortForm.substring(idx+1)); }
/** * Works like {@link #add(Permission, String)} but takes both parameters * from a single string of the form <tt>PERMISSIONID:sid</tt> */ private void add(String shortForm) { int idx = shortForm.indexOf(':'); Permission p = Permission.fromId(shortForm.substring(0, idx)); if (p==null) throw new IllegalArgumentException("Failed to parse '"+shortForm+"' --- no such permission"); add(p,shortForm.substring(idx+1)); }
/** * Works like {@link #add(Permission, String)} but takes both parameters * from a single string of the form <tt>PERMISSIONID:sid</tt> */ private void add(String shortForm) { int idx = shortForm.indexOf(':'); Permission p = Permission.fromId(shortForm.substring(0, idx)); if (p==null) throw new IllegalArgumentException("Failed to parse '"+shortForm+"' --- no such permission"); add(p, shortForm.substring(idx + 1)); }
/** * Works like {@link #add(Permission, String)} but takes both parameters * from a single string of the form <tt>PERMISSIONID:sid</tt> */ private void add(String shortForm) { int idx = shortForm.indexOf(':'); Permission p = Permission.fromId(shortForm.substring(0, idx)); if (p == null) { throw new IllegalArgumentException("Failed to parse '" + shortForm + "' --- no such permission"); } add(p, shortForm.substring(idx + 1)); }
/** * Works like {@link #add(Permission, String)} but takes both parameters * from a single string of the form <tt>PERMISSIONID:sid</tt> */ private void add(String shortForm) { int idx = shortForm.indexOf(':'); Permission p = Permission.fromId(shortForm.substring(0, idx)); if (p==null) throw new IllegalArgumentException("Failed to parse '"+shortForm+"' --- no such permission"); add(p,shortForm.substring(idx+1)); }
/** * Works like {@link #add(Permission, String)} but takes both parameters * from a single string of the form <tt>PERMISSIONID:sid</tt> */ private void add(String shortForm) { int idx = shortForm.indexOf(':'); Permission p = Permission.fromId(shortForm.substring(0, idx)); if (p==null) throw new IllegalArgumentException("Failed to parse '"+shortForm+"' --- no such permission"); add(p, shortForm.substring(idx + 1)); }
/** * Works like {@link #add(Permission, String)} but takes both parameters * from a single string of the form <tt>PERMISSIONID:sid</tt> */ private void add(String shortForm) { int idx = shortForm.indexOf(':'); Permission p = Permission.fromId(shortForm.substring(0, idx)); if (p != null) { add(p, shortForm.substring(idx + 1)); } else { // This should not happen if Hudson is fully initialized. // But Initial Setup also loads Security setup before Hudson Initialization if (Hudson.getInstance() != null) { throw new IllegalArgumentException("Failed to parse '" + shortForm + "' --- no such permission"); } } }
@Override public AuthorizationStrategy newInstance(StaplerRequest req, JSONObject formData) throws FormException { GlobalMatrixAuthorizationStrategy gmas = create(); for (Map.Entry<String, JSONObject> r : (Set<Map.Entry<String, JSONObject>>) formData.getJSONObject("data").entrySet()) { String sid = r.getKey(); for (Map.Entry<String, Boolean> e : (Set<Map.Entry<String, Boolean>>) r.getValue().entrySet()) { if (e.getValue()) { Permission p = Permission.fromId(e.getKey()); gmas.add(p, sid); } } } return gmas; }
@Override public AuthorizationStrategy newInstance(StaplerRequest req, JSONObject formData) throws FormException { GlobalMatrixAuthorizationStrategy gmas = create(); for(Map.Entry<String,JSONObject> r : (Set<Map.Entry<String,JSONObject>>)formData.getJSONObject("data").entrySet()) { String sid = r.getKey(); for(Map.Entry<String,Boolean> e : (Set<Map.Entry<String,Boolean>>)r.getValue().entrySet()) { if(e.getValue()) { Permission p = Permission.fromId(e.getKey()); gmas.add(p,sid); } } } return gmas; }
@Override public AuthorizationStrategy newInstance(StaplerRequest req, JSONObject formData) throws FormException { GlobalMatrixAuthorizationStrategy gmas = create(); for(Map.Entry<String,JSONObject> r : (Set<Map.Entry<String,JSONObject>>)formData.getJSONObject("data").entrySet()) { String sid = r.getKey(); for(Map.Entry<String,Boolean> e : (Set<Map.Entry<String,Boolean>>)r.getValue().entrySet()) { if(e.getValue()) { Permission p = Permission.fromId(e.getKey()); gmas.add(p,sid); } } } return gmas; }
@Override public AuthorizationStrategy newInstance(StaplerRequest req, JSONObject formData) throws FormException { GlobalMatrixAuthorizationStrategy gmas = create(); for(Map.Entry<String,JSONObject> r : (Set<Map.Entry<String,JSONObject>>)formData.getJSONObject("data").entrySet()) { String sid = r.getKey(); for(Map.Entry<String,Boolean> e : (Set<Map.Entry<String,Boolean>>)r.getValue().entrySet()) { if(e.getValue()) { Permission p = Permission.fromId(e.getKey()); gmas.add(p,sid); } } } return gmas; }
@Override public JobProperty<?> newInstance(StaplerRequest req, JSONObject formData) throws FormException { formData = formData.getJSONObject("useProjectSecurity"); if (formData.isNullObject()) return null; AuthorizationMatrixProperty amp = new AuthorizationMatrixProperty(); for (Map.Entry<String, Object> r : (Set<Map.Entry<String, Object>>) formData.getJSONObject("data").entrySet()) { String sid = r.getKey(); if (r.getValue() instanceof JSONObject) { for (Map.Entry<String, Boolean> e : (Set<Map.Entry<String, Boolean>>) ((JSONObject) r .getValue()).entrySet()) { if (e.getValue()) { Permission p = Permission.fromId(e.getKey()); amp.add(p, sid); } } } } return amp; }
@Override public JobProperty<?> newInstance(StaplerRequest req, JSONObject formData) throws FormException { formData = formData.getJSONObject("useProjectSecurity"); if (formData.isNullObject()) { return null; } AuthorizationMatrixProperty amp = new AuthorizationMatrixProperty(); for (Map.Entry<String, Object> r : (Set<Map.Entry<String, Object>>) formData.getJSONObject("data").entrySet()) { String sid = r.getKey(); if (r.getValue() instanceof JSONObject) { for (Map.Entry<String, Boolean> e : (Set<Map.Entry<String, Boolean>>) ((JSONObject) r .getValue()).entrySet()) { if (e.getValue()) { Permission p = Permission.fromId(e.getKey()); amp.add(p, sid); } } } } return amp; }
@Override public JobProperty<?> newInstance(StaplerRequest req, JSONObject formData) throws FormException { formData = formData.getJSONObject("useProjectSecurity"); if (formData.isNullObject()) return null; AuthorizationMatrixProperty amp = new AuthorizationMatrixProperty(); for (Map.Entry<String, Object> r : (Set<Map.Entry<String, Object>>) formData.getJSONObject("data").entrySet()) { String sid = r.getKey(); if (r.getValue() instanceof JSONObject) { for (Map.Entry<String, Boolean> e : (Set<Map.Entry<String, Boolean>>) ((JSONObject) r .getValue()).entrySet()) { if (e.getValue()) { Permission p = Permission.fromId(e.getKey()); amp.add(p, sid); } } } } return amp; }
@Override public JobProperty<?> newInstance(StaplerRequest req, JSONObject formData) throws FormException { formData = formData.getJSONObject("useProjectSecurity"); if (formData.isNullObject()) return null; AuthorizationMatrixProperty amp = new AuthorizationMatrixProperty(); for (Map.Entry<String, Object> r : (Set<Map.Entry<String, Object>>) formData.getJSONObject("data").entrySet()) { String sid = r.getKey(); if (r.getValue() instanceof JSONObject) { for (Map.Entry<String, Boolean> e : (Set<Map.Entry<String, Boolean>>) ((JSONObject) r .getValue()).entrySet()) { if (e.getValue()) { Permission p = Permission.fromId(e.getKey()); amp.add(p, sid); } } } } return amp; }
@Initializer(after=InitMilestone.EXTENSIONS_AUGMENTED, before=InitMilestone.JOB_LOADED) // same time as Jenkins global config is loaded (e.g., AuthorizationStrategy) public static void assertPermissionId() { String thePermissionId = "hudson.model.Run.Replay"; // An AuthorizationStrategy may be loading a permission by name during Jenkins startup. Permission thePermission = Permission.fromId(thePermissionId); // Make sure it finds this addition, even though the PermissionGroup is in core. assertEquals(ReplayAction.REPLAY, thePermission); assertEquals(thePermissionId, thePermission.getId()); }