2 * WebConfig - a web administration interface for the Funambol DS Server.
3 * Copyright (C) 2008 Mathew McBride
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU Affero General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU Affero General Public License for more details.
15 * You should have received a copy of the GNU Affero General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 package net
.bionicmessage
.funambol
.webconfig
;
20 import com
.funambol
.framework
.core
.Authentication
;
21 import com
.funambol
.framework
.core
.Cred
;
22 import com
.funambol
.framework
.security
.Officer
;
23 import com
.funambol
.framework
.server
.Sync4jUser
;
24 import com
.funambol
.framework
.server
.store
.PersistentStoreException
;
25 import com
.funambol
.server
.admin
.AdminException
;
26 import com
.funambol
.server
.admin
.UserManager
;
27 import com
.funambol
.server
.config
.Configuration
;
28 import java
.io
.IOException
;
29 import java
.io
.PrintWriter
;
30 import java
.util
.logging
.Level
;
31 import java
.util
.logging
.Logger
;
32 import javax
.servlet
.ServletException
;
33 import javax
.servlet
.http
.HttpServlet
;
34 import javax
.servlet
.http
.HttpServletRequest
;
35 import javax
.servlet
.http
.HttpServletResponse
;
36 import javax
.servlet
.http
.HttpSession
;
42 public class login
extends HttpServlet
{
45 * Processes requests for both HTTP <code>GET</code> and <code>POST</code> methods.
46 * @param request servlet request
47 * @param response servlet response
49 protected void processRequest(HttpServletRequest request
, HttpServletResponse response
)
50 throws ServletException
, IOException
{
52 String username
= request
.getParameter("l_username");
53 String password
= request
.getParameter("l_password");
54 String utype
= request
.getParameter("utype");
55 HttpSession session
= request
.getSession();
56 session
.removeAttribute("notloggedin");
57 if (username
!= null && password
!= null) {
60 Configuration conf
= Configuration
.getConfiguration();
61 if ("admin".equals(utype
)) {
62 loginAdministrator(conf
, session
, username
, password
);
64 loginUser(conf
, session
, username
, password
);
66 response
.sendRedirect("index.jsp");
67 } catch (Exception ex
) {
68 ex
.printStackTrace(response
.getWriter());
76 protected void loginAdministrator(Configuration c
,
80 Sync4jUser adminUser
= new Sync4jUser(user
, password
, "", "", "", null);
82 if (c
.getUserManager().isUniqueAdministrator(adminUser
)) {
83 session
.setAttribute("isadministrator", "");
84 session
.setAttribute("user", user
);
86 session
.setAttribute("notloggedin", "");
88 } catch (Exception ex
) {
89 session
.setAttribute("notloggedin", ex
.getMessage());
93 protected void loginUser(Configuration c
,
97 Officer officer
= c
.getOfficer();
98 Authentication auth
= new Authentication("syncml:auth-basic",user
,password
);
99 Cred cred
= new Cred(auth
);
100 Sync4jUser s4ju
= officer
.authenticateUser(cred
);
102 session
.setAttribute("user",user
);
104 session
.setAttribute("notloggedin","");
107 // <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">
109 * Handles the HTTP <code>GET</code> method.
110 * @param request servlet request
111 * @param response servlet response
113 protected void doGet(HttpServletRequest request
, HttpServletResponse response
)
114 throws ServletException
, IOException
{
115 processRequest(request
, response
);
119 * Handles the HTTP <code>POST</code> method.
120 * @param request servlet request
121 * @param response servlet response
123 protected void doPost(HttpServletRequest request
, HttpServletResponse response
)
124 throws ServletException
, IOException
{
125 processRequest(request
, response
);
129 * Returns a short description of the servlet.
131 public String
getServletInfo() {
132 return "Short description";