Search in sources :

Example 21 with Restricted

use of org.kohsuke.accmod.Restricted in project configuration-as-code-plugin by jenkinsci.

the class Attribute method calculateIfSecret.

// TODO: consider Boolean and third condition
/**
 * This is a method which tries to guess whether an attribute is {@link Secret}.
 * @param targetClass Class of the target object. {@code null} if unknown
 * @param fieldName Field name
 * @return {@code true} if the attribute is secret
 *         {@code false} if not or if there is no conclusive answer.
 */
@Restricted(NoExternalUse.class)
public static boolean calculateIfSecret(@CheckForNull Class<?> targetClass, @NonNull String fieldName) {
    if (targetClass == Secret.class) {
        // Class is final, so the check is safe
        LOGGER.log(Level.FINER, "Attribute {0}#{1} is secret, because it has a Secret type", new Object[] { targetClass.getName(), fieldName });
        return true;
    }
    if (targetClass == null) {
        LOGGER.log(Level.FINER, "Attribute {0} is assumed to be non-secret, because there is no class instance in the call. " + "This call is used only for fast-fetch caching, and the result may be adjusted later", new Object[] { fieldName });
        // All methods below require a known target class
        return false;
    }
    // TODO: Cache decisions?
    Method m = locateGetter(targetClass, fieldName);
    if (m != null && m.getReturnType() == Secret.class) {
        LOGGER.log(Level.FINER, "Attribute {0}#{1} is secret, because there is a getter {2} which returns a Secret type", new Object[] { targetClass.getName(), fieldName, m });
        return true;
    }
    Field f = locatePublicField(targetClass, fieldName);
    if (f != null && f.getType() == Secret.class) {
        LOGGER.log(Level.FINER, "Attribute {0}#{1} is secret, because there is a public field {2} which has a Secret type", new Object[] { targetClass.getName(), fieldName, f });
        return true;
    }
    f = locatePrivateFieldInHierarchy(targetClass, fieldName);
    if (f != null && f.getType() == Secret.class) {
        LOGGER.log(Level.FINER, "Attribute {0}#{1} is secret, because there is a private field {2} which has a Secret type", new Object[] { targetClass.getName(), fieldName, f });
        return true;
    }
    // TODO(oleg_nenashev): Consider setters? Gonna be more interesting since there might be many of them
    LOGGER.log(Level.FINER, "Attribute {0}#{1} is not a secret, because all checks have passed", new Object[] { targetClass.getName(), fieldName });
    return false;
}
Also used : Secret(hudson.util.Secret) Field(java.lang.reflect.Field) Method(java.lang.reflect.Method) Restricted(org.kohsuke.accmod.Restricted)

Example 22 with Restricted

use of org.kohsuke.accmod.Restricted in project configuration-as-code-plugin by jenkinsci.

the class MergeStrategyAction method doIndex.

@Restricted(NoExternalUse.class)
public HttpResponse doIndex() {
    JSONArray array = new JSONArray();
    ExtensionList<MergeStrategy> mergeStrategyList = Jenkins.get().getExtensionList(MergeStrategy.class);
    array.addAll(mergeStrategyList);
    return HttpResponses.okJSON(array);
}
Also used : JSONArray(net.sf.json.JSONArray) Restricted(org.kohsuke.accmod.Restricted)

Aggregations

Restricted (org.kohsuke.accmod.Restricted)22 IOException (java.io.IOException)7 ArrayList (java.util.ArrayList)7 File (java.io.File)5 HashMap (java.util.HashMap)4 RequirePOST (org.kohsuke.stapler.interceptor.RequirePOST)4 YamlSource (io.jenkins.plugins.casc.yaml.YamlSource)3 Method (java.lang.reflect.Method)3 URL (java.net.URL)3 PathMatcher (java.nio.file.PathMatcher)3 Map (java.util.Map)3 Jenkins (jenkins.model.Jenkins)3 JSONArray (net.sf.json.JSONArray)3 JSONObject (net.sf.json.JSONObject)3 CheckForNull (edu.umd.cs.findbugs.annotations.CheckForNull)2 NonNull (edu.umd.cs.findbugs.annotations.NonNull)2 Describable (hudson.model.Describable)2 BuildStepDescriptor (hudson.tasks.BuildStepDescriptor)2 CNode (io.jenkins.plugins.casc.model.CNode)2 Source (io.jenkins.plugins.casc.model.Source)2