EventStore / EventStoreDB-Client-Java

Official Asynchronous Java 8+ Client Library for EventStoreDB 20.6+
https://eventstore.com
Apache License 2.0
63 stars 20 forks source link

OptionsBase with UserCredentials #73

Closed jselamy closed 3 years ago

jselamy commented 3 years ago

Hi,

I wanted to know

YoEight commented 3 years ago

You don't have to do that. What makes you think otherwise?

jselamy commented 3 years ago

Thanks for the quick response.

This is why i'm saying that i have this connection-string -> esdb://admin:changeit@localhost:2111,localhost:2112,localhost:2113?tls=true&tlsVerifyCert=false&nodePreference=LEADER

Appending event on a stream with no ACL works (haven't gone for as testing with ACL's) Creating a PersistentSubscription on for a specific stream is not working with implicitly passing passing the credentials in the CreatePersistentSubscriptionOptions

Here's a snippet of my code.

        final String stream = "aStream";
        final String eventType = "aType";
        final String subscription_name = "subscription_name";
        EventStoreDBClientSettings settings = EventStoreDBConnectionString.parseOrThrow("esdb://admin:changeit@localhost:2111,localhost:2112,localhost:2113?tls=true&tlsVerifyCert=false&nodePreference=LEADER");
        EventStoreDBClient dbClient = EventStoreDBClient.create(settings);
        EventStoreDBPersistentSubscriptionsClient persistentSubClient = EventStoreDBPersistentSubscriptionsClient.create(settings);

        //appending to stream
        EventData eventData = EventData
            .builderAsJson(UUID.randomUUID(), eventType, new ESConfig.TestEvent("1", "dummy"))
            .build();
        AppendToStreamOptions options = AppendToStreamOptions.get()
                .expectedRevision(ExpectedRevision.ANY);

        dbClient.appendToStream(stream, options, eventData)
                .get();

        final UserCredentials credentials = new UserCredentials("admin", "changeit");

        //Creating a persistent sub
        persistentSubClient.create(stream, subscription_name, CreatePersistentSubscriptionOptions.get()
                .authenticated(credentials)
                .settings(PersistentSubscriptionSettings.builder().build()))
                .get();

Here in this snippet i explicitly have to give the UserCredentials to the com.eventstore.dbclient.OptionsBase#authenticated otherwise there's an exception of type Permission Denied

Caused by: io.grpc.StatusRuntimeException: PERMISSION_DENIED: Access Denied
    at io.grpc.Status.asRuntimeException(Status.java:533)
    at io.grpc.stub.ClientCalls$StreamObserverToCallListenerAdapter.onClose(ClientCalls.java:478)
    at io.grpc.internal.ClientCallImpl.closeObserver(ClientCallImpl.java:434)
    at io.grpc.internal.ClientCallImpl.access$500(ClientCallImpl.java:66)
    at io.grpc.internal.ClientCallImpl$ClientStreamListenerImpl$1StreamClosed.runInternal(ClientCallImpl.java:763)
    at io.grpc.internal.ClientCallImpl$ClientStreamListenerImpl$1StreamClosed.runInContext(ClientCallImpl.java:742)
    at io.grpc.internal.ContextRunnable.run(ContextRunnable.java:37)
    at io.grpc.internal.SerializingExecutor.run(SerializingExecutor.java:123)
    at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
    at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
    at java.base/java.lang.Thread.run(Thread.java:834)
YoEight commented 3 years ago

It's a bug that has been fixed by #71. A snapshot version is available on Sonatype

https://github.com/EventStore/EventStoreDB-Client-Java/issues/68#issuecomment-827502978

jselamy commented 3 years ago

@YoEight can you point me to that Sonatype of yours ?

YoEight commented 3 years ago

You can found the instruction in our READM.md file: https://github.com/EventStore/EventStoreDB-Client-Java#snapshot-versions