use of com.swiftmq.amqp.v100.client.Consumer in project cxf by apache.
the class OAuth2TestUtils method getAccessTokenWithAuthorizationCode.
public static ClientAccessToken getAccessTokenWithAuthorizationCode(WebClient client, String code, String consumerId, String audience, String codeVerifier) {
Map<String, String> extraParams = new HashMap<>(3);
extraParams.put(OAuthConstants.REDIRECT_URI, "http://www.blah.apache.org");
if (audience != null) {
extraParams.put(OAuthConstants.CLIENT_AUDIENCE, audience);
}
if (codeVerifier != null) {
extraParams.put(OAuthConstants.AUTHORIZATION_CODE_VERIFIER, codeVerifier);
}
return OAuthClientUtils.getAccessToken(client.path("token"), new Consumer(consumerId), new AuthorizationCodeGrant(code), extraParams, false);
}
use of com.swiftmq.amqp.v100.client.Consumer in project cxf by apache.
the class OAuth2JwtFiltersTest method doTestServiceWithJwtTokenAndScope.
private void doTestServiceWithJwtTokenAndScope(String oauthService, String rsAddress) throws Exception {
final AuthorizationMetadata authorizationMetadata = OAuthClientUtils.getAuthorizationMetadata(oauthService);
final String scope = "create_book";
final URI authorizationURI = OAuthClientUtils.getAuthorizationURI(authorizationMetadata.getAuthorizationEndpoint().toString(), "consumer-id", null, null, scope);
// Get Authorization Code
WebClient oauthClient = WebClient.create(authorizationURI.toString(), OAuth2TestUtils.setupProviders(), "alice", "security", null);
// Save the Cookie for the second request...
WebClient.getConfig(oauthClient).getRequestContext().put(org.apache.cxf.message.Message.MAINTAIN_SESSION, Boolean.TRUE);
final String location = OAuth2TestUtils.getLocation(oauthClient, oauthClient.accept(MediaType.APPLICATION_JSON).get(OAuthAuthorizationData.class), null);
final String code = OAuth2TestUtils.getSubstring(location, "code");
assertNotNull(code);
// Now get the access token
final ClientAccessToken accessToken = OAuthClientUtils.getAccessToken(authorizationMetadata.getTokenEndpoint().toString(), new Consumer("consumer-id", "this-is-a-secret"), new AuthorizationCodeGrant(code), true);
assertNotNull(accessToken.getTokenKey());
JwsJwtCompactConsumer jwtConsumer = new JwsJwtCompactConsumer(accessToken.getTokenKey());
JwsSignatureVerifier verifier = JwsUtils.loadSignatureVerifier("org/apache/cxf/systest/jaxrs/security/alice.rs.properties", null);
assertTrue(jwtConsumer.verifySignatureWith(verifier));
JwtClaims claims = jwtConsumer.getJwtClaims();
assertEquals("consumer-id", claims.getStringProperty(OAuthConstants.CLIENT_ID));
assertEquals("alice", claims.getStringProperty("username"));
assertTrue(claims.getStringProperty(OAuthConstants.SCOPE).contains(scope));
// Now invoke on the service with the access token
WebClient client = WebClient.create(rsAddress, OAuth2TestUtils.setupProviders()).authorization(new ClientAccessToken(BEARER_AUTHORIZATION_SCHEME, accessToken.getTokenKey()));
Book returnedBook = client.type("application/xml").post(new Book("book", 123L), Book.class);
assertEquals(returnedBook.getName(), "book");
assertEquals(returnedBook.getId(), 123L);
}
use of com.swiftmq.amqp.v100.client.Consumer in project cxf by apache.
the class JAXRSOAuth2Test method testSAML2BearerGrant.
@Test
public void testSAML2BearerGrant() throws Exception {
String address = "https://localhost:" + port + "/oauth2/token";
WebClient wc = createWebClient(address);
Crypto crypto = new CryptoLoader().loadCrypto(CRYPTO_RESOURCE_PROPERTIES);
SelfSignInfo signInfo = new SelfSignInfo(crypto, "alice", "password");
SamlCallbackHandler samlCallbackHandler = new SamlCallbackHandler(false);
String audienceURI = "https://localhost:" + port + "/oauth2/token";
samlCallbackHandler.setAudience(audienceURI);
SamlAssertionWrapper assertionWrapper = SAMLUtils.createAssertion(samlCallbackHandler, signInfo);
Document doc = DOMUtils.newDocument();
Element assertionElement = assertionWrapper.toDOM(doc);
String assertion = DOM2Writer.nodeToString(assertionElement);
Saml2BearerGrant grant = new Saml2BearerGrant(assertion);
ClientAccessToken at = OAuthClientUtils.getAccessToken(wc, new Consumer("alice", "alice"), grant, false);
assertNotNull(at.getTokenKey());
}
use of com.swiftmq.amqp.v100.client.Consumer in project cxf by apache.
the class JAXRSOAuth2Test method testJWTBearerGrant.
@Test
public void testJWTBearerGrant() throws Exception {
String address = "https://localhost:" + port + "/oauth2/token";
WebClient wc = createWebClient(address);
// Create the JWT Token
String token = OAuth2TestUtils.createToken("resourceOwner", "alice", address, true, true);
JwtBearerGrant grant = new JwtBearerGrant(token);
ClientAccessToken at = OAuthClientUtils.getAccessToken(wc, new Consumer("alice", "alice"), grant, false);
assertNotNull(at.getTokenKey());
}
use of com.swiftmq.amqp.v100.client.Consumer in project teiid by teiid.
the class OAuth20CredentialImpl method getAccessToken.
protected ClientAccessToken getAccessToken() {
if (getAccessTokenString() != null) {
// if we have access_token directly, use it
return new ClientAccessToken(OAuthConstants.ACCESS_TOKEN_TYPE, getAccessTokenString());
}
Consumer consumer = new Consumer(getClientId(), getClientSecret());
WebClient client = WebClient.create(getAccessTokenURI());
RefreshTokenGrant grant = new RefreshTokenGrant(getRefreshToken());
return OAuthClientUtils.getAccessToken(client, consumer, grant, null, "Bearer", false);
}
Aggregations