reset or change mailbox password if mailbox exists
This commit is contained in:
parent
9ea2f82a7b
commit
63201377f2
@ -57,7 +57,24 @@ public class MailboxDAO {
|
|||||||
final Map<String, Object> userAsMap = (Map<String, Object>) rpcResult[0];
|
final Map<String, Object> userAsMap = (Map<String, Object>) rpcResult[0];
|
||||||
return (String) userAsMap.get("name");
|
return (String) userAsMap.get("name");
|
||||||
}
|
}
|
||||||
throw new MailboxNotFound();
|
throw new MailboxNotFound("mailbox for " + localpart + " not found");
|
||||||
|
}
|
||||||
|
|
||||||
|
public void changePassword(String pac, String localpart, String newPassword) throws IOException, XmlRpcException, MailboxNotFound {
|
||||||
|
final String mailbox = getMailbox(pac, localpart);
|
||||||
|
final List<Serializable> xmlRpcParamsList = new ArrayList<Serializable>();
|
||||||
|
xmlRpcParamsList.add(pac);
|
||||||
|
xmlRpcParamsList.add(ticketBox.getTicket());
|
||||||
|
final HashMap<String, Serializable> setParamsMap = new HashMap<String, Serializable>();
|
||||||
|
xmlRpcParamsList.add(setParamsMap);
|
||||||
|
setParamsMap.put("password", newPassword);
|
||||||
|
final HashMap<String, Serializable> whereParamsMap = new HashMap<String, Serializable>();
|
||||||
|
xmlRpcParamsList.add(whereParamsMap);
|
||||||
|
whereParamsMap.put("name", mailbox);
|
||||||
|
final Object[] rpcResult = (Object[])rpcClient.execute("user.update", xmlRpcParamsList);
|
||||||
|
if (rpcResult.length != 1) {
|
||||||
|
throw new MailboxNotFound("mailbox for " + localpart + " not found");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void createMailbox(String pac, String localpart, String comment) throws IOException, XmlRpcException, MailboxNotFound {
|
private void createMailbox(String pac, String localpart, String comment) throws IOException, XmlRpcException, MailboxNotFound {
|
||||||
|
@ -4,4 +4,8 @@ public class MailboxNotFound extends Exception {
|
|||||||
|
|
||||||
private static final long serialVersionUID = 1L;
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
public MailboxNotFound(String message) {
|
||||||
|
super(message);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -66,7 +66,7 @@ public class DirectoryServiceRunner {
|
|||||||
directoryService.setShutdownHookEnabled(true);
|
directoryService.setShutdownHookEnabled(true);
|
||||||
directoryService.getChangeLog().setEnabled(false);
|
directoryService.getChangeLog().setEnabled(false);
|
||||||
directoryService.setAllowAnonymousAccess(false);
|
directoryService.setAllowAnonymousAccess(false);
|
||||||
directoryService.setAccessControlEnabled(true);
|
directoryService.setAccessControlEnabled(false);
|
||||||
directoryService.setPasswordHidden(false);
|
directoryService.setPasswordHidden(false);
|
||||||
return directoryService;
|
return directoryService;
|
||||||
}
|
}
|
||||||
|
@ -11,8 +11,12 @@ import javax.servlet.http.HttpServletRequest;
|
|||||||
import javax.servlet.http.HttpServletResponse;
|
import javax.servlet.http.HttpServletResponse;
|
||||||
import javax.servlet.http.HttpSession;
|
import javax.servlet.http.HttpSession;
|
||||||
|
|
||||||
|
import org.apache.xmlrpc.XmlRpcException;
|
||||||
|
|
||||||
import de.jalin.ldapadmin.beans.User;
|
import de.jalin.ldapadmin.beans.User;
|
||||||
import de.jalin.ldapadmin.beans.ValidationException;
|
import de.jalin.ldapadmin.beans.ValidationException;
|
||||||
|
import de.jalin.ldapadmin.hsadmin.MailboxDAO;
|
||||||
|
import de.jalin.ldapadmin.hsadmin.MailboxNotFound;
|
||||||
import de.jalin.ldapadmin.ldap.GroupsDAO;
|
import de.jalin.ldapadmin.ldap.GroupsDAO;
|
||||||
import de.jalin.ldapadmin.ldap.LDAPSessionException;
|
import de.jalin.ldapadmin.ldap.LDAPSessionException;
|
||||||
import de.jalin.ldapadmin.ldap.SimplePasswordException;
|
import de.jalin.ldapadmin.ldap.SimplePasswordException;
|
||||||
@ -22,7 +26,15 @@ import de.jalin.ldapadmin.ldap.UsersDAO;
|
|||||||
public class ProfileServlet extends AbstractLDAPServlet {
|
public class ProfileServlet extends AbstractLDAPServlet {
|
||||||
|
|
||||||
private static final long serialVersionUID = 1L;
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
private String pacAdmin;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void init() throws ServletException {
|
||||||
|
super.init();
|
||||||
|
pacAdmin = config.getPacAdmin();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void doGet(final HttpServletRequest req, final HttpServletResponse resp)
|
protected void doGet(final HttpServletRequest req, final HttpServletResponse resp)
|
||||||
throws ServletException, IOException {
|
throws ServletException, IOException {
|
||||||
@ -80,6 +92,12 @@ public class ProfileServlet extends AbstractLDAPServlet {
|
|||||||
throw new ValidationException("password2", messages.getString("ProfileServlet.passwords_donot_match"));
|
throw new ValidationException("password2", messages.getString("ProfileServlet.passwords_donot_match"));
|
||||||
} else {
|
} else {
|
||||||
usr.setAndValidatePassword(password);
|
usr.setAndValidatePassword(password);
|
||||||
|
final MailboxDAO hsadminMailboxDAO = new MailboxDAO(getTicketProvider());
|
||||||
|
try {
|
||||||
|
hsadminMailboxDAO.changePassword(pacAdmin, usr.getLogin(), password);
|
||||||
|
} catch (XmlRpcException | MailboxNotFound e) {
|
||||||
|
System.out.println(e.getLocalizedMessage());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (SimplePasswordException e) {
|
} catch (SimplePasswordException e) {
|
||||||
|
@ -20,8 +20,11 @@ import javax.servlet.http.HttpSession;
|
|||||||
import org.apache.commons.net.smtp.SMTPClient;
|
import org.apache.commons.net.smtp.SMTPClient;
|
||||||
import org.apache.commons.net.smtp.SMTPReply;
|
import org.apache.commons.net.smtp.SMTPReply;
|
||||||
import org.apache.commons.net.smtp.SimpleSMTPHeader;
|
import org.apache.commons.net.smtp.SimpleSMTPHeader;
|
||||||
|
import org.apache.xmlrpc.XmlRpcException;
|
||||||
|
|
||||||
import de.jalin.ldapadmin.beans.User;
|
import de.jalin.ldapadmin.beans.User;
|
||||||
|
import de.jalin.ldapadmin.hsadmin.MailboxDAO;
|
||||||
|
import de.jalin.ldapadmin.hsadmin.MailboxNotFound;
|
||||||
import de.jalin.ldapadmin.ldap.LDAPSessionException;
|
import de.jalin.ldapadmin.ldap.LDAPSessionException;
|
||||||
import de.jalin.ldapadmin.ldap.SimplePasswordException;
|
import de.jalin.ldapadmin.ldap.SimplePasswordException;
|
||||||
import de.jalin.ldapadmin.ldap.UsersDAO;
|
import de.jalin.ldapadmin.ldap.UsersDAO;
|
||||||
@ -35,6 +38,7 @@ public class ResetPasswordServlet extends AbstractLDAPServlet {
|
|||||||
private String smtpHost;
|
private String smtpHost;
|
||||||
private String smtpPort;
|
private String smtpPort;
|
||||||
private String smtpFrom;
|
private String smtpFrom;
|
||||||
|
private String hsadminPacAdmin;
|
||||||
private String tempDir;
|
private String tempDir;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -43,6 +47,7 @@ public class ResetPasswordServlet extends AbstractLDAPServlet {
|
|||||||
smtpHost = config.getSmtpHost();
|
smtpHost = config.getSmtpHost();
|
||||||
smtpPort = config.getSmtpPort();
|
smtpPort = config.getSmtpPort();
|
||||||
smtpFrom = config.getSmtpFromAddress();
|
smtpFrom = config.getSmtpFromAddress();
|
||||||
|
hsadminPacAdmin = config.getPacAdmin();
|
||||||
tempDir = config.getTempDir();
|
tempDir = config.getTempDir();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -82,6 +87,7 @@ public class ResetPasswordServlet extends AbstractLDAPServlet {
|
|||||||
final UsersDAO usrDAO = new UsersDAO(ldapSession);
|
final UsersDAO usrDAO = new UsersDAO(ldapSession);
|
||||||
final String loginParam = req.getParameter("login");
|
final String loginParam = req.getParameter("login");
|
||||||
final User sessUsr = (User) httpSession.getAttribute("user");
|
final User sessUsr = (User) httpSession.getAttribute("user");
|
||||||
|
final MailboxDAO hsMailboxDAO = new MailboxDAO(getTicketProvider());
|
||||||
if (loginParam != null && sessUsr != null && loginParam.equals(sessUsr.getLogin())) {
|
if (loginParam != null && sessUsr != null && loginParam.equals(sessUsr.getLogin())) {
|
||||||
final String password1 = req.getParameter("password");
|
final String password1 = req.getParameter("password");
|
||||||
final String password2 = req.getParameter("password2");
|
final String password2 = req.getParameter("password2");
|
||||||
@ -94,6 +100,11 @@ public class ResetPasswordServlet extends AbstractLDAPServlet {
|
|||||||
try {
|
try {
|
||||||
sessUsr.setAndValidatePassword(password1);
|
sessUsr.setAndValidatePassword(password1);
|
||||||
usrDAO.update(sessUsr);
|
usrDAO.update(sessUsr);
|
||||||
|
try {
|
||||||
|
hsMailboxDAO.changePassword(hsadminPacAdmin, sessUsr.getLogin(), password1);
|
||||||
|
} catch (XmlRpcException | MailboxNotFound e) {
|
||||||
|
System.out.println(e.getLocalizedMessage());
|
||||||
|
}
|
||||||
httpSession.setAttribute("successmessage", messages.getString("ResetPasswordServlet.password_changed"));
|
httpSession.setAttribute("successmessage", messages.getString("ResetPasswordServlet.password_changed"));
|
||||||
req.getRequestDispatcher("/new-password.jsp").forward(req, resp);
|
req.getRequestDispatcher("/new-password.jsp").forward(req, resp);
|
||||||
return;
|
return;
|
||||||
|
Loading…
Reference in New Issue
Block a user