use of org.apache.oltu.oauth2.common.exception.OAuthProblemException in project BIMserver by opensourceBIM.
the class URLConnectionClient method execute.
public <T extends OAuthClientResponse> T execute(OAuthClientRequest request, Map<String, String> headers, String requestMethod, Class<T> responseClass) throws OAuthSystemException, OAuthProblemException {
InputStream responseBody = null;
URLConnection c;
Map<String, List<String>> responseHeaders = new HashMap<String, List<String>>();
int responseCode;
try {
URL url = new URL(request.getLocationUri());
c = url.openConnection();
responseCode = -1;
if (c instanceof HttpURLConnection) {
HttpURLConnection httpURLConnection = (HttpURLConnection) c;
if (headers != null && !headers.isEmpty()) {
for (Map.Entry<String, String> header : headers.entrySet()) {
httpURLConnection.addRequestProperty(header.getKey(), header.getValue());
}
}
if (request.getHeaders() != null) {
for (Map.Entry<String, String> header : request.getHeaders().entrySet()) {
httpURLConnection.addRequestProperty(header.getKey(), header.getValue());
}
}
if (OAuthUtils.isEmpty(requestMethod)) {
httpURLConnection.setRequestMethod(OAuth.HttpMethod.GET);
} else {
httpURLConnection.setRequestMethod(requestMethod);
setRequestBody(request, requestMethod, httpURLConnection);
}
httpURLConnection.connect();
InputStream inputStream;
responseCode = httpURLConnection.getResponseCode();
if (responseCode == SC_BAD_REQUEST || responseCode == SC_UNAUTHORIZED) {
inputStream = httpURLConnection.getErrorStream();
} else {
inputStream = httpURLConnection.getInputStream();
}
responseHeaders = httpURLConnection.getHeaderFields();
responseBody = inputStream;
}
} catch (IOException e) {
throw new OAuthSystemException(e);
}
return OAuthClientResponseFactory.createCustomResponse(responseBody, c.getContentType(), responseCode, responseHeaders, responseClass);
}
use of org.apache.oltu.oauth2.common.exception.OAuthProblemException in project tesla by linking12.
the class OauthTokenController method authorize.
@RequestMapping("token")
public void authorize(HttpServletRequest request, HttpServletResponse response) throws OAuthSystemException {
try {
OAuthTokenxRequest tokenRequest = new OAuthTokenxRequest(request);
OAuthTokenHandleDispatcher tokenHandleDispatcher = new OAuthTokenHandleDispatcher(tokenRequest, response);
tokenHandleDispatcher.dispatch();
} catch (OAuthProblemException e) {
LOG.debug(e.getMessage(), e);
OAuthResponse oAuthResponse = OAuthASResponse.errorResponse(HttpServletResponse.SC_FOUND).location(e.getRedirectUri()).error(e).buildJSONMessage();
WebUtils.writeOAuthJsonResponse(response, oAuthResponse);
}
}
use of org.apache.oltu.oauth2.common.exception.OAuthProblemException in project tesla by linking12.
the class ClientCredentialsTokenHandler method handleAfterValidation.
@Override
public void handleAfterValidation() throws OAuthProblemException, OAuthSystemException {
AccessToken accessToken = oauthService.retrieveClientCredentialsAccessToken(clientDetails(), tokenRequest.getScopes());
final OAuthResponse tokenResponse = createTokenResponse(accessToken, false);
LOG.debug("'client_credentials' response: {}", tokenResponse);
WebUtils.writeOAuthJsonResponse(response, tokenResponse);
}
use of org.apache.oltu.oauth2.common.exception.OAuthProblemException in project tesla by linking12.
the class PasswordTokenHandler method handleAfterValidation.
@Override
public void handleAfterValidation() throws OAuthProblemException, OAuthSystemException {
AccessToken accessToken = oauthService.retrievePasswordAccessToken(clientDetails(), tokenRequest.getScopes(), tokenRequest.getUsername());
final OAuthResponse tokenResponse = createTokenResponse(accessToken, false);
LOG.debug("'password' response: {}", tokenResponse);
WebUtils.writeOAuthJsonResponse(response, tokenResponse);
}
use of org.apache.oltu.oauth2.common.exception.OAuthProblemException in project components by Talend.
the class Oauth2ImplicitClient method getToken.
public <T extends OAuthAccessTokenResponse> T getToken(Class<T> tokenResponseClass) {
try {
TokenRequestBuilder builder = //
OAuthClientRequest.tokenLocation(//
tokenLocation.toString()).setGrantType(//
grantType).setClientId(//
clientID).setClientSecret(clientSecret);
if (GrantType.AUTHORIZATION_CODE == grantType) {
builder = //
builder.setRedirectURI(callbackURL.toString()).setCode(getAuthorizationCode());
} else if (GrantType.REFRESH_TOKEN == grantType) {
builder = builder.setRefreshToken(refreshToken);
}
OAuthClientRequest request = builder.buildQueryMessage();
OAuthClient oauthClient = new OAuthClient(new URLConnectionClient());
return oauthClient.accessToken(request, tokenResponseClass);
} catch (OAuthSystemException e) {
throw new RuntimeException(e);
} catch (OAuthProblemException e) {
throw new RuntimeException(e);
}
}
Aggregations