Skip to content

Commit

Permalink
[JENKINS-34792] Don't cast inconvertible un/pw token
Browse files Browse the repository at this point in the history
Fixes JENKINS-34792
  • Loading branch information
SamClinckspoor committed Jun 3, 2016
1 parent 2fb42f0 commit ba0fcbd
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 ba0fcbd

Please sign in to comment.