1 package com.atlassian.seraph.filter;
2
3 import com.atlassian.seraph.RequestParameterConstants;
4
5 import javax.servlet.http.HttpServletRequest;
6
7 /**
8 * This is a filter that logs the user in. It works a little like J2EE form-based seraph, except it looks for the
9 * parameters 'os_username' and 'os_password' instead of j_username and j_password.
10 * <p>
11 * The form post/get action should be the URL of the login servlet/JSP/action - given by SecurityFilter.LOGIN_URL.
12 * <p>
13 * If the parameters exist and authentication is successful, the user will be redirected by the filter to the URL given
14 * by the session attribute at SecurityFilter.ORIGINAL_URL_KEY.
15 * <p>
16 * If this URL doesn't exist, it will look for a parameter 'os_destination' to use as the redirected URL instead.
17 * <p>
18 * If neither is found, it is assumed that the page will check the authorisation status and handle redirection itself.
19 * <p>
20 * From the any other filter in the request, or the servlet/JSP/action which processes the request, you can look up the
21 * status of the authorisation attempt. The status is a String request attribute, with the key 'os_authstatus'.
22 * <p>
23 * The possible statuses are:
24 * <ul>
25 * <li> LoginFilter.LOGIN_SUCCESS - the login was processed, and user was logged in
26 * <li> LoginFilter.LOGIN_FAILURE - the login was processed, the user gave a bad username or password
27 * <li> LoginFilter.LOGIN_ERROR - the login was processed, an exception occurred trying to log the user in
28 * <li> LoginFilter.LOGIN_NOATTEMPT - the login was no processed, no form parameters existed
29 * </ul>
30 */
31 public class LoginFilter extends PasswordBasedLoginFilter
32 {
33 UserPasswordPair extractUserPasswordPair(HttpServletRequest request)
34 {
35 // check for parameters
36 String username = request.getParameter(RequestParameterConstants.OS_USERNAME);
37 String password = request.getParameter(RequestParameterConstants.OS_PASSWORD);
38 boolean persistentLogin = "true".equals(request.getParameter(RequestParameterConstants.OS_COOKIE));
39 return new UserPasswordPair(username, password, persistentLogin);
40 }
41 }