use of com.swiftmq.amqp.v100.client.Consumer in project ddf by codice.
the class OAuthPlugin method refreshTokens.
/**
* Attempts to refresh the user's access token and saves the new tokens in the token storage
*
* @param refreshToken refresh token used to refresh access token
* @param oauthSource source being queried
* @throws OAuthPluginException if the access token could not be renewed
*/
private void refreshTokens(String refreshToken, OAuthFederatedSource oauthSource, String sessionId, OIDCProviderMetadata metadata) throws StopProcessingException {
if (refreshToken == null) {
throw createNoAuthException(oauthSource, sessionId, metadata, "unable to find the user's refresh token.");
}
ClientAccessToken clientAccessToken;
try {
LOGGER.debug("Attempting to refresh the user's access token.");
WebClient webClient = createWebclient(metadata.getTokenEndpointURI().toURL().toString());
Consumer consumer = new Consumer(oauthSource.getOauthClientId(), oauthSource.getOauthClientSecret());
AccessTokenGrant accessTokenGrant = new RefreshTokenGrant(refreshToken);
clientAccessToken = OAuthClientUtils.getAccessToken(webClient, consumer, accessTokenGrant);
} catch (OAuthServiceException e) {
String error = e.getError() != null ? e.getError().getError() : "";
throw createNoAuthException(oauthSource, sessionId, metadata, "failed to refresh access token " + error);
} catch (MalformedURLException e) {
throw createNoAuthException(oauthSource, sessionId, metadata, "malformed token endpoint URL. " + e.getMessage());
}
// Validate new access token
try {
AccessToken accessToken = convertCxfAccessTokenToNimbusdsToken(clientAccessToken);
OidcTokenValidator.validateAccessToken(accessToken, null, resourceRetriever, metadata, null);
} catch (OidcValidationException e) {
throw createNoAuthException(oauthSource, sessionId, metadata, "failed to validate refreshed access token.");
}
// Store new tokens
String newAccessToken = clientAccessToken.getTokenKey();
String newRefreshToken = clientAccessToken.getRefreshToken();
int status = tokenStorage.create(sessionId, oauthSource.getId(), newAccessToken, newRefreshToken, oauthSource.getOauthDiscoveryUrl());
if (status != SC_OK) {
LOGGER.warn("Error updating the token information.");
}
}
use of com.swiftmq.amqp.v100.client.Consumer in project activemq by apache.
the class SwiftMQClientTest method testSendReceive.
@Test
public void testSendReceive() throws Exception {
String queue = "testqueue";
int nMsgs = 100;
final String dataFormat = "%01024d";
int qos = QoS.AT_MOST_ONCE;
AMQPContext ctx = new AMQPContext(AMQPContext.CLIENT);
try {
Connection connection = new Connection(ctx, "127.0.0.1", port, false);
connection.setContainerId("client");
connection.setIdleTimeout(-1);
connection.setMaxFrameSize(1024 * 4);
connection.setExceptionListener(new ExceptionListener() {
public void onException(Exception e) {
e.printStackTrace();
}
});
connection.connect();
{
Session session = connection.createSession(10, 10);
Producer p = session.createProducer(queue, qos);
for (int i = 0; i < nMsgs; i++) {
AMQPMessage msg = new AMQPMessage();
System.out.println("Sending " + i);
msg.setAmqpValue(new AmqpValue(new AMQPString(String.format(dataFormat, i))));
p.send(msg);
}
p.close();
session.close();
}
System.out.println("=======================================================================================");
System.out.println(" receiving ");
System.out.println("=======================================================================================");
{
Session session = connection.createSession(10, 10);
Consumer c = session.createConsumer(queue, 100, qos, true, null);
// Receive messages non-transacted
int i = 0;
while (i < nMsgs) {
AMQPMessage msg = c.receive();
if (msg != null) {
final AMQPType value = msg.getAmqpValue().getValue();
if (value instanceof AMQPString) {
String s = ((AMQPString) value).getValue();
assertEquals(String.format(dataFormat, i), s);
System.out.println("Received: " + i);
}
if (!msg.isSettled())
msg.accept();
i++;
}
}
c.close();
session.close();
}
connection.close();
} catch (Exception e) {
e.printStackTrace();
}
}
use of com.swiftmq.amqp.v100.client.Consumer in project cxf by apache.
the class JAXRSOAuth2Test method testConfidentialClientIdOnly.
@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());
}
}
use of com.swiftmq.amqp.v100.client.Consumer in project cxf by apache.
the class JAXRSOAuth2Test method testBasicAuthClientCred.
@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());
}
use of com.swiftmq.amqp.v100.client.Consumer in project cxf by apache.
the class JAXRSOAuth2Test method testPublicClientIdOnly.
@Test
public void testPublicClientIdOnly() throws Exception {
String pubPort = JCACHE_PORT_PUBLIC;
if (JWT_JCACHE_PORT.equals(port)) {
pubPort = JWT_JCACHE_PORT_PUBLIC;
} else if (JPA_PORT.equals(port)) {
pubPort = JPA_PORT_PUBLIC;
} else if (JWT_NON_PERSIST_JCACHE_PORT.equals(port)) {
pubPort = JWT_NON_PERSIST_JCACHE_PORT_PUBLIC;
}
String address = "http://localhost:" + pubPort + "/oauth2Public/token";
WebClient wc = WebClient.create(address);
ClientAccessToken at = OAuthClientUtils.getAccessToken(wc, new Consumer("fredPublic"), new CustomGrant(), false);
assertNotNull(at.getTokenKey());
}
Aggregations