java - Why am I getting a com.stormpath.sdk.lang.InstantiationException while trying to get an OAuth2 key from Stormpath? -
i'm building java rest api, using jersey. tomcat web server. user account , oauth2 key management, i'm using stormpath's java sdk. have 1 sample user created through website, , every time post json username/password request account app's v1/token
endpoint in postman, exception , stacktrace:
com.stormpath.sdk.lang.instantiationexception: unable instantiate instance constructor [public com.stormpath.sdk.impl.oauth.defaultaccesstoken(com.stormpath.sdk.impl.ds.internaldatastore,java.util.map)] @ com.stormpath.sdk.lang.classes.instantiate(classes.java:191) @ com.stormpath.sdk.impl.ds.defaultresourcefactory.instantiate(defaultresourcefactory.java:65) @ com.stormpath.sdk.impl.ds.defaultdatastore.instantiate(defaultdatastore.java:170) @ com.stormpath.sdk.impl.oauth.defaultgrantauthenticationtoken.getasaccesstoken(defaultgrantauthenticationtoken.java:79) @ com.stormpath.sdk.impl.oauth.defaultoauthgrantauthenticationresultbuilder.build(defaultoauthgrantauthenticationresultbuilder.java:87) @ com.stormpath.sdk.impl.oauth.defaultoauthgrantauthenticationresultbuilder.build(defaultoauthgrantauthenticationresultbuilder.java:24) @ com.stormpath.sdk.impl.oauth.defaultpasswordgrantauthenticator.authenticate(defaultpasswordgrantauthenticator.java:56) @ com.stormpath.sdk.impl.oauth.defaultpasswordgrantauthenticator.authenticate(defaultpasswordgrantauthenticator.java:28) @ com.ficcy.api.services.authservice.gettoken(authservice.java:33) @ sun.reflect.nativemethodaccessorimpl.invoke0(native method) @ sun.reflect.nativemethodaccessorimpl.invoke(nativemethodaccessorimpl.java:62) @ sun.reflect.delegatingmethodaccessorimpl.invoke(delegatingmethodaccessorimpl.java:43) @ java.lang.reflect.method.invoke(method.java:497) @ org.glassfish.jersey.server.model.internal.resourcemethodinvocationhandlerfactory$1.invoke(resourcemethodinvocationhandlerfactory.java:81) @ org.glassfish.jersey.server.model.internal.abstractjavaresourcemethoddispatcher$1.run(abstractjavaresourcemethoddispatcher.java:144) @ org.glassfish.jersey.server.model.internal.abstractjavaresourcemethoddispatcher.invoke(abstractjavaresourcemethoddispatcher.java:161) @ org.glassfish.jersey.server.model.internal.javaresourcemethoddispatcherprovider$typeoutinvoker.dodispatch(javaresourcemethoddispatcherprovider.java:205) @ org.glassfish.jersey.server.model.internal.abstractjavaresourcemethoddispatcher.dispatch(abstractjavaresourcemethoddispatcher.java:99) @ org.glassfish.jersey.server.model.resourcemethodinvoker.invoke(resourcemethodinvoker.java:389) @ org.glassfish.jersey.server.model.resourcemethodinvoker.apply(resourcemethodinvoker.java:347) @ org.glassfish.jersey.server.model.resourcemethodinvoker.apply(resourcemethodinvoker.java:102) @ org.glassfish.jersey.server.serverruntime$2.run(serverruntime.java:326) @ org.glassfish.jersey.internal.errors$1.call(errors.java:271) @ org.glassfish.jersey.internal.errors$1.call(errors.java:267) @ org.glassfish.jersey.internal.errors.process(errors.java:315) @ org.glassfish.jersey.internal.errors.process(errors.java:297) @ org.glassfish.jersey.internal.errors.process(errors.java:267) @ org.glassfish.jersey.process.internal.requestscope.runinscope(requestscope.java:317) @ org.glassfish.jersey.server.serverruntime.process(serverruntime.java:305) @ org.glassfish.jersey.server.applicationhandler.handle(applicationhandler.java:1154) @ org.glassfish.jersey.servlet.webcomponent.serviceimpl(webcomponent.java:471) @ org.glassfish.jersey.servlet.webcomponent.service(webcomponent.java:425) @ org.glassfish.jersey.servlet.servletcontainer.service(servletcontainer.java:383) @ org.glassfish.jersey.servlet.servletcontainer.service(servletcontainer.java:336) @ org.glassfish.jersey.servlet.servletcontainer.service(servletcontainer.java:223) @ org.apache.catalina.core.applicationfilterchain.internaldofilter(applicationfilterchain.java:291) @ org.apache.catalina.core.applicationfilterchain.dofilter(applicationfilterchain.java:206) @ org.apache.tomcat.websocket.server.wsfilter.dofilter(wsfilter.java:52) @ org.apache.catalina.core.applicationfilterchain.internaldofilter(applicationfilterchain.java:239) @ org.apache.catalina.core.applicationfilterchain.dofilter(applicationfilterchain.java:206) @ org.apache.catalina.core.standardwrappervalve.invoke(standardwrappervalve.java:219) @ org.apache.catalina.core.standardcontextvalve.invoke(standardcontextvalve.java:106) @ org.apache.catalina.authenticator.authenticatorbase.invoke(authenticatorbase.java:502) @ org.apache.catalina.core.standardhostvalve.invoke(standardhostvalve.java:142) @ org.apache.catalina.valves.errorreportvalve.invoke(errorreportvalve.java:79) @ org.apache.catalina.core.standardenginevalve.invoke(standardenginevalve.java:88) @ org.apache.catalina.connector.coyoteadapter.service(coyoteadapter.java:518) @ org.apache.coyote.http11.abstracthttp11processor.process(abstracthttp11processor.java:1091) @ org.apache.coyote.abstractprotocol$abstractconnectionhandler.process(abstractprotocol.java:668) @ org.apache.tomcat.util.net.nioendpoint$socketprocessor.dorun(nioendpoint.java:1521) @ org.apache.tomcat.util.net.nioendpoint$socketprocessor.run(nioendpoint.java:1478) @ java.util.concurrent.threadpoolexecutor.runworker(threadpoolexecutor.java:1142) @ java.util.concurrent.threadpoolexecutor$worker.run(threadpoolexecutor.java:617) @ org.apache.tomcat.util.threads.taskthread$wrappingrunnable.run(taskthread.java:61) @ java.lang.thread.run(thread.java:745) caused by: java.lang.reflect.invocationtargetexception @ sun.reflect.nativeconstructoraccessorimpl.newinstance0(native method) @ sun.reflect.nativeconstructoraccessorimpl.newinstance(nativeconstructoraccessorimpl.java:62) @ sun.reflect.delegatingconstructoraccessorimpl.newinstance(delegatingconstructoraccessorimpl.java:45) @ java.lang.reflect.constructor.newinstance(constructor.java:422) @ com.stormpath.sdk.lang.classes.instantiate(classes.java:188) ... 54 more caused by: io.jsonwebtoken.jwtexception: jwt failed validation; cannot trusted. @ com.stormpath.sdk.impl.oauth.defaultaccesstoken.ensureaccesstoken(defaultaccesstoken.java:56) @ com.stormpath.sdk.impl.oauth.defaultaccesstoken.<init>(defaultaccesstoken.java:35) ... 59 more
my json:
{ "login": "**email**", "password": "**password**" }
there wasn't in docs exception. endpoint/service. (i started catching , exceptions take @ happening. also, authrequest simple bean not null constraints on login , password fields):
package com.ficcy.api.services; //truncated imports @path("/token") public class authservice { @post @consumes(mediatype.application_json) @produces(mediatype.application_json) public accesstoken gettoken(authrequest ar) { accesstoken rtn = null; try { passwordgrantrequest pgr = oauth2requests.password_grant_request.builder().setlogin(ar.getlogin()) .setpassword(ar.getpassword()).build(); oauthgrantauthenticationresult authresult = authenticators.password_grant_authenticator .forapplication(config.getapplication()).authenticate(pgr); rtn = authresult.getaccesstoken(); } catch (exception e) { system.err.println(e.getmessage()); e.printstacktrace(); } return rtn; } }
edit: here's config class, store stormpath application:
package com.ficcy.api.config; //truncated imports public class config { private static client client = clients.builder().build(); private static application application; static { tenant tenant = client.getcurrenttenant(); applicationlist applications = tenant .getapplications(applications.where(applications.name().eqignorecase("ficcy-api"))); application = applications.iterator().next(); } public static client getclient() { return client; } public static application getapplication() { return application; } public static hashids gethashid(string salt) { return new hashids(salt, 6); } }
and build.gradle:
repositories { mavencentral() } apply plugin: 'java' apply plugin: 'war' apply plugin: 'eclipse-wtp' apply from: 'https://raw.github.com/akhikhl/gretty/master/pluginscripts/gretty.plugin' dependencies { compile 'org.glassfish.jersey.core:jersey-server:2.22.1' compile 'org.glassfish.jersey.containers:jersey-container-servlet-core:2.22.1' compile 'org.glassfish.jersey.core:jersey-client:2.22.1' compile 'org.glassfish.jersey.containers:jersey-container-servlet:2.22.1' compile 'org.glassfish.jersey.security:oauth1-client:2.22.1' compile 'org.glassfish.jersey.media:jersey-media-json-jackson:2.22.1' compile 'mysql:mysql-connector-java:5.1.38' compile 'com.stormpath.sdk:stormpath-sdk-api:1.0.rc8.3' compile 'junit:junit-dep:4.+' compile 'org.hashids:hashids:1.0.1' testcompile 'junit:junit-dep:4.+' runtime 'com.stormpath.sdk:stormpath-sdk-impl:1.0.rc8.3' runtime 'com.stormpath.sdk:stormpath-sdk-httpclient:1.0.rc8.3' } gretty { port = 8080 servletcontainer = 'tomcat8' fastreload = true contextpath = '/' httpsenabled = true }
are sure getting error when creating access_token
? have suspicion trying authenticate erroneous access_token
. try re-creating , re-executing piece of code throwing exception time newly generated access_token
?
Comments
Post a Comment