use of hudson.util.Secret in project hudson-2.x by hudson.
the class PasswordParameterDefinitionEqualsHashCodeTest method setUp.
@Before
public void setUp() throws Exception {
Hudson hudson = createMock(Hudson.class);
mockStatic(Hudson.class);
expect(Hudson.getInstance()).andReturn(hudson).anyTimes();
mockStatic(Secret.class);
Secret secret = Whitebox.invokeConstructor(Secret.class, new Class<?>[] { String.class }, new String[] { "value" });
expect(Secret.fromString(EasyMock.<String>anyObject())).andReturn(secret).anyTimes();
expect(Secret.toString(EasyMock.<Secret>anyObject())).andReturn(secret.toString()).anyTimes();
replayAll();
}
use of hudson.util.Secret in project hudson-2.x by hudson.
the class ClientAuthenticationCache method get.
/**
* 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()));
// failed to decrypt
if (userName == null)
return Hudson.ANONYMOUS;
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;
}
}
Aggregations