package org.libvirt; /** * @author stoty * */ public class VirConnectCredential { public static enum VirConnectCredentialType { //This is off by one, but we don't care, because we can't convert java Enum to C enum in a sane way anyway /** * Identity to act as */ VIR_CRED_USERNAME, /** * Identify to authorize as */ VIR_CRED_AUTHNAME, /** * RFC 1766 languages, comma separated */ VIR_CRED_LANGUAGE, /** * client supplies a nonce */ VIR_CRED_CNONCE, /** * Passphrase secret */ VIR_CRED_PASSPHRASE, /** * Challenge response */ VIR_CRED_ECHOPROMPT, /** * Challenge response */ VIR_CRED_NOECHOPROMPT, /** * Authentication realm */ VIR_CRED_REALM, /** * Externally managed credential More may be added - expect the unexpected */ VIR_CRED_EXTERNAL; /** * Maps the java VirConnectCredentialType Enum to libvirt's integer constant * * @return The integer equivalent */ private int mapToInt(){ switch(this){ case VIR_CRED_USERNAME: return 1; case VIR_CRED_AUTHNAME: return 2; case VIR_CRED_LANGUAGE: return 3; case VIR_CRED_CNONCE: return 4; case VIR_CRED_PASSPHRASE: return 5; case VIR_CRED_ECHOPROMPT: return 6; case VIR_CRED_NOECHOPROMPT: return 7; case VIR_CRED_REALM: return 8; case VIR_CRED_EXTERNAL: return 9; } //We may never reach this point assert(false); return 0; } } /** * One of virConnectCredentialType constants */ public VirConnectCredentialType type; /** * Prompt to show to user */ public String prompt; /** * Additional challenge to show */ public String challenge; /** * Optional default result */ public String defresult; /** * Result to be filled with user response (or defresult) */ public String result; /** * Convenience constructor to be called from the JNI side * * @param type * @param prompt * @param challenge * @param defresult */ VirConnectCredential(int type, String prompt, String challenge, String defresult){ switch(type){ case 1: this.type=VirConnectCredentialType.VIR_CRED_USERNAME; break; case 2: this.type=VirConnectCredentialType.VIR_CRED_AUTHNAME; break; case 3: this.type=VirConnectCredentialType.VIR_CRED_LANGUAGE; break; case 4: this.type=VirConnectCredentialType.VIR_CRED_CNONCE; break; case 5: this.type=VirConnectCredentialType.VIR_CRED_PASSPHRASE; break; case 6: this.type=VirConnectCredentialType.VIR_CRED_ECHOPROMPT; break; case 7: this.type=VirConnectCredentialType.VIR_CRED_NOECHOPROMPT; break; case 8: this.type=VirConnectCredentialType.VIR_CRED_REALM; break; case 9: this.type=VirConnectCredentialType.VIR_CRED_EXTERNAL; break; default: assert(false); } this.prompt = prompt; this.challenge = challenge; this.defresult = defresult; } }