2014-01-12 4 views
0

Я разрабатываю webapp используя SS для управления ролью. когда я пытаюсь войти в систему как admin, он отлично работает, но проблема в том, что я хочу войти в систему как пользователь, который он тоже делает, чего я не хочу. любые идеи плзSpring Security

это моя безопасность-cpntext.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.1.xsd"> 

<!-- We will be defining all security related configurations in this file --> 
<http pattern="/login" security="none" /> 

<http use-expressions="true" > 
     <intercept-url pattern="/login" access="IS_AUTHENTICATED_ANONYMOUSLY" /> 
     <intercept-url pattern="/login" access="permitAll" /> 
     <intercept-url pattern="/index" access="hasRole('Admin')"/> 
     <form-login login-page="/login" default-target-url="/index" authentication-failure-url="/login"/> <!-- We will just use the built-in form login page in Spring --> 
     <access-denied-handler error-page="/login" /> 
     <!-- <intercept-url pattern="/**" access="isAuthenticated()"/> --><!-- this means all URL in this app will be checked if user is authenticated --> 
     <logout logout-url="/logout" logout-success-url="/index"/> <!-- the logout url we will use in JSP --> 
</http> 

<beans:bean id="daoAuthenticationProvider" class="org.springframework.security.authentication.dao.DaoAuthenticationProvider"> 
    <beans:property name="userDetailsService" ref="userDetailsService" ></beans:property> 

</beans:bean> 

<beans:bean id="authenticationManager" class="org.springframework.security.authentication.ProviderManager"> 
    <beans:property name="providers"> 
     <beans:list> 
      <beans:ref local="daoAuthenticationProvider"/> 
     </beans:list> 
    </beans:property> 
</beans:bean> 

<authentication-manager> 
    <authentication-provider user-service-ref="userDetailsService"> 
     <password-encoder hash="md5"></password-encoder> 
    </authentication-provider> 
</authentication-manager> 

ответ

0

Я вижу два возможных проблем здесь, которые могут вызывать проблемы.

1) Вы указываете hasRole('Admin') для /index. Если имя роли называется Admin, тогда вы должны указать hasRole('ROLE_Admin').

2) У вас есть дублирование в вашей конфигурации. <authentication-manager> сообщает Spring безопасности, чтобы создать экземпляр ProviderManager. Таким образом, вы объявили об этом, но вы также вручную указали ProviderManager как экземпляр компонента, который дублирует то, что делает <authentication-manager>. Удалить следующее:

<beans:bean id="daoAuthenticationProvider" class="org.springframework.security.authentication.dao.DaoAuthenticationProvider"> 
    <beans:property name="userDetailsService" ref="userDetailsService" ></beans:property> 

</beans:bean> 

<beans:bean id="authenticationManager" class="org.springframework.security.authentication.ProviderManager"> 
    <beans:property name="providers"> 
     <beans:list> 
      <beans:ref local="daoAuthenticationProvider"/> 
     </beans:list> 
    </beans:property> 
</beans:bean> 

И оставить:

<authentication-manager> 
    <authentication-provider user-service-ref="userDetailsService"> 
     <password-encoder hash="md5"></password-encoder> 
    </authentication-provider> 
</authentication-manager> 

Попробуйте это и посмотреть, что получится.

Смежные вопросы