Java 如何设置仅通过链接访问jsp页面
春天我是新来的,但这里我有一些问题,我找不到任何答案。 所以,我需要设置一个注册页面的访问权限,只有那些有管理员链接的用户才可以访问。我看到像,管理员发送链接,只有一个用户可以进入和注册后,该链接将不可用。 首先,我知道管理员应该生成一些链接,但我不知道如何生成。 我不知道如何通过链接设置访问权限。嗯,我可以说我什么都不知道:) 你能帮助我吗?我甚至找不到关于这个的教程或信息。 代码是:Java 如何设置仅通过链接访问jsp页面,java,spring,spring-mvc,Java,Spring,Spring Mvc,春天我是新来的,但这里我有一些问题,我找不到任何答案。 所以,我需要设置一个注册页面的访问权限,只有那些有管理员链接的用户才可以访问。我看到像,管理员发送链接,只有一个用户可以进入和注册后,该链接将不可用。 首先,我知道管理员应该生成一些链接,但我不知道如何生成。 我不知道如何通过链接设置访问权限。嗯,我可以说我什么都不知道:) 你能帮助我吗?我甚至找不到关于这个的教程或信息。 代码是: protected void configure(final HttpSecurity http) thro
protected void configure(final HttpSecurity http) throws Exception {
http
.csrf().disable()
.authorizeRequests()
.antMatchers("/").permitAll()
.antMatchers("/index").hasAnyRole(USER, ADMIN)
.antMatchers("/admin").hasRole(ADMIN)
.antMatchers("/addUser").hasRole(ADMIN)
.and()
.formLogin()
.loginPage("/login")
.defaultSuccessUrl("/index")
.failureUrl("/login?error")
.usernameParameter("username")
.passwordParameter("password")
.and()
.logout()
.logoutSuccessUrl("/login?logout")
.and()
.exceptionHandling()
.accessDeniedPage("/login")
.and()
.rememberMe()
.rememberMeParameter("remember-me")
.tokenRepository(persistentTokenRepository())
.tokenValiditySeconds(900);
}
管理页面,其中是注册新用户的按钮
<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%>
<%@ page isELIgnored="false" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Users List</title>
<link href="<c:url value='/resources/css/bootstrap.min.css' />" rel="stylesheet"></link>
</head>
<body>
<div class="generic-container">
<%--<%@include file="authheader.jsp" %>--%>
<div class="panel panel-default">
<!-- Default panel contents -->
<div class="panel-heading"><span class="lead">User Administration</span></div>
<table class="table table-hover">
<thead>
<tr>
<th>Username</th>
<th>Firstname</th>
<th>Lastname</th>
<th>Email</th>
<th>Role</th>
<sec:authorize access="hasRole('ADMIN')">
<th width="100"></th>
</sec:authorize>
<sec:authorize access="hasRole('ADMIN')">
<th width="100"></th>
</sec:authorize>
</tr>
</thead>
<tbody>
<c:forEach items="${users}" var="user">
<tr>
<td>${user.username}</td>
<td>${user.firstname}</td>
<td>${user.lastname}</td>
<td>${user.email}</td>
<td>${user.roles}</td>
<sec:authorize access="hasRole('ROLE_ADMIN')">
<td><a href="<c:url value='/edit-user-${user.username}' />" class="btn btn-success custom-width">edit</a></td>
</sec:authorize>
<sec:authorize access="hasRole('ROLE_ADMIN')">
<td><a href="<c:url value='/delete-user-${user.username}' />" class="btn btn-danger custom-width">delete</a></td>
</sec:authorize>
</tr>
</c:forEach>
</tbody>
</table>
</div>
<sec:authorize access="hasRole('ADMIN')">
<div class="well">
<a href="<c:url value='/addUser' />">Add New User</a>
</div>
</sec:authorize>
</div>
</body>
</html>
用户列表
用户管理
用户名
名字
姓氏
电子邮件
角色
${user.username}
${user.firstname}
${user.lastname}
${user.email}
${user.roles}
如果你需要一些额外的代码,告诉我。
抱歉,如果出现问题,这是我的第二个问题。您可以生成一个令牌(这很难猜测)
在请求处理中,将令牌放入RestController并
//let t be the captured token
Token token = tokenRepo.findByUuid(t);
if(token.expired){
//tell them link is expired
}else{
token.setExpired(true)
//give them the reg page and take it from here
}
你能给我举个例子吗?我在这个问题上完全是新手。很多!请告诉我,我是否可以在不创建包含令牌数据的表模型的情况下执行此操作?就像我不能在不创建模型的情况下用hql插入它一样,这很痛苦。我对数据库的请求太多。是什么阻止您创建模型?使用imo模型管理数据库将很容易。
//let t be the captured token
Token token = tokenRepo.findByUuid(t);
if(token.expired){
//tell them link is expired
}else{
token.setExpired(true)
//give them the reg page and take it from here
}