(ROLE_ADMIN ROLE_USER)Spring Security Spring WebFlow

时间:2015-08-04 00:51:30

标签: spring spring-security spring-webflow

这是我第一次将 Spring Security Spring WebFlow 一起使用。我有两个用户(管理员;用户),每个用户都有她唯一的空间。

我的项目结构如下:

enter image description here

文件夹" compte "对于用户包含:

  • file.xhtml
  • 孔特-flow.xml

文件夹" compteAdmin " for Admin包含:

  • file.xhtml
  • compteAdmin-flow.xml

文件夹" 主要"包含:

  • fileAuthentication.xhtml
  • 主flow.xml

main-flow.xml 的配置是:

<view-state id="authentification" view="authentification.xhtml" model="user">
    <transition on="valider" to="authentifierUser" />

</view-state>

<action-state id="authentifierUser">
    <evaluate
        expression="userAuthenticationProviderService.processUserAuthentication(user)" />
    <transition on="yes" to="finish" />
    <transition on="no" to="authentification" />
</action-state>

<end-state id="finish" view="externalRedirect:compteAdmin" />

security-config.xml 的配置是:

<security:http auto-config="true" use-expressions="true">

    <!-- Restrict URLs based on role -->
    <security:intercept-url pattern="/app/main" access="permitAll"/>
    <security:intercept-url pattern="/app/main/compteAdmin" access="hasRole('ROLE_ADMIN')" />
    <security:intercept-url pattern="/app/main/compte" access="hasRole('ROLE_USER')" />

    <security:form-login login-page="/app/main" default-target-url="/app/main"/>

    <security:logout logout-url="/app/logout"
        logout-success-url="/app/main" />
</security:http>

<security:authentication-manager>
    <security:authentication-provider>
        <security:jdbc-user-service
            data-source-ref="dataSource" />
    </security:authentication-provider>
</security:authentication-manager>

<bean id="daoAuthenticationProvider"
    class="org.springframework.security.authentication.dao.DaoAuthenticationProvider">
    <property name="userDetailsService" ref="userService" />
    <property name="hideUserNotFoundExceptions" value="false" />
</bean>

<bean id="authenticationManager"
    class="org.springframework.security.authentication.ProviderManager">
    <constructor-arg>
        <ref local="daoAuthenticationProvider" />
    </constructor-arg>
</bean>

在这种情况下,只有管理员才能访问她的空间。那么如何配置 main-flow.xml 以便让用户也可以访问她的空间。 提前致谢。

0 个答案:

没有答案