View Javadoc
1   /**
2    * Waffle (https://github.com/dblock/waffle)
3    *
4    * Copyright (c) 2010 - 2015 Application Security, Inc.
5    *
6    * All rights reserved. This program and the accompanying materials
7    * are made available under the terms of the Eclipse Public License v1.0
8    * which accompanies this distribution, and is available at
9    * http://www.eclipse.org/legal/epl-v10.html
10   *
11   * Contributors:
12   *     Application Security, Inc.
13   */
14  package waffle.servlet;
15  
16  import javax.servlet.http.HttpSessionBindingEvent;
17  import javax.servlet.http.HttpSessionBindingListener;
18  
19  import waffle.windows.auth.IWindowsIdentity;
20  import waffle.windows.auth.PrincipalFormat;
21  
22  /**
23   * The Class AutoDisposableWindowsPrincipal.
24   */
25  public class AutoDisposableWindowsPrincipal extends WindowsPrincipal implements HttpSessionBindingListener {
26  
27      /** The Constant serialVersionUID. */
28      private static final long serialVersionUID = 1L;
29  
30      /**
31       * Instantiates a new auto disposable windows principal.
32       *
33       * @param windowsIdentity
34       *            the windows identity
35       */
36      public AutoDisposableWindowsPrincipal(final IWindowsIdentity windowsIdentity) {
37          super(windowsIdentity);
38      }
39  
40      /**
41       * Instantiates a new auto disposable windows principal.
42       *
43       * @param windowsIdentity
44       *            the windows identity
45       * @param principalFormat
46       *            the principal format
47       * @param roleFormat
48       *            the role format
49       */
50      public AutoDisposableWindowsPrincipal(final IWindowsIdentity windowsIdentity,
51              final PrincipalFormat principalFormat, final PrincipalFormat roleFormat) {
52          super(windowsIdentity, principalFormat, roleFormat);
53      }
54  
55      /* (non-Javadoc)
56       * @see javax.servlet.http.HttpSessionBindingListener#valueBound(javax.servlet.http.HttpSessionBindingEvent)
57       */
58      @Override
59      public void valueBound(final HttpSessionBindingEvent evt) {
60          // Do nothing
61      }
62  
63      /* (non-Javadoc)
64       * @see javax.servlet.http.HttpSessionBindingListener#valueUnbound(javax.servlet.http.HttpSessionBindingEvent)
65       */
66      @Override
67      public void valueUnbound(final HttpSessionBindingEvent evt) {
68          if (this.getIdentity() != null) {
69              this.getIdentity().dispose();
70          }
71      }
72  
73  }