/** * Persists the state of this object into XML. Default implementation delegates to {@link #getContext()} if it * implements {@link Saveable} otherwise dropping back to a no-op. * * @see Saveable#save() * @since 2.1.9 */ @Override public void save() throws IOException { if (BulkChange.contains(this)) { return; } if (getContext() instanceof Saveable) { ((Saveable) getContext()).save(); } } }
/** * Persists the state of this object into XML. Default implementation delegates to {@link #getContext()} if it * implements {@link Saveable} otherwise dropping back to a no-op. * * @see Saveable#save() * @since 2.1.9 */ @Override public void save() throws IOException { if (BulkChange.contains(this)) { return; } if (getContext() instanceof Saveable) { ((Saveable) getContext()).save(); } } }
/** * In some cases the nearest {@link AncestorInPath} {@link ModelObject} is one of the Credentials plugins wrapper * classes. * This helper method unwraps those to return the correct context. * * @param context the context (wrapped or unwrapped). * @return the unwrapped context. * @since 2.1.5 */ @NonNull public static ModelObject unwrapContext(@NonNull ModelObject context) { if (context instanceof CredentialsSelectHelper.WrappedCredentialsStore) { return ((CredentialsSelectHelper.WrappedCredentialsStore) context).getStore().getContext(); } if (context instanceof CredentialsStoreAction.CredentialsWrapper) { return ((CredentialsStoreAction.CredentialsWrapper) context).getStore().getContext(); } if (context instanceof CredentialsStoreAction.DomainWrapper) { return ((CredentialsStoreAction.DomainWrapper) context).getStore().getContext(); } return context; }
/** * Exposes the {@link CredentialsStore} instances available to the {@link #getContext()}. * * @return the {@link CredentialsStore} instances available to the {@link #getContext()}. */ @NonNull public List<CredentialsStore> getParentStores() { List<CredentialsStore> result = new ArrayList<CredentialsStore>(); for (CredentialsStore s : CredentialsProvider.lookupStores(getContext())) { if (context != s.getContext() && s.hasPermission(CredentialsProvider.VIEW)) { result.add(s); } } return result; }
/** * Exposes the {@link CredentialsStore} instances available to the {@link #getContext()}. * * @return the {@link CredentialsStore} instances available to the {@link #getContext()}. */ @NonNull public List<CredentialsStore> getLocalStores() { List<CredentialsStore> result = new ArrayList<CredentialsStore>(); for (CredentialsStore s : CredentialsProvider.lookupStores(getContext())) { if (context == s.getContext() && s.hasPermission(CredentialsProvider.VIEW)) { result.add(s); } } return result; }
/** * Returns the {@link CredentialsScope} instances that are applicable to this store. * @return the {@link CredentialsScope} instances that are applicable to this store or {@code null} if the store * instance is no longer enabled. * * @since 2.1.5 */ @Nullable public final Set<CredentialsScope> getScopes() { CredentialsProvider provider = getProvider(); return provider == null ? null : provider.getScopes(getContext()); }
/** * Exposes the {@link CredentialsStore} instances available to the {@link #getContext()}. * * @return the {@link CredentialsStore} instances available to the {@link #getContext()}. */ @NonNull public List<CredentialsStore> getParentStores() { List<CredentialsStore> result = new ArrayList<CredentialsStore>(); for (CredentialsStore s : CredentialsProvider.lookupStores(getContext())) { if (context != s.getContext() && s.hasPermission(CredentialsProvider.VIEW)) { result.add(s); } } return result; }
/** * Exposes the {@link CredentialsStore} instances available to the {@link #getContext()}. * * @return the {@link CredentialsStore} instances available to the {@link #getContext()}. */ @NonNull public List<CredentialsStore> getLocalStores() { List<CredentialsStore> result = new ArrayList<CredentialsStore>(); for (CredentialsStore s : CredentialsProvider.lookupStores(getContext())) { if (context == s.getContext() && s.hasPermission(CredentialsProvider.VIEW)) { result.add(s); } } return result; }
/** * Returns the {@link CredentialsScope} instances that are applicable to this store. * @return the {@link CredentialsScope} instances that are applicable to this store or {@code null} if the store * instance is no longer enabled. * * @since 2.1.5 */ @Nullable public final Set<CredentialsScope> getScopes() { CredentialsProvider provider = getProvider(); return provider == null ? null : provider.getScopes(getContext()); }
/** * Exposes the {@link #getLocalStores()} {@link CredentialsStore#getStoreAction()}. * * @return the {@link #getLocalStores()} {@link CredentialsStore#getStoreAction()}. */ @NonNull @SuppressWarnings("unused") // Jelly EL public List<CredentialsStoreAction> getStoreActions() { List<CredentialsStoreAction> result = new ArrayList<CredentialsStoreAction>(); for (final CredentialsStore s : CredentialsProvider.lookupStores(getContext())) { if (context == s.getContext() && s.hasPermission(CredentialsProvider.VIEW)) { CredentialsStoreAction action = s.getStoreAction(); if (action != null) { result.add(action); } } } return result; }
/** * Exposes the {@link #getLocalStores()} {@link CredentialsStore#getStoreAction()}. * * @return the {@link #getLocalStores()} {@link CredentialsStore#getStoreAction()}. */ @NonNull @SuppressWarnings("unused") // Jelly EL public List<CredentialsStoreAction> getStoreActions() { List<CredentialsStoreAction> result = new ArrayList<CredentialsStoreAction>(); for (final CredentialsStore s : CredentialsProvider.lookupStores(getContext())) { if (context == s.getContext() && s.hasPermission(CredentialsProvider.VIEW)) { CredentialsStoreAction action = s.getStoreAction(); if (action != null) { result.add(action); } } } return result; }
private CredentialsStore getFolderStore(Folder f) { Iterable<CredentialsStore> stores = CredentialsProvider.lookupStores(f); CredentialsStore folderStore = null; for (CredentialsStore s : stores) { if (s.getProvider() instanceof FolderCredentialsProvider && s.getContext() == f) { folderStore = s; break; } } return folderStore; }
/** * Gets the check id url for the specified store. * * @param store the store. * @return the url of the id check endpoint. * @throws UnsupportedEncodingException if the JVM does not implement the JLS. */ public String getCheckIdUrl(CredentialsStore store) throws UnsupportedEncodingException { ModelObject context = store.getContext(); for (ContextResolver r : ExtensionList.lookup(ContextResolver.class)) { String token = r.getToken(context); if (token != null) { return Jenkins.getActiveInstance().getRootUrlFromRequest() + "/" + getDescriptorUrl() + "/checkId?provider=" + r.getClass().getName() + "&token=" + URLEncoder.encode(token, "UTF-8"); } } return Jenkins.getActiveInstance().getRootUrlFromRequest() + "/" + getDescriptorUrl() + "/checkId?provider=null&token=null"; }
private CredentialsStore getFolderStore(Folder f) { Iterable<CredentialsStore> stores = CredentialsProvider.lookupStores(f); CredentialsStore folderStore = null; for (CredentialsStore s : stores) { if (s.getProvider() instanceof FolderCredentialsProvider && s.getContext() == f) { folderStore = s; break; } } return folderStore; }
/** * Gets the check id url for the specified store. * * @param store the store. * @return the url of the id check endpoint. * @throws UnsupportedEncodingException if the JVM does not implement the JLS. */ public String getCheckIdUrl(CredentialsStore store) throws UnsupportedEncodingException { ModelObject context = store.getContext(); for (ContextResolver r : ExtensionList.lookup(ContextResolver.class)) { String token = r.getToken(context); if (token != null) { return Jenkins.getActiveInstance().getRootUrlFromRequest() + "/" + getDescriptorUrl() + "/checkId?provider=" + r.getClass().getName() + "&token=" + URLEncoder.encode(token, "UTF-8"); } } return Jenkins.getActiveInstance().getRootUrlFromRequest() + "/" + getDescriptorUrl() + "/checkId?provider=null&token=null"; }
/** * 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(); }
/** * Exposes the {@link #getStoreActions()} by {@link CredentialsStoreAction#getUrlName()} for Stapler. * * @param name the {@link CredentialsStoreAction#getUrlName()} to match. * @return the {@link CredentialsStoreAction} or {@code null} */ @CheckForNull @SuppressWarnings("unused") // Stapler binding public CredentialsStoreAction getStore(String name) { for (final CredentialsStore s : CredentialsProvider.lookupStores(getContext())) { if (context == s.getContext()) { // local stores only CredentialsStoreAction action = s.getStoreAction(); if (action != null && name.equals(action.getUrlName())) { return s.hasPermission(CredentialsProvider.VIEW) ? action : null; } } } return null; }
/** * Exposes the {@link #getStoreActions()} by {@link CredentialsStoreAction#getUrlName()} for Stapler. * * @param name the {@link CredentialsStoreAction#getUrlName()} to match. * @return the {@link CredentialsStoreAction} or {@code null} */ @CheckForNull @SuppressWarnings("unused") // Stapler binding public CredentialsStoreAction getStore(String name) { for (final CredentialsStore s : CredentialsProvider.lookupStores(getContext())) { if (context == s.getContext()) { // local stores only CredentialsStoreAction action = s.getStoreAction(); if (action != null && name.equals(action.getUrlName())) { return s.hasPermission(CredentialsProvider.VIEW) ? action : null; } } } return null; }
/** * 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(); }
/** * 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.CredentialsWrapper 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(); }