我正在查看正在开发的网站的安全模型。在研究了网络之后,我发现有几种安全模型可以保护网站的安全,即基本身份验证,JWT ...
目前,尚未在开发人员中启用SSL。网站有一个登录页面,并通过API进行通信(包括登录和注销)。作为测试,在登录页面上,我尝试使用错误的详细信息登录,然后查看了用于确定安全性机制的开发人员工具,并找到了以下屏幕截图。我认为该网站使用的是基本身份验证,尽管我注意到该电子邮件/密码未进行编码并且正在使用自定义登录表单。有人可以确认是否使用了基本身份验证吗?
[[请求标题图像] [2]
更新:我发现,一旦通过电子邮件/密码对用户进行身份验证,我就应该发布屏幕截图,因为这是返回密钥的地方。在下面的屏幕截图中,将投标人令牌和投标人机密发送回客户端。我认为这些是通过后端的加密生成的。所以我不认为它是JWT,但这是创建密钥而不在标头中发送但在响应正文中发送的合适方法吗?
Network tab after user logged in
登录表单代码:
{
/* prepare ui */
progress.classList.remove('hide');
login_btn.innerText = 'Logging In';
login_btn.setAttribute('disabled', true);
/* make http request */
var http = new XMLHttpRequest();
var url = SERVER + '/api/bidder/login';
var body = {
email: email.value,
password: password.value
};
http.open('POST', url, true);
http.setRequestHeader('Content-type', 'application/JSON');
http.onreadystatechange = function () { //Call a function when the state changes.
if (http.readyState == 4 && http.status == 200) {
var res = JSON.parse(http.responseText);
if (res.status) {
localStorage.setItem("bidData", JSON.stringify(res.data));
window.location.href = window.location.href.replace('login.html','');
} else {
Toast.show('Danger', res.message);
}
/* reset ui */
progress.classList.add('hide');
login_btn.innerText = 'Log In';
login_btn.removeAttribute('disabled');
}
}
http.send(JSON.stringify(body));
}
Spring安全性是Spring项目中最基本的身份验证如果要启用Spring安全性,那么必须首先添加的是Spring Security库到您的项目中。添加之后,您将创建一个类来配置Spring安全性。
Spring安全性的类配置中的一个函数。
@Override
protected void configure(HttpSecurity http) throws Exception {
http
.cors()
.and()
.csrf()
.disable()
.exceptionHandling()
.authenticationEntryPoint(unauthorizedHandler)
.and()
.sessionManagement()
.sessionCreationPolicy(SessionCreationPolicy.STATELESS)
.and()
.authorizeRequests()
.antMatchers("/",
"/api/statistical/**",
"/static/**",
"/webjars/**",
"/img/**",
"/css/**",
"/js/**",
"/api/diary/**")
.permitAll()
.antMatchers("/api/auth/**")
.permitAll()
.antMatchers("/api/user/checkUsernameAvailability", "/api/user/checkEmailAvailability")
.permitAll()
.antMatchers(HttpMethod.GET, "/api/users/**") //, "/api/polls/**"
.permitAll()
.anyRequest()
.authenticated();