1 package org.jahia.params.valves; 2 3 import org.jahia.pipelines.valves.Valve; 4 import org.jahia.pipelines.valves.ValveContext; 5 import org.jahia.pipelines.PipelineException; 6 import org.jahia.params.ParamBean; 7 import org.jahia.services.sites.JahiaSite; 8 import org.jahia.services.usermanager.JahiaUser; 9 import org.jahia.registries.ServicesRegistry; 10 11 import javax.servlet.http.HttpServletRequest ; 12 import java.security.Principal ; 13 14 20 public class JCIFSAuthValveImpl implements Valve { 21 22 private static final org.apache.log4j.Logger logger = 23 org.apache.log4j.Logger.getLogger (JCIFSAuthValveImpl.class); 24 25 public void invoke(Object context, ValveContext valveContext) throws PipelineException { 26 ParamBean paramBean = (ParamBean) context; 27 HttpServletRequest request = ((ParamBean)paramBean).getRequest(); 28 if (request.getAttribute("ntlmAuthType") != null) { 29 Principal principal = (Principal ) request.getAttribute("ntlmPrincipal"); 30 if (principal != null) { 31 String userName = principal.getName(); 34 int backslashPos = principal.getName().lastIndexOf("\\"); 35 if (backslashPos != -1) { 36 userName = principal.getName().substring(backslashPos+1); 37 } 38 if (logger.isDebugEnabled()) { 39 logger.debug("Found user "+userName+ " passed by JCIFS filter, using it to try to login...(Principal.toString=" + principal); 40 } 41 try { 42 JahiaSite site = (JahiaSite) request.getSession().getAttribute(ParamBean.SESSION_SITE); 43 JahiaUser jahiaUser = null; 44 jahiaUser = ServicesRegistry.getInstance().getJahiaSiteUserManagerService().getMember(site.getID(), userName); 45 if (jahiaUser != null) { 46 paramBean.setTheUser(jahiaUser); 47 return; 48 } 49 } catch (Exception e) { 50 } 51 } 52 } 53 valveContext.invokeNext(context); 54 } 55 56 public void initialize() { 57 } 59 } 60 | Popular Tags |