1 9 package org.jboss.portal.core.servlet; 10 11 import java.io.IOException ; 12 13 import javax.servlet.ServletException ; 14 import javax.servlet.http.HttpServlet ; 15 import javax.servlet.http.HttpServletRequest ; 16 import javax.servlet.http.HttpServletResponse ; 17 18 import org.jboss.portal.common.util.Tools; 19 import org.jboss.portal.common.util.UUIDGenerator; 20 import org.jboss.portal.core.CoreConstants; 21 import org.jboss.portal.core.security.jaas.CacheLoginModule; 22 23 29 public class LoginServlet extends HttpServlet 30 { 31 32 private UUIDGenerator generator = new UUIDGenerator(); 33 34 protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException , IOException 35 { 36 doPost(req, resp); 37 } 38 39 protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException , IOException 40 { 41 String username = (String )req.getAttribute("username"); 43 String password = (String )req.getAttribute("password"); 44 String redirect = (String )req.getAttribute("redirect"); 45 46 if (username == null || password == null) 48 { 49 username = req.getParameter("username"); 50 password = req.getParameter("password"); 51 redirect = req.getParameter("redirect"); 52 } 53 54 if (username == null) 56 { 57 throw new ServletException ("No username specified"); 58 } 59 if (password == null) 60 { 61 throw new ServletException ("No password specified"); 62 } 63 64 String hash = Tools.md5AsHexString(generator.generateKey()); 65 CacheLoginModule.Handle handle = CacheLoginModule.cache(hash, username, password); 66 67 req.getSession().setAttribute(CoreConstants.SES_SECURITY_HANDLE, handle); 69 70 StringBuffer buffer = new StringBuffer (); 72 buffer.append(req.getContextPath()). 73 append("/authentication?username="). 74 append(Tools.createXWWWFormURLEncoded(username)). 75 append("&password="). 76 append(Tools.createXWWWFormURLEncoded(hash)); 77 if (redirect != null) 78 { 79 buffer.append("&redirect="). 80 append(Tools.createXWWWFormURLEncoded(redirect)); 81 } 82 83 String url = buffer.toString(); 85 resp.sendRedirect(url); 86 } 87 } 88 | Popular Tags |