Search in sources :

Example 11 with User

use of org.alfresco.web.bean.repository.User in project acs-community-packaging by Alfresco.

the class HTTPRequestAuthenticationFilter method doFilter.

/**
 * Run the filter
 *
 * @param sreq
 *            ServletRequest
 * @param sresp
 *            ServletResponse
 * @param chain
 *            FilterChain
 * @exception IOException
 * @exception ServletException
 */
public void doFilter(ServletRequest sreq, ServletResponse sresp, FilterChain chain) throws IOException, ServletException {
    // Get the HTTP request/response/session
    HttpServletRequest req = (HttpServletRequest) sreq;
    HttpServletResponse resp = (HttpServletResponse) sresp;
    // Check for the auth header
    String authHdr = req.getHeader(httpServletRequestAuthHeaderName);
    if (logger.isDebugEnabled()) {
        if (authHdr == null) {
            logger.debug("Header not found: " + httpServletRequestAuthHeaderName);
        } else {
            logger.debug("Header is <" + authHdr + ">");
        }
    }
    if ((authHdr == null) || (authHdr.length() < 1)) {
        resp.sendRedirect(req.getContextPath() + "/jsp/noaccess.jsp");
        return;
    }
    // Get the user
    String userName = "";
    if (authPattern != null) {
        Matcher matcher = authPattern.matcher(authHdr);
        if (matcher.matches()) {
            userName = matcher.group();
            if ((userName == null) || (userName.length() < 1)) {
                if (logger.isDebugEnabled()) {
                    logger.debug("Extracted null or empty user name from pattern " + authPatternString + " against " + authHdr);
                }
                resp.sendRedirect(req.getContextPath() + "/jsp/noaccess.jsp");
                return;
            }
        } else {
            if (logger.isDebugEnabled()) {
                logger.debug("no pattern match for " + authPatternString + " against " + authHdr);
            }
            resp.sendRedirect(req.getContextPath() + "/jsp/noaccess.jsp");
            return;
        }
    } else {
        userName = authHdr;
    }
    if (logger.isDebugEnabled()) {
        logger.debug("User = " + userName);
    }
    // See if there is a user in the session and test if it matches
    User user = AuthenticationHelper.getUser(this.context, req, resp);
    if (user != null) {
        try {
            if (logger.isDebugEnabled())
                logger.debug("User " + user.getUserName() + " validate ticket");
            if (user.getUserName().equals(userName)) {
                // Set the current locale
                authComponent.clearCurrentSecurityContext();
                authComponent.setCurrentUser(user.getUserName());
                AuthenticationHelper.setupThread(this.context, req, resp, true);
                chain.doFilter(sreq, sresp);
                return;
            } else {
                // No match
                setAuthenticatedUser(req, resp, userName);
            }
        } catch (AuthenticationException ex) {
            if (logger.isErrorEnabled())
                logger.error("Failed to validate user " + user.getUserName(), ex);
        }
    }
    setAuthenticatedUser(req, resp, userName);
    // Redirect the login page as it is never seen as we always login by name
    if (req.getRequestURI().endsWith(getLoginPage()) == true) {
        if (logger.isDebugEnabled())
            logger.debug("Login page requested, chaining ...");
        resp.sendRedirect(req.getContextPath() + BaseServlet.FACES_SERVLET + FacesHelper.BROWSE_VIEW_ID);
        return;
    } else {
        chain.doFilter(sreq, sresp);
        return;
    }
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) User(org.alfresco.web.bean.repository.User) Matcher(java.util.regex.Matcher) AuthenticationException(org.alfresco.repo.security.authentication.AuthenticationException) HttpServletResponse(javax.servlet.http.HttpServletResponse)

Example 12 with User

use of org.alfresco.web.bean.repository.User in project acs-community-packaging by Alfresco.

the class KerberosAuthenticationFilter method createUserObject.

/* (non-Javadoc)
     * @see org.alfresco.repo.webdav.auth.BaseAuthenticationFilter#createUserObject(java.lang.String, java.lang.String, org.alfresco.service.cmr.repository.NodeRef, org.alfresco.service.cmr.repository.NodeRef)
     */
@Override
protected SessionUser createUserObject(String userName, String ticket, NodeRef personNode, NodeRef homeSpaceRef) {
    // Create a web client user object
    User user = new User(userName, ticket, personNode);
    user.setHomeSpaceId(homeSpaceRef.getId());
    return user;
}
Also used : SessionUser(org.alfresco.repo.SessionUser) User(org.alfresco.web.bean.repository.User)

