public class MITKerberosOperationHandler extends KerberosOperationHandler
Modifier and Type | Class and Description |
---|---|
protected static class |
KDCKerberosOperationHandler.InteractivePasswordHandler
InteractivePasswordHandler is a
ShellCommandUtil.InteractiveHandler
implementation that answers queries from kadmin or kdamin.local command for the admin and/or user
passwords. |
KERBEROS_ENV_AD_CREATE_ATTRIBUTES_TEMPLATE, KERBEROS_ENV_ADMIN_SERVER_HOST, KERBEROS_ENV_ENCRYPTION_TYPES, KERBEROS_ENV_EXECUTABLE_SEARCH_PATHS, KERBEROS_ENV_KADMIN_PRINCIPAL_NAME, KERBEROS_ENV_KDC_CREATE_ATTRIBUTES, KERBEROS_ENV_KDC_HOSTS, KERBEROS_ENV_LDAP_URL, KERBEROS_ENV_PRINCIPAL_CONTAINER_DN, KERBEROS_ENV_USER_PRINCIPAL_GROUP
Constructor and Description |
---|
MITKerberosOperationHandler() |
Modifier and Type | Method and Description |
---|---|
void |
close()
Closes and cleans up any resources used by this KerberosOperationHandler
It is expected that this KerberosOperationHandler will not be used after this call.
|
protected org.apache.directory.server.kerberos.shared.keytab.Keytab |
createKeytab(String principal,
String password,
Integer keyNumber)
Creates a key tab by using the ipa commandline utilities.
|
Integer |
createPrincipal(String principal,
String password,
boolean service)
Creates a new principal in a previously configured MIT KDC
This implementation creates a query to send to the kadmin shell command and then interrogates
the result from STDOUT to determine if the operation executed successfully.
|
protected ShellCommandUtil.Result |
executeCommand(String[] command,
Map<String,String> envp,
ShellCommandUtil.InteractiveHandler interactiveHandler)
Executes a shell command in a credentials context
See
ShellCommandUtil.runCommand(String[]) |
protected void |
exportKeytabFile(String principal,
String keytabFileDestinationPath,
Set<org.apache.directory.shared.kerberos.codec.types.EncryptionType> keyEncryptionTypes)
Export the requested keytab entries for a given principal into the specified file.
|
protected String[] |
getKinitCommand(String executableKinit,
PrincipalKeyCredential credentials,
String credentialsCache,
Map<String,String> kerberosConfiguration)
Return an array of Strings containing the command and the relavant arguments needed authenticate
with the KDC and create the Kerberos ticket/credential cache.
|
protected boolean |
init(Map<String,String> kerberosConfiguration)
Initialize the Kerberos ticket cache using the supplied KDC administrator's credentials.
|
protected ShellCommandUtil.Result |
invokeKAdmin(String query)
Invokes the kadmin shell command to issue queries
|
void |
open(PrincipalKeyCredential administratorCredentials,
String realm,
Map<String,String> kerberosConfiguration)
Prepares and creates resources to be used by this KerberosOperationHandler
It is expected that this KerberosOperationHandler will not be used before this call.
|
boolean |
principalExists(String principal,
boolean service)
Test to see if the specified principal exists in a previously configured MIT KDC
This implementation creates a query to send to the kadmin shell command and then interrogates
the result from STDOUT to determine if the presence of the specified principal.
|
boolean |
removePrincipal(String principal,
boolean service)
Removes an existing principal in a previously configured KDC
The implementation is specific to a particular type of KDC.
|
Integer |
setPrincipalPassword(String principal,
String password,
boolean service)
Updates the password for an existing user principal in a previously configured IPA KDC
This implementation creates a query to send to the ipa shell command and then interrogates
the exit code to determine if the operation executed successfully.
|
createDeconstructPrincipal, createKeytabFile, createKeytabFile, createKeytabFile, createKeytabFile, escapeCharacters, executeCommand, executeCommand, getAdministratorCredential, getDefaultRealm, getExecutable, getExecutableSearchPaths, getKeyEncryptionTypes, isOpen, mergeKeytabs, readKeytabFile, setAdministratorCredential, setDefaultRealm, setExecutableSearchPaths, setExecutableSearchPaths, setKeyEncryptionTypes, setOpen, testAdministratorCredentials, translateEncryptionType, translateEncryptionTypes
public void open(PrincipalKeyCredential administratorCredentials, String realm, Map<String,String> kerberosConfiguration) throws KerberosOperationException
administratorCredentials
- a PrincipalKeyCredential containing the administrative credential
for the relevant KDCrealm
- a String declaring the default Kerberos realm (or domain)kerberosConfiguration
- a Map of key/value pairs containing data from the kerberos-env configuration setKerberosKDCConnectionException
- if a connection to the KDC cannot be madeKerberosAdminAuthenticationException
- if the administrator credentials fail to authenticateKerberosRealmException
- if the realm does not map to a KDCKerberosOperationException
- if an unexpected error occurredpublic void close() throws KerberosOperationException
KerberosOperationHandler
KerberosOperationException
public boolean principalExists(String principal, boolean service) throws KerberosOperationException
principalExists
in class KerberosOperationHandler
principal
- a String containing the principal to testservice
- a boolean value indicating whether the principal is for a service or notKerberosKDCConnectionException
- if a connection to the KDC cannot be madeKerberosAdminAuthenticationException
- if the administrator credentials fail to authenticateKerberosRealmException
- if the realm does not map to a KDCKerberosOperationException
- if an unexpected error occurredpublic Integer createPrincipal(String principal, String password, boolean service) throws KerberosOperationException
createPrincipal
in class KerberosOperationHandler
principal
- a String containing the principal addpassword
- a String containing the password to use when creating the principalservice
- a boolean value indicating whether the principal is to be created as a service principal or notKerberosKDCConnectionException
- if a connection to the KDC cannot be madeKerberosAdminAuthenticationException
- if the administrator credentials fail to authenticateKerberosRealmException
- if the realm does not map to a KDCKerberosPrincipalAlreadyExistsException
- if the principal already existsKerberosOperationException
- if an unexpected error occurredpublic boolean removePrincipal(String principal, boolean service) throws KerberosOperationException
removePrincipal
in class KerberosOperationHandler
principal
- a String containing the principal to removeservice
- a boolean value indicating whether the principal is for a service or notKerberosKDCConnectionException
- if a connection to the KDC cannot be madeKerberosAdminAuthenticationException
- if the administrator credentials fail to authenticateKerberosRealmException
- if the realm does not map to a KDCKerberosOperationException
- if an unexpected error occurredprotected ShellCommandUtil.Result invokeKAdmin(String query) throws KerberosOperationException
query
- a String containing the query to send to the kdamin commandKerberosKDCConnectionException
- if a connection to the KDC cannot be madeKerberosAdminAuthenticationException
- if the administrator credentials fail to authenticateKerberosRealmException
- if the realm does not map to a KDCKerberosOperationException
- if an unexpected error occurredprotected String[] getKinitCommand(String executableKinit, PrincipalKeyCredential credentials, String credentialsCache, Map<String,String> kerberosConfiguration) throws KerberosOperationException
executableKinit
- the absolute path to the kinit executablecredentials
- the KDC adminisrator's credentialscredentialsCache
- the absolute path to the expected location of the Kerberos ticket/credential cache filekerberosConfiguration
- a Map of key/value pairs containing data from the kerberos-env configuration setKerberosOperationException
- in case there was any error during kinit command creationprotected void exportKeytabFile(String principal, String keytabFileDestinationPath, Set<org.apache.directory.shared.kerberos.codec.types.EncryptionType> keyEncryptionTypes) throws KerberosOperationException
principal
- the principal namekeytabFileDestinationPath
- the absolute path to the keytab filekeyEncryptionTypes
- a collection of encrption algorithm types indicating which ketyab entries are requestedKerberosOperationException
public Integer setPrincipalPassword(String principal, String password, boolean service) throws KerberosOperationException
setPrincipalPassword
in class KerberosOperationHandler
principal
- a String containing the principal to updatepassword
- a String containing the password to setservice
- a boolean value indicating whether the principal is for a service or notKerberosOperationException
- if an unexpected error occurredprotected org.apache.directory.server.kerberos.shared.keytab.Keytab createKeytab(String principal, String password, Integer keyNumber) throws KerberosOperationException
createKeytab
in class KerberosOperationHandler
principal
- a String containing the principal to testpassword
- (IGNORED) a String containing the password to use when creating the principalkeyNumber
- (IGNORED) a Integer indicating the key number for the keytab entriesKerberosOperationException
protected ShellCommandUtil.Result executeCommand(String[] command, Map<String,String> envp, ShellCommandUtil.InteractiveHandler interactiveHandler) throws KerberosOperationException
ShellCommandUtil.runCommand(String[])
This implementation sets the proper environment for the custom KRB5CCNAME
value.
executeCommand
in class KerberosOperationHandler
command
- an array of String value representing the command and its argumentsenvp
- a map of string, string of environment variablesinteractiveHandler
- a handler to provide responses to queries from the command,
or null if no queries are expectedKerberosOperationException
protected boolean init(Map<String,String> kerberosConfiguration) throws KerberosOperationException
A randomly named temporary file is created to store the Kerberos ticket cache for this KerberosOperationHandler
's
session. The file will be removed upon closing when the session is complete. The geneated ticket cache
filename is set in the environment variable map using the variable name "KRB5CCNAME". This will be passed
in for all relevant-system commands.
KerberosOperationException
Copyright © 2022 Apache Software Foundation. All rights reserved.