View Javadoc

1   // ========================================================================
2   // Copyright (c) 2008-2009 Mort Bay Consulting Pty. Ltd.
3   // ------------------------------------------------------------------------
4   // All rights reserved. This program and the accompanying materials
5   // are made available under the terms of the Eclipse Public License v1.0
6   // and Apache License v2.0 which accompanies this distribution.
7   // The Eclipse Public License is available at 
8   // http://www.eclipse.org/legal/epl-v10.html
9   // The Apache License v2.0 is available at
10  // http://www.opensource.org/licenses/apache2.0.php
11  // You may elect to redistribute this code under either of these licenses. 
12  // ========================================================================
13  
14  package org.eclipse.jetty.security.authentication;
15  
16  import java.security.Principal;
17  
18  import javax.security.auth.Subject;
19  
20  import org.eclipse.jetty.security.IdentityService;
21  
22  /**
23   * This is similar to the jaspi PasswordValidationCallback but includes user
24   * principal and group info as well.
25   * 
26   * @version $Rev: 4793 $ $Date: 2009-03-19 00:00:01 +0100 (Thu, 19 Mar 2009) $
27   */
28  public class LoginCallbackImpl implements LoginCallback
29  {
30      // initial data
31      private final Subject subject;
32  
33      private final String userName;
34  
35      private Object credential;
36  
37      private boolean success;
38  
39      private Principal userPrincipal;
40  
41      private String[] roles = IdentityService.NO_ROLES;
42  
43      //TODO could use Credential instance instead of Object if Basic/Form create a Password object
44      public LoginCallbackImpl (Subject subject, String userName, Object credential)
45      {
46          this.subject = subject;
47          this.userName = userName;
48          this.credential = credential;
49      }
50  
51      public Subject getSubject()
52      {
53          return subject;
54      }
55  
56      public String getUserName()
57      {
58          return userName;
59      }
60  
61      public Object getCredential()
62      {
63          return credential;
64      }
65  
66      public boolean isSuccess()
67      {
68          return success;
69      }
70  
71      public void setSuccess(boolean success)
72      {
73          this.success = success;
74      }
75  
76      public Principal getUserPrincipal()
77      {
78          return userPrincipal;
79      }
80  
81      public void setUserPrincipal(Principal userPrincipal)
82      {
83          this.userPrincipal = userPrincipal;
84      }
85  
86      public String[] getRoles()
87      {
88          return roles;
89      }
90  
91      public void setRoles(String[] groups)
92      {
93          this.roles = groups;
94      }
95  
96      public void clearPassword()
97      {
98          if (credential != null)
99          {
100             credential = null;
101         }
102     }
103 
104 }