| 1 |
/* |
| 2 |
* Copyright 2004-2023 H2 Group. Multiple-Licensed under the MPL 2.0, |
| 3 |
* and the EPL 1.0 (https://h2database.com/html/license.html). |
| 4 |
* Initial Developer: Alessandro Ventura |
| 5 |
*/ |
| 6 |
package org.h2.security.auth; |
| 7 |
|
| 8 |
import org.h2.engine.ConnectionInfo; |
| 9 |
import org.h2.util.StringUtils; |
| 10 |
|
| 11 |
/** |
| 12 |
* Input data for authenticators; it wraps ConnectionInfo |
| 13 |
*/ |
| 14 |
public class AuthenticationInfo { |
| 15 |
|
| 16 |
private ConnectionInfo connectionInfo; |
| 17 |
|
| 18 |
private String password; |
| 19 |
|
| 20 |
private String realm; |
| 21 |
|
| 22 |
/** |
| 23 |
* Can be used by authenticator to hold information. |
| 24 |
*/ |
| 25 |
Object nestedIdentity; |
| 26 |
|
| 27 |
public AuthenticationInfo(ConnectionInfo connectionInfo) { |
| 28 |
this.connectionInfo = connectionInfo; |
| 29 |
this.realm = connectionInfo.getProperty("AUTHREALM", null); |
| 30 |
if (this.realm != null) { |
| 31 |
this.realm = StringUtils.toUpperEnglish(this.realm); |
| 32 |
} |
| 33 |
this.password = connectionInfo.getProperty("AUTHZPWD", null); |
| 34 |
} |
| 35 |
|
| 36 |
public String getUserName() { |
| 37 |
return connectionInfo.getUserName(); |
| 38 |
} |
| 39 |
|
| 40 |
public String getRealm() { |
| 41 |
return realm; |
| 42 |
} |
| 43 |
|
| 44 |
public String getPassword() { |
| 45 |
return password; |
| 46 |
} |
| 47 |
|
| 48 |
public ConnectionInfo getConnectionInfo() { |
| 49 |
return connectionInfo; |
| 50 |
} |
| 51 |
|
| 52 |
public String getFullyQualifiedName() { |
| 53 |
if (realm == null) { |
| 54 |
return connectionInfo.getUserName(); |
| 55 |
} else { |
| 56 |
return connectionInfo.getUserName() + "@" + realm; |
| 57 |
} |
| 58 |
} |
| 59 |
|
| 60 |
/** |
| 61 |
* Gets nested identity object that can be used by authenticator to hold information. |
| 62 |
* |
| 63 |
* @return nested identity object. |
| 64 |
*/ |
| 65 |
public Object getNestedIdentity() { |
| 66 |
return nestedIdentity; |
| 67 |
} |
| 68 |
|
| 69 |
/** |
| 70 |
* Method used by authenticators to hold information about authenticated |
| 71 |
* user |
| 72 |
* |
| 73 |
* @param nestedIdentity |
| 74 |
* = nested identity object |
| 75 |
*/ |
| 76 |
public void setNestedIdentity(Object nestedIdentity) { |
| 77 |
this.nestedIdentity = nestedIdentity; |
| 78 |
} |
| 79 |
|
| 80 |
/** |
| 81 |
* Clean authentication data. |
| 82 |
*/ |
| 83 |
public void clean() { |
| 84 |
this.password = null; |
| 85 |
this.nestedIdentity = null; |
| 86 |
connectionInfo.cleanAuthenticationInfo(); |
| 87 |
} |
| 88 |
|
| 89 |
} |