Spring Security技术栈开发企业级认证与授权

205 阅读2分钟

download:Spring Security技术栈开发企业级认证与授权

全网最细致地讲解Spring Security、Spring Social 、Spring Security OAuth三种技术开发安全的REST服务,彻底掌握一线互联网公司主流的身份认证和授权方式。

适合人群及技术储备要求
本课程适合有一定的开发经验,想要深入了解认证和授权相关知识的Java开发人员
如果你对设计模式,设计思想感兴趣,这门课对你来说会有很大帮助

学前必备技术
JavaWeb基础丨Spring基础丨Maven基础
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.io.FileUtil;
import cn.hutool.core.util.CharsetUtil;
import org.apache.hc.client5.http.config.RequestConfig;
import org.apache.hc.client5.http.entity.UrlEncodedFormEntity;
import org.apache.hc.client5.http.entity.mime.MultipartEntityBuilder;
import org.apache.hc.client5.http.fluent.Form;
import org.apache.hc.client5.http.fluent.Request;
import org.apache.hc.client5.http.fluent.Response;
import org.apache.hc.client5.http.impl.classic.CloseableHttpClient;
import org.apache.hc.client5.http.impl.classic.HttpClientBuilder;
import org.apache.hc.client5.http.impl.io.PoolingHttpClientConnectionManagerBuilder;
import org.apache.hc.client5.http.ssl.NoopHostnameVerifier;
import org.apache.hc.client5.http.ssl.SSLConnectionSocketFactory;
import org.apache.hc.core5.http.ContentType;
import org.apache.hc.core5.http.HttpEntity;
import org.apache.hc.core5.http.io.entity.EntityUtils;
import org.apache.hc.core5.http.io.entity.HttpEntities;
import org.apache.hc.core5.util.TimeValue;
import org.apache.hc.core5.util.Timeout;

import javax.net.ssl.SSLContext;
import javax.net.ssl.SSLEngine;
import javax.net.ssl.TrustManager;
import javax.net.ssl.X509ExtendedTrustManager;
import java.io.File;
import java.io.IOException;
import java.net.Socket;
import java.nio.charset.Charset;
import java.security.KeyManagementException;
import java.security.NoSuchAlgorithmException;
import java.security.cert.X509Certificate;
import java.util.Map;

/**

  • @author sun

  • @date 2021-02-25
    **/
    public class HttpUtil {
    private static final int maxConnTotal = 200;
    private static final Timeout connectTimeout = Timeout.ofSeconds(10);
    private static final Timeout requestTimeout = Timeout.ofSeconds(30);

    public static String uploadFile(String urlString, Map<String, Object> paramMap) throws Exception {
    return uploadFile(urlString, null, paramMap, CharsetUtil.CHARSET_UTF_8)
    .returnContent()
    .asString(CharsetUtil.CHARSET_UTF_8);
    }

    public static String uploadFile(String urlString, Map<String, Object> paramMap, Charset charSet) throws Exception {
    return uploadFile(urlString, null, paramMap, charSet)
    .returnContent()
    .asString(charSet);
    }

    public static Response uploadFile(String urlString, Map<String, Object> handlerMap, Map<String, Object> paramMap) throws Exception {
    return uploadFile(urlString, handlerMap, paramMap, CharsetUtil.CHARSET_UTF_8);
    }

    public static Response uploadFile(String urlString, Map<String, Object> handlerMap, Map<String, Object> paramMap, Charset charSet) throws Exception {
    MultipartEntityBuilder builder = MultipartEntityBuilder.create().setCharset(charSet);
    paramMap.forEach((k, v) -> {
    //判断是文件还是文本
    if (v instanceof File) {
    File file = (File) v;
    builder.addBinaryBody(k, file, ContentType.MULTIPART_FORM_DATA.withCharset(charSet), FileUtil.getName(file));
    } else {
    builder.addTextBody(k, v.toString(), ContentType.TEXT_PLAIN.withCharset(charSet));
    }
    });
    Request request = Request.post(urlString)
    .body(builder.build());
    //添加消息头
    if (CollUtil.isNotEmpty(handlerMap)) {
    handlerMap.forEach((k, v) -> request.addHeader(k, v.toString()));
    }
    return call(request);
    }

    public static String post(String urlString, Map<String, Object> paramMap) throws Exception {
    return post(urlString, paramMap, CharsetUtil.CHARSET_UTF_8);
    }

    public static String post(String urlString, Map<String, Object> paramMap, Charset charSet) throws Exception {
    return post(urlString, null, paramMap, charSet)
    .returnContent()
    .asString(charSet);
    }

    public static Response post(String urlString, Map<String, Object> handlerMap, Map<String, Object> paramMap) throws Exception {
    return post(urlString, handlerMap, paramMap, CharsetUtil.CHARSET_UTF_8);
    }

    public static Response post(String urlString, Map<String, Object> handlerMap, Map<String, Object> paramMap, Charset charSet) throws Exception {
    Form form = Form.form();
    if (CollUtil.isNotEmpty(paramMap)) {
    paramMap.forEach((k, v) -> form.add(k, v.toString()));
    }
    Request request = Request.post(urlString)
    .bodyForm(form.build(), charSet);
    //添加消息头
    if (CollUtil.isNotEmpty(handlerMap)) {
    handlerMap.forEach((k, v) -> request.addHeader(k, v.toString()));
    }
    return call(request);
    }

    public static String post(String urlString, String body) throws IOException {
    return post(urlString, body, CharsetUtil.CHARSET_UTF_8);
    }

    public static String post(String urlString, String body, Charset charSet) throws IOException {
    return post(urlString, null, body, charSet)
    .returnContent()
    .asString(charSet);
    }

    public static Response post(String urlString, Map<String, Object> handlerMap, String body) throws IOException {
    return post(urlString, handlerMap, body, CharsetUtil.CHARSET_UTF_8);
    }

    public static Response post(String urlString, Map<String, Object> handlerMap, String body, Charset charSet) throws IOException {
    HttpEntity httpEntity = HttpEntities.create(body, charSet);
    Request request = Request.post(urlString)
    .body(httpEntity);
    //添加消息头
    if (CollUtil.isNotEmpty(handlerMap)) {
    handlerMap.forEach((k, v) -> request.addH