* Gets the persisted authentication for this Jenkins.
*
* @return {@link jenkins.model.Jenkins#ANONYMOUS} if no such credential is found, or if the stored credential is invalid.
*/
public Authentication get() {
Jenkins h = Jenkins.getInstance();
Secret userName = Secret.decrypt(props.getProperty(getPropertyKey()));
if (userName==null) return Jenkins.ANONYMOUS; // failed to decrypt
try {
UserDetails u = h.getSecurityRealm().loadUserByUsername(userName.getPlainText());
return new UsernamePasswordAuthenticationToken(u.getUsername(), "", u.getAuthorities());
} catch (AuthenticationException e) {
return Jenkins.ANONYMOUS;
} catch (DataAccessException e) {
return Jenkins.ANONYMOUS;