日韩久久久精品,亚洲精品久久久久久久久久久,亚洲欧美一区二区三区国产精品 ,一区二区福利

Spring security 3.1 +JSF 2.0 . problem with

系統(tǒng) 1943 0

Hy .What i am trying to do is to integrate Spring security with a Jsf+spring IOC +hibernate application.I have managed to set the login page and filter some other pages.So far so good, but when i tried to put @Secured or @PreAuthorize annotation on methods inside managedBeans (inside Dao's the annotation do work), i realized they do absolutely nothing. I have read that i need FORCE class proxies. Spring uses proxy based aop,the managed bean implements an interface hence jdk dynamic proxy instead of class proxy is used. So i did this in my config file:

      
        <
      
      
        beans 
      
      
        xmlns
      
      
        ="http://www.springframework.org/schema/beans"
      
      
        

xmlns:xsi
      
      
        ="http://www.w3.org/2001/XMLSchema-instance"
      
      
        

    xmlns:aop
      
      
        ="http://www.springframework.org/schema/aop"
      
      
        **    

xsi:schemaLocation
      
      
        ="http://www.springframework.org/schema/beans 

http://www.springframework.org/schema/beans/spring-beans-2.5.xsd         

http://www.springframework.org/schema/aop 

    http://www.springframework.org/schema/aop/spring-aop-3.0.xsd"
      
      
        >
      
      
        <
      
      
        aop:aspectj-autoproxy 
      
      
        proxy-target-class
      
      
        ="true"
      
      
        />
      
      
        

 //the rest of the beans

 
      
      
        </
      
      
        beans
      
      
        >
      
    

The applicationContext-security Xml looks like this:

      
        <?
      
      
        xml version="1.0" encoding="UTF-8"
      
      
        ?>
      
      
        <!--
      
      
         - Sample namespace-based configuration - - $Id: applicationContext-security.xml 

3019 2008-05-01 17:51:48Z luke_t $ 
      
      
        -->
      
      
        <
      
      
        beans:beans 
      
      
        xmlns
      
      
        ="http://www.springframework.org/schema/security"
      
      
        

xmlns:beans
      
      
        ="http://www.springframework.org/schema/beans"
      
      
         xmlns:xsi
      
      
        ="http://www.w3.org/2001/XMLSchema-instance"
      
      
        

xsi:schemaLocation
      
      
        ="http://www.springframework.org/schema/beans

       http://www.springframework.org/schema/beans/spring-beans-3.0.xsd

       http://www.springframework.org/schema/security

       http://www.springframework.org/schema/security/spring-security-3.1.xsd"
      
      
        >
      
      
        <
      
      
        global-method-security 
      
      
        secured-annotations
      
      
        ="enabled"
      
      
          jsr250-annotations
      
      
        ="enabled"
      
      
        />
      
      
        <
      
      
        http 
      
      
        pattern
      
      
        ="/css/**"
      
      
         security
      
      
        ="none"
      
      
        />
      
      
        <
      
      
        http 
      
      
        pattern
      
      
        ="/pages/login.xhtml"
      
      
         security
      
      
        ="none"
      
      
        />
      
      
        <
      
      
        http 
      
      
        auto-config
      
      
        ='false'
      
      
        >
      
      
        <
      
      
        intercept-url 
      
      
        pattern
      
      
        ="/pages/customer/**"
      
      
         access
      
      
        ='ROLE_SITE_ADMIN'
      
      
        />
      
      
        <
      
      
        intercept-url 
      
      
        pattern
      
      
        ="/pages/department/overhead*"
      
      
         access
      
      
        ='ROLE_SITE_ADMIN'
      
      
        />
      
      
        <
      
      
        intercept-url 
      
      
        pattern
      
      
        ="/**"
      
      
        

        access
      
      
        ='ROLE_SITE_ADMIN,ROLE_PROJECT_MANAGER,ROLE_DEPARTMENT_MANAGER,ROLE_ACCOUNTING'
      
      
        />
      
      
        <
      
      
        form-login 
      
      
        login-page
      
      
        ="/pages/login.xhtml"
      
      
        

        default-target-url
      
      
        ='/pages/reports.xhtml'
      
      
         always-use-default-target
      
      
        ='true'
      
      
        

        authentication-failure-handler-ref
      
      
        ="userLoginService"
      
      
        />
      
      
        <
      
      
        logout 
      
      
        invalidate-session
      
      
        ="true"
      
      
         logout-success-url
      
      
        ="/pages/login.xhtml"
      
      
        />
      
      
        </
      
      
        http
      
      
        >
      
      
        <
      
      
        authentication-manager
      
      
        >
      
      
        <
      
      
        authentication-provider 
      
      
        user-service-ref
      
      
        ='userLoginService'
      
      
        >
      
      
        <
      
      
        password-encoder 
      
      
        hash
      
      
        ="md5"
      
      
        />
      
      
        </
      
      
        authentication-provider
      
      
        >
      
      
        </
      
      
        authentication-manager
      
      
        >
      
      
        <
      
      
        beans:bean 
      
      
        id
      
      
        ="userLoginService"
      
      
         class
      
      
        ="com.evozon.demo.bean.SecureLoginService"
      
      
        >
      
      
        <
      
      
        beans:property 
      
      
        name
      
      
        ="defaultFailureUrl"
      
      
         value
      
      
        ="/pages/login.xhtml"
      
      
        />
      
      
        <
      
      
        beans:property 
      
      
        name
      
      
        ="userDao"
      
      
         ref
      
      
        ="userDao"
      
      
        />
      
      
        <
      
      
        beans:property 
      
      
        name
      
      
        ="loginReportDao"
      
      
         ref
      
      
        ="loginReportDao"
      
      
        />
      
      
        </
      
      
        beans:bean
      
      
        >
      
      
        </
      
      
        beans:beans
      
      
        >
      
    

Can someone tell my why the annotations do not work inside a managed bean,and how to resolve the problem ? ex:

      
        @PreAuthorize("ROLE_PROJECT_MANAGER")

public void aproveVacation(Vacation vacation) {...}
      
    

?

?

?

?

Answer:

The problem has been solved.The solution is to transform the Managed beans to Spring beans. Here is how :
web.xml does not need the jsf listener only the sprin ones :

      
        <
      
      
        listener
      
      
        >
      
      
        <
      
      
        listener-class
      
      
        >
      
      org.springframework.web.context.ContextLoaderListener
      
        </
      
      
        listener-class
      
      
        >
      
      
        </
      
      
        listener
      
      
        >
      
      
        <
      
      
        listener
      
      
        >
      
      
        <
      
      
        listener-class
      
      
        >
      
      org.springframework.web.context.request.RequestContextListener
      
        </
      
      
        listener-class
      
      
        >
      
      
        </
      
      
        listener
      
      
        >
      
    

The application context need this config to work at first :

      
        <
      
      
        beans 
      
      
        xmlns
      
      
        ="http://www.springframework.org/schema/beans"
      
      
        

xmlns:xsi
      
      
        ="http://www.w3.org/2001/XMLSchema-instance"
      
      
         xmlns:aop
      
      
        ="http://www.springframework.org/schema/aop"
      
      
        

xmlns:tx
      
      
        ="http://www.springframework.org/schema/tx"
      
      
         xmlns:context
      
      
        ="http://www.springframework.org/schema/context"
      
      
        

xsi:schemaLocation
      
      
        ="http://www.springframework.org/schema/beans 

http://www.springframework.org/schema/beans/spring-beans-2.5.xsd         

http://www.springframework.org/schema/aop 

http://www.springframework.org/schema/aop/spring-aop-3.0.xsd

http://www.springframework.org/schema/tx 

http://www.springframework.org/schema/tx/spring-tx-3.0.xsd

 http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd"
      
      
        >
      
      
        <
      
      
        context:component-scan 
      
      
        base-package
      
      
        ="com.company.demo.bean"
      
      
        />
      
      
        <
      
      
        context:annotation-config 
      
      
        />
      
      
        <
      
      
        aop:config 
      
      
        proxy-target-class
      
      
        ="true"
      
      
        />
      
      
        

//other configs


      
      
        </
      
      
        beans
      
      
        >
      
    

Note that the first two need to define the base package for the spring beans (for the Components) and that the beans are annotated.The third config is needed to force the class proxy, here is why you need that .
Ok.once we know that we change the annotations from jsf managedBeans to Spring components :

      
        @ManagedBean

@SessionScoped


      
      
        public
      
      
        class
      
      
         UserLoginBean {



@ManagedProperty(name 
      
      = "userDao", value = "#{userDao}"
      
        )


      
      
        private
      
      
         UserDao userDao; 

}   
      
    

to:

      
        @Component

@Scope(
      
      "session"
      
        )

@Qualifier(
      
      "userLoginBean"
      
        )


      
      
        public
      
      
        class
      
      
         UserLoginBean  {



@Autowired


      
      
        private
      
      
         UserDao userDao;

}     
      
    

That's all.If you have already this config and doesn't work you should set <aop:config proxy-target-class="true" /> into your applicationContext.xml.

?

PS:if nothing happened, you can change the

      
        <
      
      
        sec:global-method-security 
      
      
        secured-annotations
      
      
        ="enabled"
      
      
         jsr250-annotations
      
      
        ="enabled"
      
      
        >
      
      
        </
      
      
        sec:global-method-security
      
      
        >
      
    

to

      
        <
      
      
        sec:global-method-security 
      
      
        pre-post-annotations
      
      
        ="enabled"
      
      
        >
      
      
        </
      
      
        sec:global-method-security
      
      
        >
      
    

?

Spring security 3.1 +JSF 2.0 . problem with annotating methods in ManagedBeans?


更多文章、技術(shù)交流、商務(wù)合作、聯(lián)系博主

微信掃碼或搜索:z360901061

微信掃一掃加我為好友

QQ號(hào)聯(lián)系: 360901061

您的支持是博主寫作最大的動(dòng)力,如果您喜歡我的文章,感覺我的文章對(duì)您有幫助,請(qǐng)用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點(diǎn)擊下面給點(diǎn)支持吧,站長(zhǎng)非常感激您!手機(jī)微信長(zhǎng)按不能支付解決辦法:請(qǐng)將微信支付二維碼保存到相冊(cè),切換到微信,然后點(diǎn)擊微信右上角掃一掃功能,選擇支付二維碼完成支付。

【本文對(duì)您有幫助就好】

您的支持是博主寫作最大的動(dòng)力,如果您喜歡我的文章,感覺我的文章對(duì)您有幫助,請(qǐng)用微信掃描上面二維碼支持博主2元、5元、10元、自定義金額等您想捐的金額吧,站長(zhǎng)會(huì)非常 感謝您的哦!!!

發(fā)表我的評(píng)論
最新評(píng)論 總共0條評(píng)論
主站蜘蛛池模板: 淮南市| 焉耆| 工布江达县| 农安县| 年辖:市辖区| 黑龙江省| 永州市| 徐闻县| 广宁县| 平果县| 灌阳县| 定日县| 许昌县| 丰县| 自治县| 乌拉特后旗| 青浦区| 武鸣县| 嫩江县| 云安县| 林芝县| 建昌县| 怀柔区| 文成县| 闽清县| 翁源县| 夹江县| 右玉县| 乌拉特前旗| 六枝特区| 定西市| 泾川县| 马公市| 长阳| 尉犁县| 博罗县| 葫芦岛市| 水城县| 资溪县| 怀仁县| 上饶县|