/** * Returns the {@link IdCredentials#getId()} of the {@link #credentials}. * * @return the {@link IdCredentials#getId()} of the {@link #credentials}. */ public String getId() { return credentials instanceof IdCredentials ? ((IdCredentials) credentials).getId() : null; }
/** * Returns the {@link IdCredentials#getId()} of the {@link #credentials}. * * @return the {@link IdCredentials#getId()} of the {@link #credentials}. */ public String getId() { return credentials instanceof IdCredentials ? ((IdCredentials) credentials).getId() : null; }
/** * The standard {@link #hashCode()} implementation. * * @param self the {@code this} reference. * @return the hash code. */ public static int hashCode(IdCredentials self) { return self.getId().hashCode(); }
/** * The standard {@link #hashCode()} implementation. * * @param self the {@code this} reference. * @return the hash code. */ public static int hashCode(IdCredentials self) { return self.getId().hashCode(); }
/** * Standard {@link #equals(Object)} implementation. * * @param self the {@code this} reference. * @param o the other object. * @return true if equal. */ public static boolean equals(IdCredentials self, Object o) { if (self == o) { return true; } if (!(o instanceof IdCredentials)) { return false; } IdCredentials that = (IdCredentials) o; if (!self.getId().equals(that.getId())) { return false; } return true; }
/** * Standard {@link #equals(Object)} implementation. * * @param self the {@code this} reference. * @param o the other object. * @return true if equal. */ public static boolean equals(IdCredentials self, Object o) { if (self == o) { return true; } if (!(o instanceof IdCredentials)) { return false; } IdCredentials that = (IdCredentials) o; if (!self.getId().equals(that.getId())) { return false; } return true; }
/** * {@inheritDoc} */ public boolean matches(@NonNull Credentials item) { return item instanceof IdCredentials && id.equals(((IdCredentials) item).getId()); }
/** * {@inheritDoc} */ public boolean matches(@NonNull Credentials item) { return item instanceof IdCredentials && id.equals(((IdCredentials) item).getId()); }
protected static Credentials getCredentialsById(CredentialsStore store, Domain domain, String id) { List<Credentials> credentialsList = store.getCredentials(domain); Set<String> ids = new HashSet<String>(credentialsList.size()); Credentials existing = null; int index = 0; for (Credentials c : credentialsList) { String cid; if (c instanceof IdCredentials) { cid = ((IdCredentials) c).getId(); } else { while (ids.contains("index-" + index)) { index++; } cid = "index-" + index; index++; } if (id.equals(cid)) { existing = c; break; } ids.add(cid); } return existing; }
protected static Credentials getCredentialsById(CredentialsStore store, Domain domain, String id) { List<Credentials> credentialsList = store.getCredentials(domain); Set<String> ids = new HashSet<String>(credentialsList.size()); Credentials existing = null; int index = 0; for (Credentials c : credentialsList) { String cid; if (c instanceof IdCredentials) { cid = ((IdCredentials) c).getId(); } else { while (ids.contains("index-" + index)) { index++; } cid = "index-" + index; index++; } if (id.equals(cid)) { existing = c; break; } ids.add(cid); } return existing; }
@Override public String apply(@javax.annotation.Nullable Credentials credentials) { if (credentials == null) return "null"; String result = ClassUtils.getShortName(credentials.getClass()) + "["; if (credentials instanceof IdCredentials) { IdCredentials idCredentials = (IdCredentials) credentials; result += "id: " + idCredentials.getId() + ","; } if (credentials instanceof UsernameCredentials) { UsernameCredentials usernameCredentials = (UsernameCredentials) credentials; result += "username: " + usernameCredentials.getUsername() + ""; } result += "]"; return result; } }
/** * Exposes a map of the wrapped credentials. * * @return a map of the wrapped credentials. */ @NonNull public Map<String, CredentialsWrapper> getCredentials() { Map<String, CredentialsWrapper> result = new LinkedHashMap<String, CredentialsWrapper>(); int index = 0; for (Credentials c : getStore().getCredentials(domain)) { String id; if (c instanceof IdCredentials) { id = ((IdCredentials) c).getId(); } else { while (result.containsKey("index-" + index)) { index++; } id = "index-" + index; index++; } result.put(id, new CredentialsWrapper(this, c, id)); } return result; }
/** * Exposes a map of the wrapped credentials. * * @return a map of the wrapped credentials. */ @NonNull public Map<String, CredentialsWrapper> getCredentials() { Map<String, CredentialsWrapper> result = new LinkedHashMap<String, CredentialsWrapper>(); int index = 0; for (Credentials c : getStore().getCredentials(domain)) { String id; if (c instanceof IdCredentials) { id = ((IdCredentials) c).getId(); } else { while (result.containsKey("index-" + index)) { index++; } id = "index-" + index; index++; } result.put(id, new CredentialsWrapper(this, c, id)); } return result; }
private String url(CredentialsStore store) { for (Domain d: store.getDomains()) { for (Credentials c: store.getCredentials(d)) { if (c instanceof IdCredentials && value.equals(((IdCredentials) c).getId())) { String link = store.getRelativeLinkToAction(); return link == null ? null : link + d.getUrl() + "credential/"+ Util.rawEncode(value); } } } return null; }
private String url(CredentialsStore store) { for (Domain d: store.getDomains()) { for (Credentials c: store.getCredentials(d)) { if (c instanceof IdCredentials && value.equals(((IdCredentials) c).getId())) { String link = store.getRelativeLinkToAction(); return link == null ? null : link + d.getUrl() + "credential/"+ Util.rawEncode(value); } } } return null; }
/** * Adds a single credential. * * @param u the credential to add. * @return {@code this} for method chaining. */ @NonNull public AbstractIdCredentialsListBoxModel<T, C> with(@CheckForNull C u) { if (u != null) { add(describe(u), u.getId()); } return this; }
/** * Creates a fingerprint that can be used to track the usage of a specific credential. * * @param c the credential to fingerprint. * @return the Fingerprint. * @throws IOException if the credential's fingerprint hash could not be computed. * @since 2.1.1 */ @NonNull public static Fingerprint getOrCreateFingerprintOf(@NonNull Credentials c) throws IOException { String pseudoFilename = String.format("Credential id=%s name=%s", c instanceof IdCredentials ? ((IdCredentials) c).getId() : "unknown", CredentialsNameProvider.name(c)); try { MessageDigest md5 = MessageDigest.getInstance("MD5"); DigestOutputStream out = new DigestOutputStream(new NullOutputStream(), md5); try { FINGERPRINT_XML.toXML(c, new OutputStreamWriter(out, Charset.forName("UTF-8"))); } finally { IOUtils.closeQuietly(out); } return Jenkins.getActiveInstance().getFingerprintMap().getOrCreate(null, pseudoFilename, md5.digest()); } catch (NoSuchAlgorithmException e) { throw new IllegalStateException("JLS mandates MD5 as a supported digest algorithm"); } }
/** * Adds a single credential. * * @param u the credential to add. * @return {@code this} for method chaining. */ @NonNull public AbstractIdCredentialsListBoxModel<T, C> with(@CheckForNull C u) { if (u != null) { add(describe(u), u.getId()); } return this; }
/** * Creates a fingerprint that can be used to track the usage of a specific credential. * * @param c the credential to fingerprint. * @return the Fingerprint. * @throws IOException if the credential's fingerprint hash could not be computed. * @since 2.1.1 */ @NonNull public static Fingerprint getOrCreateFingerprintOf(@NonNull Credentials c) throws IOException { String pseudoFilename = String.format("Credential id=%s name=%s", c instanceof IdCredentials ? ((IdCredentials) c).getId() : "unknown", CredentialsNameProvider.name(c)); try { MessageDigest md5 = MessageDigest.getInstance("MD5"); DigestOutputStream out = new DigestOutputStream(new NullOutputStream(), md5); try { FINGERPRINT_XML.toXML(c, new OutputStreamWriter(out, Charset.forName("UTF-8"))); } finally { IOUtils.closeQuietly(out); } return Jenkins.getActiveInstance().getFingerprintMap().getOrCreate(null, pseudoFilename, md5.digest()); } catch (NoSuchAlgorithmException e) { throw new IllegalStateException("JLS mandates MD5 as a supported digest algorithm"); } }
String id = ((IdCredentials) c).getId(); masked = ids.contains(id); ids.add(id);