View Javadoc
1   /*
2    * MIT License
3    *
4    * Copyright (c) 2010-2022 The Waffle Project Contributors: https://github.com/Waffle/waffle/graphs/contributors
5    *
6    * Permission is hereby granted, free of charge, to any person obtaining a copy
7    * of this software and associated documentation files (the "Software"), to deal
8    * in the Software without restriction, including without limitation the rights
9    * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10   * copies of the Software, and to permit persons to whom the Software is
11   * furnished to do so, subject to the following conditions:
12   *
13   * The above copyright notice and this permission notice shall be included in all
14   * copies or substantial portions of the Software.
15   *
16   * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17   * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18   * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19   * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20   * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21   * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22   * SOFTWARE.
23   */
24  package waffle.shiro.negotiate;
25  
26  import javax.security.auth.Subject;
27  
28  import org.apache.shiro.authc.AuthenticationInfo;
29  import org.apache.shiro.subject.PrincipalCollection;
30  import org.apache.shiro.subject.SimplePrincipalCollection;
31  
32  /**
33   * Information about a user authenticated via the HTTP Negotiate authentication mechanism.
34   * <p>
35   * Derived from net.skorgenes.security.jsecurity.negotiate.NegotiateToken. see:
36   * https://bitbucket.org/lothor/shiro-negotiate
37   * /src/7b25efde130b/src/main/java/net/skorgenes/security/jsecurity/negotiate/NegotiateInfo.java?at=default
38   *
39   * @author Dan Rollo
40   *
41   * @since 1.0.0
42   */
43  public class NegotiateInfo implements AuthenticationInfo {
44  
45      /** The Constant serialVersionUID. */
46      private static final long serialVersionUID = -1537448549089922914L;
47  
48      /** The subject. */
49      private final Subject subject;
50  
51      /** The realm name. */
52      private final String realmName;
53  
54      /**
55       * Creates a new info object.
56       *
57       * @param newSubject
58       *            a subject containing the authenticated users {@link waffle.servlet.WindowsPrincipal}.
59       * @param newRealmName
60       *            a <code>String</code> containing the name of the authentication realm
61       */
62      public NegotiateInfo(final Subject newSubject, final String newRealmName) {
63          this.subject = newSubject;
64          this.realmName = newRealmName;
65      }
66  
67      /**
68       * Creates a new principal collection using the subject as the principal.
69       *
70       * @return a new principal collection using the subject as the principal
71       */
72      @Override
73      public PrincipalCollection getPrincipals() {
74          return new SimplePrincipalCollection(this.subject.getPrincipals(), this.realmName);
75      }
76  
77      /**
78       * Returns the subject.
79       *
80       * @return the subject
81       */
82      @Override
83      public Object getCredentials() {
84          return this.subject;
85      }
86  
87  }