spring boot 配置ldaps 連線

2022-09-09 02:06:11 字數 4204 閱讀 6634

package

com.github.wxiaoqi.security.common.config;

import

lombok.extern.slf4j.slf4j;

import

org.springframework.beans.factory.annotation.value;

import

org.springframework.boot.autoconfigure.condition.conditionalonexpression;

import

org.springframework.context.annotation.bean;

import

org.springframework.context.annotation.primary;

import

org.springframework.ldap.core.ldaptemplate;

import

org.springframework.ldap.core.support.ldapcontextsource;

import

j**a.util.hashtable;

import

j**a.util.objects;

/***

@author

margo

* @date 2021/11/4 */

@slf4j

//@conditionalonexpression("$")

public

class

ldapconfiguration ")

private

string ldapurl;

@value("$")

private

string ldapbasedc;

@value("$")

private

string ldapusername;

@value("$")

private

/*** 繼承ldapcontextsource重寫getanonymousenv方法來載入,

* 使連線ldap時用ssl連線(由於修改ad密碼時必須使用ssl連線)

*/public

class ssldapcontextsource extends

ldapcontextsource

}@bean

public

ldapcontextsource contextsource()

@bean

public

ldaptemplate ldaptemplate(ldapcontextsource contextsource)

if (null ==ldaptemplate)

return

ldaptemplate;

}}

package

com.github.wxiaoqi.security.common.config;

import

j**ax.net.socketfactory;

import

j**ax.net.ssl.sslcontext;

import

j**ax.net.ssl.sslsocketfactory;

import

j**ax.net.ssl.trustmanager;

import

j**ax.net.ssl.x509trustmanager;

import

j**a.io.ioexception;

import

j**a.net.inetaddress;

import

j**a.net.socket;

import

j**a.net.unknownhostexception;

import

j**a.security.securerandom;

import

j**a.security.cert.certificateexception;

import

j**a.security.cert.x509certificate;

/*** 自定義的ssl工廠裡面載入自己實現x509trustmanager,信任自簽證書

* @authorcb

*/public

class customsslsocketfactory extends

sslsocketfactory , new

securerandom());

socketfactory =ctx.getsocketfactory();

} catch

(exception ex)

}public

static

socketfactory getdefault()

@override

public

string getdefaultciphersuites()

@override

public

string getsupportedciphersuites()

@override

public socket createsocket(socket socket, string string, int num, boolean bool) throws

ioexception

@override

public socket createsocket(string string, int num) throws

ioexception, unknownhostexception

@override

public socket createsocket(string string, int num, inetaddress netadd, int i) throws

ioexception, unknownhostexception

@override

public socket createsocket(inetaddress netadd, int num) throws

ioexception

@override

public socket createsocket(inetaddress netadd1, int num, inetaddress netadd2, int i) throws

ioexception

/*** 證書

*/public

static

class dummytrustmanager implements

x509trustmanager

@override

public

void checkservertrusted(x509certificate cert, string string) throws

certificateexception

@override

public

x509certificate getacceptedissuers()

}}

主要的配置是 customsslsocketfactory  這個類,其他的正常配置。

配置好後啟動應用,又出現了另外乙個錯誤,

j**ax.net.ssl.sslhandshakeexception: j**a.security.cert.certificateexception

那麼在啟動main方法中加上一行環境變數配置即可

@enableeurekaclient

@enableconfigurationproperties

@enabletransactionmanagement

@import(value = )

@enablescheduling

public

class

public

static

void

main(string args)

@bean

public

resttemplate resttemplate()

}

system.setproperty("com.sun.jndi.ldap.object.disableendpointidentification", "true");  這行

LDA 動手實現LDA

這段時間對lda比較感興趣,嘗試在工作中使用它。平時做想法的快速驗證,都用的是 gibbslda 0.2 乙個c實現版本的lda。這兩天用c stl自己寫了乙個單機版的lda,初衷如下 1.gibbslda 0.2 雖說號稱是最popular的lda工具包,不過依然有明顯的bug,參考 lda 修正...

lda 協方差矩陣 LDA模型

lda是一種文件主題生成模型,也稱為乙個三層貝葉斯概率模型,包含詞 主題和文件三層結構。作為一種非監督機器學習技術,可以用來識別大規模文件集或語料庫中潛藏的主題資訊。它採用了詞袋的方法,這種方法將每一篇文件視為乙個詞頻向量,從而將文字資訊轉化為了易於建模的數字資訊。但是詞袋方法沒有考慮詞與詞之間的順...

SpringBoot常用配置

前言 springboot整合了主流的第三方框架,但是需要使用springboot那一套配置方式。但是我這裡只列舉了非常非常常用的,可以看已發的幾篇部落格,慢慢會補充。當然官方文件裡也有相應的配置,可惜沒有注釋。spring.resources.cache period 設定資源的快取時效,以秒為單...