Spring security Spring security如何从每个页面登录?
我有一个SpringMVC应用程序,我想在其中有一个登录栏,显示在多个页面上,并使用jQuery的对话框系统在模式对话框窗口中显示表单。我应该在Spring security Spring security如何从每个页面登录?,spring-security,Spring Security,我有一个SpringMVC应用程序,我想在其中有一个登录栏,显示在多个页面上,并使用jQuery的对话框系统在模式对话框窗口中显示表单。我应该在securityContext.xml中使用什么样的Spring安全设置才能工作 这是我目前使用的: 如果使用jsp,可以利用spring标记: <sec:authorize ifNotGranted="ROLE_ANONYMOUS"> //User is loggedin Welcome, ${pageConte
securityContext.xml
中使用什么样的Spring安全设置才能工作
这是我目前使用的:
如果使用jsp,可以利用spring标记:
<sec:authorize ifNotGranted="ROLE_ANONYMOUS">
//User is loggedin
Welcome, ${pageContext.request.userPrincipal.principal.nameToDisplay}
<a href="j_spring_security_logout">Logout</a>
</sec:authorize>
<sec:authorize access="isAnonymous()">
//user is not loggedin, show login form
<form id="loginForm" onsubmit="DoLoginInline();" target="passwordIframe" >
<label>Login:</label>
<input type="text" class="headerInputs" id="LoginUsername" name="j_username">
<label>Password:</label>
<input type="password" class="headerInputs" id="LoginPassword" name="j_password">
<button type="submit" value="Submit"></button>
</form>
</sec:authorize>
//用户是loggedin
欢迎,${pageContext.request.userPrincipal.principal.nameToDisplay}
//用户未登录,显示登录表单
登录:
密码:
从每个页面登录是表示应用程序没有任何入口点的另一种方式。所以我们需要配置一个不做任何事情的入口点
我们可以这样做:
public class DoNothingEntryPoint implements AuthenticationEntryPoint {
@Override
public void commence(HttpServletRequest request, HttpServletResponse response, AuthenticationException authException)
throws IOException, ServletException {
/* do nothing */
}
}
in XML:
<beans:bean id="doNothingEntryPoint" class="xyz.package.DoNothingEntryPoint" />
<http entry-point-ref="doNothingEntryPoint" use-expressions="true">
....
公共类DonothingtryPoint实现AuthenticationEntryPoint{
@凌驾
公共无效开始(HttpServletRequest请求、HttpServletResponse响应、AuthenticationException authException)
抛出IOException、ServletException{
/*无所事事*/
}
}
在XML中:
....