java - Implementation for Custom AuthenticationManager -


i trying implementing in simple application full customized login based on spring security, serve me base more complex project. in moment, need write custom authenticationmanager.

in other topic here stackoverflow, ilhave learned "the authenticationmanager delegates fetching of persistent user information 1 or more authenticationproviders". have 1 authenticationprovider user data database.

i read in other place (i can't find link anymore), configure methodsecurityconfig custompermissionevaluator in class (but how lost link, can't sure).

the problem have no idea how should put in code in minimal structure:

public class customauthenticationmanager implements authenticationmanager {      @override     public authentication authenticate(authentication arg0) throws authenticationexception {         // todo auto-generated method stub         return null;     }  } 

anyone can point me direction of how this? link tutorial, or github project contain class that, or of nature of great help.

ps.: classes security package are:

https://github.com/klebermo/webapp2/tree/master/src/com/spring/webapp/lojavirtual/config/security

update

ok, need correct third paragraph above: in fact, include authenticationmanager because when try run application, after include method:

protected methodsecurityexpressionhandler createexpressionhandler() {     defaultmethodsecurityexpressionhandler expressionhandler = new defaultmethodsecurityexpressionhandler();     expressionhandler.setpermissionevaluator(new custompermissionevaluator());     return expressionhandler; } 

to securityconfig, face error in console of eclipse, says need authenticationmanager.

org.springframework.beans.factory.beancreationexception: error creating bean name 'privadocontroller' defined in file [/home/kleber/workspace/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/webapp2/web-inf/classes/com/spring/webapp/lojavirtual/acesso/controller/privadocontroller.class]: initialization of bean failed; nested exception org.springframework.aop.framework.aopconfigexception: unexpected aop exception; nested exception org.springframework.beans.factory.beancreationexception: error creating bean name 'methodsecurityinterceptor' defined in class path resource [org/springframework/security/config/annotation/method/configuration/globalmethodsecurityconfiguration.class]: invocation of init method failed; nested exception java.lang.illegalargumentexception: authenticationmanager required     @ org.springframework.beans.factory.support.abstractautowirecapablebeanfactory.docreatebean(abstractautowirecapablebeanfactory.java:529)     @ org.springframework.beans.factory.support.abstractautowirecapablebeanfactory.createbean(abstractautowirecapablebeanfactory.java:458)     @ org.springframework.beans.factory.support.abstractbeanfactory$1.getobject(abstractbeanfactory.java:295)     @ org.springframework.beans.factory.support.defaultsingletonbeanregistry.getsingleton(defaultsingletonbeanregistry.java:223)     @ org.springframework.beans.factory.support.abstractbeanfactory.dogetbean(abstractbeanfactory.java:292)     @ org.springframework.beans.factory.support.abstractbeanfactory.getbean(abstractbeanfactory.java:194)     @ org.springframework.beans.factory.support.defaultlistablebeanfactory.preinstantiatesingletons(defaultlistablebeanfactory.java:628)     @ org.springframework.context.support.abstractapplicationcontext.finishbeanfactoryinitialization(abstractapplicationcontext.java:932)     @ org.springframework.context.support.abstractapplicationcontext.refresh(abstractapplicationcontext.java:479)     @ org.springframework.web.context.contextloader.configureandrefreshwebapplicationcontext(contextloader.java:389)     @ org.springframework.web.context.contextloader.initwebapplicationcontext(contextloader.java:294)     @ org.springframework.web.context.contextloaderlistener.contextinitialized(contextloaderlistener.java:112)     @ org.apache.catalina.core.standardcontext.listenerstart(standardcontext.java:4937)     @ org.apache.catalina.core.standardcontext.startinternal(standardcontext.java:5434)     @ org.apache.catalina.util.lifecyclebase.start(lifecyclebase.java:150)     @ org.apache.catalina.core.containerbase$startchild.call(containerbase.java:1559)     @ org.apache.catalina.core.containerbase$startchild.call(containerbase.java:1549)     @ java.util.concurrent.futuretask.run(futuretask.java:262)     @ java.util.concurrent.threadpoolexecutor.runworker(threadpoolexecutor.java:1145)     @ java.util.concurrent.threadpoolexecutor$worker.run(threadpoolexecutor.java:615)     @ java.lang.thread.run(thread.java:744) caused by: org.springframework.aop.framework.aopconfigexception: unexpected aop exception; nested exception org.springframework.beans.factory.beancreationexception: error creating bean name 'methodsecurityinterceptor' defined in class path resource [org/springframework/security/config/annotation/method/configuration/globalmethodsecurityconfiguration.class]: invocation of init method failed; nested exception java.lang.illegalargumentexception: authenticationmanager required     @ org.springframework.aop.framework.cglibaopproxy.getproxy(cglibaopproxy.java:224)     @ org.springframework.aop.framework.proxyfactory.getproxy(proxyfactory.java:111)     @ org.springframework.aop.framework.autoproxy.abstractautoproxycreator.createproxy(abstractautoproxycreator.java:477)     @ org.springframework.aop.framework.autoproxy.abstractautoproxycreator.wrapifnecessary(abstractautoproxycreator.java:362)     @ org.springframework.aop.framework.autoproxy.abstractautoproxycreator.postprocessafterinitialization(abstractautoproxycreator.java:322)     @ org.springframework.beans.factory.support.abstractautowirecapablebeanfactory.applybeanpostprocessorsafterinitialization(abstractautowirecapablebeanfactory.java:409)     @ org.springframework.beans.factory.support.abstractautowirecapablebeanfactory.initializebean(abstractautowirecapablebeanfactory.java:1488)     @ org.springframework.beans.factory.support.abstractautowirecapablebeanfactory.docreatebean(abstractautowirecapablebeanfactory.java:521)     ... 20 more caused by: org.springframework.beans.factory.beancreationexception: error creating bean name 'methodsecurityinterceptor' defined in class path resource [org/springframework/security/config/annotation/method/configuration/globalmethodsecurityconfiguration.class]: invocation of init method failed; nested exception java.lang.illegalargumentexception: authenticationmanager required     @ org.springframework.beans.factory.support.abstractautowirecapablebeanfactory.initializebean(abstractautowirecapablebeanfactory.java:1482)     @ org.springframework.beans.factory.support.abstractautowirecapablebeanfactory.docreatebean(abstractautowirecapablebeanfactory.java:521)     @ org.springframework.beans.factory.support.abstractautowirecapablebeanfactory.createbean(abstractautowirecapablebeanfactory.java:458)     @ org.springframework.beans.factory.support.abstractbeanfactory$1.getobject(abstractbeanfactory.java:295)     @ org.springframework.beans.factory.support.defaultsingletonbeanregistry.getsingleton(defaultsingletonbeanregistry.java:223)     @ org.springframework.beans.factory.support.abstractbeanfactory.dogetbean(abstractbeanfactory.java:292)     @ org.springframework.beans.factory.support.abstractbeanfactory.getbean(abstractbeanfactory.java:198)     @ org.springframework.security.access.intercept.aopalliance.methodsecuritymetadatasourceadvisor.getadvice(methodsecuritymetadatasourceadvisor.java:96)     @ org.springframework.aop.framework.cglibaopproxy$proxycallbackfilter.hashcode(cglibaopproxy.java:916)     @ org.springframework.cglib.proxy.enhancer$enhancerkey$$keyfactorybycglib$$4ce19e8f.hashcode(<generated>)     @ java.util.hashmap.hash(hashmap.java:366)     @ java.util.hashmap.getentry(hashmap.java:466)     @ java.util.hashmap.get(hashmap.java:421)     @ org.springframework.cglib.core.abstractclassgenerator.create(abstractclassgenerator.java:199)     @ org.springframework.cglib.proxy.enhancer.createhelper(enhancer.java:377)     @ org.springframework.cglib.proxy.enhancer.create(enhancer.java:285)     @ org.springframework.aop.framework.cglibaopproxy.getproxy(cglibaopproxy.java:205)     ... 27 more caused by: java.lang.illegalargumentexception: authenticationmanager required     @ org.springframework.util.assert.notnull(assert.java:112)     @ org.springframework.security.access.intercept.abstractsecurityinterceptor.afterpropertiesset(abstractsecurityinterceptor.java:121)     @ org.springframework.beans.factory.support.abstractautowirecapablebeanfactory.invokeinitmethods(abstractautowirecapablebeanfactory.java:1541)     @ org.springframework.beans.factory.support.abstractautowirecapablebeanfactory.initializebean(abstractautowirecapablebeanfactory.java:1479)     ... 43 more  abr 16, 2014 8:57:42 pm org.apache.catalina.core.standardcontext listenerstart grave: exception sending context initialized event listener instance of class org.springframework.web.context.contextloaderlistener org.springframework.beans.factory.beancreationexception: error creating bean name 'privadocontroller' defined in file [/home/kleber/workspace/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/webapp2/web-inf/classes/com/spring/webapp/lojavirtual/acesso/controller/privadocontroller.class]: initialization of bean failed; nested exception org.springframework.aop.framework.aopconfigexception: unexpected aop exception; nested exception org.springframework.beans.factory.beancreationexception: error creating bean name 'methodsecurityinterceptor' defined in class path resource [org/springframework/security/config/annotation/method/configuration/globalmethodsecurityconfiguration.class]: invocation of init method failed; nested exception java.lang.illegalargumentexception: authenticationmanager required     @ org.springframework.beans.factory.support.abstractautowirecapablebeanfactory.docreatebean(abstractautowirecapablebeanfactory.java:529)     @ org.springframework.beans.factory.support.abstractautowirecapablebeanfactory.createbean(abstractautowirecapablebeanfactory.java:458)     @ org.springframework.beans.factory.support.abstractbeanfactory$1.getobject(abstractbeanfactory.java:295)     @ org.springframework.beans.factory.support.defaultsingletonbeanregistry.getsingleton(defaultsingletonbeanregistry.java:223)     @ org.springframework.beans.factory.support.abstractbeanfactory.dogetbean(abstractbeanfactory.java:292)     @ org.springframework.beans.factory.support.abstractbeanfactory.getbean(abstractbeanfactory.java:194)     @ org.springframework.beans.factory.support.defaultlistablebeanfactory.preinstantiatesingletons(defaultlistablebeanfactory.java:628)     @ org.springframework.context.support.abstractapplicationcontext.finishbeanfactoryinitialization(abstractapplicationcontext.java:932)     @ org.springframework.context.support.abstractapplicationcontext.refresh(abstractapplicationcontext.java:479)     @ org.springframework.web.context.contextloader.configureandrefreshwebapplicationcontext(contextloader.java:389)     @ org.springframework.web.context.contextloader.initwebapplicationcontext(contextloader.java:294)     @ org.springframework.web.context.contextloaderlistener.contextinitialized(contextloaderlistener.java:112)     @ org.apache.catalina.core.standardcontext.listenerstart(standardcontext.java:4937)     @ org.apache.catalina.core.standardcontext.startinternal(standardcontext.java:5434)     @ org.apache.catalina.util.lifecyclebase.start(lifecyclebase.java:150)     @ org.apache.catalina.core.containerbase$startchild.call(containerbase.java:1559)     @ org.apache.catalina.core.containerbase$startchild.call(containerbase.java:1549)     @ java.util.concurrent.futuretask.run(futuretask.java:262)     @ java.util.concurrent.threadpoolexecutor.runworker(threadpoolexecutor.java:1145)     @ java.util.concurrent.threadpoolexecutor$worker.run(threadpoolexecutor.java:615)     @ java.lang.thread.run(thread.java:744) caused by: org.springframework.aop.framework.aopconfigexception: unexpected aop exception; nested exception org.springframework.beans.factory.beancreationexception: error creating bean name 'methodsecurityinterceptor' defined in class path resource [org/springframework/security/config/annotation/method/configuration/globalmethodsecurityconfiguration.class]: invocation of init method failed; nested exception java.lang.illegalargumentexception: authenticationmanager required     @ org.springframework.aop.framework.cglibaopproxy.getproxy(cglibaopproxy.java:224)     @ org.springframework.aop.framework.proxyfactory.getproxy(proxyfactory.java:111)     @ org.springframework.aop.framework.autoproxy.abstractautoproxycreator.createproxy(abstractautoproxycreator.java:477)     @ org.springframework.aop.framework.autoproxy.abstractautoproxycreator.wrapifnecessary(abstractautoproxycreator.java:362)     @ org.springframework.aop.framework.autoproxy.abstractautoproxycreator.postprocessafterinitialization(abstractautoproxycreator.java:322)     @ org.springframework.beans.factory.support.abstractautowirecapablebeanfactory.applybeanpostprocessorsafterinitialization(abstractautowirecapablebeanfactory.java:409)     @ org.springframework.beans.factory.support.abstractautowirecapablebeanfactory.initializebean(abstractautowirecapablebeanfactory.java:1488)     @ org.springframework.beans.factory.support.abstractautowirecapablebeanfactory.docreatebean(abstractautowirecapablebeanfactory.java:521)     ... 20 more caused by: org.springframework.beans.factory.beancreationexception: error creating bean name 'methodsecurityinterceptor' defined in class path resource [org/springframework/security/config/annotation/method/configuration/globalmethodsecurityconfiguration.class]: invocation of init method failed; nested exception java.lang.illegalargumentexception: authenticationmanager required     @ org.springframework.beans.factory.support.abstractautowirecapablebeanfactory.initializebean(abstractautowirecapablebeanfactory.java:1482)     @ org.springframework.beans.factory.support.abstractautowirecapablebeanfactory.docreatebean(abstractautowirecapablebeanfactory.java:521)     @ org.springframework.beans.factory.support.abstractautowirecapablebeanfactory.createbean(abstractautowirecapablebeanfactory.java:458)     @ org.springframework.beans.factory.support.abstractbeanfactory$1.getobject(abstractbeanfactory.java:295)     @ org.springframework.beans.factory.support.defaultsingletonbeanregistry.getsingleton(defaultsingletonbeanregistry.java:223)     @ org.springframework.beans.factory.support.abstractbeanfactory.dogetbean(abstractbeanfactory.java:292)     @ org.springframework.beans.factory.support.abstractbeanfactory.getbean(abstractbeanfactory.java:198)     @ org.springframework.security.access.intercept.aopalliance.methodsecuritymetadatasourceadvisor.getadvice(methodsecuritymetadatasourceadvisor.java:96)     @ org.springframework.aop.framework.cglibaopproxy$proxycallbackfilter.hashcode(cglibaopproxy.java:916)     @ org.springframework.cglib.proxy.enhancer$enhancerkey$$keyfactorybycglib$$4ce19e8f.hashcode(<generated>)     @ java.util.hashmap.hash(hashmap.java:366)     @ java.util.hashmap.getentry(hashmap.java:466)     @ java.util.hashmap.get(hashmap.java:421)     @ org.springframework.cglib.core.abstractclassgenerator.create(abstractclassgenerator.java:199)     @ org.springframework.cglib.proxy.enhancer.createhelper(enhancer.java:377)     @ org.springframework.cglib.proxy.enhancer.create(enhancer.java:285)     @ org.springframework.aop.framework.cglibaopproxy.getproxy(cglibaopproxy.java:205)     ... 27 more caused by: java.lang.illegalargumentexception: authenticationmanager required     @ org.springframework.util.assert.notnull(assert.java:112)     @ org.springframework.security.access.intercept.abstractsecurityinterceptor.afterpropertiesset(abstractsecurityinterceptor.java:121)     @ org.springframework.beans.factory.support.abstractautowirecapablebeanfactory.invokeinitmethods(abstractautowirecapablebeanfactory.java:1541)     @ org.springframework.beans.factory.support.abstractautowirecapablebeanfactory.initializebean(abstractautowirecapablebeanfactory.java:1479)     ... 43 more 

so, after more search in web, code customauthenticationmanager:

public class customauthenticationmanager implements authenticationmanager {      @autowired     private customauthenticationprovider authenticationprovider;      @override     public authentication authenticate(authentication authentication) throws authenticationexception {         system.out.println("customauthenticationmanager.authenticate");         return authenticationprovider.authenticate(authentication);     }  } 

and add class methodsecurityconfig make reference custompermissionevaluator:

@configuration @componentscan(value="com.spring.webapp.lojavirtual") @enableglobalmethodsecurity(prepostenabled = true) public class methodsecurityconfig extends globalmethodsecurityconfiguration {      protected methodsecurityexpressionhandler createexpressionhandler() {         system.out.println("methodsecurityconfig.createexpressionhandler");         defaultmethodsecurityexpressionhandler expressionhandler = new defaultmethodsecurityexpressionhandler();         expressionhandler.setpermissionevaluator(new custompermissionevaluator());         return expressionhandler;     }  } 

Comments

Popular posts from this blog

javascript - jquery or ashx not working -

opencv - DataType<cv::detail::deriv_type>::depth what is it used for -

python 3.x - Mapping specific letters onto a list of words -