Expose server credentials thru Java APIs
This commit is contained in:
		| @@ -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 | ||||||
|  |   ) | ||||||
|  | { | ||||||
|  | 	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;		 | 	int rcode = 0;		 | ||||||
| 	uint32_t iCredType = SSCS_CRED_TYPE_BASIC_F; |  | ||||||
| 	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,6 +240,63 @@ 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 | ||||||
|   | |||||||
| @@ -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, | ||||||
| @@ -55,6 +59,34 @@ public class MiCasa { | |||||||
| 		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"); | ||||||
| @@ -65,22 +97,54 @@ public class MiCasa { | |||||||
| 									 String sSharedSecretID, | 									 String sSharedSecretID, | ||||||
| 									 int iUserFlag, | 									 int iUserFlag, | ||||||
| 									 String sUsername, | 									 String sUsername, | ||||||
|                                      String sPassword) throws Exception { | 									 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, | ||||||
|  | 									 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, | 	public static NetCredential getCredential(int iSSFlags, | ||||||
| 											  String sAppSecretID, | 											  String sAppSecretID, | ||||||
| 											  String sSharedSecretID, | 											  String sSharedSecretID, | ||||||
|                                               int iUserFlag) throws Exception { | 											  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, | ||||||
|  | 											  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); | ||||||
|  | 		} | ||||||
|  |  | ||||||
|  | 	} | ||||||
|  |  | ||||||
|  |  | ||||||
| } | } | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user