1   package com.atlassian.security.auth.trustedapps.seraph.filter;
2   
3   import com.atlassian.security.auth.trustedapps.filter.AuthenticationListener;
4   import com.atlassian.security.auth.trustedapps.filter.Authenticator;
5   import com.atlassian.seraph.auth.DefaultAuthenticator;
6   import com.atlassian.seraph.filter.BaseLoginFilter;
7   import com.mockobjects.servlet.MockHttpServletRequest;
8   import com.mockobjects.servlet.MockHttpServletResponse;
9   import com.mockobjects.servlet.MockHttpSession;
10  import junit.framework.TestCase;
11  
12  import java.security.Principal;
13  
14  /**
15   * Tests for {@link com.atlassian.security.auth.trustedapps.seraph.filter.SeraphAuthenticationListener}
16   */
17  public class TestSeraphAuthenticationListener extends TestCase
18  {
19      private AuthenticationListener authenticationListener;
20  
21      protected void setUp() throws Exception
22      {
23          authenticationListener = new SeraphAuthenticationListener();
24      }
25  
26      protected void tearDown() throws Exception
27      {
28          authenticationListener = null;
29      }
30  
31      public void testAuthenticationSuccess()
32      {
33          final Principal principal = new Principal()
34          {
35              public String getName()
36              {
37                  return "some principal";
38              }
39          };
40  
41          final Authenticator.Result result = new Authenticator.Result.Success(
42              principal);
43  
44  
45          final MockHttpServletResponse response = new MockHttpServletResponse();
46          final MockHttpSession session = new MockHttpSession();
47  
48          final MockHttpServletRequest request = new MockHttpServletRequest();
49          request.setSession(session);
50  
51          session.setExpectedAttribute(DefaultAuthenticator.LOGGED_IN_KEY, principal);
52          session.setExpectedAttribute(DefaultAuthenticator.LOGGED_OUT_KEY, null);
53  
54          request.addExpectedSetAttribute(BaseLoginFilter.OS_AUTHSTATUS_KEY, BaseLoginFilter.LOGIN_SUCCESS);
55  
56  
57          authenticationListener.authenticationSuccess(result, request, response);
58  
59          session.verify();
60          request.verify();
61      }
62  }