Thursday, 15 March 2012

exception - Spring-Security-Oauth2: java.lang.NoClassDefFoundError: org/springframework/security/authentication/InternalAuthenticationServiceException -



exception - Spring-Security-Oauth2: java.lang.NoClassDefFoundError: org/springframework/security/authentication/InternalAuthenticationServiceException -

i trying integrate oauth2.0 spring security in web application using java based configuration. when trying tun sample application, thow exception below:

severe: exception sending context initialized event listener instance of class org.springframework.web.context.contextloaderlistener org.springframework.beans.factory.beancreationexception: error creating bean name 'com.harmeetsingh13.config.oauth2springsecurityconfig$oauthwebsecurityconfigureadapter': injection of autowired dependencies failed; nested exception org.springframework.beans.factory.beancreationexception: not autowire field: private org.springframework.security.oauth2.provider.client.clientcredentialstokenendpointfilter com.harmeetsingh13.config.oauth2springsecurityconfig$oauthwebsecurityconfigureadapter.clientcredentialstokenendpointfilter; nested exception org.springframework.beans.factory.beancreationexception: error creating bean name 'clientcredentialstokenendpointfilter' defined in class com.harmeetsingh13.config.oauth2springsecurityconfig: instantiation of bean failed; nested exception org.springframework.beans.factory.beandefinitionstoreexception: mill method [public org.springframework.security.oauth2.provider.client.clientcredentialstokenendpointfilter com.harmeetsingh13.config.oauth2springsecurityconfig.clientcredentialstokenendpointfilter(org.springframework.security.authentication.authenticationmanager)] threw exception; nested exception java.lang.noclassdeffounderror: org/springframework/security/authentication/internalauthenticationserviceexception @ org.springframework.beans.factory.annotation.autowiredannotationbeanpostprocessor.postprocesspropertyvalues(autowiredannotationbeanpostprocessor.java:334) @ org.springframework.beans.factory.support.abstractautowirecapablebeanfactory.populatebean(abstractautowirecapablebeanfactory.java:1204) @ org.springframework.beans.factory.support.abstractautowirecapablebeanfactory.docreatebean(abstractautowirecapablebeanfactory.java:538) @ org.springframework.beans.factory.support.abstractautowirecapablebeanfactory.createbean(abstractautowirecapablebeanfactory.java:476) @ org.springframework.beans.factory.support.abstractbeanfactory$1.getobject(abstractbeanfactory.java:302) @ org.springframework.beans.factory.support.defaultsingletonbeanregistry.getsingleton(defaultsingletonbeanregistry.java:229) @ org.springframework.beans.factory.support.abstractbeanfactory.dogetbean(abstractbeanfactory.java:298) @ org.springframework.beans.factory.support.abstractbeanfactory.getbean(abstractbeanfactory.java:193) @ org.springframework.beans.factory.support.defaultlistablebeanfactory.preinstantiatesingletons(defaultlistablebeanfactory.java:725) @ org.springframework.context.support.abstractapplicationcontext.finishbeanfactoryinitialization(abstractapplicationcontext.java:757) @ org.springframework.context.support.abstractapplicationcontext.refresh(abstractapplicationcontext.java:480) @ org.springframework.web.context.contextloader.configureandrefreshwebapplicationcontext(contextloader.java:403) @ org.springframework.web.context.contextloader.initwebapplicationcontext(contextloader.java:306) @ org.springframework.web.context.contextloaderlistener.contextinitialized(contextloaderlistener.java:106) @ org.apache.catalina.core.standardcontext.listenerstart(standardcontext.java:4749) @ org.apache.catalina.core.standardcontext.startinternal(standardcontext.java:5175) @ org.apache.catalina.util.lifecyclebase.start(lifecyclebase.java:150) @ org.apache.catalina.core.containerbase$startchild.call(containerbase.java:1408) @ org.apache.catalina.core.containerbase$startchild.call(containerbase.java:1398) @ java.util.concurrent.futuretask.run(futuretask.java:266) @ java.util.concurrent.threadpoolexecutor.runworker(threadpoolexecutor.java:1142) @ java.util.concurrent.threadpoolexecutor$worker.run(threadpoolexecutor.java:617) @ java.lang.thread.run(thread.java:745) caused by: org.springframework.beans.factory.beancreationexception: not autowire field: private org.springframework.security.oauth2.provider.client.clientcredentialstokenendpointfilter com.harmeetsingh13.config.oauth2springsecurityconfig$oauthwebsecurityconfigureadapter.clientcredentialstokenendpointfilter; nested exception org.springframework.beans.factory.beancreationexception: error creating bean name 'clientcredentialstokenendpointfilter' defined in class com.harmeetsingh13.config.oauth2springsecurityconfig: instantiation of bean failed; nested exception org.springframework.beans.factory.beandefinitionstoreexception: mill method [public org.springframework.security.oauth2.provider.client.clientcredentialstokenendpointfilter com.harmeetsingh13.config.oauth2springsecurityconfig.clientcredentialstokenendpointfilter(org.springframework.security.authentication.authenticationmanager)] threw exception; nested exception java.lang.noclassdeffounderror: org/springframework/security/authentication/internalauthenticationserviceexception @ org.springframework.beans.factory.annotation.autowiredannotationbeanpostprocessor$autowiredfieldelement.inject(autowiredannotationbeanpostprocessor.java:555) @ org.springframework.beans.factory.annotation.injectionmetadata.inject(injectionmetadata.java:87) @ org.springframework.beans.factory.annotation.autowiredannotationbeanpostprocessor.postprocessproperty

