Java Spring身份验证使用DataSase,如何删除角色模型?

Java Spring身份验证使用DataSase,如何删除角色模型?,java,mysql,spring,spring-mvc,Java,Mysql,Spring,Spring Mvc,我有一个Spring身份验证项目,我想在将来的工作中像使用模板一样使用它。 有与数据库(mysql)的连接。 问题是——这个项目包括角色模型。有两个角色:角色用户和角色管理员,但我不想使用它 我如何从我的项目中删除这个东西,并且仅通过检查数据库中一个表的登录名和密码来使用身份验证 对于附件-spring安全xml文件的一部分: <http auto-config="true"> <remember-me data-source-ref="dataSource" /&g

我有一个Spring身份验证项目,我想在将来的工作中像使用模板一样使用它。 有与数据库(mysql)的连接。 问题是——这个项目包括角色模型。有两个角色:角色用户和角色管理员,但我不想使用它

我如何从我的项目中删除这个东西,并且仅通过检查数据库中一个表的登录名和密码来使用身份验证

对于附件-spring安全xml文件的一部分:

<http auto-config="true">

    <remember-me data-source-ref="dataSource" />
    <access-denied-handler error-page="/accessDenied" />
    <intercept-url pattern="/" access="ROLE_USER" />
    <intercept-url pattern="/user" access="ROLE_USER" />
    <intercept-url pattern="/admin" access="ROLE_ADMIN" />
    <form-login login-page='/login' default-target-url="/"
        authentication-failure-url="/login?error=true" username-parameter="user_login"
        password-parameter="password_login" />
    <logout logout-success-url="/login" />
</http>

<beans:bean id="jdbcGroupsImpl"
    class="org.springframework.security.core.userdetails.jdbc.JdbcDaoImpl">
    <beans:property name="enableGroups" value="true" />
    <beans:property name="enableAuthorities" value="false" />
    <beans:property name="dataSource" ref="dataSource" />
</beans:bean>

<authentication-manager>
    <authentication-provider user-service-ref="jdbcGroupsImpl" />
</authentication-manager>


提前谢谢你

您可以只拥有一个用户角色,如role\u user,并使用表单根据您的数据库对其进行身份验证。安全xml可以是这样的:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:security="http://www.springframework.org/schema/security"
       xmlns:context="http://www.springframework.org/schema/context"
       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">

<bean class="org.springframework.security.web.access.expression.DefaultWebSecurityExpressionHandler"/>
<context:component-scan base-package="my.pachage"/>

<security:http auto-config="true" use-expressions="true">
<security:form-login login-page="/login" login-processing-url="/login"
       username-parameter="userName" 
       password-parameter="password" default-target-url="/login/"
       authentication-failure-url="/login?error=true"/>

<security:intercept-url pattern="/yourURL/*" access="hasAuthority('ROLE_USER')"/>
        <security:intercept-url pattern="/" access="permitAll"/>
</security:http>

<security:authentication-manager>
       <security:authentication-provider user-service-ref="jdbcGroupsImpl"/>
</security:authentication-manager>

</beans>


在您的控制器中,您可以通过从LDAP或DB获取身份验证信息来对用户进行身份验证。

您可以只拥有一个用户角色,如role\u user,并使用表单对您的DB进行身份验证。安全xml可以是这样的:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:security="http://www.springframework.org/schema/security"
       xmlns:context="http://www.springframework.org/schema/context"
       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">

<bean class="org.springframework.security.web.access.expression.DefaultWebSecurityExpressionHandler"/>
<context:component-scan base-package="my.pachage"/>

<security:http auto-config="true" use-expressions="true">
<security:form-login login-page="/login" login-processing-url="/login"
       username-parameter="userName" 
       password-parameter="password" default-target-url="/login/"
       authentication-failure-url="/login?error=true"/>

<security:intercept-url pattern="/yourURL/*" access="hasAuthority('ROLE_USER')"/>
        <security:intercept-url pattern="/" access="permitAll"/>
</security:http>

<security:authentication-manager>
       <security:authentication-provider user-service-ref="jdbcGroupsImpl"/>
</security:authentication-manager>

</beans>


在中,您可以通过从LDAP或DB获取身份验证信息来验证用户。

在身份验证提供程序中分配任何角色,并将访问级别更改为“isAuthenticated”

例如:

<intercept-url pattern="/user" access="isAuthenticated" />

在身份验证提供程序中分配任何角色,并将访问级别更改为“isAuthenticated”

例如:

<intercept-url pattern="/user" access="isAuthenticated" />


那么您希望有一种类型的用户可以登录并执行操作?您是否尝试删除“intercept url”标记?这是spring请求角色的唯一一点,所以您希望有一种类型的用户可以登录并执行操作?您是否尝试删除“intercept url”标记?这是spring唯一要求角色的地方