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  import org.eclipse.jetty.server.UserIdentity;
22  
23  /**
24   * This is similar to the jaspi PasswordValidationCallback but includes user
25   * principal and group info as well.
26   * 
27   * @version $Rev: 4793 $ $Date: 2009-03-19 00:00:01 +0100 (Thu, 19 Mar 2009) $
28   */
29  public class LoginCallbackImpl implements LoginCallback
30  {
31      // initial data
32      private final Subject subject;
33  
34      private final String userName;
35  
36      private Object credential;
37  
38      private boolean success;
39  
40      private Principal userPrincipal;
41  
42      private String[] roles = IdentityService.NO_ROLES;
43  
44      //TODO could use Credential instance instead of Object if Basic/Form create a Password object
45      public LoginCallbackImpl (Subject subject, String userName, Object credential)
46      {
47          this.subject = subject;
48          this.userName = userName;
49          this.credential = credential;
50      }
51  
52      public Subject getSubject()
53      {
54          return subject;
55      }
56  
57      public String getUserName()
58      {
59          return userName;
60      }
61  
62      public Object getCredential()
63      {
64          return credential;
65      }
66  
67      public boolean isSuccess()
68      {
69          return success;
70      }
71  
72      public void setSuccess(boolean success)
73      {
74          this.success = success;
75      }
76  
77      public Principal getUserPrincipal()
78      {
79          return userPrincipal;
80      }
81  
82      public void setUserPrincipal(Principal userPrincipal)
83      {
84          this.userPrincipal = userPrincipal;
85      }
86  
87      public String[] getRoles()
88      {
89          return roles;
90      }
91  
92      public void setRoles(String[] groups)
93      {
94          this.roles = groups;
95      }
96  
97      public void clearPassword()
98      {
99          if (credential != null)
100         {
101             credential = null;
102         }
103     }
104 
105 }