微信网站链接怎么做,响应式网站的字体设置,免费做试卷的网站或试卷,五金 东莞网站建设目录 服务端这么做服务端告知客户端使用 Basic Authentication 方式进行认证服务端接收并处理客户端按照 Basic Authentication 方式发送的数据 客户端这么做如果客户端是浏览器如果客户端是 RestTemplat如果客户端是 HttpClient 其它参考 服务端这么做
服务端告知客户端使用 … 目录 服务端这么做服务端告知客户端使用 Basic Authentication 方式进行认证服务端接收并处理客户端按照 Basic Authentication 方式发送的数据 客户端这么做如果客户端是浏览器如果客户端是 RestTemplat如果客户端是 HttpClient 其它参考 服务端这么做
服务端告知客户端使用 Basic Authentication 方式进行认证服务端接收并处理客户端按照 Basic Authentication 方式发送的数据
服务端告知客户端使用 Basic Authentication 方式进行认证
服务端返回 401Unauthozied状态码给客户端服务端在Response 的 header “WWW-Authenticate” 中添加信息 服务端接收并处理客户端按照 Basic Authentication 方式发送的数据
private boolean checkBasicAuthorization(HttpServletRequest request) {String rawStringAuthorization request.getHeader(Authorization);Assert.isTrue(StringUtils.startsWith(rawStringAuthorization, Basic), Basic 认证失败);String base64StringAuthorization StringUtils.replaceOnce(rawStringAuthorization, Basic, );base64StringAuthorization StringUtils.trim(base64StringAuthorization);byte[] bytesAuthorization Base64Utils.decodeFromString(base64StringAuthorization);String stringAuthorization new String(bytesAuthorization);String[] arrUserAndPass StringUtils.split(stringAuthorization, :);Assert.isTrue(2arrUserAndPass.length, Basic 认证失败);String username arrUserAndPass[0];String password arrUserAndPass[1];if (StringUtils.equals(username, myuser) StringUtils.equals(password, mypassword)) {return true;}return false;
}org.apache.commons.lang3.StringUtilsorg.springframework.util.Base64Utils
客户端这么做
客户端按照 Basic Authentication 方式向服务端发送数据
如果客户端是浏览器
浏览器支持 Basic Authentication 方式认证。浏览器会自动弹出提示窗体并自动向该地址发送认证请求。
浏览器自动弹出的对话框 点击“登录”后浏览器自动向该地址发送请求
输入用户名myuser密码mypassword“bXl1c2VyOm15cGFzc3dvcmQ” base64(myuser:mypassword)
如果客户端是 RestTemplat
Configuration
public class RestTemplateConfig {Beanpublic RestTemplate restTemplate() {RestTemplate restTemplate new RestTemplate();restTemplate.getInterceptors().add(new BasicAuthenticationInterceptor(myuser,mypassword));
;return restTemplate;}
}如果客户端是 HttpClient
略
其它
Basic Authentication 方式的认证通常不需要登录页面只需要登录Action即可。
参考
https://developer.atlassian.com/server/jira/platform/basic-authentication/