KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jahia > params > valves > JCIFSAuthValveImpl


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 JavaDoc;
12 import java.security.Principal JavaDoc;
13
14 /**
15  * User: Serge Huber
16  * Date: 22 août 2005
17  * Time: 18:59:12
18  * Copyright (C) Jahia Inc.
19  */

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 JavaDoc context, ValveContext valveContext) throws PipelineException {
26         ParamBean paramBean = (ParamBean) context;
27         HttpServletRequest JavaDoc request = ((ParamBean)paramBean).getRequest();
28         if (request.getAttribute("ntlmAuthType") != null) {
29             Principal JavaDoc principal = (Principal JavaDoc) request.getAttribute("ntlmPrincipal");
30             if (principal != null) {
31                 // JCIFS delivers the Principal name under the form DOMAIN\Username. We
32
// will now truncate to only keep the username.
33
String JavaDoc 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 JavaDoc e) {
50                 }
51             }
52         }
53         valveContext.invokeNext(context);
54     }
55
56     public void initialize() {
57         //To change body of implemented methods use File | Settings | File Templates.
58
}
59 }
60
Popular Tags