Search in sources :

Example 1 with BaseAction

use of org.apache.qpid.server.util.BaseAction in project qpid-broker-j by apache.

the class PreemptiveAuthenticationTest method configForAnonymous.

private HttpTestHelper configForAnonymous() throws Exception {
    final Deque<BaseAction<Void, Exception>> deleteActions = new ArrayDeque<>();
    final Map<String, Object> authAttr = new HashMap<>();
    authAttr.put(AnonymousAuthenticationManager.TYPE, AnonymousAuthenticationManager.PROVIDER_TYPE);
    getHelper().submitRequest("authenticationprovider/myanon", "PUT", authAttr, SC_CREATED);
    deleteActions.add(object -> getHelper().submitRequest("authenticationprovider/myanon", "DELETE", SC_OK));
    final Map<String, Object> portAttr = new HashMap<>();
    portAttr.put(Port.TYPE, "HTTP");
    portAttr.put(Port.PORT, 0);
    portAttr.put(Port.AUTHENTICATION_PROVIDER, "myanon");
    portAttr.put(Port.PROTOCOLS, Collections.singleton(Protocol.HTTP));
    portAttr.put(Port.TRANSPORTS, Collections.singleton(Transport.TCP));
    getHelper().submitRequest("port/myport", "PUT", portAttr, SC_CREATED);
    deleteActions.add(object -> getHelper().submitRequest("port/myport", "DELETE", SC_OK));
    Map<String, Object> clientAuthPort = getHelper().getJsonAsMap("port/myport");
    int boundPort = Integer.parseInt(String.valueOf(clientAuthPort.get("boundPort")));
    assertThat(boundPort, is(greaterThan(0)));
    _tearDownActions = deleteActions;
    HttpTestHelper helper = new HttpTestHelper(getBrokerAdmin(), null, boundPort);
    helper.setPassword(null);
    helper.setUserName(null);
    return helper;
}
Also used : HashMap(java.util.HashMap) HttpTestHelper(org.apache.qpid.tests.http.HttpTestHelper) BaseAction(org.apache.qpid.server.util.BaseAction) ArrayDeque(java.util.ArrayDeque)

Example 2 with BaseAction

use of org.apache.qpid.server.util.BaseAction in project qpid-broker-j by apache.

the class PreemptiveAuthenticationTest method configForClientAuth.

private HttpTestHelper configForClientAuth(final String x500Name) throws Exception {
    final KeyCertificatePair clientKeyCertPair = getKeyCertPair(x500Name);
    final byte[] clientCertificate = clientKeyCertPair.getCertificate().getEncoded();
    final String clientKeyStore = createKeyStoreDataUrl(clientKeyCertPair);
    final KeyCertificatePair brokerKeyCertPair = getKeyCertPair(x500Name);
    final String brokerKeyStore = createKeyStoreDataUrl(brokerKeyCertPair);
    final Deque<BaseAction<Void, Exception>> deleteActions = new ArrayDeque<>();
    final Map<String, Object> authAttr = new HashMap<>();
    authAttr.put(ExternalAuthenticationManager.TYPE, "External");
    authAttr.put(ExternalAuthenticationManager.ATTRIBUTE_USE_FULL_DN, false);
    getHelper().submitRequest("authenticationprovider/myexternal", "PUT", authAttr, SC_CREATED);
    deleteActions.add(object -> getHelper().submitRequest("authenticationprovider/myexternal", "DELETE", SC_OK));
    final Map<String, Object> keystoreAttr = new HashMap<>();
    keystoreAttr.put(FileKeyStore.TYPE, "FileKeyStore");
    keystoreAttr.put(FileKeyStore.STORE_URL, brokerKeyStore);
    keystoreAttr.put(FileKeyStore.PASSWORD, STORE_PASSWORD);
    keystoreAttr.put(FileKeyStore.KEY_STORE_TYPE, KeyStore.getDefaultType());
    getHelper().submitRequest("keystore/mykeystore", "PUT", keystoreAttr, SC_CREATED);
    deleteActions.add(object -> getHelper().submitRequest("keystore/mykeystore", "DELETE", SC_OK));
    final Map<String, Object> truststoreAttr = new HashMap<>();
    truststoreAttr.put(ManagedPeerCertificateTrustStore.TYPE, ManagedPeerCertificateTrustStore.TYPE_NAME);
    truststoreAttr.put(ManagedPeerCertificateTrustStore.STORED_CERTIFICATES, Collections.singletonList(Base64.getEncoder().encodeToString(clientCertificate)));
    getHelper().submitRequest("truststore/mytruststore", "PUT", truststoreAttr, SC_CREATED);
    deleteActions.add(object -> getHelper().submitRequest("truststore/mytruststore", "DELETE", SC_OK));
    final Map<String, Object> portAttr = new HashMap<>();
    portAttr.put(Port.TYPE, "HTTP");
    portAttr.put(Port.PORT, 0);
    portAttr.put(Port.AUTHENTICATION_PROVIDER, "myexternal");
    portAttr.put(Port.PROTOCOLS, Collections.singleton(Protocol.HTTP));
    portAttr.put(Port.TRANSPORTS, Collections.singleton(Transport.SSL));
    portAttr.put(Port.NEED_CLIENT_AUTH, true);
    portAttr.put(Port.KEY_STORE, "mykeystore");
    portAttr.put(Port.TRUST_STORES, Collections.singletonList("mytruststore"));
    getHelper().submitRequest("port/myport", "PUT", portAttr, SC_CREATED);
    deleteActions.add(object -> getHelper().submitRequest("port/myport", "DELETE", SC_OK));
    Map<String, Object> clientAuthPort = getHelper().getJsonAsMap("port/myport");
    int boundPort = Integer.parseInt(String.valueOf(clientAuthPort.get("boundPort")));
    assertThat(boundPort, is(greaterThan(0)));
    _tearDownActions = deleteActions;
    HttpTestHelper helper = new HttpTestHelper(getBrokerAdmin(), null, boundPort);
    helper.setTls(true);
    helper.setKeyStore(clientKeyStore, STORE_PASSWORD);
    return helper;
}
Also used : KeyCertificatePair(org.apache.qpid.test.utils.tls.KeyCertificatePair) HashMap(java.util.HashMap) HttpTestHelper(org.apache.qpid.tests.http.HttpTestHelper) BaseAction(org.apache.qpid.server.util.BaseAction) ArrayDeque(java.util.ArrayDeque)

Aggregations

ArrayDeque (java.util.ArrayDeque)2 HashMap (java.util.HashMap)2 BaseAction (org.apache.qpid.server.util.BaseAction)2 HttpTestHelper (org.apache.qpid.tests.http.HttpTestHelper)2 KeyCertificatePair (org.apache.qpid.test.utils.tls.KeyCertificatePair)1