diff --git a/CASA/jwrapper/jnsscs/jmicasa.c b/CASA/jwrapper/jnsscs/jmicasa.c index 616c947a..f5adaad7 100644 --- a/CASA/jwrapper/jnsscs/jmicasa.c +++ b/CASA/jwrapper/jnsscs/jmicasa.c @@ -30,7 +30,6 @@ extern "C" { #endif - JNIEXPORT jint JNICALL Java_com_novell_casa_MiCasa_jmiCASASetCredential (JNIEnv *env, jobject notused, @@ -41,6 +40,29 @@ Java_com_novell_casa_MiCasa_jmiCASASetCredential jstring jsUsername, 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; SSCS_SECRET_ID_T appSecretId = {0}; @@ -90,7 +112,7 @@ Java_com_novell_casa_MiCasa_jmiCASASetCredential ssFlags, &appSecretId, &sharedSecretId, - SSCS_CRED_TYPE_BASIC_F, + jiCredType, &credential, NULL ); @@ -99,7 +121,7 @@ Java_com_novell_casa_MiCasa_jmiCASASetCredential ssFlags, &appSecretId, NULL, - SSCS_CRED_TYPE_BASIC_F, + jiCredType, &credential, NULL ); @@ -107,11 +129,6 @@ Java_com_novell_casa_MiCasa_jmiCASASetCredential return rcode; } -/* - * 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_jmiCASAGetCredential (JNIEnv *env, jobject unused, @@ -119,13 +136,42 @@ Java_com_novell_casa_MiCasa_jmiCASAGetCredential jstring jsAppSecretID, jstring jsSharedSecretID, jint jUsernameType, - jobject jcred) + jobject jcred + ) { - int rcode = 0; - uint32_t iCredType = SSCS_CRED_TYPE_BASIC_F; + return Java_com_novell_casa_MiCasa_jmiCASAGetCredentialEx + (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 sharedSecretId = {0}; SSCS_BASIC_CREDENTIAL credential = {0}; + uint32_t iCredType = jiCredType; const char* utf_string; jboolean isCopy; @@ -194,7 +240,64 @@ Java_com_novell_casa_MiCasa_jmiCASAGetCredential 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 * Method: jmiCASARemoveCredential diff --git a/CASA/jwrapper/src/com/novell/casa/MiCasa.java b/CASA/jwrapper/src/com/novell/casa/MiCasa.java index 67457513..a29cc0d4 100644 --- a/CASA/jwrapper/src/com/novell/casa/MiCasa.java +++ b/CASA/jwrapper/src/com/novell/casa/MiCasa.java @@ -32,6 +32,10 @@ public class MiCasa { public static int USERNAME_TYPE_EMAIL_F = 0x00000008; 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( int iSSFlags, String sAppSecretID, @@ -49,38 +53,98 @@ public class MiCasa { NetCredential credential ); - public static native int jmiCASARemoveCredential( - int iSSFlags, - String sAppSecretID, - String sSharedSecretID - ); + public static native int jmiCASARemoveCredential( + int iSSFlags, + String sAppSecretID, + 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 { 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, String sAppSecretID, String sSharedSecretID, int iUserFlag, String sUsername, - String sPassword) throws Exception { + String sPassword, + int iCredType) throws Exception + { int rcode = 0; - rcode = jmiCASASetCredential(iSSFlags, sAppSecretID, sSharedSecretID, iUserFlag, sUsername, sPassword); + rcode = jmiCASASetCredentialEx(iSSFlags, sAppSecretID, sSharedSecretID, iUserFlag, sUsername, sPassword, iCredType); if (rcode != 0) { 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, String sAppSecretID, String sSharedSecretID, - int iUserFlag) throws Exception { + int iUserFlag, + int iCredType) throws Exception + { int rcode = 0; NetCredential netCred = new NetCredential(); - rcode = jmiCASAGetCredential(iSSFlags, sAppSecretID, sSharedSecretID, iUserFlag, netCred); + rcode = jmiCASAGetCredentialEx(iSSFlags, sAppSecretID, sSharedSecretID, iUserFlag, netCred, iCredType); if (rcode != 0) { 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); + } + + } + + }