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;
}
}
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;
}
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;
}
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);
}
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;
}
}
Aggregations