Expose server credentials thru Java APIs

This commit is contained in:
Jim Norman 2007-02-09 17:41:25 +00:00
parent f2318eadd2
commit 8ceff1a109
2 changed files with 203 additions and 21 deletions

View File

@ -30,7 +30,6 @@
extern "C" { extern "C" {
#endif #endif
JNIEXPORT jint JNICALL JNIEXPORT jint JNICALL
Java_com_novell_casa_MiCasa_jmiCASASetCredential Java_com_novell_casa_MiCasa_jmiCASASetCredential
(JNIEnv *env, jobject notused, (JNIEnv *env, jobject notused,
@ -41,6 +40,29 @@ Java_com_novell_casa_MiCasa_jmiCASASetCredential
jstring jsUsername, jstring jsUsername,
jstring jsPassword jstring jsPassword
) )
{
return Java_com_novell_casa_MiCasa_jmiCASASetCredentialEx
(env, notused,
ssFlags,
jsAppSecretID,
jsSharedSecretID,
jUsernameType,
jsUsername,
jsPassword,
SSCS_CRED_TYPE_BASIC_F);
}
JNIEXPORT jint JNICALL
Java_com_novell_casa_MiCasa_jmiCASASetCredentialEx
(JNIEnv *env, jobject notused,
jint ssFlags,
jstring jsAppSecretID,
jstring jsSharedSecretID,
jint jUsernameType,
jstring jsUsername,
jstring jsPassword,
jint jiCredType
)
{ {
int rcode = 0; int rcode = 0;
SSCS_SECRET_ID_T appSecretId = {0}; SSCS_SECRET_ID_T appSecretId = {0};
@ -90,7 +112,7 @@ Java_com_novell_casa_MiCasa_jmiCASASetCredential
ssFlags, ssFlags,
&appSecretId, &appSecretId,
&sharedSecretId, &sharedSecretId,
SSCS_CRED_TYPE_BASIC_F, jiCredType,
&credential, &credential,
NULL NULL
); );
@ -99,7 +121,7 @@ Java_com_novell_casa_MiCasa_jmiCASASetCredential
ssFlags, ssFlags,
&appSecretId, &appSecretId,
NULL, NULL,
SSCS_CRED_TYPE_BASIC_F, jiCredType,
&credential, &credential,
NULL NULL
); );
@ -107,11 +129,6 @@ Java_com_novell_casa_MiCasa_jmiCASASetCredential
return rcode; return rcode;
} }
/*
* Class: com_novell_casa_micasa_SecretStore
* Method: jmiCASAGetCredential
* Signature: (I[B[BILcom/novell/casa/micasa/Secret;)I
*/
JNIEXPORT jint JNICALL JNIEXPORT jint JNICALL
Java_com_novell_casa_MiCasa_jmiCASAGetCredential Java_com_novell_casa_MiCasa_jmiCASAGetCredential
(JNIEnv *env, jobject unused, (JNIEnv *env, jobject unused,
@ -119,13 +136,42 @@ Java_com_novell_casa_MiCasa_jmiCASAGetCredential
jstring jsAppSecretID, jstring jsAppSecretID,
jstring jsSharedSecretID, jstring jsSharedSecretID,
jint jUsernameType, jint jUsernameType,
jobject jcred) jobject jcred
)
{ {
int rcode = 0; return Java_com_novell_casa_MiCasa_jmiCASAGetCredentialEx
uint32_t iCredType = SSCS_CRED_TYPE_BASIC_F; (env,
unused,
ssFlags,
jsAppSecretID,
jsSharedSecretID,
jUsernameType,
jcred,
SSCS_CRED_TYPE_BASIC_F);
}
/*
* Class: com_novell_casa_micasa_SecretStore
* Method: jmiCASAGetCredential
* Signature: (I[B[BILcom/novell/casa/micasa/Secret;)I
*/
JNIEXPORT jint JNICALL
Java_com_novell_casa_MiCasa_jmiCASAGetCredentialEx
(JNIEnv *env, jobject unused,
jint ssFlags,
jstring jsAppSecretID,
jstring jsSharedSecretID,
jint jUsernameType,
jobject jcred,
jint jiCredType)
{
int rcode = 0;
SSCS_SECRET_ID_T appSecretId = {0}; SSCS_SECRET_ID_T appSecretId = {0};
SSCS_SECRET_ID_T sharedSecretId = {0}; SSCS_SECRET_ID_T sharedSecretId = {0};
SSCS_BASIC_CREDENTIAL credential = {0}; SSCS_BASIC_CREDENTIAL credential = {0};
uint32_t iCredType = jiCredType;
const char* utf_string; const char* utf_string;
jboolean isCopy; jboolean isCopy;
@ -194,7 +240,64 @@ Java_com_novell_casa_MiCasa_jmiCASAGetCredential
return rcode; return rcode;
} }
/*
* Class: com_novell_casa_MiCasa
* Method: jmiCASADeleteCredentialEx
* Signature: (ILjava/lang/String;Ljava/lang/String;I)I
*/
JNIEXPORT jint JNICALL Java_com_novell_casa_MiCasa_jmiCASADeleteCredentialEx
(JNIEnv *env, jobject unused,
jint ssFlags,
jstring jsAppSecretID,
jstring jsSharedSecretID,
jint jiCredType)
{
int rcode = 0;
SSCS_SECRET_ID_T appSecretId = {0};
SSCS_SECRET_ID_T sharedSecretId = {0};
const char* utf_string;
jboolean isCopy;
utf_string = (*env)->GetStringUTFChars(env, jsAppSecretID, &isCopy);
sscs_Utf8Strcpy((char*)appSecretId.id, utf_string);
appSecretId.len = sscs_Utf8Strlen(utf_string) + 1;
if (isCopy == JNI_TRUE)
(*env)->ReleaseStringUTFChars(env, jsAppSecretID, utf_string);
// handle sharedsecretid
if (jsSharedSecretID)
{
utf_string = (*env)->GetStringUTFChars(env, jsSharedSecretID, &isCopy);
sscs_Utf8Strcpy((char*)sharedSecretId.id, utf_string);
sharedSecretId.len = sscs_Utf8Strlen(utf_string)+1;
if (isCopy == JNI_TRUE)
(*env)->ReleaseStringUTFChars(env, jsSharedSecretID, utf_string);
}
// make the call
if (jsSharedSecretID)
rcode = miCASADeleteCredential(
ssFlags,
&appSecretId,
&sharedSecretId,
jiCredType,
NULL);
else
rcode = miCASADeleteCredential(
ssFlags,
&appSecretId,
NULL,
jiCredType,
NULL);
return rcode;
}
/* /*
* Class: com_novell_casa_micasa_SecretStore * Class: com_novell_casa_micasa_SecretStore
* Method: jmiCASARemoveCredential * Method: jmiCASARemoveCredential

View File

@ -32,6 +32,10 @@ public class MiCasa {
public static int USERNAME_TYPE_EMAIL_F = 0x00000008; public static int USERNAME_TYPE_EMAIL_F = 0x00000008;
public static int USERNAME_TYPE_OTHER_F = 0x00000010; public static int USERNAME_TYPE_OTHER_F = 0x00000010;
public static int SSCS_CRED_TYPE_BASIC_F = 0x00000001;
public static int SSCS_CRED_TYPE_BINARY_F = 0x00000002;
public static int SSCS_CRED_TYPE_SERVER_F = 0x00000004;
public static native int jmiCASASetCredential( public static native int jmiCASASetCredential(
int iSSFlags, int iSSFlags,
String sAppSecretID, String sAppSecretID,
@ -49,38 +53,98 @@ public class MiCasa {
NetCredential credential NetCredential credential
); );
public static native int jmiCASARemoveCredential( public static native int jmiCASARemoveCredential(
int iSSFlags, int iSSFlags,
String sAppSecretID, String sAppSecretID,
String sSharedSecretID String sSharedSecretID
); );
public static native int jmiCASASetCredentialEx(
int iSSFlags,
String sAppSecretID,
String sSharedSecretID,
int unFlag,
String sUsername,
String sPassword,
int iCredType
);
public static native int jmiCASAGetCredentialEx(
int iSSFlags,
String sAppSecretID,
String sSharedSecretID,
int unFlag,
NetCredential credential,
int iCredType
);
public static native int jmiCASADeleteCredentialEx(
int iSSFlags,
String sAppSecretID,
String sSharedSecretID,
int iCredType
);
// ********************************************************************************************** // **********************************************************************************************
static { static {
System.loadLibrary("jmicasa"); System.loadLibrary("jmicasa");
} }
public static void setCredential(int iSSFlags,
String sAppSecretID,
String sSharedSecretID,
int iUserFlag,
String sUsername,
String sPassword) throws Exception
{
setCredential(iSSFlags,
sAppSecretID,
sSharedSecretID,
iUserFlag, sUsername,
sPassword,
SSCS_CRED_TYPE_BASIC_F);
}
public static void setCredential(int iSSFlags, public static void setCredential(int iSSFlags,
String sAppSecretID, String sAppSecretID,
String sSharedSecretID, String sSharedSecretID,
int iUserFlag, int iUserFlag,
String sUsername, String sUsername,
String sPassword) throws Exception { String sPassword,
int iCredType) throws Exception
{
int rcode = 0; int rcode = 0;
rcode = jmiCASASetCredential(iSSFlags, sAppSecretID, sSharedSecretID, iUserFlag, sUsername, sPassword); rcode = jmiCASASetCredentialEx(iSSFlags, sAppSecretID, sSharedSecretID, iUserFlag, sUsername, sPassword, iCredType);
if (rcode != 0) { if (rcode != 0) {
throw new MiCasaException(rcode); throw new MiCasaException(rcode);
} }
} }
public static NetCredential getCredential(int iSSFlags,
String sAppSecretID,
String sSharedSecretID,
int iUserFlag) throws Exception
{
return getCredential(iSSFlags,
sAppSecretID,
sSharedSecretID,
iUserFlag,
SSCS_CRED_TYPE_BASIC_F);
}
public static NetCredential getCredential(int iSSFlags, public static NetCredential getCredential(int iSSFlags,
String sAppSecretID, String sAppSecretID,
String sSharedSecretID, String sSharedSecretID,
int iUserFlag) throws Exception { int iUserFlag,
int iCredType) throws Exception
{
int rcode = 0; int rcode = 0;
NetCredential netCred = new NetCredential(); NetCredential netCred = new NetCredential();
rcode = jmiCASAGetCredential(iSSFlags, sAppSecretID, sSharedSecretID, iUserFlag, netCred); rcode = jmiCASAGetCredentialEx(iSSFlags, sAppSecretID, sSharedSecretID, iUserFlag, netCred, iCredType);
if (rcode != 0) { if (rcode != 0) {
throw new MiCasaException(rcode); throw new MiCasaException(rcode);
} }
@ -99,4 +163,19 @@ public class MiCasa {
} }
public static void deleteCredential(int iSSFlags,
String sAppSecretID,
String sSharedSecretID,
int iCredType) throws Exception
{
int rcode = 0;
rcode = jmiCASADeleteCredentialEx(iSSFlags, sAppSecretID, sSharedSecretID, iCredType);
if (rcode != 0)
{
throw new MiCasaException(rcode);
}
}
} }