spark二次开发之客户端实名制实现
服务端openfire数据可以通过LDAP来同步已经存在的完整用户信息。
客户端连接服务端后,对应查找用户并得到用户信息保存。
具体代码如下:
public PersonalPanel() {initPerson();//初始化 setLayout(new GridBagLayout()); JLabel firstNameLabel = new JLabel(); firstNameField = new JTextField(); ResourceUtils.resLabel(firstNameLabel, firstNameField, Res.getString("label.first.name") + ":"); if(null==firstNameField.getText()||"".equals(firstNameField.getText())){ setRealUserName(realUserName); firstNameField.setEditable(false); }
?
void initPerson(){ positions = CommonProfile.getPosition(jobTitleField.getText());//职称 sex = CommonProfile.getSex(sexField.getText()); realUserName = GetUserRealName();//查找用户名方法}
?
查找用户名方法(相当于搜索用户)
private String GetUserRealName() {final String byname = SparkManager.getSessionManager().getJID().substring(0, SparkManager.getSessionManager().getJID().indexOf("@"));//得到JID前缀final Collection<String> _usersearchservice = SearchManager.getInstance().getSearchServicesAsString();//得到服务器名称String name = null;try {for (String search : _usersearchservice) {ReportedData data;UserSearchManager usersearchManager = new UserSearchManager(SparkManager.getConnection());Form f = usersearchManager.getSearchForm(search);Form answer = f.createAnswerForm();//设置搜索条件answer.setAnswer("Name", true);answer.setAnswer("Email", true);answer.setAnswer("Username", true);answer.setAnswer("search", byname);data = usersearchManager.getSearchResults(answer, search);ArrayList<String> columnnames = new ArrayList<String>();Iterator<Column> columns = data.getColumns();while (columns.hasNext()) {ReportedData.Column column = (ReportedData.Column) columns.next();String label = column.getLabel();columnnames.add(label);}Iterator<Row> rows = data.getRows();if (rows.equals("") || rows == null) {JOptionPane.showMessageDialog(null,Res.getString("title.user.not.exists"));}while (rows.hasNext()) {ReportedData.Row row = (ReportedData.Row) rows.next();if(row.getValues(columnnames.get(1)).hasNext()){if (row.getValues(columnnames.get(2)).hasNext()&&byname.equals(row.getValues(columnnames.get(1)).next())) {name = (String) row.getValues(columnnames.get(2)).next();//得到具体用户名}}}}} catch (Exception e) {}return name;}