Java源码示例:org.apache.directory.shared.ldap.entry.client.DefaultClientAttribute
示例1
public void addAttribute(String dn, String attrName, String attrValue)
throws Exception {
EntryAttribute attr = new DefaultClientAttribute(attrName, attrValue);
Modification addValue = new ClientModification(
ModificationOperation.ADD_ATTRIBUTE, attr);
service.getAdminSession().modify(new DN(dn),
Collections.singletonList(addValue));
}
示例2
public void removeAttribute(String dn, String attrName, String attrValue)
throws Exception {
EntryAttribute attr = new DefaultClientAttribute(attrName, attrValue);
Modification removeValue = new ClientModification(
ModificationOperation.REMOVE_ATTRIBUTE, attr);
service.getAdminSession().modify(new DN(dn),
Collections.singletonList(removeValue));
}
示例3
public void addAttribute(String dn, String attrName, String attrValue)
throws Exception {
EntryAttribute attr = new DefaultClientAttribute(attrName, attrValue);
Modification addValue = new ClientModification(
ModificationOperation.ADD_ATTRIBUTE, attr);
service.getAdminSession().modify(new DN(dn),
Collections.singletonList(addValue));
}
示例4
public void removeAttribute(String dn, String attrName, String attrValue)
throws Exception {
EntryAttribute attr = new DefaultClientAttribute(attrName, attrValue);
Modification removeValue = new ClientModification(
ModificationOperation.REMOVE_ATTRIBUTE, attr);
service.getAdminSession().modify(new DN(dn),
Collections.singletonList(removeValue));
}
示例5
@Override
protected void doPost(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {
Locale locale = req.getLocale();
HttpSession session = req.getSession();
if (session == null) {
res.sendRedirect("/");
return;
}
String userid = (String) session.getAttribute("userid");
String password = StringUtils.trim(req.getParameter("password"));
if (!StringUtils.isBlank(userid) && !StringUtils.isBlank(password) && password.length() >= 8) {
try {
DefaultClientAttribute entryAttribute = new DefaultClientAttribute("userPassword", encodeForLDAP(password.trim()));
ClientModification clientModification = new ClientModification();
clientModification.setAttribute(entryAttribute);
clientModification.setOperation(ModificationOperation.REPLACE_ATTRIBUTE);
ModifyRequestImpl modifyRequest = new ModifyRequestImpl(1);
modifyRequest.setName(new LdapDN("uid=" + encodeForLDAP(userid.trim()) + ",ou=people,dc=t246osslab,dc=org"));
modifyRequest.addModification(clientModification);
EmbeddedADS.getAdminSession().modify(modifyRequest);
StringBuilder bodyHtml = new StringBuilder();
bodyHtml.append("<form>");
bodyHtml.append(getMsg("msg.passwd.changed", locale));
bodyHtml.append("<br><br>");
bodyHtml.append("<a href=\"/admins/main\">" + getMsg("label.goto.admin.page", locale) + "</a>");
bodyHtml.append("</form>");
responseToClient(req, res, getMsg("title.csrf.page", locale), bodyHtml.toString());
} catch (Exception e) {
log.error("Exception occurs: ", e);
req.setAttribute("errorMessage", getErrMsg("msg.passwd.change.failed", locale));
doGet(req, res);
}
} else {
if (StringUtils.isBlank(password) || password.length() < 8) {
req.setAttribute("errorMessage", getErrMsg("msg.passwd.is.too.short", locale));
} else {
req.setAttribute("errorMessage", getErrMsg("msg.unknown.exception.occur",
new String[] { "userid: " + userid }, locale));
}
doGet(req, res);
}
}
示例6
@Override
protected void doPost(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {
Locale locale = req.getLocale();
HttpSession session = req.getSession();
if (session == null) {
res.sendRedirect("/");
return;
}
String userid = (String) session.getAttribute("userid");
if (userid == null) {
res.sendRedirect("/");
return;
}
String mail = StringUtils.trim(req.getParameter("mail"));
if (!StringUtils.isBlank(mail) && EmailUtils.isValidEmailAddress(mail)) {
try {
DefaultClientAttribute entryAttribute = new DefaultClientAttribute("mail", encodeForLDAP(mail.trim()));
ClientModification clientModification = new ClientModification();
clientModification.setAttribute(entryAttribute);
clientModification.setOperation(ModificationOperation.REPLACE_ATTRIBUTE);
ModifyRequestImpl modifyRequest = new ModifyRequestImpl(1);
modifyRequest.setName(new LdapDN("uid=" + encodeForLDAP(userid.trim()) + ",ou=people,dc=t246osslab,dc=org"));
modifyRequest.addModification(clientModification);
EmbeddedADS.getAdminSession().modify(modifyRequest);
StringBuilder bodyHtml = new StringBuilder();
bodyHtml.append("<form>");
bodyHtml.append(getMsg("msg.mail.changed", locale));
bodyHtml.append("<br><br>");
bodyHtml.append("<a href=\"/admins/main\">" + getMsg("label.goto.admin.page", locale) + "</a>");
bodyHtml.append("</form>");
responseToClient(req, res, getMsg("title.clickjacking.page", locale), bodyHtml.toString());
} catch (Exception e) {
log.error("Exception occurs: ", e);
req.setAttribute("errorMessage", getErrMsg("msg.mail.change.failed", locale));
doGet(req, res);
}
} else {
req.setAttribute("errorMessage", getErrMsg("msg.mail.format.is.invalid", locale));
doGet(req, res);
}
}
示例7
private static Modification replaceMod(String attrName, String newValue) {
return new ClientModification(
REPLACE_ATTRIBUTE, new DefaultClientAttribute(attrName, newValue));
}