This project has retired. For details please refer to its Attic page.
AuthenticationResult xref
View Javadoc

1   package org.apache.archiva.redback.authentication;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   * http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  
22  import org.apache.archiva.redback.users.User;
23  
24  import java.io.Serializable;
25  import java.util.ArrayList;
26  import java.util.HashMap;
27  import java.util.List;
28  import java.util.Map;
29  
30  /**
31   * AuthenticationResult: wrapper object for information that comes back from the authentication system
32   *
33   * @author Jesse McConnell <jesse@codehaus.org>
34   */
35  public class AuthenticationResult
36      implements Serializable
37  {
38  
39      private static final long serialVersionUID = 354054054054L;
40  
41      private boolean isAuthenticated;
42  
43      private String principal;
44  
45      /**
46       * as we can search the User store it here for reuse.
47       *
48       * @since 2.1
49       */
50      private User user;
51  
52      // TODO: why aren't these just thrown from the authenticate() method?
53      private Exception exception;
54  
55      private List<AuthenticationFailureCause> authenticationFailureCauses;
56  
57      public AuthenticationResult()
58      {
59          this.isAuthenticated = false;
60          this.principal = null;
61          this.exception = null;
62      }
63  
64      public AuthenticationResult( boolean authenticated, String principal, Exception exception )
65      {
66          isAuthenticated = authenticated;
67          this.principal = principal;
68          this.exception = exception;
69      }
70  
71      public AuthenticationResult( boolean authenticated, String principal, Exception exception,
72                                   List<AuthenticationFailureCause> authenticationFailureCauses )
73      {
74          isAuthenticated = authenticated;
75          this.principal = principal;
76          this.exception = exception;
77          this.authenticationFailureCauses = authenticationFailureCauses;
78      }
79  
80      public boolean isAuthenticated()
81      {
82          return isAuthenticated;
83      }
84  
85      public String getPrincipal()
86      {
87          return principal;
88      }
89  
90      public Exception getException()
91      {
92          return exception;
93      }
94  
95      public List<AuthenticationFailureCause> getAuthenticationFailureCauses()
96      {
97          if ( authenticationFailureCauses == null )
98          {
99              this.authenticationFailureCauses = new ArrayList<AuthenticationFailureCause>();
100         }
101         return authenticationFailureCauses;
102     }
103 
104     /**
105      * <b>can be <code>null</code></b>
106      */
107     public User getUser()
108     {
109         return user;
110     }
111 
112     public void setUser( User user )
113     {
114         this.user = user;
115     }
116 
117     public AuthenticationResult user( User user )
118     {
119         this.setUser( user );
120         return this;
121     }
122 
123     public String toString()
124     {
125         StringBuilder sb = new StringBuilder();
126         sb.append( "AuthenticationResult[" );
127         sb.append( "principal=" ).append( principal );
128         sb.append( ",isAuthenticated=" ).append( Boolean.toString( isAuthenticated ) );
129         sb.append( ",exception=" );
130         if ( exception != null )
131         {
132             sb.append( exception.getClass().getName() );
133             sb.append( " : " ).append( exception.getMessage() );
134         }
135         else
136         {
137             sb.append( "<null>" );
138         }
139         sb.append( ']' );
140         return sb.toString();
141     }
142 }