/** * Returns the {@link CredentialsDescriptor#getDisplayName()}. * * @return the {@link CredentialsDescriptor#getDisplayName()}. */ public String getKind() { return credentials.getDescriptor().getDisplayName(); }
public Object parse(StaplerRequest request, ContextInPath contextInPath, Class type, String parameterName) throws ServletException { String $provider = request.getParameter("$provider"); String $token = request.getParameter("$token"); if (StringUtils.isNotBlank($provider) && StringUtils.isNotBlank($token)) { ModelObject context = CredentialsDescriptor.lookupContext($provider, $token); if (type.isInstance(context)) { return type.cast(context); } } return CredentialsDescriptor.findContextInPath(request, type); } }
/** * {@inheritDoc} */ @Override public String getIconClassName() { return credentials.getDescriptor().getIconClassName(); }
/** * Similar to {@link #isScopeRelevant()} but used by {@link CredentialsSelectHelper}. * * @param wrapper the wrapper for the domain that is going to contain the credential. * @return {@code true} if there is more than one {@link CredentialsScope} that can be used for the specified * object. * @since 2.1.5 */ @SuppressWarnings("unused") // used by stapler @Restricted(NoExternalUse.class) public boolean isScopeRelevant(CredentialsSelectHelper.WrappedCredentialsStore wrapper) { if (wrapper != null) { return isScopeRelevant(wrapper.getStore().getContext()); } CredentialsStoreAction action = Stapler.getCurrentRequest().findAncestorObject(CredentialsStoreAction.class); if (action != null) { return isScopeRelevant(action.getStore().getContext()); } return isScopeRelevant(); }
/** * Returns the list of {@link CredentialsDescriptor} instances that are applicable within this * {@link CredentialsStore}. * * @return the list of {@link CredentialsDescriptor} instances that are applicable within this * {@link CredentialsStore}. * @since 2.0 */ public final List<CredentialsDescriptor> getCredentialsDescriptors() { CredentialsProvider provider = getProvider(); List<CredentialsDescriptor> result = DescriptorVisibilityFilter.apply(this, ExtensionList.lookup(CredentialsDescriptor.class)); if (provider != null && provider.isEnabled()) { if (!(result instanceof ArrayList)) { // should never happen, but let's be defensive in case the DescriptorVisibilityFilter contract changes result = new ArrayList<CredentialsDescriptor>(result); } for (Iterator<CredentialsDescriptor> iterator = result.iterator(); iterator.hasNext(); ) { CredentialsDescriptor d = iterator.next(); if (!_isApplicable(d) || !provider._isApplicable(d) || !d.isApplicable(provider)) { iterator.remove(); } } } return result; }
/** * Returns the scopes allowed for credentials stored within the specified object or {@code null} if the * object is not relevant for scopes and the object's container should be considered instead. * * @param object the object. * @return the set of scopes that are relevant for the object or {@code null} if the object is not a credentials * container. */ @CheckForNull public static Set<CredentialsScope> lookupScopes(ModelObject object) { object = CredentialsDescriptor.unwrapContext(object); Set<CredentialsScope> result = null; for (CredentialsProvider provider : all()) { if (provider.isEnabled(object)) { try { Set<CredentialsScope> scopes = provider.getScopes(object); if (scopes != null) { // if multiple providers for the same object, then combine scopes if (result == null) { result = new LinkedHashSet<CredentialsScope>(); } result.addAll(scopes); } } catch (NoClassDefFoundError e) { // ignore optional dependency } } } return result; }
/** * Returns the config page for the credentials. * * @return the config page for the credentials. */ @SuppressWarnings("unused") // used by stapler public String getCredentialsPage() { return getViewPage(clazz, "credentials.jelly"); }
/** * Attempts to resolve the credentials context from the {@link Stapler#getCurrentRequest()} (includes special * handling of the HTTP Referer to enable resolution from AJAX requests). * * @param type the type of context. * @param <T> the type of context. * @return the context from the request * @since 2.1.5 */ @CheckForNull public static <T extends ModelObject> T findContextInPath(@NonNull Class<T> type) { return findContextInPath(Stapler.getCurrentRequest(), type); }
/** * Similar to {@link #isScopeRelevant()} but used by {@link CredentialsSelectHelper}. * * @param wrapper the wrapper for the domain that is going to contain the credential. * @return {@code true} if there is more than one {@link CredentialsScope} that can be used for the specified * object. * @since 2.1.5 */ @SuppressWarnings("unused") // used by stapler @Restricted(NoExternalUse.class) public boolean isScopeRelevant(CredentialsSelectHelper.WrappedCredentialsStore wrapper) { if (wrapper != null) { return isScopeRelevant(wrapper.getStore().getContext()); } CredentialsStoreAction action = Stapler.getCurrentRequest().findAncestorObject(CredentialsStoreAction.class); if (action != null) { return isScopeRelevant(action.getStore().getContext()); } return isScopeRelevant(); }
/** * Returns the list of {@link CredentialsDescriptor} instances that are applicable within this * {@link CredentialsStore}. * * @return the list of {@link CredentialsDescriptor} instances that are applicable within this * {@link CredentialsStore}. * @since 2.0 */ public final List<CredentialsDescriptor> getCredentialsDescriptors() { CredentialsProvider provider = getProvider(); List<CredentialsDescriptor> result = DescriptorVisibilityFilter.apply(this, ExtensionList.lookup(CredentialsDescriptor.class)); if (provider != null && provider.isEnabled()) { if (!(result instanceof ArrayList)) { // should never happen, but let's be defensive in case the DescriptorVisibilityFilter contract changes result = new ArrayList<CredentialsDescriptor>(result); } for (Iterator<CredentialsDescriptor> iterator = result.iterator(); iterator.hasNext(); ) { CredentialsDescriptor d = iterator.next(); if (!_isApplicable(d) || !provider._isApplicable(d) || !d.isApplicable(provider)) { iterator.remove(); } } } return result; }
/** * Returns the scopes allowed for credentials stored within the specified object or {@code null} if the * object is not relevant for scopes and the object's container should be considered instead. * * @param object the object. * @return the set of scopes that are relevant for the object or {@code null} if the object is not a credentials * container. */ @CheckForNull public static Set<CredentialsScope> lookupScopes(ModelObject object) { object = CredentialsDescriptor.unwrapContext(object); Set<CredentialsScope> result = null; for (CredentialsProvider provider : all()) { if (provider.isEnabled(object)) { try { Set<CredentialsScope> scopes = provider.getScopes(object); if (scopes != null) { // if multiple providers for the same object, then combine scopes if (result == null) { result = new LinkedHashSet<CredentialsScope>(); } result.addAll(scopes); } } catch (NoClassDefFoundError e) { // ignore optional dependency } } } return result; }
/** * Returns the config page for the credentials. * * @return the config page for the credentials. */ @SuppressWarnings("unused") // used by stapler public String getCredentialsPage() { return getViewPage(clazz, "credentials.jelly"); }
/** * Attempts to resolve the credentials context from the {@link Stapler#getCurrentRequest()} (includes special * handling of the HTTP Referer to enable resolution from AJAX requests). * * @param type the type of context. * @param <T> the type of context. * @return the context from the request * @since 2.1.5 */ @CheckForNull public static <T extends ModelObject> T findContextInPath(@NonNull Class<T> type) { return findContextInPath(Stapler.getCurrentRequest(), type); }
/** * Returns the {@link CredentialsDescriptor#getDisplayName()}. * * @return the {@link CredentialsDescriptor#getDisplayName()}. */ public String getKind() { return credentials.getDescriptor().getDisplayName(); }
public Object parse(StaplerRequest request, ContextInPath contextInPath, Class type, String parameterName) throws ServletException { String $provider = request.getParameter("$provider"); String $token = request.getParameter("$token"); if (StringUtils.isNotBlank($provider) && StringUtils.isNotBlank($token)) { ModelObject context = CredentialsDescriptor.lookupContext($provider, $token); if (type.isInstance(context)) { return type.cast(context); } } return CredentialsDescriptor.findContextInPath(request, type); } }
/** * {@inheritDoc} */ @Override public String getIconClassName() { return credentials.getDescriptor().getIconClassName(); }
/** * Similar to {@link #isScopeRelevant()} but used by {@link CredentialsStoreAction}. * * @param wrapper the wrapper for the domain that is going to contain the credential. * @return {@code true} if there is more than one {@link CredentialsScope} that can be used for the specified * object. */ @SuppressWarnings("unused") // used by stapler @Restricted(NoExternalUse.class) @RestrictedSince("2.1.5") public boolean isScopeRelevant(CredentialsStoreAction.DomainWrapper wrapper) { if (wrapper != null) { return isScopeRelevant(wrapper.getStore().getContext()); } CredentialsStoreAction action = Stapler.getCurrentRequest().findAncestorObject(CredentialsStoreAction.class); if (action != null) { return isScopeRelevant(action.getStore().getContext()); } return isScopeRelevant(); }
/** * Returns {@code true} if the supplied {@link Descriptor} is applicable to this {@link CredentialsProvider}. * * @param descriptor the {@link Descriptor} to check. * @return {@code true} if and only if the supplied {@link Descriptor} is applicable in this * {@link CredentialsProvider}. * @since 2.0 */ public final boolean isApplicable(Descriptor<?> descriptor) { if (!isEnabled()) { return false; } if (descriptor instanceof CredentialsDescriptor) { if (!((CredentialsDescriptor) descriptor).isApplicable(this)) { return false; } } for (DescriptorVisibilityFilter filter : DescriptorVisibilityFilter.all()) { if (!filter.filter(this, descriptor)) { return false; } } return _isApplicable(descriptor); }
/** * Checks if asking for a credentials scope is relevant. For example, when a scope will be stored in * {@link UserCredentialsProvider}, there is no need to specify the scope, * as it can only be {@link CredentialsScope#USER}, but where the credential will be stored in * {@link SystemCredentialsProvider}, there are multiple scopes relevant for that container, so the scope * field is relevant. * * @return {@code true} if the nearest request object that acts as a container for credentials needs a scope * to be specified. */ @SuppressWarnings("unused") // used by stapler @Restricted(NoExternalUse.class) @RestrictedSince("2.1.5") public boolean isScopeRelevant() { Ancestor ancestor = Stapler.getCurrentRequest().findAncestor(Object.class); while (ancestor != null) { if (ancestor.getObject() instanceof ModelObject) { ModelObject context = unwrapContext((ModelObject) ancestor.getObject()); Set<CredentialsScope> scopes = CredentialsProvider.lookupScopes(context); if (scopes != null) { return scopes.size() > 1; } } ancestor = ancestor.getPrev(); } return false; }
/** * Gets the display name of the {@link CredentialsDescriptor}. * * @return the display name of the {@link CredentialsDescriptor}. */ @Exported public String getTypeName() { return credentials.getDescriptor().getDisplayName(); }