use of com.swiftmq.amqp.v100.client.Consumer in project cxf by apache.
the class OIDCFlowTest method getIdToken.
private static IdToken getIdToken(ClientAccessToken accessToken, String jwksUri, String clientId) {
WebClient c = WebClient.create(jwksUri, Collections.singletonList(new JsonWebKeysProvider()), "alice", "security", null).accept(MediaType.APPLICATION_JSON);
IdTokenReader idTokenReader = new IdTokenReader();
idTokenReader.setJwkSetClient(c);
idTokenReader.setIssuerId("OIDC IdP");
return idTokenReader.getIdToken(accessToken, new Consumer(clientId));
}
use of com.swiftmq.amqp.v100.client.Consumer in project teiid by teiid.
the class JWTBearerTokenLoginModule method login.
@Override
public boolean login() throws LoginException {
this.callerSubject = getSubject();
this.callerPrincipal = getPrincipal();
final String assertion = getJWTAssertion();
if (assertion == null) {
return false;
}
OAuth20CredentialImpl cred = new OAuth20CredentialImpl() {
protected ClientAccessToken getAccessToken() {
Consumer consumer = new Consumer(getClientId(), getClientSecret());
WebClient client = WebClient.create(getAccessTokenURI());
JwtBearerGrant grant = null;
if (scope != null) {
grant = new JwtBearerGrant(assertion, true, scope);
} else {
grant = new JwtBearerGrant(assertion, true);
}
return OAuthClientUtils.getAccessToken(client, consumer, grant, null, false);
}
};
cred.setClientId(getClientId());
cred.setClientSecret(getClientSecret());
cred.setAccessTokenURI(getAccessTokenURI());
setCredential(cred);
return super.login();
}
use of com.swiftmq.amqp.v100.client.Consumer in project teiid by teiid.
the class SAMLBearerTokenLoginModule method login.
@Override
public boolean login() throws LoginException {
this.callerSubject = getSubject();
this.callerPrincipal = getPrincipal();
final String samlToken = getSAMLResponseToken();
if (samlToken == null) {
return false;
}
OAuth20CredentialImpl cred = new OAuth20CredentialImpl() {
protected ClientAccessToken getAccessToken() {
Consumer consumer = new Consumer(getClientId(), getClientSecret());
WebClient client = WebClient.create(getAccessTokenURI());
Saml2BearerGrant grant = null;
if (scope != null) {
grant = new Saml2BearerGrant(samlToken, scope);
} else {
grant = new Saml2BearerGrant(samlToken);
}
return OAuthClientUtils.getAccessToken(client, consumer, grant, null, false);
}
};
cred.setClientId(getClientId());
cred.setClientSecret(getClientSecret());
cred.setAccessTokenURI(getAccessTokenURI());
setCredential(cred);
return super.login();
}
use of com.swiftmq.amqp.v100.client.Consumer in project ddf by codice.
the class OAuthSecurityImpl method refreshToken.
/**
* Attempts to refresh an expired access token
*
* @param id The ID to use when storing tokens
* @param sourceId The ID of the source using OAuth to use when storing tokens
* @param clientId The client ID registered with the OAuth provider
* @param clientSecret The client secret registered with the OAuth provider
* @param discoveryUrl The URL where the OAuth provider's metadata is hosted
* @param refreshToken The unexpired refresh token to use
* @param metadata The OAuh provider's metadata
* @return refreshed access token
*/
private String refreshToken(String id, String sourceId, String clientId, String clientSecret, String discoveryUrl, String refreshToken, OIDCProviderMetadata metadata) {
if (refreshToken == null || isExpired(refreshToken)) {
LOGGER.debug("Error refreshing access token: unable to find an unexpired refresh token.");
return null;
}
ClientAccessToken clientAccessToken;
try {
LOGGER.debug("Attempting to refresh the user's access token.");
WebClient webClient = createWebClient(metadata.getTokenEndpointURI());
Consumer consumer = new Consumer(clientId, clientSecret);
AccessTokenGrant accessTokenGrant = new RefreshTokenGrant(refreshToken);
clientAccessToken = OAuthClientUtils.getAccessToken(webClient, consumer, accessTokenGrant);
} catch (OAuthServiceException e) {
LOGGER.debug("Error refreshing access token.", e);
return null;
}
// Validate new access token
try {
AccessToken accessToken = convertCxfAccessTokenToNimbusdsToken(clientAccessToken);
OidcTokenValidator.validateAccessToken(accessToken, null, resourceRetriever, metadata, null);
} catch (OidcValidationException e) {
LOGGER.debug("Error validating access token.");
return null;
}
// Store new tokens
String newAccessToken = clientAccessToken.getTokenKey();
String newRefreshToken = clientAccessToken.getRefreshToken();
int status = tokenStorage.create(id, sourceId, newAccessToken, newRefreshToken, discoveryUrl);
if (status != SC_OK) {
LOGGER.warn("Error updating the token information.");
}
return newAccessToken;
}
use of com.swiftmq.amqp.v100.client.Consumer in project swiftmq-ce by iitsoftware.
the class ReceiverTransactedRetirement method main.
public static void main(String[] args) {
if (args.length == 1 && args[0].equals("?")) {
System.out.println();
System.out.println("Usage: <host> <port> <source> <nmsgs> <qos> <txsize> <authanon> [<username> <password>]");
System.out.println(" <qos> ::= AT_LEAST_ONCE | AT_MOST_ONCE | EXACTLY_ONCE");
System.out.println(" Suppress <username> <password> and set <authanon> to false to avoid SASL.");
System.out.println();
System.exit(0);
}
String host = "localhost";
int port = 5672;
String source = "testqueue";
int nMsgs = 100;
String qosS = "EXACTLY_ONCE";
int txSize = 10;
boolean authAnon = true;
String user = null;
String password = null;
if (args.length >= 1)
host = args[0];
if (args.length >= 2)
port = Integer.parseInt(args[1]);
if (args.length >= 3)
source = args[2];
if (args.length >= 4)
nMsgs = Integer.parseInt(args[3]);
if (args.length >= 5)
qosS = args[4];
if (args.length >= 6)
txSize = Integer.parseInt(args[5]);
if (args.length >= 7)
authAnon = Boolean.parseBoolean(args[6]);
if (args.length >= 8)
user = args[7];
if (args.length >= 9)
password = args[8];
System.out.println();
System.out.println("Host : " + host);
System.out.println("Port : " + port);
System.out.println("Source : " + source);
System.out.println("Number Msgs : " + nMsgs);
System.out.println("QoS : " + qosS);
System.out.println("Tx Size : " + txSize);
System.out.println("Auth as Anon: " + authAnon);
System.out.println("User : " + user);
System.out.println("Password : " + password);
System.out.println();
try {
// Create connection and connect
AMQPContext ctx = new AMQPContext(AMQPContext.CLIENT);
Connection connection = null;
if (args.length < 8)
connection = new Connection(ctx, host, port, authAnon);
else
connection = new Connection(ctx, host, port, user, password);
if (port == 5671) {
System.out.println("Using SSL on port 5671");
connection.setSocketFactory(new JSSESocketFactory());
}
connection.connect();
// Create session and consumer
Session session = connection.createSession(50, 50);
Consumer c = session.createConsumer(source, 100, toIntQoS(qosS), true, null);
// Get the transaction controller
TransactionController txc = session.getTransactionController();
// Receive messages in transactions in size <txSize>
int currentTxSize = 0;
TxnIdIF txnId = txc.createTxnId();
for (int i = 0; i < nMsgs; i++) {
AMQPMessage msg = c.receive();
if (msg == null)
break;
AmqpValue value = msg.getAmqpValue();
System.out.println("Received: " + ((AMQPString) value.getValue()).getValue());
msg.setTxnIdIF(txnId);
msg.accept();
currentTxSize++;
if ((i + 1) % txSize == 0) {
txc.commit(txnId);
txnId = txc.createTxnId();
currentTxSize = 0;
}
}
if (currentTxSize > 0)
txc.commit(txnId);
// Close everything down
Thread.sleep(2000);
c.close();
session.close();
connection.close();
} catch (Exception e) {
e.printStackTrace();
}
}
Aggregations