move Authenticator and Filters from scm-webapp to scm-web-api

This commit is contained in:
Sebastian Sdorra
2010-09-26 15:53:26 +02:00
parent 4d1507d13a
commit 9619a92d41
10 changed files with 33 additions and 17 deletions

View File

@@ -1,49 +0,0 @@
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package sonia.scm.security;
//~--- non-JDK imports --------------------------------------------------------
import sonia.scm.User;
//~--- JDK imports ------------------------------------------------------------
import javax.servlet.http.HttpServletRequest;
/**
*
* @author Sebastian Sdorra
*/
public interface Authenticator
{
/**
* Method description
*
*
* @param request
* @param username
* @param password
*
* @return
*/
public User authenticate(HttpServletRequest request, String username,
String password);
//~--- get methods ----------------------------------------------------------
/**
* Method description
*
*
* @param request
*
* @return
*/
public User getUser(HttpServletRequest request);
}

View File

@@ -1,91 +0,0 @@
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package sonia.scm.security;
//~--- non-JDK imports --------------------------------------------------------
import sonia.scm.User;
//~--- JDK imports ------------------------------------------------------------
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
/**
*
* @author Sebastian Sdorra
*/
public class DemoAuthenticator implements Authenticator
{
/** Field description */
private static final String DEMO_DISPLAYNAME = "Hans am Schalter";
/** Field description */
private static final String DEMO_MAIL = "hans@schalter.de";
/** Field description */
private static final String DEMO_PASSWORD = "hans123";
/** Field description */
private static final String DEMO_USERNAME = "hans";
//~--- methods --------------------------------------------------------------
/**
* Method description
*
*
* @param request
* @param username
* @param password
*
* @return
*/
@Override
public User authenticate(HttpServletRequest request, String username,
String password)
{
User user = null;
if (DEMO_USERNAME.equals(username) && DEMO_PASSWORD.equals(password))
{
user = new User(username, DEMO_DISPLAYNAME, DEMO_MAIL);
HttpSession session = request.getSession(true);
session.setAttribute(DemoAuthenticator.class.getName(), user);
}
return user;
}
//~--- get methods ----------------------------------------------------------
/**
* Method description
*
*
* @param request
*
* @return
*/
@Override
public User getUser(HttpServletRequest request)
{
User user = null;
HttpSession session = request.getSession();
if (session != null)
{
user = (User) session.getAttribute(DemoAuthenticator.class.getName());
}
return user;
}
}