Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/374.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Spring安全登录表单_Java_Spring_Spring Security - Fatal编程技术网

Java Spring安全登录表单

Java Spring安全登录表单,java,spring,spring-security,Java,Spring,Spring Security,我需要你的帮助。我需要使用Spring Security的默认登录形式。当我启动webapp时,它应该打开登录页面,成功登录后将用户重定向到我的jsp页面,而不查看角色(管理员或仅用户)。我试过这个: <http auto-config="true" create-session="stateless" use-expressions="true"> <intercept-url pattern="/_ah*" access="permitAll" />

我需要你的帮助。我需要使用Spring Security的默认登录形式。当我启动webapp时,它应该打开登录页面,成功登录后将用户重定向到我的jsp页面,而不查看角色(管理员或仅用户)。我试过这个:

<http auto-config="true" create-session="stateless"
    use-expressions="true">
    <intercept-url pattern="/_ah*" access="permitAll" />
    <intercept-url pattern="/pages/*" access="hasRole('ROLE_ADMIN')" />
    <intercept-url pattern="/index*" access="hasRole('ROLE_ADMIN')" />
</http>

<authentication-manager>
    <authentication-provider>
        <jdbc-user-service data-source-ref="dataSource"
            users-by-username-query="working_sql_script"
            authorities-by-username-query="other_working_sql_script" />
    </authentication-provider>
</authentication-manager>

但它仍然在开始时打开空白页。

您需要在应用程序中定义一个页面,不受角色限制。并将该页面设置为默认表单登录。验证成功时重定向到其他页面

我的spring-security.xml部分代码如下

 <http pattern="/login" security="none"/>
<http pattern="/accessDenied" security="none"/>
<http auto-config="true">
    <remember-me/>
    <!-- Don't set any role restrictions on login.jsf -->
    <intercept-url pattern="/login" access="IS_AUTHENTICATED_ANONYMOUSLY" />
    <intercept-url pattern="/pages/admin/*" access="ROLE_SADMIN" />
    <intercept-url pattern="/pages/applicants/*" access="ROLE_SADMIN,ROLE_APPLICANT" />

    <!-- Set the login page and what to do if login fails -->
    <form-login login-page="/login" authentication-failure-url="/login"
                default-target-url="/manageHome" authentication-success-handler-ref="customAuthenticationSuccessHandler"/>

    <logout success-handler-ref="customLogoutSuccessHandler" />
    <access-denied-handler ref="customAccessDeniedHandler"/>

</http>


感谢所有试图帮助我的人。我解决了这个问题。并为其他将面临此类问题的开发人员撰写本文。我创建了欢迎页面,可以访问所有用户和匿名用户。第页代码:

<a href="index">Catalog</a>
<br>
<a href="registration">Registration</a>


我的spring安全文件包含以下内容:

<http auto-config="true" create-session="stateless"
    use-expressions="true">
    <intercept-url pattern="/welcome" access="isAnonymous()" />
    <intercept-url pattern="/registration" access="isAnonymous()" />
    <intercept-url pattern="/index" access="isAuthenticated()" />
    <form-login default-target-url="/main"/>
</http>

和安全的主页:

<h2>Catalog</h2>
<a href="logout">Logout</a>
<a href="goods">Goods</a>
<a href="vendors">Vendors</a>
目录

Spring Security只允许在登录后访问此页面。Spring Security生成的登录页面。希望,这将对某人有所帮助。

此处指定的身份验证提供程序在哪里?这是一个很好的示例,希望有帮助。我更新了我的问题。链接中的这个例子对我没有帮助。我无法运行此应用程序。它说java.lang.ClassNotFoundException:org.springframework.web.context.ContextLoaderListener。Bu我确信这个类在classpath中,我创建了WEB-INF/lib文件夹,并将所有必需的JARST复制到这个文件夹。谢谢你们,但我有一个任务:不要使用自定义登录表单。只有默认设置才能限制所有页面,并且在web.xml中指定一个页面作为欢迎页面,在重定向到该页面之前,spring security将提示登录。
<h2>Catalog</h2>
<a href="logout">Logout</a>
<a href="goods">Goods</a>
<a href="vendors">Vendors</a>