2011-08-25 16 views
6

मैं स्प्रिंग फ्रेमवर्क एमवीसी 3 + वसंत सुरक्षा का उपयोग कर रहा हूं 3. मैं अपनी वसंत सुरक्षा में भूमिका पदानुक्रम को सक्षम करना चाहता हूं। http://static.springsource.org/spring-security/site/docs/3.1.x/reference/authz-arch.html के अनुसार मैं लिखना चाहिएजावा: स्प्रिंग सुरक्षा 3 रोल पदानुक्रम

<bean id="roleVoter" class="org.springframework.security.access.vote.RoleHierarchyVoter"> 
    <constructor-arg ref="roleHierarchy" /> 
</bean> 
<bean id="roleHierarchy" 
    class="org.springframework.security.access.hierarchicalroles.RoleHierarchyImpl"> 
<property name="hierarchy"> 
    ROLE_ADMIN > ROLE_STAFF 
    ROLE_STAFF > ROLE_USER 
    ROLE_USER > ROLE_GUEST 
</property> 
</bean> 

लेकिन मैं इसे कहाँ रखना चाहिए? मैं इसे अपने एप्लिकेशन-security.xml में डाल करने की कोशिश की:

<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.0.xsd"> 
    <http> 
     <intercept-url pattern="/entryPost/**" access="ROLE_USER" requires-channel="https"/> 
     <intercept-url pattern="/entryDelete/**" access="ROLE_ADMIN" requires-channel="https"/> 
     <intercept-url pattern="/commentDelete/**" access="ROLE_ADMIN" requires-channel="https"/> 
     <intercept-url pattern="/login" access="ROLE_ANONYMOUS" requires-channel="https"/> 
     <form-login login-page="/login" default-target-url="/entryList/1" authentication-failure-url="/login?error=true" /> 
     <logout logout-success-url="/login" /> 
     <session-management> 
      <concurrency-control max-sessions="1" /> 
     </session-management> 
     <access-denied-handler error-page="/accessDenied"/> 
    </http> 
    <authentication-manager> 
     <authentication-provider> 
      <jdbc-user-service data-source-ref="dataSource" 
      users-by-username-query="SELECT username,password,'true' as enabled FROM member WHERE username=?" 
      authorities-by-username-query="SELECT member.username,role FROM member,memberRole WHERE member.username=? AND member.id=memberRole.member_id"/> 
     </authentication-provider> 
    </authentication-manager> 
<bean id="roleVoter" class="org.springframework.security.access.vote.RoleHierarchyVoter"> 
    <constructor-arg ref="roleHierarchy" /> 
</bean> 
<bean id="roleHierarchy" class="org.springframework.security.access.hierarchicalroles.RoleHierarchyImpl"> 
    <property name="hierarchy"> 
     ROLE_ADMIN > ROLE_STAFF 
     ROLE_STAFF > ROLE_USER 
     ROLE_USER > ROLE_GUEST 
    </property> 
</bean> 

लेकिन यह काम नहीं करता है: HTTP स्थिति 404.

जब मैं यह एप्लिकेशन-servlet.xml में डाल दिया:

<?xml version="1.0" encoding="UTF-8"?> 
<beans xmlns="http://www.springframework.org/schema/beans" 
xmlns:mvc="http://www.springframework.org/schema/mvc" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xmlns:context="http://www.springframework.org/schema/context" 
xsi:schemaLocation="http://www.springframework.org/schema/beans 
    http://www.springframework.org/schema/beans/spring-beans-3.0.xsd 
    http://www.springframework.org/schema/context 
    http://www.springframework.org/schema/context/spring-context-3.0.xsd 
    http://www.springframework.org/schema/mvc 
    http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd"> 
    <context:component-scan base-package="rus.web"/> 
    <bean id="entryValidator" class="rus.domain.EntryValidator"/> 
    <bean id="commentValidator" class="rus.domain.CommentValidator"/> 
    <mvc:annotation-driven/> 
    <mvc:resources mapping="/resources/**" location="/resources/"/> 
    <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"> 
     <property name="prefix" value="/WEB-INF/jsp/"/> 
     <property name="suffix" value=".jsp"/> 
    </bean> 
    <bean id="messageSource" class="org.springframework.context.support.ResourceBundleMessageSource"> 
     <property name="basename" value="messages"/> 
    </bean> 
    <!--<bean class="org.springframework.web.servlet.handler.SimpleMappingExceptionResolver"> 
     <property name="defaultErrorView" value="error"/> 
    </bean> --> 

<bean id="roleVoter" class="org.springframework.security.access.vote.RoleHierarchyVoter"> 
    <constructor-arg ref="roleHierarchy" /> 
</bean> 
<bean id="roleHierarchy" class="org.springframework.security.access.hierarchicalroles.RoleHierarchyImpl"> 
    <property name="hierarchy"> 
     ROLE_ADMIN > ROLE_STAFF 
     ROLE_STAFF > ROLE_USER 
     ROLE_USER > ROLE_GUEST 
    </property> 
</bean> 
</beans> 

यह फेंकता अपवाद:

org.springfram ework.beans.factory.xml.XmlBeanDefinitionStoreException: ServletContext संसाधन [/WEB-INF/rus-servlet.xml] से XML दस्तावेज़ में लाइन 35 अमान्य है; नेस्टेड अपवाद है org.xml.sax.SAXParseException: cvc-complex-type.2.3: एलिमेंट 'प्रॉपर्टी' में वर्ण [बच्चे] नहीं हो सकता है, क्योंकि प्रकार की सामग्री प्रकार केवल तत्व है।

org.xml.sax.SAXParseException: cvc-complex-type.2.3: तत्व 'संपत्ति' में चरित्र [बच्चों] नहीं हो सकता है, क्योंकि प्रकार की सामग्री प्रकार केवल तत्व है।

इस समस्या को हल करने के लिए मुझे क्या करना चाहिए?

+0

मुझे एक ही समस्या थी। मैंने यहां निर्देशों का पालन करके समस्या हल की: http://stackoverflow.com/questions/7809313/accessdeniedexception-if-using-rolehierarchyimpl –

उत्तर

6

प्रलेखन गलत है, यह वैध नहीं है: उन्हें पूछ ठीक करने के लिए

<property name="hierarchy"> 
    <value> 
     ROLE_ADMIN > ROLE_STAFF 
     ROLE_STAFF > ROLE_USER 
     ROLE_USER > ROLE_GUEST 
    </value> 
</property> 

मैं SpringSource JIRA पर एक मुद्दा दाखिल करने का सुझाव,:

<property name="hierarchy"> 
    ROLE_ADMIN > ROLE_STAFF 
    ROLE_STAFF > ROLE_USER 
    ROLE_USER > ROLE_GUEST 
</property> 

आप <value> अंदर सामग्री रैप करने के लिए की जरूरत है दस्तावेज़

+2

ठीक है, इससे मदद मिली, लेकिन इतना नहीं ... जब मैं ROLE_ADMIN के साथ जाने की कोशिश कर रहा हूं पेज एंट्री पोस्ट/(एक्सेस = "ROLE_USER") में यह कहता है: "एक्सेस अस्वीकृत"। ऐसा क्यों है? – Twisty

संबंधित मुद्दे