-
Notifications
You must be signed in to change notification settings - Fork 2.3k
/
ShiroAuthenticationInfo.java
91 lines (79 loc) · 3.84 KB
/
ShiroAuthenticationInfo.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
/*
* Copyright (c) 2002-2016 "Neo Technology,"
* Network Engine for Objects in Lund AB [http://neotechnology.com]
*
* This file is part of Neo4j.
*
* Neo4j is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.neo4j.server.security.enterprise.auth;
import org.apache.shiro.authc.AuthenticationInfo;
import org.apache.shiro.authc.SimpleAuthenticationInfo;
import org.neo4j.kernel.api.security.AuthenticationResult;
import static org.neo4j.kernel.api.security.AuthenticationResult.FAILURE;
import static org.neo4j.kernel.api.security.AuthenticationResult.PASSWORD_CHANGE_REQUIRED;
import static org.neo4j.kernel.api.security.AuthenticationResult.SUCCESS;
import static org.neo4j.kernel.api.security.AuthenticationResult.TOO_MANY_ATTEMPTS;
public class ShiroAuthenticationInfo extends SimpleAuthenticationInfo
{
private AuthenticationResult authenticationResult;
public ShiroAuthenticationInfo()
{
super();
this.authenticationResult = AuthenticationResult.FAILURE;
}
public ShiroAuthenticationInfo( Object principal, Object credentials, String realmName,
AuthenticationResult authenticationResult )
{
super( principal, credentials, realmName );
this.authenticationResult = authenticationResult;
}
public AuthenticationResult getAuthenticationResult()
{
return authenticationResult;
}
@Override
public void merge( AuthenticationInfo info )
{
if (info == null || info.getPrincipals() == null || info.getPrincipals().isEmpty()) {
return;
}
super.merge( info );
if ( info instanceof ShiroAuthenticationInfo )
{
authenticationResult = mergeAuthenticationResult( authenticationResult,
((ShiroAuthenticationInfo) info).getAuthenticationResult() );
}
else
{
// If we get here (which means no AuthenticationException or UnknownAccountException was thrown)
// it means the realm that provided the info was able to authenticate the subject,
// so we claim the result to be an implicit success
authenticationResult = mergeAuthenticationResult( authenticationResult, AuthenticationResult.SUCCESS );
}
}
private static AuthenticationResult[][] mergeMatrix = {
/* v result | new res > SUCCESS, FAILURE, TOO_MANY_ATTEMPTS, PASSWORD_CHANGE_REQUIRED */
/* SUCCESS */ { SUCCESS, SUCCESS, SUCCESS , PASSWORD_CHANGE_REQUIRED },
/* FAILURE */ { SUCCESS, FAILURE, TOO_MANY_ATTEMPTS, PASSWORD_CHANGE_REQUIRED },
/* TOO_MANY_ATTEMPTS */ { SUCCESS, TOO_MANY_ATTEMPTS, TOO_MANY_ATTEMPTS, PASSWORD_CHANGE_REQUIRED },
/* PASSWORD_CHANGE.. */ { PASSWORD_CHANGE_REQUIRED, PASSWORD_CHANGE_REQUIRED, PASSWORD_CHANGE_REQUIRED, PASSWORD_CHANGE_REQUIRED }
};
private static AuthenticationResult mergeAuthenticationResult(
AuthenticationResult result, AuthenticationResult newResult )
{
AuthenticationResult mergedResult = mergeMatrix[result.ordinal()][newResult.ordinal()];
return mergedResult;
}
}