支持使用LDAPS的认证插件。
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

165 lines
5.1 KiB

package com.fr.plugin.decision.passport.ldaps;
import com.fr.decision.authorize.Passport;
import com.fr.decision.config.FSConfig;
import com.fr.decision.webservice.bean.authentication.PassportBean;
import com.fr.decision.webservice.utils.DecisionServiceConstants;
import com.fr.decision.webservice.utils.WebServiceUtils;
import com.fr.stable.StringUtils;
import com.fr.third.fasterxml.jackson.annotation.JsonSubTypes;
/**
* LDAP认证方式
* Created by zhouping on 2018/3/4.
*/
@JsonSubTypes.Type(value = LdapsAuthenticBean.class, name = "LdapAuthenticBean")
public class LdapsAuthenticBean extends PassportBean<LdapsPassport> {
private static final long serialVersionUID = -5233155996986308766L;
//认证URL
private String url;
//检索位置
private String searchBase;
//是否将BaseDN作为检索位置,是的话就加到url中,否则加到search的参数中
private boolean retrieveLocAsBaseDN;
//LDAP认证方式种类,none,simple,strong
private String authentication;
//context初始化的Factory,一般用这个默认值
private String contextFactory;
//指定将如何处理服务提供者遇到的引用的环境属性名称,follow, ignore, throw
private String referral;
//ldap用户后缀,如@finereport.com
private String principalSuffix;
//ldap系统的管理员姓名
private String systemName;
//ldap系统的管理员密码
private String systemPassword;
//ldaps证书路径
private String certPath;
public LdapsAuthenticBean() {
}
public String getAuthentication() {
return authentication;
}
public void setAuthentication(String authentication) {
this.authentication = authentication;
}
public String getContextFactory() {
return contextFactory;
}
public void setContextFactory(String contextFactory) {
this.contextFactory = contextFactory;
}
public String getPrincipalSuffix() {
return principalSuffix;
}
public void setPrincipalSuffix(String principalSuffix) {
this.principalSuffix = principalSuffix;
}
public String getReferral() {
return referral;
}
public void setReferral(String referral) {
this.referral = referral;
}
public String getSearchBase() {
return searchBase;
}
public void setSearchBase(String searchBase) {
this.searchBase = searchBase;
}
public String getSystemPassword() {
return systemPassword;
}
public void setSystemPassword(String systemPassword) {
this.systemPassword = systemPassword;
}
public String getSystemName() {
return systemName;
}
public void setSystemName(String systemName) {
this.systemName = systemName;
}
public boolean isRetrieveLocAsBaseDN() {
return retrieveLocAsBaseDN;
}
public void setRetrieveLocAsBaseDN(boolean retrieveLocAsBaseDN) {
this.retrieveLocAsBaseDN = retrieveLocAsBaseDN;
}
public String getUrl() {
return url;
}
public void setUrl(String url) {
this.url = url;
}
public String getCertPath() {
return certPath;
}
public void setCertPath(String certPath) {
this.certPath = certPath;
}
@Override
public String markType() {
return LdapsPassportProvider.PASSPORT_TYPE;
}
@Override
public PassportBean<LdapsPassport> createPassportBean(LdapsPassport passport) {
this.setUrl(passport.getLdapUrl());
this.setSearchBase(passport.getLdapSearchBase());
this.setRetrieveLocAsBaseDN(passport.isRetrieveLocAsBaseDN());
this.setAuthentication(passport.getAuthentication());
this.setContextFactory(passport.getContextFactory());
this.setReferral(passport.getReferral());
this.setPrincipalSuffix(passport.getPrincipalSuffix());
this.setSystemName(passport.getLdapSystemName());
if (StringUtils.isNotEmpty(passport.getLdapSystemPassword())) {
this.setSystemPassword(DecisionServiceConstants.DEFAULT_PASSWORD);
}
this.setCertPath(passport.getCertPath());
return this;
}
@Override
public Passport createPassport() {
LdapsPassport passport = new LdapsPassport();
passport.setLdapUrl(getUrl());
passport.setLdapSearchBase(getSearchBase());
passport.setRetrieveLocAsBaseDN(isRetrieveLocAsBaseDN());
passport.setAuthentication(getAuthentication());
passport.setContextFactory(getContextFactory());
passport.setReferral(getReferral());
passport.setPrincipalSuffix(getPrincipalSuffix());
passport.setLdapSystemName(getSystemName());
if (WebServiceUtils.isDefaultPassword(this.systemPassword)) {
String oldPassword = FSConfig.getInstance().getPassport(LdapsPassport.class).getLdapSystemPassword();
passport.setLdapSystemPassword(oldPassword);
} else {
passport.setLdapSystemPassword(WebServiceUtils.getBase64DecodeStr(this.systemPassword));
}
passport.setCertPath(getCertPath());
return passport;
}
}