01: package com.technoetic.xplanner.tags;
02:
03: import java.security.Principal;
04: import java.util.List;
05: import javax.servlet.http.HttpServletRequest;
06: import javax.servlet.jsp.JspException;
07:
08: import com.technoetic.xplanner.domain.Person;
09: import com.technoetic.xplanner.security.SecurityHelper;
10: import com.technoetic.xplanner.tags.db.DatabaseTagSupport;
11:
12: public class AuthenticatedUserTag extends DatabaseTagSupport {
13:
14: public int doStartTag() throws JspException {
15: try {
16: if (SecurityHelper
17: .isUserAuthenticated((HttpServletRequest) pageContext
18: .getRequest())) {
19: Principal userPrincipal = SecurityHelper
20: .getUserPrincipal((HttpServletRequest) pageContext
21: .getRequest());
22: //DEBT(DAO) : Move this to a dao
23: if (getSession() != null) {
24: List users = getSession().createQuery(
25: "from p in " + Person.class
26: + " where p.userId = :userId")
27: .setString("userId",
28: userPrincipal.getName())
29: .setCacheable(true).list();
30: if (users.size() > 0) {
31: pageContext.setAttribute(id, users.get(0));
32: }
33: }
34: }
35: return super .doStartTag();
36: } catch (Exception ex) {
37: pageContext.getServletContext().log(
38: "error getting authenticated user", ex);
39: throw new JspException(ex.getMessage());
40: }
41: }
42:
43: public void release() {
44: super.release();
45: }
46: }
|