LAPTOP-SB56SG4Q\86185
3 years ago
16 changed files with 823 additions and 1 deletions
Binary file not shown.
@ -1,3 +1,6 @@
|
||||
# open-JSD-8070 |
||||
|
||||
JSD-8070 LDAP用户同步 |
||||
JSD-8070 LDAP用户同步\ |
||||
免责说明:该源码为第三方爱好者提供,不保证源码和方案的可靠性,也不提供任何形式的源码教学指导和协助!\ |
||||
仅作为开发者学习参考使用!禁止用于任何商业用途!\ |
||||
为保护开发者隐私,开发者信息已隐去!若原开发者希望公开自己的信息,可联系hugh处理。 |
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -0,0 +1,18 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="no"?> |
||||
<plugin> |
||||
<id>com.fr.plugin.third.party.jsd8070</id> |
||||
<name><![CDATA[LADP用户同步]]></name> |
||||
<active>yes</active> |
||||
<version>0.1</version> |
||||
<env-version>10.0</env-version> |
||||
<jartime>2019-01-01</jartime> |
||||
<vendor>fr.open</vendor> |
||||
<description><![CDATA[]]></description> |
||||
<change-notes><![CDATA[]]></change-notes> |
||||
<extra-designer> |
||||
<ServerTableDataDefineProvider class="com.fr.plugin.third.party.jsdiaha.data.CustomHttpTableDataDefine"/> |
||||
<TableDataDefineProvider class="com.fr.plugin.third.party.jsdiaha.data.CustomHttpTableDataDefine"/> |
||||
</extra-designer> |
||||
<function-recorder class="com.fr.plugin.third.party.jsdiaha.config.DataConfigInitializeMonitor"/> |
||||
<lifecycle-monitor class="com.fr.plugin.third.party.jsdiaha.config.DataConfigInitializeMonitor"/> |
||||
</plugin> |
@ -0,0 +1,130 @@
|
||||
package com.fr.plugin.third.party.jsdiaha.config; |
||||
|
||||
|
||||
import com.fr.config.*; |
||||
import com.fr.config.holder.Conf; |
||||
import com.fr.config.holder.factory.Holders; |
||||
|
||||
/** |
||||
* 配置数据保存 |
||||
*/ |
||||
@Visualization(category = "LADP用户同步配置") |
||||
public class CustomDataConfig extends DefaultConfiguration { |
||||
private static volatile CustomDataConfig config = null; |
||||
|
||||
public String getNameSpace() { |
||||
return this.getClass().getName(); |
||||
} |
||||
|
||||
public static CustomDataConfig getInstance() { |
||||
if (config == null) { |
||||
config = ConfigContext.getConfigInstance(CustomDataConfig.class); |
||||
} |
||||
return config; |
||||
} |
||||
|
||||
|
||||
@Identifier(value = "hostname", name = "主机地址", description = "", status = Status.SHOW) |
||||
private Conf<String> hostname = Holders.simple(""); |
||||
|
||||
@Identifier(value = "port", name = "主机端口号", description = "", status = Status.SHOW) |
||||
private Conf<Integer> port = Holders.simple(389); |
||||
|
||||
@Identifier(value = "userDN", name = "用户DN", description = "", status = Status.SHOW) |
||||
private Conf<String> userDN = Holders.simple(""); |
||||
|
||||
@Identifier(value = "password", name = "密码", description = "", status = Status.SHOW) |
||||
private Conf<String> password = Holders.simple(""); |
||||
|
||||
@Identifier(value = "baseDN", name = "基准DN", description = "", status = Status.SHOW) |
||||
private Conf<String> baseDN = Holders.simple(""); |
||||
|
||||
|
||||
@Identifier(value = "userIdColumn", name = "用户字段名", description = "", status = Status.SHOW) |
||||
private Conf<String> userIdColumn = Holders.simple("sAMAccountName"); |
||||
|
||||
@Identifier(value = "usernameColumn", name = "用户姓名字段名", description = "", status = Status.SHOW) |
||||
private Conf<String> usernameColumn = Holders.simple("displayName"); |
||||
|
||||
@Identifier(value = "emailColumn", name = "邮箱字段名", description = "", status = Status.SHOW) |
||||
private Conf<String> emailColumn = Holders.simple("email"); |
||||
|
||||
|
||||
public String getHostname() { |
||||
return hostname.get(); |
||||
} |
||||
|
||||
public void setHostname(String hostname) { |
||||
this.hostname.set(hostname); |
||||
} |
||||
|
||||
public Integer getPort() { |
||||
return port.get(); |
||||
} |
||||
|
||||
public void setPort(Integer port) { |
||||
this.port.set(port); |
||||
} |
||||
|
||||
public String getUserDN() { |
||||
return userDN.get(); |
||||
} |
||||
|
||||
public void setUserDN(String userDN) { |
||||
this.userDN.set(userDN); |
||||
} |
||||
|
||||
public String getPassword() { |
||||
return password.get(); |
||||
} |
||||
|
||||
public void setPassword(String password) { |
||||
this.password.set(password); |
||||
} |
||||
|
||||
public String getBaseDN() { |
||||
return baseDN.get(); |
||||
} |
||||
|
||||
public void setBaseDN(String baseDN) { |
||||
this.baseDN.set(baseDN); |
||||
} |
||||
|
||||
public String getUserIdColumn() { |
||||
return userIdColumn.get(); |
||||
} |
||||
|
||||
public void setUserIdColumn(String userIdColumn) { |
||||
this.userIdColumn.set(userIdColumn); |
||||
} |
||||
|
||||
public String getUsernameColumn() { |
||||
return usernameColumn.get(); |
||||
} |
||||
|
||||
public void setUsernameColumn(String usernameColumn) { |
||||
this.usernameColumn.set(usernameColumn); |
||||
} |
||||
|
||||
public String getEmailColumn() { |
||||
return emailColumn.get(); |
||||
} |
||||
|
||||
public void setEmailColumn(String emailColumn) { |
||||
this.emailColumn.set(emailColumn); |
||||
} |
||||
|
||||
@Override |
||||
public Object clone() throws CloneNotSupportedException { |
||||
CustomDataConfig cloned = (CustomDataConfig) super.clone(); |
||||
cloned.hostname = (Conf<String>) hostname.clone(); |
||||
cloned.port = (Conf<Integer>) port.clone(); |
||||
cloned.userDN = (Conf<String>) userDN.clone(); |
||||
cloned.password = (Conf<String>) password.clone(); |
||||
cloned.baseDN = (Conf<String>) baseDN.clone(); |
||||
cloned.userIdColumn = (Conf<String>) userIdColumn.clone(); |
||||
cloned.usernameColumn = (Conf<String>) usernameColumn.clone(); |
||||
cloned.emailColumn = (Conf<String>) emailColumn.clone(); |
||||
return cloned; |
||||
} |
||||
} |
@ -0,0 +1,24 @@
|
||||
package com.fr.plugin.third.party.jsdiaha.config; |
||||
|
||||
import com.fr.intelli.record.Focus; |
||||
import com.fr.intelli.record.Original; |
||||
import com.fr.plugin.context.PluginContext; |
||||
import com.fr.plugin.observer.inner.AbstractPluginLifecycleMonitor; |
||||
import com.fr.record.analyzer.EnableMetrics; |
||||
|
||||
/** |
||||
* 配置信息初始化 |
||||
*/ |
||||
@EnableMetrics |
||||
public class DataConfigInitializeMonitor extends AbstractPluginLifecycleMonitor { |
||||
@Override |
||||
@Focus(id = "com.fr.plugin.third.party.jsd8070", text = "plugin-jsd-8070", source = Original.PLUGIN) |
||||
public void afterRun(PluginContext pluginContext) { |
||||
CustomDataConfig.getInstance(); |
||||
} |
||||
|
||||
@Override |
||||
public void beforeStop(PluginContext pluginContext) { |
||||
|
||||
} |
||||
} |
@ -0,0 +1,134 @@
|
||||
package com.fr.plugin.third.party.jsdiaha.data; |
||||
|
||||
import com.fanruan.api.log.LogKit; |
||||
import com.fanruan.api.util.StringKit; |
||||
import com.fr.base.TableData; |
||||
import com.fr.data.AbstractDataModel; |
||||
import com.fr.general.data.TableDataException; |
||||
import com.fr.plugin.third.party.jsdiaha.ldap.LdapInfo; |
||||
import com.fr.plugin.third.party.jsdiaha.ldap.LdapObject; |
||||
|
||||
import java.util.ArrayList; |
||||
import java.util.List; |
||||
import java.util.Map; |
||||
|
||||
public class CustomHttpDataModel extends AbstractDataModel { |
||||
private static String[] COLUMN_NAMES = {"user_id", "username", "password", "mail"}; |
||||
private int rowCount = TableData.RESULT_ALL; |
||||
private DatasetData datas = new DatasetData(); |
||||
|
||||
public CustomHttpDataModel(int count) { |
||||
this.rowCount = count; |
||||
if (this.rowCount == 0) { |
||||
return; |
||||
} |
||||
queryData(); |
||||
} |
||||
|
||||
@Override |
||||
public int getColumnCount() throws TableDataException { |
||||
return COLUMN_NAMES.length; |
||||
} |
||||
|
||||
@Override |
||||
public String getColumnName(int i) throws TableDataException { |
||||
return COLUMN_NAMES[i]; |
||||
} |
||||
|
||||
@Override |
||||
public boolean hasRow(int rowIndex) throws TableDataException { |
||||
int count = getRowCount(); |
||||
return rowIndex < count; |
||||
} |
||||
|
||||
@Override |
||||
public int getRowCount() throws TableDataException { |
||||
if (this.datas == null) { |
||||
return 0; |
||||
} |
||||
List<List<Object>> values = this.datas.getValues(); |
||||
if (values == null) { |
||||
return 0; |
||||
} |
||||
int count = values.size(); |
||||
return count; |
||||
} |
||||
|
||||
@Override |
||||
public Object getValueAt(int rowIndex, int columnIndex) throws TableDataException { |
||||
if (this.datas == null) { |
||||
return ""; |
||||
} |
||||
List<List<Object>> values = this.datas.getValues(); |
||||
if ((values == null) || (values.size() <= rowIndex)) { |
||||
return ""; |
||||
} |
||||
List<Object> rowValues = values.get(rowIndex); |
||||
if ((rowValues == null) || (rowValues.size() <= columnIndex)) { |
||||
return ""; |
||||
} |
||||
return rowValues.get(columnIndex); |
||||
} |
||||
|
||||
@Override |
||||
public void release() throws Exception { |
||||
this.datas = null; |
||||
} |
||||
|
||||
/** |
||||
* 查询数据 |
||||
*/ |
||||
private void queryData() { |
||||
try { |
||||
createDatas(); |
||||
} catch (Exception e) { |
||||
LogKit.error("LDAP数据集获取用户信息,请求出错," + e.getMessage(), e); |
||||
throw new NullPointerException("LDAP数据集获取用户信息为空"); |
||||
} |
||||
} |
||||
|
||||
|
||||
private void createDatas() throws Exception { |
||||
String deptName = "", jobTitle = "", userId = "", userName = "", password = "", code = "", fCode = "", mobile = "", mail = ""; |
||||
LdapInfo ldapInfo = new LdapInfo(); |
||||
ldapInfo.queryData(); |
||||
|
||||
List<LdapObject> ldapObjects = ldapInfo.getLdapObjects(); |
||||
Map<String, LdapObject> orgMap = ldapInfo.getOrgMap(); |
||||
LdapObject tempLdapObject, tempLdapObject1, tempLdapObject2; |
||||
for (int i = 0, max = ldapObjects.size() - 1; i <= max; i++) { |
||||
deptName = ""; |
||||
jobTitle = ""; |
||||
userId = ""; |
||||
userName = ""; |
||||
password = "111111"; |
||||
mobile = ""; |
||||
mail = ""; |
||||
code = ""; |
||||
fCode = ""; |
||||
tempLdapObject = ldapObjects.get(i); |
||||
if (tempLdapObject.isPerson()) { |
||||
userId = tempLdapObject.getUserId(); |
||||
userId = userId.trim(); |
||||
if (StringKit.isEmpty(userId)) { |
||||
continue; |
||||
} |
||||
|
||||
userName = tempLdapObject.getName(); |
||||
mail = tempLdapObject.getMail(); |
||||
addRowDatas(userId, userName, password, mail); |
||||
} |
||||
} |
||||
} |
||||
|
||||
// {"dept_name", "job_title", "user_id", "username", "password", "mobile", "mail", "code", "fcode"};
|
||||
private void addRowDatas(String userId, String userName, String password, String mail) { |
||||
List<Object> rowDatas = new ArrayList<>(); |
||||
rowDatas.add(userId); |
||||
rowDatas.add(userName); |
||||
rowDatas.add(password); |
||||
rowDatas.add(mail); |
||||
List<List<Object>> values = this.datas.getValues(); |
||||
values.add(rowDatas); |
||||
} |
||||
} |
@ -0,0 +1,18 @@
|
||||
package com.fr.plugin.third.party.jsdiaha.data; |
||||
|
||||
import com.fr.base.TableData; |
||||
import com.fr.data.AbstractParameterTableData; |
||||
import com.fr.general.data.DataModel; |
||||
import com.fr.script.Calculator; |
||||
|
||||
public class CustomHttpTableData extends AbstractParameterTableData { |
||||
@Override |
||||
public DataModel createDataModel(Calculator calculator) { |
||||
return createDataModel(calculator, TableData.RESULT_ALL); |
||||
} |
||||
|
||||
@Override |
||||
public DataModel createDataModel(Calculator calculator, int rowCount) { |
||||
return new CustomHttpDataModel(rowCount); |
||||
} |
||||
} |
@ -0,0 +1,50 @@
|
||||
package com.fr.plugin.third.party.jsdiaha.data; |
||||
|
||||
|
||||
import com.fr.base.TableData; |
||||
import com.fr.design.data.tabledata.tabledatapane.AbstractTableDataPane; |
||||
import com.fr.design.fun.ServerTableDataDefineProvider; |
||||
import com.fr.design.fun.impl.AbstractTableDataDefineProvider; |
||||
import com.fr.design.i18n.Toolkit; |
||||
|
||||
|
||||
public class CustomHttpTableDataDefine extends AbstractTableDataDefineProvider implements ServerTableDataDefineProvider { |
||||
|
||||
@Override |
||||
public int currentAPILevel() { |
||||
return CURRENT_LEVEL; |
||||
} |
||||
|
||||
@Override |
||||
public Class<? extends TableData> classForTableData() { |
||||
return CustomHttpTableData.class; |
||||
} |
||||
|
||||
@Override |
||||
public Class<? extends TableData> classForInitTableData() { |
||||
return CustomHttpTableData.class; |
||||
} |
||||
|
||||
@Override |
||||
public Class<? extends AbstractTableDataPane> appearanceForTableData() { |
||||
|
||||
return CustomHttpTableDataPane.class; |
||||
} |
||||
|
||||
@Override |
||||
public String nameForTableData() { |
||||
return Toolkit.i18nText("LDAP数据集"); |
||||
} |
||||
|
||||
@Override |
||||
public String prefixForTableData() { |
||||
return "ldap"; |
||||
} |
||||
|
||||
@Override |
||||
public String iconPathForTableData() { |
||||
return ""; |
||||
} |
||||
|
||||
|
||||
} |
@ -0,0 +1,76 @@
|
||||
package com.fr.plugin.third.party.jsdiaha.data; |
||||
|
||||
import com.fanruan.api.design.DesignKit; |
||||
import com.fanruan.api.design.ui.component.UIButton; |
||||
import com.fr.design.data.datapane.preview.PreviewTablePane; |
||||
import com.fr.design.data.tabledata.tabledatapane.AbstractTableDataPane; |
||||
import com.fr.general.IOUtils; |
||||
|
||||
import javax.swing.*; |
||||
import java.awt.*; |
||||
import java.awt.event.ActionEvent; |
||||
import java.awt.event.ActionListener; |
||||
|
||||
|
||||
public class CustomHttpTableDataPane extends AbstractTableDataPane<CustomHttpTableData> { |
||||
public CustomHttpTableDataPane() { |
||||
super(); |
||||
createContent(); |
||||
} |
||||
|
||||
|
||||
|
||||
@Override |
||||
public void populateBean(CustomHttpTableData ob) { |
||||
if (ob == null) { |
||||
return; |
||||
} |
||||
|
||||
} |
||||
|
||||
@Override |
||||
public CustomHttpTableData updateBean() { |
||||
CustomHttpTableData tableData = new CustomHttpTableData(); |
||||
return tableData; |
||||
} |
||||
|
||||
@Override |
||||
protected String title4PopupWindow() { |
||||
return DesignKit.i18nText("LDAP数据集"); |
||||
} |
||||
|
||||
|
||||
private void createContent() { |
||||
setLayout(new BorderLayout()); |
||||
JPanel contentPane = new JPanel(); |
||||
contentPane.setLayout(new BorderLayout()); |
||||
add(contentPane, BorderLayout.CENTER); |
||||
|
||||
|
||||
JPanel connectionPanel = new JPanel(new FlowLayout(FlowLayout.LEFT, 10, 5)); |
||||
|
||||
UIButton previewButton = createIconButton("Fine-Design_Basic_Preview", "/com/fr/design/images/m_file/preview.png"); |
||||
previewButton.addActionListener(new ActionListener() { |
||||
public void actionPerformed(ActionEvent e) { |
||||
PreviewTablePane.previewTableData(updateBean()); |
||||
} |
||||
}); |
||||
connectionPanel.add(previewButton); |
||||
contentPane.add(connectionPanel, BorderLayout.NORTH); |
||||
|
||||
} |
||||
|
||||
/** |
||||
* 获取图标按钮 |
||||
* |
||||
* @param toolTip 提示信息,国际化key |
||||
* @param iconPath 图标路径 |
||||
* @return |
||||
*/ |
||||
public static UIButton createIconButton(String toolTip, String iconPath) { |
||||
UIButton iconButton = new UIButton(IOUtils.readIcon(iconPath)); |
||||
iconButton.setToolTipText(DesignKit.i18nText(toolTip)); |
||||
return iconButton; |
||||
} |
||||
|
||||
} |
@ -0,0 +1,67 @@
|
||||
package com.fr.plugin.third.party.jsdiaha.data; |
||||
|
||||
import java.util.ArrayList; |
||||
import java.util.List; |
||||
|
||||
/** |
||||
* 数据集数据 |
||||
*/ |
||||
public class DatasetData { |
||||
private String name; |
||||
private List<String> columns; |
||||
private List<List<Object>> values; |
||||
|
||||
public DatasetData() { |
||||
columns = new ArrayList<String>(); |
||||
values = new ArrayList<List<Object>>(); |
||||
} |
||||
|
||||
/** |
||||
* 获取表名 |
||||
* @return 表名 |
||||
*/ |
||||
public String getName() { |
||||
return this.name; |
||||
} |
||||
|
||||
/** |
||||
* 设置表名 |
||||
* @param name 表名 |
||||
*/ |
||||
public void setName(String name) { |
||||
this.name = name; |
||||
} |
||||
|
||||
/** |
||||
* 获取列名 |
||||
* @return 列名 |
||||
*/ |
||||
public List<String> getColumns() { |
||||
return this.columns; |
||||
} |
||||
|
||||
/** |
||||
* 设置列名 |
||||
* @param columns 列名 |
||||
*/ |
||||
public void setColumns(List<String> columns) { |
||||
this.columns = columns; |
||||
} |
||||
|
||||
/** |
||||
* 获取表数据 |
||||
* @return 表数据 |
||||
*/ |
||||
public List<List<Object>> getValues() { |
||||
return this.values; |
||||
} |
||||
|
||||
/** |
||||
* 设置表数据 |
||||
* @param values |
||||
*/ |
||||
public void setValues(List<List<Object>> values) { |
||||
this.values = values; |
||||
} |
||||
|
||||
} |
@ -0,0 +1,95 @@
|
||||
package com.fr.plugin.third.party.jsdiaha.ldap; |
||||
|
||||
import com.fr.plugin.third.party.jsdiaha.config.CustomDataConfig; |
||||
import com.novell.ldap.LDAPConnection; |
||||
import com.novell.ldap.LDAPEntry; |
||||
import com.novell.ldap.LDAPSearchConstraints; |
||||
import com.novell.ldap.LDAPSearchResults; |
||||
|
||||
import java.util.ArrayList; |
||||
import java.util.HashMap; |
||||
import java.util.List; |
||||
import java.util.Map; |
||||
|
||||
public class LdapInfo { |
||||
private String hostName = "localhost"; |
||||
private int port = 389; |
||||
private String userDN = "cn=Manager,dc=micmiu,dc=com"; |
||||
private String password = "secret"; |
||||
private String baseDN = "dc=micmiu,dc=com"; |
||||
private String searchFilter = "objectClass=*"; |
||||
|
||||
private List<LdapObject> ldapObjects = new ArrayList<>(); |
||||
private Map<String, LdapObject> orgMap = new HashMap<>(); |
||||
|
||||
public void queryData() throws Exception { |
||||
this.hostName = CustomDataConfig.getInstance().getHostname(); |
||||
this.port = CustomDataConfig.getInstance().getPort(); |
||||
this.userDN = CustomDataConfig.getInstance().getUserDN(); |
||||
this.password = CustomDataConfig.getInstance().getPassword(); |
||||
this.baseDN = CustomDataConfig.getInstance().getBaseDN(); |
||||
|
||||
// 查询范围
|
||||
// SCOPE_BASE、SCOPE_ONE、SCOPE_SUB、SCOPE_SUBORDINATESUBTREE
|
||||
int searchScope = LDAPConnection.SCOPE_SUB; |
||||
|
||||
//超时30秒
|
||||
int timeout = 30000; |
||||
LDAPConnection lc = new LDAPConnection(timeout); |
||||
lc.connect(this.hostName, this.port); |
||||
lc.bind(LDAPConnection.LDAP_V3, this.userDN, this.password.getBytes("UTF8")); |
||||
LDAPSearchConstraints ldsc = new LDAPSearchConstraints(); |
||||
ldsc.setMaxResults(100000); |
||||
lc.setConstraints(ldsc); |
||||
LDAPSearchResults searchResults = lc.search(baseDN, |
||||
searchScope, null, null, false); |
||||
LDAPEntry nextEntry = null; |
||||
LdapObject ldapObject; |
||||
while (searchResults.hasMore()) { |
||||
nextEntry = searchResults.next(); |
||||
|
||||
ldapObject = new LdapObject(); |
||||
ldapObject.loadData(nextEntry); |
||||
if (!ldapObject.isValidOption()) { |
||||
continue; |
||||
} |
||||
ldapObjects.add(ldapObject); |
||||
if (ldapObject.isOrg()) { |
||||
orgMap.put(ldapObject.getDn(), ldapObject); |
||||
} |
||||
|
||||
|
||||
/* |
||||
LogKit.info("DN =: " + nextEntry.getDN()); |
||||
LogKit.info("|---- Attributes list: "); |
||||
LDAPAttributeSet attributeSet = nextEntry.getAttributeSet(); |
||||
Iterator<LDAPAttribute> allAttributes = attributeSet.iterator(); |
||||
while (allAttributes.hasNext()) { |
||||
LDAPAttribute attribute = allAttributes.next(); |
||||
String attributeName = attribute.getName(); |
||||
Enumeration<String> allValues = attribute.getStringValues(); |
||||
if (null == allValues) { |
||||
continue; |
||||
} |
||||
while (allValues.hasMoreElements()) { |
||||
String value = allValues.nextElement(); |
||||
//if (!Base64.isLDIFSafe(value)) {
|
||||
// base64 encode and then print out
|
||||
// value = Base64.encode(value.getBytes());
|
||||
//}
|
||||
LogKit.info("|---- ---- " + attributeName + " = " + value); |
||||
} |
||||
}*/ |
||||
|
||||
} |
||||
} |
||||
|
||||
public List<LdapObject> getLdapObjects() { |
||||
return ldapObjects; |
||||
} |
||||
|
||||
public Map<String, LdapObject> getOrgMap() { |
||||
return orgMap; |
||||
} |
||||
|
||||
} |
@ -0,0 +1,207 @@
|
||||
package com.fr.plugin.third.party.jsdiaha.ldap; |
||||
|
||||
import com.fanruan.api.util.StringKit; |
||||
import com.fr.plugin.third.party.jsdiaha.config.CustomDataConfig; |
||||
import com.novell.ldap.LDAPAttribute; |
||||
import com.novell.ldap.LDAPEntry; |
||||
import com.novell.ldap.util.Base64; |
||||
|
||||
public class LdapObject { |
||||
public static String LDAP_OBJECT_TYPE_ORG = "ORG"; |
||||
public static String LDAP_OBJECT_TYPE_PERSON = "PERSON"; |
||||
public static String LDAP_OBJECT_TYPE_NONE = "NONE"; |
||||
|
||||
private LDAPEntry ldapEntry; |
||||
|
||||
private String dn = ""; |
||||
private String type = ""; |
||||
private String objectGUID = ""; |
||||
private String name = ""; |
||||
|
||||
private String userId; |
||||
private String jobTitle; |
||||
private String mobile; |
||||
private String mail; |
||||
|
||||
private String parentDn = ""; |
||||
|
||||
private boolean validOption = false; |
||||
|
||||
|
||||
public void loadData(LDAPEntry entry) { |
||||
setValidOption(false); |
||||
if (entry == null) { |
||||
return; |
||||
} |
||||
this.ldapEntry = entry; |
||||
setDn(this.ldapEntry.getDN()); |
||||
setType(createType()); |
||||
if (LDAP_OBJECT_TYPE_NONE.equals(this.type)) { |
||||
return; |
||||
} |
||||
|
||||
//String tempValue = getAttribute("objectGUID");
|
||||
//setObjectGUID(Base64.encode(tempValue.getBytes()));
|
||||
//tempValue = getAttribute("name");
|
||||
//setName(tempValue);
|
||||
|
||||
//setParentDn(createParentDn());
|
||||
//用户名(登录的username)
|
||||
//用户姓名(realname)
|
||||
//角色(对应域的usergroup)
|
||||
//邮箱
|
||||
String tempValue; |
||||
if (isPerson()) { |
||||
tempValue = getAttribute(CustomDataConfig.getInstance().getUserIdColumn()); |
||||
setUserId(tempValue); |
||||
tempValue = getAttribute(CustomDataConfig.getInstance().getUsernameColumn()); |
||||
setName(tempValue); |
||||
tempValue = getAttribute(CustomDataConfig.getInstance().getEmailColumn()); |
||||
setMail(tempValue); |
||||
} |
||||
setValidOption(true); |
||||
} |
||||
|
||||
|
||||
private String getAttribute(String attrName) { |
||||
if ((this.ldapEntry == null) || (StringKit.isEmpty(attrName))) { |
||||
return ""; |
||||
} |
||||
LDAPAttribute ldapAttribute = this.ldapEntry.getAttribute(attrName); |
||||
if (ldapAttribute == null) { |
||||
return ""; |
||||
} |
||||
|
||||
String[] values = ldapAttribute.getStringValueArray(); |
||||
if ((values == null) || (values.length <= 0)) { |
||||
return ""; |
||||
} |
||||
String value = values[0]; |
||||
return value; |
||||
} |
||||
|
||||
private String createParentDn() { |
||||
if (StringKit.isEmpty(this.dn)) { |
||||
return ""; |
||||
} |
||||
int index = this.dn.indexOf(","); |
||||
if (index < 0) { |
||||
return ""; |
||||
} |
||||
String tempValue = this.dn.substring(index + 1); |
||||
return tempValue; |
||||
} |
||||
|
||||
|
||||
private String createType() { |
||||
if (StringKit.isEmpty(this.dn)) { |
||||
return LDAP_OBJECT_TYPE_NONE; |
||||
} |
||||
if (this.dn.startsWith("CN=")) { |
||||
return LDAP_OBJECT_TYPE_PERSON; |
||||
} |
||||
if (this.dn.startsWith("OU=")) { |
||||
return LDAP_OBJECT_TYPE_ORG; |
||||
} |
||||
return LDAP_OBJECT_TYPE_NONE; |
||||
} |
||||
|
||||
|
||||
public boolean isOrg() { |
||||
if (LDAP_OBJECT_TYPE_ORG.equals(this.type)) { |
||||
return true; |
||||
} |
||||
return false; |
||||
} |
||||
|
||||
public boolean isPerson() { |
||||
if (LDAP_OBJECT_TYPE_PERSON.equals(this.type)) { |
||||
return true; |
||||
} |
||||
return false; |
||||
} |
||||
|
||||
|
||||
public String getDn() { |
||||
return dn; |
||||
} |
||||
|
||||
public void setDn(String dn) { |
||||
this.dn = dn; |
||||
} |
||||
|
||||
public String getType() { |
||||
return type; |
||||
} |
||||
|
||||
public void setType(String type) { |
||||
this.type = type; |
||||
} |
||||
|
||||
public boolean isValidOption() { |
||||
return validOption; |
||||
} |
||||
|
||||
public void setValidOption(boolean option) { |
||||
this.validOption = option; |
||||
} |
||||
|
||||
public String getObjectGUID() { |
||||
return objectGUID; |
||||
} |
||||
|
||||
public void setObjectGUID(String guid) { |
||||
this.objectGUID = guid; |
||||
} |
||||
|
||||
public String getName() { |
||||
return name; |
||||
} |
||||
|
||||
public void setName(String name) { |
||||
this.name = name; |
||||
} |
||||
|
||||
public String getUserId() { |
||||
return userId; |
||||
} |
||||
|
||||
public void setUserId(String id) { |
||||
//if (StringKit.isNotEmpty(id)) {
|
||||
// id = id.toUpperCase();
|
||||
//}
|
||||
this.userId = id; |
||||
} |
||||
|
||||
public String getJobTitle() { |
||||
return jobTitle; |
||||
} |
||||
|
||||
public void setJobTitle(String jobTitle) { |
||||
this.jobTitle = jobTitle; |
||||
} |
||||
|
||||
public String getMobile() { |
||||
return mobile; |
||||
} |
||||
|
||||
public void setMobile(String mobile) { |
||||
this.mobile = mobile; |
||||
} |
||||
|
||||
public String getMail() { |
||||
return mail; |
||||
} |
||||
|
||||
public void setMail(String mail) { |
||||
this.mail = mail; |
||||
} |
||||
|
||||
public String getParentDn() { |
||||
return parentDn; |
||||
} |
||||
|
||||
public void setParentDn(String dn) { |
||||
this.parentDn = dn; |
||||
} |
||||
} |
Loading…
Reference in new issue