Search in sources :

Example 26 with Consumer

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));
}
Also used : JsonWebKeysProvider(org.apache.cxf.rs.security.jose.jaxrs.JsonWebKeysProvider) JwsJwtCompactConsumer(org.apache.cxf.rs.security.jose.jws.JwsJwtCompactConsumer) Consumer(org.apache.cxf.rs.security.oauth2.client.Consumer) WebClient(org.apache.cxf.jaxrs.client.WebClient) IdTokenReader(org.apache.cxf.rs.security.oidc.rp.IdTokenReader)

Example 27 with Consumer

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();
}
Also used : Consumer(org.apache.cxf.rs.security.oauth2.client.Consumer) JwtBearerGrant(org.apache.cxf.rs.security.oauth2.grants.jwt.JwtBearerGrant) WebClient(org.apache.cxf.jaxrs.client.WebClient)

Example 28 with Consumer

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();
}
Also used : Saml2BearerGrant(org.apache.cxf.rs.security.oauth2.grants.saml.Saml2BearerGrant) Consumer(org.apache.cxf.rs.security.oauth2.client.Consumer) WebClient(org.apache.cxf.jaxrs.client.WebClient)

Example 29 with Consumer

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;
}
Also used : Consumer(org.apache.cxf.rs.security.oauth2.client.Consumer) OAuthServiceException(org.apache.cxf.rs.security.oauth2.provider.OAuthServiceException) RefreshTokenGrant(org.apache.cxf.rs.security.oauth2.grants.refresh.RefreshTokenGrant) ClientAccessToken(org.apache.cxf.rs.security.oauth2.common.ClientAccessToken) AccessToken(com.nimbusds.oauth2.sdk.token.AccessToken) BearerAccessToken(com.nimbusds.oauth2.sdk.token.BearerAccessToken) TypelessAccessToken(com.nimbusds.oauth2.sdk.token.TypelessAccessToken) ClientAccessToken(org.apache.cxf.rs.security.oauth2.common.ClientAccessToken) AccessTokenGrant(org.apache.cxf.rs.security.oauth2.common.AccessTokenGrant) WebClient(org.apache.cxf.jaxrs.client.WebClient) OidcValidationException(org.codice.ddf.security.oidc.validator.OidcValidationException)

Example 30 with Consumer

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();
    }
}
Also used : TxnIdIF(com.swiftmq.amqp.v100.generated.transactions.coordination.TxnIdIF) AMQPString(com.swiftmq.amqp.v100.types.AMQPString) AMQPMessage(com.swiftmq.amqp.v100.messaging.AMQPMessage) AmqpValue(com.swiftmq.amqp.v100.generated.messaging.message_format.AmqpValue) AMQPContext(com.swiftmq.amqp.AMQPContext) AMQPString(com.swiftmq.amqp.v100.types.AMQPString) JSSESocketFactory(com.swiftmq.net.JSSESocketFactory)

Aggregations

Consumer (org.apache.cxf.rs.security.oauth2.client.Consumer)19 WebClient (org.apache.cxf.jaxrs.client.WebClient)17 ClientAccessToken (org.apache.cxf.rs.security.oauth2.common.ClientAccessToken)12 AMQPMessage (com.swiftmq.amqp.v100.messaging.AMQPMessage)9 AMQPString (com.swiftmq.amqp.v100.types.AMQPString)9 Test (org.junit.Test)9 AMQPContext (com.swiftmq.amqp.AMQPContext)7 AmqpValue (com.swiftmq.amqp.v100.generated.messaging.message_format.AmqpValue)7 JSSESocketFactory (com.swiftmq.net.JSSESocketFactory)6 JwsJwtCompactConsumer (org.apache.cxf.rs.security.jose.jws.JwsJwtCompactConsumer)6 OAuthServiceException (org.apache.cxf.rs.security.oauth2.provider.OAuthServiceException)4 TxnIdIF (com.swiftmq.amqp.v100.generated.transactions.coordination.TxnIdIF)3 IOException (java.io.IOException)3 HashMap (java.util.HashMap)3 RefreshTokenGrant (org.apache.cxf.rs.security.oauth2.grants.refresh.RefreshTokenGrant)3 AccessToken (com.nimbusds.oauth2.sdk.token.AccessToken)2 BearerAccessToken (com.nimbusds.oauth2.sdk.token.BearerAccessToken)2 TypelessAccessToken (com.nimbusds.oauth2.sdk.token.TypelessAccessToken)2 Connection (com.swiftmq.amqp.v100.client.Connection)2 InvalidStateException (com.swiftmq.amqp.v100.client.InvalidStateException)2