001: package com.ecyrd.jspwiki.ui.admin.beans;
002:
003: import java.util.Date;
004:
005: import javax.management.NotCompliantMBeanException;
006: import javax.servlet.http.HttpServletRequest;
007:
008: import com.ecyrd.jspwiki.WikiContext;
009: import com.ecyrd.jspwiki.WikiEngine;
010: import com.ecyrd.jspwiki.WikiSession;
011: import com.ecyrd.jspwiki.auth.NoSuchPrincipalException;
012: import com.ecyrd.jspwiki.auth.UserManager;
013: import com.ecyrd.jspwiki.auth.WikiSecurityException;
014: import com.ecyrd.jspwiki.auth.user.UserProfile;
015: import com.ecyrd.jspwiki.ui.admin.AdminBean;
016: import com.ecyrd.jspwiki.ui.admin.SimpleAdminBean;
017:
018: public class UserBean extends SimpleAdminBean {
019: public UserBean(WikiEngine engine)
020: throws NotCompliantMBeanException {
021: super ();
022: }
023:
024: public String[] getAttributeNames() {
025: return new String[0];
026: }
027:
028: // FIXME: We don't yet support MBean for this kind of stuff.
029: public String[] getMethodNames() {
030: return new String[0];
031: }
032:
033: public String doPost(WikiContext context) {
034: HttpServletRequest request = context.getHttpRequest();
035: WikiSession session = context.getWikiSession();
036: UserManager mgr = context.getEngine().getUserManager();
037:
038: String loginid = request.getParameter("loginid");
039: String loginname = request.getParameter("loginname");
040: String fullname = request.getParameter("fullname");
041: String password = request.getParameter("password");
042: String password2 = request.getParameter("password2");
043: String email = request.getParameter("email");
044:
045: if (request.getParameter("action").equalsIgnoreCase("remove")) {
046: try {
047: mgr.getUserDatabase().deleteByLoginName(loginid);
048: session.addMessage("User profile " + loginid + " ("
049: + fullname + ") has been deleted");
050: } catch (NoSuchPrincipalException e) {
051: session
052: .addMessage("User profile has already been removed");
053: } catch (WikiSecurityException e) {
054: session.addMessage("Security problem: " + e);
055: }
056: return "";
057: }
058:
059: if (password != null && password.length() > 0
060: && !password.equals(password2)) {
061: session.addMessage("Passwords do not match!");
062: return "";
063: }
064:
065: UserProfile p;
066:
067: if (loginid.equals("--New--")) {
068: // Create new user
069:
070: p = mgr.getUserDatabase().newProfile();
071: p.setCreated(new Date());
072: } else {
073: try {
074: p = mgr.getUserDatabase().findByLoginName(loginid);
075: } catch (NoSuchPrincipalException e) {
076: session.addMessage("I could not find user profile "
077: + loginid);
078: return "";
079: }
080: }
081:
082: p.setEmail(email);
083: p.setFullname(fullname);
084: if (password != null && password.length() > 0)
085: p.setPassword(password);
086: p.setLoginName(loginname);
087:
088: try {
089: mgr.getUserDatabase().save(p);
090: } catch (WikiSecurityException e) {
091: session.addMessage("Unable to save " + e.getMessage());
092: }
093:
094: session.addMessage("User profile has been updated");
095:
096: return "";
097: }
098:
099: public String getTitle() {
100: return "User administration";
101: }
102:
103: public int getType() {
104: return AdminBean.UNKNOWN;
105: }
106:
107: }
|