List of usage examples for org.springframework.security.oauth2.common.exceptions InvalidGrantException InvalidGrantException
public InvalidGrantException(String msg, Throwable t)
From source file:org.osiam.auth.login.oauth.OsiamResourceOwnerPasswordTokenGranter.java
@Override protected OAuth2Authentication getOAuth2Authentication(AuthorizationRequest clientToken) { Map<String, String> parameters = clientToken.getAuthorizationParameters(); String username = parameters.get("username"); String password = parameters.get("password"); Authentication userAuth = new InternalAuthentication(username, password, new ArrayList<GrantedAuthority>()); try {// w w w. j av a 2 s.c o m userAuth = authenticationManager.authenticate(userAuth); } catch (AccountStatusException ase) { // covers expired, locked, disabled cases (mentioned in section 5.2, draft 31) throw new InvalidGrantException(ase.getMessage(), ase); } catch (BadCredentialsException e) { // If the username/password are wrong the spec says we should send 400/bad grant throw new InvalidGrantException(e.getMessage(), e); } if (userAuth == null || !userAuth.isAuthenticated()) { throw new InvalidGrantException("Could not authenticate user: " + username); } DefaultAuthorizationRequest request = new DefaultAuthorizationRequest(clientToken); request.remove(Arrays.asList("password")); return new OAuth2Authentication(request, userAuth); }