|
3 | 3 | import java.util.List; |
4 | 4 | import java.util.Map; |
5 | 5 |
|
| 6 | +import javax.ws.rs.core.Response; |
| 7 | + |
6 | 8 | import org.apache.oltu.oauth2.client.HttpClient; |
7 | 9 | import org.apache.oltu.oauth2.client.OAuthClient; |
8 | 10 | import org.apache.oltu.oauth2.client.request.OAuthClientRequest; |
@@ -84,17 +86,28 @@ public synchronized void updateAccessToken() { |
84 | 86 | } catch (Exception e) { |
85 | 87 | throw new ClientHandlerException(e.getMessage(), e); |
86 | 88 | } |
87 | | - if (accessTokenResponse != null && accessTokenResponse.getAccessToken() != null) { |
| 89 | + if (accessTokenResponse != null) |
| 90 | + { |
| 91 | + // FIXME: This does not work in case of non HTTP 200 :-( oauthClient needs to return the plain HTTP resonse |
| 92 | + if (accessTokenResponse.getResponseCode() != Response.Status.OK.getStatusCode()) |
| 93 | + { |
| 94 | + throw new ClientHandlerException("Error while requesting an access token, received HTTP code: " + accessTokenResponse.getResponseCode()); |
| 95 | + } |
| 96 | + |
88 | 97 | if (accessTokenResponse.getAccessToken() == null) { |
89 | 98 | throw new ClientHandlerException("Error while requesting an access token. No 'access_token' found."); |
90 | 99 | } |
91 | 100 | if (accessTokenResponse.getExpiresIn() == null) { |
92 | 101 | throw new ClientHandlerException("Error while requesting an access token. No 'expires_in' found."); |
93 | 102 | } |
| 103 | + |
94 | 104 | setAccessToken(accessTokenResponse.getAccessToken(), accessTokenResponse.getExpiresIn()); |
95 | | - if (accessTokenListener != null) { |
96 | | - accessTokenListener.notify((BasicOAuthToken) accessTokenResponse.getOAuthToken()); |
| 105 | + if (this.accessTokenListener != null) { |
| 106 | + this.accessTokenListener.notify((BasicOAuthToken)accessTokenResponse.getOAuthToken()); |
97 | 107 | } |
| 108 | + } else { |
| 109 | + // in case of HTTP error codes accessTokenResponse is null, thus no check of accessTokenResponse.getResponseCode() possible :-( |
| 110 | + throw new ClientHandlerException("Error while requesting an access token. No accessTokenResponse object recieved, maybe a non HTTP 200 received?"); |
98 | 111 | } |
99 | 112 | } |
100 | 113 |
|
|
0 commit comments