001: package org.manentia.kasai.ui;
002:
003: import java.util.Collection;
004: import java.util.HashMap;
005: import java.util.List;
006: import java.util.Map;
007: import java.util.ResourceBundle;
008:
009: import javax.servlet.http.HttpServletRequest;
010:
011: import org.directwebremoting.WebContext;
012: import org.directwebremoting.WebContextFactory;
013: import org.manentia.kasai.Constants;
014: import org.manentia.kasai.KasaiFacade;
015: import org.manentia.kasai.exceptions.CannotAuditException;
016: import org.manentia.kasai.exceptions.DataAccessException;
017: import org.manentia.kasai.exceptions.DoesntExistsException;
018: import org.manentia.kasai.exceptions.InvalidAttributesException;
019: import org.manentia.kasai.exceptions.InvalidPasswordException;
020: import org.manentia.kasai.exceptions.NotEnoughPermissionException;
021: import org.manentia.kasai.exceptions.NotFoundException;
022: import org.manentia.kasai.exceptions.ServiceException;
023: import org.manentia.kasai.exceptions.ServiceNotAvailableException;
024: import org.manentia.kasai.exceptions.UserBlockedException;
025: import org.manentia.kasai.ui.actions.BaseAction;
026: import org.manentia.kasai.ui.exceptions.SessionExpiredException;
027: import org.manentia.kasai.ui.roles.RoleFacade;
028:
029: import com.manentia.commons.log.Log;
030: import com.manentia.commons.xml.XMLException;
031:
032: public class BaseFacade {
033: public void login(String username, String password)
034: throws DataAccessException, NotFoundException,
035: UserBlockedException, InvalidPasswordException,
036: ServiceException, ServiceNotAvailableException,
037: CannotAuditException, XMLException {
038: WebContext ctx = WebContextFactory.get();
039: HttpServletRequest request = ctx.getHttpServletRequest();
040:
041: KasaiFacade.getInstance().checkPasswordUser(username, password,
042: request.getRemoteAddr());
043:
044: UserView userView = new UserView();
045: userView.setUser(username);
046:
047: request.getSession().setAttribute("userView", userView);
048: }
049:
050: public void changePassword(String oldPassword, String newPassword,
051: String confirmation) throws SessionExpiredException,
052: DataAccessException, InvalidAttributesException,
053: ServiceException, ServiceNotAvailableException,
054: DoesntExistsException, CannotAuditException,
055: InvalidPasswordException, XMLException {
056: WebContext ctx = WebContextFactory.get();
057: HttpServletRequest request = ctx.getHttpServletRequest();
058:
059: UserView userView = new BaseAction().validateSession(request);
060:
061: KasaiFacade.getInstance().changePasswordUser(
062: userView.getUser(), oldPassword, newPassword,
063: confirmation, request.getRemoteAddr());
064: }
065:
066: public Collection listObjectRoles(String objectId)
067: throws SessionExpiredException, DataAccessException {
068: WebContext ctx = WebContextFactory.get();
069: HttpServletRequest request = ctx.getHttpServletRequest();
070:
071: UserView userView = new BaseAction().validateSession(request);
072:
073: return KasaiFacade.getInstance().listObjectRoles(
074: userView.getUser(), objectId);
075: }
076:
077: public Map decodeMessage(String data) {
078: HashMap map = new HashMap();
079:
080: String message = data;
081: String level = "error";
082:
083: try {
084: WebContext ctx = WebContextFactory.get();
085: HttpServletRequest request = ctx.getHttpServletRequest();
086:
087: // we hope the module programmer used a key instead of a hard coded text
088: ResourceBundle res = ResourceBundle.getBundle(
089: Constants.MESSAGES_PROPERTY_FILE, request
090: .getLocale());
091:
092: level = res.getString(message + ".level");
093: message = res.getString(message); // dahhh ?? :)
094: } catch (Exception unhandledBastard) {
095: }
096:
097: map.put("message", message);
098: map.put("level", level);
099:
100: return map;
101: }
102:
103: public Map listUsersGroupsRoles() throws DataAccessException,
104: SessionExpiredException, XMLException {
105: WebContext ctx = WebContextFactory.get();
106: HttpServletRequest request = ctx.getHttpServletRequest();
107:
108: UserView userView = new BaseAction().validateSession(request);
109:
110: Map result = new HashMap();
111:
112: List users = KasaiFacade.getInstance().listUsers(
113: userView.getUser(), null, null, null, null, -1, null,
114: null);
115: List groups = KasaiFacade.getInstance().listGroups(
116: userView.getUser(), null, null, -1, -1);
117: List roles = KasaiFacade.getInstance().listRoles(
118: userView.getUser(), null);
119:
120: result.put("users", users);
121: result.put("groups", groups);
122: result.put("roles", roles);
123:
124: return result;
125: }
126:
127: public void deleteObjectUserRole(int id)
128: throws SessionExpiredException, DataAccessException,
129: CannotAuditException {
130: WebContext ctx = WebContextFactory.get();
131: HttpServletRequest request = ctx.getHttpServletRequest();
132:
133: UserView userView = new BaseAction().validateSession(request);
134:
135: KasaiFacade.getInstance().deleteObjectUserRole(
136: userView.getUser(), id, request.getRemoteAddr());
137: }
138:
139: public void deleteObjectGroupRole(int id)
140: throws SessionExpiredException, DataAccessException,
141: CannotAuditException {
142: WebContext ctx = WebContextFactory.get();
143: HttpServletRequest request = ctx.getHttpServletRequest();
144:
145: UserView userView = new BaseAction().validateSession(request);
146:
147: KasaiFacade.getInstance().deleteObjectGroupRole(
148: userView.getUser(), id, request.getRemoteAddr());
149: }
150:
151: public void createObjectUserRole(String objectId, String user,
152: int roleId) throws SessionExpiredException,
153: DataAccessException, DoesntExistsException,
154: NotEnoughPermissionException, CannotAuditException,
155: XMLException {
156: WebContext ctx = WebContextFactory.get();
157: HttpServletRequest request = ctx.getHttpServletRequest();
158:
159: UserView userView = new BaseAction().validateSession(request);
160:
161: KasaiFacade.getInstance().createObjectUserRole(
162: userView.getUser(), objectId, user, roleId,
163: request.getRemoteAddr());
164: }
165:
166: public void createObjectGroupRole(String objectId, String group,
167: int roleId) throws SessionExpiredException,
168: DataAccessException, DoesntExistsException,
169: NotEnoughPermissionException, CannotAuditException,
170: XMLException {
171: WebContext ctx = WebContextFactory.get();
172: HttpServletRequest request = ctx.getHttpServletRequest();
173:
174: UserView userView = new BaseAction().validateSession(request);
175:
176: KasaiFacade.getInstance().createObjectGroupRole(
177: userView.getUser(), objectId, group, roleId,
178: request.getRemoteAddr());
179: }
180:
181: public String[] listUsernames() throws DataAccessException {
182: return KasaiFacade.getInstance().listUsernames();
183: }
184:
185: public Collection listOperatives() throws DataAccessException,
186: SessionExpiredException {
187: WebContext ctx = WebContextFactory.get();
188: HttpServletRequest request = ctx.getHttpServletRequest();
189: UserView userView = new BaseAction().validateSession(request);
190:
191: Collection result = KasaiFacade.getInstance().listOperatives(
192: userView.getUser());
193:
194: Log.write("Operativas: " + result.size(), Log.DEBUG, "TEST",
195: RoleFacade.class);
196:
197: return result;
198: }
199: }
|