Skip to content

Commit

Permalink
Merge pull request #1 from SamClinckspoor/JENKINS-34792
Browse files Browse the repository at this point in the history
[JENKINS-34792] Don't cast inconvertible un/pw token
  • Loading branch information
mallowlabs committed Jun 4, 2016
2 parents 2fb42f0 + ba0fcbd commit 6ee7820
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/main/java/org/jenkinsci/plugins/BitbucketSecurityRealm.java
Expand Up @@ -159,10 +159,16 @@ public UserDetails loadUserByUsername(String username) throws UserMayOrMayNotEx
@Override
public UserDetails loadUserByUsername(String username) {
UserDetails result = null;
BitbucketAuthenticationToken authToken = (BitbucketAuthenticationToken) SecurityContextHolder.getContext().getAuthentication();
if (authToken == null) {
Authentication token = SecurityContextHolder.getContext().getAuthentication();
if (token == null) {
throw new UsernameNotFoundException("BitbucketAuthenticationToken = null, no known user: " + username);
}
BitbucketAuthenticationToken authToken;
if (token instanceof BitbucketAuthenticationToken) {
authToken = (BitbucketAuthenticationToken) token;
} else {
throw new UserMayOrMayNotExistException("Unexpected authentication type: " + token);
}
result = new BitbucketApiService(clientID, clientSecret).getUserByUsername(username);
if (result == null) {
throw new UsernameNotFoundException("User does not exist for login: " + username);
Expand Down

0 comments on commit 6ee7820

Please sign in to comment.