cyberark / conjur-api-java

Java client for the CyberArk Conjur API
Apache License 2.0
17 stars 14 forks source link

NullPointerException when using single Conjur instance to retrieve multiple secrets #16

Open derekjwashington opened 6 years ago

derekjwashington commented 6 years ago

When running the following test I receive the exception below. I am attempting to retrieve multiple secrets from a single Conjur instance. My goal is to inject a Conjur singleton into a class for parsing a config file that contains references to Conjur secrets.

If I instantiate Conjur each time I retrieve a secret then the test succeeds

    @Test
    public void getMultiple() {

        System.setProperty("CONJUR_ACCOUNT", "cloud");
        System.setProperty("CONJUR_AUTHN_LOGIN", "host/configuration-service");
        System.setProperty("CONJUR_AUTHN_API_KEY", "3c4gtv62qeprhbyedben2t4pa6s3jj5q8y12t356s3nzxtxg2vh8yrw");
        System.setProperty("CONJUR_APPLIANCE_URL", "http://localhost:8080");
        Conjur conjur = new Conjur();
        String username = conjur.variables().retrieveSecret("mongo/username");
//        conjur = new Conjur();
        String password = conjur.variables().retrieveSecret("mongo/password");
        System.out.format("%s/$s\n", username, password);
    }
javax.ws.rs.ProcessingException: java.lang.NullPointerException
    at org.apache.cxf.jaxrs.client.AbstractClient.checkClientException(AbstractClient.java:544)
    at org.apache.cxf.jaxrs.client.AbstractClient.preProcessResult(AbstractClient.java:526)
    at org.apache.cxf.jaxrs.client.WebClient.doResponse(WebClient.java:1093)
    at org.apache.cxf.jaxrs.client.WebClient.doChainedInvocation(WebClient.java:1052)
    at org.apache.cxf.jaxrs.client.WebClient.doInvoke(WebClient.java:854)
    at org.apache.cxf.jaxrs.client.WebClient.doInvoke(WebClient.java:825)
    at org.apache.cxf.jaxrs.client.WebClient.invoke(WebClient.java:393)
    at org.apache.cxf.jaxrs.client.WebClient$SyncInvokerImpl.method(WebClient.java:1567)
    at org.apache.cxf.jaxrs.client.WebClient$SyncInvokerImpl.get(WebClient.java:1487)
    at org.apache.cxf.jaxrs.client.spec.InvocationBuilderImpl.get(InvocationBuilderImpl.java:81)
    at net.conjur.api.clients.ResourceClient.retrieveSecret(ResourceClient.java:30)
    at net.conjur.api.Variables.retrieveSecret(Variables.java:15)
    at com.insulet.cloud.config.ConjurTest.getValue(ConjurTest.java:18)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
    at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
    at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
    at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
    at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
    at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
    at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68)
    at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:47)
    at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242)
    at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)
Caused by: java.lang.NullPointerException
    at org.joda.time.format.DateTimeFormatterBuilder$NumberFormatter.parseInto(DateTimeFormatterBuilder.java:1305)
    at org.joda.time.format.DateTimeFormatterBuilder$Composite.parseInto(DateTimeFormatterBuilder.java:2516)
    at org.joda.time.format.DateTimeFormatter.parseDateTime(DateTimeFormatter.java:925)
    at net.conjur.api.Token.getTimestamp(Token.java:57)
    at net.conjur.api.Token.getExpiration(Token.java:65)
    at net.conjur.api.Token.willExpireWithin(Token.java:74)
    at net.conjur.util.rs.TokenAuthFilter.isTokenValid(TokenAuthFilter.java:35)
    at net.conjur.util.rs.TokenAuthFilter.filter(TokenAuthFilter.java:27)
    at org.apache.cxf.jaxrs.client.spec.ClientRequestFilterInterceptor.handleMessage(ClientRequestFilterInterceptor.java:60)
    at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:308)
    at org.apache.cxf.jaxrs.client.AbstractClient.doRunInterceptorChain(AbstractClient.java:611)
    at org.apache.cxf.jaxrs.client.WebClient.doChainedInvocation(WebClient.java:1051)
    ... 31 more
{
"protected":"eyJhbGciOiJjb25qdXIub3JnL3Nsb3NpbG8vdjIiLCJraWQiOiJiOTQ3Y2NiMTY2NjQwOGZmYmQxMzRkMDNlMTRlNDg2ZSJ9",
"payload":"eyJzdWIiOiJob3N0L2NvbmZpZ3VyYXRpb24tc2VydmljZSIsImlhdCI6MTUxNjczNDA5Mn0=",
"signature":"nbGvUbQyZS_ndiFd9boSDpGlJb3AlKaKV-HrHSvDkjElR2xUPRhyeGI0DBcQGUwv62nXt_fYtF5I9YdXaPhx5mG3UT7p_tvIT4cNXlXIy8AqkwbDCha4hNtxKy0Ut89t5fx-OaJxa8oLFNeS3gbLG7h9ziYoEsV3tpWovvVjwoNdZ9iM8sziL4fJpgkxN0aIjPSlGcasRAgLMZCYrZzg3rPr9t4EBCkgfZTEnC2jmXe_i549lNWP5tKUUaMXo2AfMKDX9t8CG_bC-oqy7OPuSRiztf4Bk_VrdTxZjeqcPrFRtN_CotK99iE-hqVmOGnnDKuzv10Y7FMyjcXcgyEwsmfe7lIZU2Ln671UUM6n9LMPIbNTV-DAGNzo66nvf4lq"
}
AndrewCopeland commented 4 years ago

To resolve this issue cxf-core-3.3.5.jar must be a Referenced Libraries