1 package org.apache.archiva.redback.authentication;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
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
32
33
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
47
48
49
50 private User user;
51
52
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
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 }