use of com.swiftmq.amqp.v100.client.Consumer in project cxf by apache.
the class JAXRSOAuth2Test method testConfidentialClientIdAndSecret.
@Test
public void testConfidentialClientIdAndSecret() throws Exception {
String address = "https://localhost:" + port + "/oauth2/token";
WebClient wc = createWebClient(address);
ClientAccessToken at = OAuthClientUtils.getAccessToken(wc, new Consumer("fred", "password"), new CustomGrant(), false);
assertNotNull(at.getTokenKey());
}
use of com.swiftmq.amqp.v100.client.Consumer in project cxf by apache.
the class OIDCFlowTest method testAuthorizationCodeFlowRefreshToken.
@org.junit.Test
public void testAuthorizationCodeFlowRefreshToken() throws Exception {
String address = "https://localhost:" + port + "/services/";
WebClient client = WebClient.create(address, OAuth2TestUtils.setupProviders(), "alice", "security", null);
// Save the Cookie for the second request...
WebClient.getConfig(client).getRequestContext().put(org.apache.cxf.message.Message.MAINTAIN_SESSION, Boolean.TRUE);
// Get Authorization Code
String code = OAuth2TestUtils.getAuthorizationCode(client, String.join(" ", OidcUtils.getOpenIdScope(), OAuthConstants.REFRESH_TOKEN_SCOPE), "consumer-id-oidc");
assertNotNull(code);
// Now get the access token
client = WebClient.create(address, "consumer-id-oidc", "this-is-a-secret", null);
ClientAccessToken accessToken = OAuth2TestUtils.getAccessTokenWithAuthorizationCode(client, code, "consumer-id-oidc", null);
assertNotNull(accessToken.getTokenKey());
assertTrue(accessToken.getApprovedScope().contains("openid"));
IdToken idToken = getIdToken(accessToken, address + "keys/", "consumer-id-oidc");
assertNotNull(idToken);
Long issuedAt = idToken.getIssuedAt();
TimeUnit.SECONDS.sleep(1L);
accessToken = OAuthClientUtils.refreshAccessToken(client, new Consumer("consumer-id-oidc"), accessToken);
idToken = getIdToken(accessToken, address + "keys/", "consumer-id-oidc");
assertNotEquals(issuedAt, idToken.getIssuedAt());
}
use of com.swiftmq.amqp.v100.client.Consumer in project cxf by apache.
the class JAXRSOAuth2TlsTest method doTestTwoWayTLSClientIdBoundJwt.
private void doTestTwoWayTLSClientIdBoundJwt(String clientId) throws Exception {
String atServiceAddress = "https://localhost:" + PORT + "/oauth2Jwt/token";
WebClient wc = createOAuth2WebClient(atServiceAddress);
ClientAccessToken at = OAuthClientUtils.getAccessToken(wc, new Consumer(clientId), new CustomGrant());
assertNotNull(at.getTokenKey());
JwsJwtCompactConsumer c = new JwsJwtCompactConsumer(at.getTokenKey());
JwtClaims claims = JwtUtils.jsonToClaims(c.getDecodedJwsPayload());
Map<String, Object> cnfs = claims.getMapProperty(JwtConstants.CLAIM_CONFIRMATION);
assertNotNull(cnfs);
assertNotNull(cnfs.get(JoseConstants.HEADER_X509_THUMBPRINT_SHA256));
String protectedRsAddress = "https://localhost:" + PORT + "/rsJwt/bookstore/books/123";
WebClient wcRs = createRsWebClient(protectedRsAddress, at, "client.xml");
Book book = wcRs.get(Book.class);
assertEquals(123L, book.getId());
String protectedRsAddress2 = "https://localhost:" + PORT + "/rsJwt2/bookstore/books/123";
WebClient wcRs2 = createRsWebClient(protectedRsAddress2, at, "client.xml");
book = wcRs2.get(Book.class);
assertEquals(123L, book.getId());
String unprotectedRsAddress = "https://localhost:" + PORT + "/rsUnprotected/bookstore/books/123";
WebClient wcRsDiffClientCert = createRsWebClient(unprotectedRsAddress, at, "client2.xml");
// Unprotected resource
book = wcRsDiffClientCert.get(Book.class);
assertEquals(123L, book.getId());
// Protected resource, access token was created with Morpit.jks key, RS is accessed with
// Bethal.jks key, thus 401 is expected
wcRsDiffClientCert = createRsWebClient(protectedRsAddress, at, "client2.xml");
assertEquals(401, wcRsDiffClientCert.get().getStatus());
wcRsDiffClientCert = createRsWebClient(protectedRsAddress2, at, "client2.xml");
assertEquals(401, wcRsDiffClientCert.get().getStatus());
}
use of com.swiftmq.amqp.v100.client.Consumer in project cxf by apache.
the class JAXRSOAuth2TlsTest method testTwoWayTLSClientUnbound.
@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());
}
}
use of com.swiftmq.amqp.v100.client.Consumer in project cxf by apache.
the class JAXRSOAuth2TlsTest method testTwoWayTLSClientIdBound.
@Test
public void testTwoWayTLSClientIdBound() throws Exception {
String atServiceAddress = "https://localhost:" + PORT + "/oauth2/token";
WebClient wc = createOAuth2WebClient(atServiceAddress);
ClientAccessToken at = OAuthClientUtils.getAccessToken(wc, new Consumer("bound"), new CustomGrant());
assertNotNull(at.getTokenKey());
}
Aggregations