following spring data, java based configuration code:

@configuration @enabletransactionmanagement @enablejparepositories(basepackages={"com.harmeetsingh13.repo"}) @propertysource(value="classpath:properties/db.properties") public class springdataconfig { @autowired private environment environment; @bean public datasource datasource() { try{ combopooleddatasource datasource = new combopooleddatasource(); datasource.setjdbcurl(environment.getproperty("db.url")); datasource.setdriverclass(environment.getproperty("db.driver.class")); datasource.setuser(environment.getproperty("db.username")); datasource.setpassword(environment.getproperty("db.password")); datasource.setacquireincrement(5); datasource.setidleconnectiontestperiod(60); datasource.setmaxpoolsize(100); datasource.setmaxstatements(50); datasource.setminpoolsize(10); homecoming datasource; }catch(exception ex){ throw new runtimeexception(ex); } } private jpavendoradapter jpavendoradapter() { hibernatejpavendoradapter jpavendoradapter = new hibernatejpavendoradapter(); jpavendoradapter.setshowsql(true); jpavendoradapter.setdatabase(database.mysql); homecoming jpavendoradapter; } @bean @autowired public localcontainerentitymanagerfactorybean entitymanagerfactory(datasource datasource) { localcontainerentitymanagerfactorybean factorybean = new localcontainerentitymanagerfactorybean(); factorybean.setdatasource(datasource); factorybean.setpackagestoscan(environment.getproperty("package.scan")); factorybean.setpersistenceproviderclass(hibernatepersistenceprovider.class); factorybean.setjpavendoradapter(jpavendoradapter()); homecoming factorybean; } @bean @autowired public jpatransactionmanager transactionmanager(localcontainerentitymanagerfactorybean factorybean) { jpatransactionmanager transactionmanager = new jpatransactionmanager(); transactionmanager.setentitymanagerfactory(factorybean.getobject()); homecoming transactionmanager; }

}

follwoing oauth2.0 integration code:

