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.shiro.negotiate;
15  
16  /**
17   * Derived from net.skorgenes.security.jsecurity.negotiate.NegotiateToken.
18   * see: https://bitbucket.org/lothor/shiro-negotiate/src/7b25efde130b/src/main/java/net/skorgenes/security/jsecurity/negotiate/NegotiateInfo.java?at=default
19   *
20   * @author Dan Rollo
21   * Date: 1/15/13
22   * Time: 11:00 PM
23   */
24  import javax.security.auth.Subject;
25  
26  import org.apache.shiro.authc.AuthenticationInfo;
27  import org.apache.shiro.subject.PrincipalCollection;
28  import org.apache.shiro.subject.SimplePrincipalCollection;
29  
30  /**
31   * Information about a user authenticated via the HTTP Negotiate authentication mechanism.
32   * 
33   * 
34   * @author Dan Rollo
35   * @since 1.0.0
36   */
37  public class NegotiateInfo implements AuthenticationInfo {
38      
39      /** The Constant serialVersionUID. */
40      private static final long serialVersionUID = -1537448549089922914L;
41  
42      /** The subject. */
43      private final Subject     subject;
44  
45      /** The realm name. */
46      private final String      realmName;
47  
48      /**
49       * Creates a new info object.
50       * 
51       * @param newSubject
52       *            a subject containing the authenticated users {@link waffle.servlet.WindowsPrincipal}.
53       * @param newRealmName
54       *            a <code>String</code> containing the name of the authentication realm
55       */
56      public NegotiateInfo(final Subject newSubject, final String newRealmName) {
57          this.subject = newSubject;
58          this.realmName = newRealmName;
59      }
60  
61      /**
62       * Creates a new principal collection using the subject as the principal.
63       * 
64       * @return a new principal collection using the subject as the principal
65       */
66      @Override
67      public PrincipalCollection getPrincipals() {
68          return new SimplePrincipalCollection(this.subject.getPrincipals(), this.realmName);
69      }
70  
71      /**
72       * Returns the subject.
73       * 
74       * @return the subject
75       */
76      @Override
77      public Object getCredentials() {
78          return this.subject;
79      }
80  }