@Override protected int run() throws Exception { Authentication a = Jenkins.getAuthentication(); if (a== Jenkins.ANONYMOUS) throw new CmdLineException("No credentials specified."); // this causes CLI to show the command line options. ClientAuthenticationCache store = new ClientAuthenticationCache(checkChannel()); store.set(a); SecurityListener.fireLoggedIn(a.getName()); return 0; }
/** * Loads the persisted authentication information from {@link ClientAuthenticationCache} * if the current transport provides {@link Channel}. * @deprecated Assumes Remoting, and vulnerable to JENKINS-12543. */ @Deprecated protected Authentication loadStoredAuthentication() throws InterruptedException { try { if (channel!=null){ Authentication authLoadedFromCache = new ClientAuthenticationCache(channel).get(); if(!ACL.isAnonymous(authLoadedFromCache)){ UserDetails userDetails = new CLIUserDetails(authLoadedFromCache); SecurityListener.fireAuthenticated(userDetails); } return authLoadedFromCache; } } catch (IOException e) { stderr.println("Failed to access the stored credential"); Functions.printStackTrace(e, stderr); // recover } return Jenkins.ANONYMOUS; }
/** * Removes the persisted credential, if there's one. */ public void remove() throws IOException, InterruptedException { if (props.remove(getPropertyKey())!=null) save(); }
@VisibleForTesting void setUsingLegacyMethod(String username) throws IOException, InterruptedException { props.setProperty(getPropertyKey(), username + USERNAME_VERIFICATION_SEPARATOR + getMacOf(username)); save(); }
@Override protected int run() throws Exception { ClientAuthenticationCache store = new ClientAuthenticationCache(checkChannel()); Authentication auth = store.get(); store.remove(); SecurityListener.fireLoggedOut(auth.getName()); return 0; } }
@Override protected int run() throws Exception { ClientAuthenticationCache store = new ClientAuthenticationCache(channel); store.remove(); return 0; } }
setUsingLegacyMethod(username); return; userSeed = userSeedProperty.getSeed(); String mac = getMacOf(username); String validationFragment = String.join(VERIFICATION_FRAGMENT_SEPARATOR, mac, VERSION_2, userSeed); props.setProperty(getPropertyKey(), propertyValue); save();
String val = props.getProperty(getPropertyKey()); if (val == null) { LOGGER.finer("No stored CLI authentication");
String val = props.getProperty(getPropertyKey()); if (val == null) { LOGGER.finer("No stored CLI authentication"); int indexOfSeparator = verificationPart.indexOf(VERIFICATION_FRAGMENT_SEPARATOR); if (indexOfSeparator == -1) { return legacy(username, verificationPart, val); authFromVersion = version2(username, restOfFragments, val); } else { LOGGER.log(Level.FINE, "Unrecognized version for stored CLI authentication verification: {0}", val); return getUserAuthIfValidMac(username, macFragment, val);
@Override protected int run() throws Exception { ClientAuthenticationCache store = new ClientAuthenticationCache(channel); store.remove(); return 0; } }
/** * Gets the persisted authentication for this Hudson. * * @return {@link Hudson#ANONYMOUS} if no such credential is found, or if * the stored credential is invalid. */ public Authentication get() { Secret userName = Secret.decrypt(props.getProperty(getPropertyKey())); if (userName == null) { return Hudson.ANONYMOUS; // failed to decrypt } try { UserDetails u = HudsonSecurityEntitiesHolder.getHudsonSecurityManager().getSecurityRealm().loadUserByUsername(userName.toString()); return new UsernamePasswordAuthenticationToken(u.getUsername(), u.getPassword(), u.getAuthorities()); } catch (AuthenticationException e) { return Hudson.ANONYMOUS; } catch (DataAccessException e) { return Hudson.ANONYMOUS; } }
/** * Removes the persisted credential, if there's one. */ public void remove() throws IOException, InterruptedException { if (props.remove(getPropertyKey())!=null) save(); }
@Override protected int run() throws Exception { Authentication a = Hudson.getAuthentication(); if (a==Hudson.ANONYMOUS) throw new CmdLineException("No credentials specified."); // this causes CLI to show the command line options. ClientAuthenticationCache store = new ClientAuthenticationCache(channel); store.set(a); return 0; }
/** * Loads the persisted authentication information from {@link ClientAuthenticationCache}. */ protected Authentication loadStoredAuthentication() throws InterruptedException { try { return new ClientAuthenticationCache(channel).get(); } catch (IOException e) { stderr.println("Failed to access the stored credential"); e.printStackTrace(stderr); // recover return Hudson.ANONYMOUS; } }
@Override protected int run() throws Exception { ClientAuthenticationCache store = new ClientAuthenticationCache(channel); store.remove(); return 0; } }
/** * Gets the persisted authentication for this Hudson. * * @return {@link Hudson#ANONYMOUS} if no such credential is found, or if the stored credential is invalid. */ public Authentication get() { Hudson h = Hudson.getInstance(); Secret userName = Secret.decrypt(props.getProperty(getPropertyKey())); if (userName==null) return Hudson.ANONYMOUS; // failed to decrypt try { UserDetails u = h.getSecurityRealm().loadUserByUsername(userName.toString()); return new UsernamePasswordAuthenticationToken(u.getUsername(), u.getPassword(), u.getAuthorities()); } catch (AuthenticationException e) { return Hudson.ANONYMOUS; } catch (DataAccessException e) { return Hudson.ANONYMOUS; } }
/** * Removes the persisted credential, if there's one. */ public void remove() throws IOException, InterruptedException { if (props.remove(getPropertyKey())!=null) save(); }
@Override protected int run() throws Exception { Authentication a = Hudson.getAuthentication(); if (a == HudsonSecurityManager.ANONYMOUS) { throw new CmdLineException("No credentials specified."); // this causes CLI to show the command line options. } ClientAuthenticationCache store = new ClientAuthenticationCache(channel); store.set(a); return 0; } }
/** * Loads the persisted authentication information from {@link ClientAuthenticationCache}. */ protected Authentication loadStoredAuthentication() throws InterruptedException { try { return new ClientAuthenticationCache(channel).get(); } catch (IOException e) { stderr.println("Failed to access the stored credential"); e.printStackTrace(stderr); // recover return Hudson.ANONYMOUS; } }
@Override protected int run() throws Exception { ClientAuthenticationCache store = new ClientAuthenticationCache(channel); store.remove(); return 0; } }