protected void reportInvalidRequestError(String errorDescription, MediaType mt) { OAuthError error = new OAuthError(OAuthConstants.INVALID_REQUEST, errorDescription); reportInvalidRequestError(error, mt); }
private void writeOAuthError(OAuthError obj, OutputStream os) throws IOException { StringBuilder sb = new StringBuilder(); sb.append("{"); appendJsonPair(sb, OAuthConstants.ERROR_KEY, obj.getError()); if (obj.getErrorDescription() != null) { sb.append(","); appendJsonPair(sb, OAuthConstants.ERROR_DESCRIPTION_KEY, obj.getErrorDescription()); } if (obj.getErrorUri() != null) { sb.append(","); appendJsonPair(sb, OAuthConstants.ERROR_URI_KEY, obj.getErrorUri()); } sb.append("}"); String result = sb.toString(); os.write(result.getBytes(StandardCharsets.UTF_8)); os.flush(); }
finalResponse = createErrorResponse(params, redirectUri, ex.getError().getError());
OAuthError error = new OAuthError(map.get(OAuthConstants.ERROR_KEY), map.get(OAuthConstants.ERROR_DESCRIPTION_KEY)); error.setErrorUri(map.get(OAuthConstants.ERROR_URI_KEY)); throw new OAuthServiceException(error);
finalResponse = createErrorResponse(params, redirectUri, ex.getError().getError());
OAuthError error = new OAuthError(map.get(OAuthConstants.ERROR_KEY), map.get(OAuthConstants.ERROR_DESCRIPTION_KEY)); error.setErrorUri(map.get(OAuthConstants.ERROR_URI_KEY)); throw new OAuthServiceException(error);
protected Response reportInvalidResponseType() { return JAXRSUtils.toResponseBuilder(400) .type("application/json").entity(new OAuthError(OAuthConstants.UNSUPPORTED_RESPONSE_TYPE)).build(); } }
private void writeOAuthError(OAuthError obj, OutputStream os) throws IOException { StringBuilder sb = new StringBuilder(); sb.append("{"); appendJsonPair(sb, OAuthConstants.ERROR_KEY, obj.getError()); if (obj.getErrorDescription() != null) { sb.append(","); appendJsonPair(sb, OAuthConstants.ERROR_DESCRIPTION_KEY, obj.getErrorDescription()); } if (obj.getErrorUri() != null) { sb.append(","); appendJsonPair(sb, OAuthConstants.ERROR_URI_KEY, obj.getErrorUri()); } sb.append("}"); String result = sb.toString(); os.write(result.getBytes(StandardCharsets.UTF_8)); os.flush(); }
@Test public void testTwoWayTLSClientUnbound() throws Exception { String address = "https://localhost:" + PORT + "/oauth2/token"; WebClient wc = createOAuth2WebClient(address); try { OAuthClientUtils.getAccessToken(wc, new Consumer("unbound"), new CustomGrant()); fail("exception_expected"); } catch (OAuthServiceException ex) { assertEquals("invalid_client", ex.getError().getError()); } }
protected Response createErrorResponse(MultivaluedMap<String, String> params, String error) { return createErrorResponseFromBean(new OAuthError(error)); }
@Test() public void testConfidentialClientIdOnly() throws Exception { String address = "https://localhost:" + port + "/oauth2/token"; WebClient wc = createWebClient(address); try { OAuthClientUtils.getAccessToken(wc, new Consumer("fredNoPassword"), new CustomGrant(), false); fail("NotAuthorizedException exception is expected"); } catch (OAuthServiceException ex) { assertEquals("invalid_client", ex.getError().getError()); } }
protected void reportInvalidRequestError(String errorDescription, MediaType mt) { OAuthError error = new OAuthError(OAuthConstants.INVALID_REQUEST, errorDescription); reportInvalidRequestError(error, mt); }
@Test public void testBasicAuthClientCred() throws Exception { String address = "https://localhost:" + port + "/oauth2/token"; WebClient wc = createWebClient(address); ClientCredentialsGrant grant = new ClientCredentialsGrant(); // Pass client_id & client_secret as form properties // (instead WebClient can be initialized with username & password) grant.setClientId("bob"); grant.setClientSecret("bobPassword"); try { OAuthClientUtils.getAccessToken(wc, grant); fail("Form based authentication is not supported"); } catch (OAuthServiceException ex) { assertEquals(OAuthConstants.UNAUTHORIZED_CLIENT, ex.getError().getError()); } ClientAccessToken at = OAuthClientUtils.getAccessToken(wc, new Consumer("bob", "bobPassword"), new ClientCredentialsGrant(), true); assertNotNull(at.getTokenKey()); }
protected Response reportInvalidResponseType() { return JAXRSUtils.toResponseBuilder(400) .type("application/json").entity(new OAuthError(OAuthConstants.UNSUPPORTED_RESPONSE_TYPE)).build(); } }
protected Response createErrorResponse(MultivaluedMap<String, String> params, String error) { return createErrorResponseFromBean(new OAuthError(error)); }
protected void reportInvalidClient() { reportInvalidClient(new OAuthError(OAuthConstants.INVALID_CLIENT)); }
protected Response createErrorResponseFromErrorCode(String error) { return createErrorResponseFromBean(new OAuthError(error)); }
protected void reportInvalidClient() { reportInvalidClient(new OAuthError(OAuthConstants.INVALID_CLIENT)); }
protected Response createErrorResponseFromErrorCode(String error) { return createErrorResponseFromBean(new OAuthError(error)); }
protected void checkAudience(Client c, MultivaluedMap<String, String> params) { String audienceParam = params.getFirst(OAuthConstants.CLIENT_AUDIENCE); if (!OAuthUtils.validateAudience(audienceParam, c.getRegisteredAudiences())) { LOG.log(Level.FINE, "Error validating the audience parameter. Supplied audience {0} " + "does not match with the registered audiences {1}", new Object[] {audienceParam, c.getRegisteredAudiences() }); throw new OAuthServiceException(new OAuthError(OAuthConstants.ACCESS_DENIED)); } }