Example 13 with User

use of org.alfresco.web.bean.repository.User in project acs-community-packaging by Alfresco.

the class NTLMAuthenticationFilter method createUserObject.

/* (non-Javadoc)
     * @see org.alfresco.repo.webdav.auth.BaseAuthenticationFilter#createUserObject(java.lang.String, java.lang.String, org.alfresco.service.cmr.repository.NodeRef, org.alfresco.service.cmr.repository.NodeRef)
     */
@Override
protected SessionUser createUserObject(String userName, String ticket, NodeRef personNode, NodeRef homeSpaceRef) {
    // Create a web client user object
    User user = new User(userName, ticket, personNode);
    user.setHomeSpaceId(homeSpaceRef.getId());
    return user;
}
Also used : SessionUser(org.alfresco.repo.SessionUser) User(org.alfresco.web.bean.repository.User)

Example 14 with User

use of org.alfresco.web.bean.repository.User in project acs-community-packaging by Alfresco.

the class GuestTemplateContentServlet method buildModel.

@Override
protected Map<String, Object> buildModel(ServiceRegistry services, HttpServletRequest req, NodeRef templateRef) {
    // setup the guest user to pass to the build model helper method
    AuthenticationService auth = (AuthenticationService) services.getAuthenticationService();
    PersonService personService = (PersonService) services.getPersonService();
    NodeService nodeService = (NodeService) services.getNodeService();
    NodeRef guestRef = personService.getPerson(AuthenticationUtil.getGuestUserName());
    User guestUser = new User(AuthenticationUtil.getGuestUserName(), auth.getCurrentTicket(), guestRef);
    NodeRef guestHomeRef = (NodeRef) nodeService.getProperty(guestRef, ContentModel.PROP_HOMEFOLDER);
    if (nodeService.exists(guestHomeRef) == false) {
        throw new InvalidNodeRefException(guestHomeRef);
    }
    guestUser.setHomeSpaceId(guestHomeRef.getId());
    // build the default model
    return DefaultModelHelper.buildDefaultModel(services, guestUser, templateRef, this.imageResolver);
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) User(org.alfresco.web.bean.repository.User) PersonService(org.alfresco.service.cmr.security.PersonService) NodeService(org.alfresco.service.cmr.repository.NodeService) InvalidNodeRefException(org.alfresco.service.cmr.repository.InvalidNodeRefException) AuthenticationService(org.alfresco.service.cmr.security.AuthenticationService)

Example 15 with User

use of org.alfresco.web.bean.repository.User in project acs-community-packaging by Alfresco.

the class Application method getCompanyRootId.

/**
 * @return Returns id of the company root
 */
public static String getCompanyRootId(FacesContext context) {
    User user = Application.getCurrentUser(context);
    if (user != null) {
        String userCompanyRootId = user.getCompanyRootId();
        if (userCompanyRootId == null) {
            userCompanyRootId = Repository.getCompanyRoot(context).getId();
            user.setCompanyRootId(userCompanyRootId);
        }
        return userCompanyRootId;
    } else {
        return null;
    }
}
Also used : SessionUser(org.alfresco.repo.SessionUser) User(org.alfresco.web.bean.repository.User)

Aggregations

User (org.alfresco.web.bean.repository.User)29 SessionUser (org.alfresco.repo.SessionUser)14 FacesContext (javax.faces.context.FacesContext)9 AuthenticationException (org.alfresco.repo.security.authentication.AuthenticationException)8 NodeRef (org.alfresco.service.cmr.repository.NodeRef)8 WorkflowTask (org.alfresco.service.cmr.workflow.WorkflowTask)6 UserTransaction (javax.transaction.UserTransaction)5 AuthenticationService (org.alfresco.service.cmr.security.AuthenticationService)5 Node (org.alfresco.web.bean.repository.Node)5 WebApplicationContext (org.springframework.web.context.WebApplicationContext)5 HttpSession (javax.servlet.http.HttpSession)4 TransientMapNode (org.alfresco.web.bean.repository.TransientMapNode)4 TransientNode (org.alfresco.web.bean.repository.TransientNode)4 IOException (java.io.IOException)3 HashMap (java.util.HashMap)3 NodeService (org.alfresco.service.cmr.repository.NodeService)3 Map (java.util.Map)2 Set (java.util.Set)2 PortletException (javax.portlet.PortletException)2 PortletSession (javax.portlet.PortletSession)2