@configuration @enablewebmvcsecurity @enableauthorizationserver public class oauth2springsecurityconfig extends authorizationserverconfigureradapter{ @autowired private datasource datasource; @bean @autowired public clientdetailsservice clientdetailservice() { homecoming new jdbcclientdetailsservice(datasource); } @bean public passwordencoder passwordencoder() { homecoming new bcryptpasswordencoder(11); } @bean @autowired public userdetailsservice userdetailservice(clientdetailsservice clientdetailsservice) { homecoming new clientdetailsuserdetailsservice(clientdetailsservice); } @bean public tokenstore tokenstore() { homecoming new jdbctokenstore(datasource); } @bean @autowired public defaulttokenservices tokenservice(tokenstore tokenstore, clientdetailsservice clientdetailsservice) { defaulttokenservices tokenservices = new defaulttokenservices(); tokenservices.settokenstore(tokenstore); tokenservices.setclientdetailsservice(clientdetailsservice); homecoming tokenservices; } @bean @autowired public defaultoauth2requestfactory oauth2requestfactory(clientdetailsservice clientdetailsservice) { defaultoauth2requestfactory requestfactory = new defaultoauth2requestfactory(clientdetailsservice); homecoming requestfactory; } @bean @autowired public tokenstoreuserapprovalhandler userapprovalhandler(defaultoauth2requestfactory requestfactory, tokenstore tokenstore) { tokenstoreuserapprovalhandler userapprovalhandler = new tokenstoreuserapprovalhandler(); userapprovalhandler.setrequestfactory(requestfactory); userapprovalhandler.settokenstore(tokenstore); homecoming userapprovalhandler; } @bean(name="clientauthenticationentrypoint") public oauth2authenticationentrypoint clientauthenticationentrypoint() { oauth2authenticationentrypoint entrypoint = new oauth2authenticationentrypoint(); entrypoint.setrealmname("authorization/client"); entrypoint.settypename("basic"); homecoming entrypoint; } @bean(name="oauthauthenticationentrypoint") public oauth2authenticationentrypoint oauthauthenticationentrypoint() { oauth2authenticationentrypoint entrypoint = new oauth2authenticationentrypoint(); entrypoint.setrealmname("authorization"); homecoming entrypoint; } @bean public oauth2accessdeniedhandler oauthaccessdeniedhandler() { oauth2accessdeniedhandler accessdeniedhandler = new oauth2accessdeniedhandler(); homecoming accessdeniedhandler; } @bean @autowired public authenticationmanager getauthenticationmanager(clientdetailsservice clientdetailsservice,defaulttokenservices tokenservices) { oauth2authenticationmanager authenticationmanager = new oauth2authenticationmanager(); authenticationmanager.setclientdetailsservice(clientdetailsservice); authenticationmanager.settokenservices(tokenservices); homecoming authenticationmanager; } //oauth have different ways check user credentials client_cridentials, password etc. client_cridentials @bean @autowired public clientcredentialstokenendpointfilter clientcredentialstokenendpointfilter(authenticationmanager authenticationmanager) { clientcredentialstokenendpointfilter accesstokenprovider = new clientcredentialstokenendpointfilter(); accesstokenprovider.setauthenticationmanager(authenticationmanager); homecoming accesstokenprovider; } @bean public oauth2protectedresourcedetails protectedresources() { oauth2protectedresourcedetails protectedresourcedetails = new clientcredentialsresourcedetails(); homecoming protectedresourcedetails; } @configuration @enableauthorizationserver public static class autorizationendpoints extends authorizationserverconfigureradapter{ @autowired private clientdetailsservice clientdetailservice; @autowired private defaultoauth2requestfactory requestfactory; @autowired private userapprovalhandler userapprovalhandler; @autowired private defaulttokenservices tokenservice; @autowired private authenticationmanager authenticationmanager; @override public void configure(authorizationserverendpointsconfigurer endpoints) throws exception { endpoints.clientdetailsservice(clientdetailservice); endpoints.requestfactory(requestfactory); endpoints.userapprovalhandler(userapprovalhandler); endpoints.tokenservices(tokenservice); endpoints.authenticationmanager(authenticationmanager); } } @configuration @enableresourceserver public static class resurceserverconfig extends resourceserverconfigureradapter{ @autowired private userdetailsservice userdetailsservice; @autowired private defaulttokenservices tokenservices; @autowired private oauth2authenticationentrypoint oauthauthenticationentrypoint; @autowired private oauth2accessdeniedhandler oauthaccessdeniedhandler; @override public void configure(resourceserversecurityconfigurer resources) throws exception { resources.resourceid("rsourceid"); resources.tokenservices(tokenservices); } @override public void configure(httpsecurity http) throws exception { http.userdetailsservice(userdetailsservice) .anonymous().disable() .authorizerequests() .antmatchers("/api/**", "/user/**").hasrole("user") .antmatchers("/admin/**").hasrole("admin") .and() .httpbasic() .authenticationentrypoint(oauthauthenticationentrypoint) .and() .sessionmanagement().sessioncreationpolicy(sessioncreationpolicy.stateless) .and() .exceptionhandling().accessdeniedhandler(oauthaccessdeniedhandler); } } @order(1) @configuration @enableglobalmethodsecurity(prepostenabled = true) public static class websecurityconfig extends websecurityconfigureradapter{ @autowired private userdetailsservice userdetailsservice; /*@override @bean(name = "authenticationmanager") public authenticationmanager authenticationmanagerbean() throws exception { homecoming super.authenticationmanagerbean(); }*/ @override protected void configure(authenticationmanagerbuilder auth) throws exception { auth.userdetailsservice(userdetailsservice); } } @order(2) @configuration @enableglobalmethodsecurity(prepostenabled = true) public static class oauthwebsecurityconfigureadapter extends websecurityconfigureradapter{ @autowired private userdetailsservice userdetailsservice; @autowired private oauth2authenticationentrypoint clientauthenticationentrypoint; @autowired private clientcredentialstokenendpointfilter clientcredentialstokenendpointfilter; @autowired private oauth2accessdeniedhandler oauthaccessdeniedhandler; @override protected void configure(httpsecurity http) throws exception { http.userdetailsservice(userdetailsservice) .anonymous().disable() .authorizerequests() .antmatchers("/oauth/token") .fullyauthenticated() .and() .httpbasic() .authenticationentrypoint(clientauthenticationentrypoint) .and() .addfilterbefore(clientcredentialstokenendpointfilter, basicauthenticationfilter.class) .sessionmanagement().sessioncreationpolicy(sessioncreationpolicy.stateless) .and() .exceptionhandling().accessdeniedhandler(oauthaccessdeniedhandler); } } @order(3) @configuration @enableglobalmethodsecurity(prepostenabled = true) public static class webapplicationsecurityconfig extends websecurityconfigureradapter { @override protected void configure(httpsecurity http) throws exception { http .csrf().disable() .formlogin() .loginpage("/login") .failureurl("/login?login=error") .defaultsuccessurl("/successhandler") .and() .logout() .logouturl("/logout") .logoutsuccessurl("/login"); } } @order(4) @configuration @enableglobalmethodsecurity(prepostenabled = true) public static class assetssecurityconfig extends websecurityconfigureradapter{ @override public void configure(websecurity web) throws exception { web.ignoring() .antmatchers("/assets/**"); } } }

thanks in advance solution. stuck in problem.

java exception spring-security spring-security-oauth2

No comments:

Post a Comment