mirror of
https://github.com/openjdk/jdk.git
synced 2026-04-19 19:30:51 +00:00
Tidy up comments/docs
This commit is contained in:
parent
2e6cd02968
commit
307c3f285f
@ -89,7 +89,7 @@ public class NativeCacheTest {
|
||||
}
|
||||
|
||||
/**
|
||||
* Use OneKDC to create a real TGT via JAAS LoginModule
|
||||
* Use OneKDC to create a real TGT via the JAAS LoginModule
|
||||
*/
|
||||
private static void createRealTGTWithOneKDC() throws Exception {
|
||||
System.out.println("Creating TGT via OneKDC");
|
||||
@ -101,7 +101,7 @@ public class NativeCacheTest {
|
||||
System.setProperty("test.kdc.save.ccache", "onekdc_cache.ccache");
|
||||
|
||||
try {
|
||||
// Authenticate using JAAS LoginModule
|
||||
// Authenticate using the JAAS LoginModule
|
||||
LoginContext lc = new LoginContext("com.sun.security.jgss.krb5.initiate",
|
||||
new OneKDC.CallbackForClient());
|
||||
lc.login();
|
||||
@ -119,20 +119,20 @@ public class NativeCacheTest {
|
||||
}
|
||||
|
||||
/**
|
||||
* Copy the real TGT to memory cache using JNI
|
||||
* Copy the real TGT to an in-memory cache using JNI
|
||||
*/
|
||||
private static String copyTGTToInMemoryCache() throws Exception {
|
||||
System.out.println("Copying credentials to memory cache");
|
||||
|
||||
String memoryCacheName = "MEMORY:test_" + System.currentTimeMillis();
|
||||
|
||||
// Create the memory cache
|
||||
// Create the in-memory cache
|
||||
if (!NativeCredentialCacheHelper.createInMemoryCache(memoryCacheName)) {
|
||||
throw new RuntimeException("Failed to create memory cache");
|
||||
}
|
||||
System.out.println("Created memory cache: " + memoryCacheName);
|
||||
|
||||
// Try to copy credentials from saved cache file
|
||||
// Try to copy credentials from the saved cache file
|
||||
boolean copied = false;
|
||||
File savedCache = new File("onekdc_cache.ccache");
|
||||
if (savedCache.exists()) {
|
||||
@ -143,7 +143,7 @@ public class NativeCacheTest {
|
||||
);
|
||||
}
|
||||
|
||||
// Fallback to default cache if file cache doesn't exist
|
||||
// Fallback to the default cache if the file cache doesn't exist
|
||||
if (!copied) {
|
||||
copied = NativeCredentialCacheHelper.copyCredentialsToInMemoryCache(memoryCacheName, null);
|
||||
}
|
||||
@ -154,7 +154,7 @@ public class NativeCacheTest {
|
||||
System.out.println("No credentials found to copy");
|
||||
}
|
||||
|
||||
// Set as default cache for JAAS testing
|
||||
// Set as the default cache for JAAS testing
|
||||
NativeCredentialCacheHelper.setDefaultCache(memoryCacheName);
|
||||
System.setProperty("KRB5CCNAME", memoryCacheName);
|
||||
|
||||
@ -162,12 +162,12 @@ public class NativeCacheTest {
|
||||
}
|
||||
|
||||
/**
|
||||
* Test JAAS access to the memory cache (the main test)
|
||||
* Test JAAS access to an in-memory cache
|
||||
*/
|
||||
private static void testJAASAccessToInMemoryCache(String inMemoryCacheName) throws Exception {
|
||||
System.out.println("Testing JAAS access to an in-memory cache");
|
||||
|
||||
// Verify KRB5CCNAME points to our memory cache
|
||||
// Verify KRB5CCNAME points to our in-memory cache
|
||||
String krb5ccname = System.getProperty("KRB5CCNAME");
|
||||
System.out.println("KRB5CCNAME is set to: " + krb5ccname);
|
||||
System.out.println("Expected in-memory cache: " + inMemoryCacheName);
|
||||
@ -188,7 +188,7 @@ public class NativeCacheTest {
|
||||
System.out.println("Client: " + client);
|
||||
System.out.println("Server: " + server);
|
||||
|
||||
// Verify these are the OneKDC test credentials we copied
|
||||
// Verify these are the OneKDC test credentials
|
||||
if (client.contains("dummy") && server.contains("RABBIT.HOLE")) {
|
||||
System.out.println("SUCCESS: Retrieved correct OneKDC test credentials from in-memory cache");
|
||||
if (server.contains("krbtgt")) {
|
||||
|
||||
@ -26,24 +26,26 @@
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h> // for access()
|
||||
#include <limits.h> // for realpath()
|
||||
#include <unistd.h>
|
||||
#include <limits.h>
|
||||
|
||||
#include "NativeCredentialCacheHelper.h"
|
||||
|
||||
// Global krb5 context - initialized once
|
||||
// Global krb5 context
|
||||
static krb5_context g_context = NULL;
|
||||
|
||||
// Initialize krb5 context with OneKDC config if available
|
||||
/**
|
||||
* Initialize krb5 context with OneKDC config
|
||||
*/
|
||||
static krb5_error_code ensure_context() {
|
||||
// Always check for OneKDC config file and set environment
|
||||
// Check if OneKDC config file exists or needs to be created
|
||||
if (access("localkdc-krb5.conf", F_OK) != -1) {
|
||||
char *current_path = realpath("localkdc-krb5.conf", NULL);
|
||||
if (current_path != NULL) {
|
||||
setenv("KRB5_CONFIG", current_path, 1);
|
||||
free(current_path);
|
||||
|
||||
// If context already exists, reinitialize it to pick up new config
|
||||
// If context already exists, reinitialize it
|
||||
if (g_context != NULL) {
|
||||
krb5_free_context(g_context);
|
||||
g_context = NULL;
|
||||
@ -57,7 +59,9 @@ static krb5_error_code ensure_context() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Utility function to convert Java string to C string
|
||||
/**
|
||||
* Convert Java string to C string
|
||||
*/
|
||||
static char* jstring_to_cstring(JNIEnv *env, jstring jstr) {
|
||||
if (jstr == NULL) return NULL;
|
||||
|
||||
@ -69,7 +73,9 @@ static char* jstring_to_cstring(JNIEnv *env, jstring jstr) {
|
||||
return result;
|
||||
}
|
||||
|
||||
// Print error message for krb5 errors
|
||||
/**
|
||||
* Print error messages for krb5 errors
|
||||
*/
|
||||
static void print_krb5_error(const char *operation, krb5_error_code code) {
|
||||
if (code != 0) {
|
||||
printf("krb5 error in %s: %s\n", operation, error_message(code));
|
||||
@ -78,8 +84,6 @@ static void print_krb5_error(const char *operation, krb5_error_code code) {
|
||||
|
||||
/**
|
||||
* Create an in-memory credential cache using native krb5 API.
|
||||
* Creates a MEMORY: type cache that can be used for testing JAAS access
|
||||
* to in-memory credential stores.
|
||||
*/
|
||||
JNIEXPORT jboolean JNICALL Java_NativeCredentialCacheHelper_createInMemoryCache
|
||||
(JNIEnv *env, jclass cls, jstring cacheName)
|
||||
@ -114,10 +118,8 @@ JNIEXPORT jboolean JNICALL Java_NativeCredentialCacheHelper_createInMemoryCache
|
||||
return JNI_TRUE;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Set the default credential cache to the specified credential cache.
|
||||
* This makes the credential cache the target for credential lookups.
|
||||
* Set KRB5CCNAME so that the test will pick up the in-memory credential cache.
|
||||
*/
|
||||
JNIEXPORT jboolean JNICALL Java_NativeCredentialCacheHelper_setDefaultCache
|
||||
(JNIEnv *env, jclass cls, jstring cacheName)
|
||||
@ -140,9 +142,9 @@ JNIEXPORT jboolean JNICALL Java_NativeCredentialCacheHelper_setDefaultCache
|
||||
|
||||
|
||||
/**
|
||||
* Copy real Kerberos credentials from a source cache to a memory cache.
|
||||
* This preserves the proper credential format so JAAS can access them.
|
||||
* Used to move OneKDC-generated TGTs to in-memory caches for testing.
|
||||
* Copy real Kerberos credentials from a source cache to an in-memory cache.
|
||||
* in-memory cache. Used to move OneKDC-generated TGTs to an in-memory cache
|
||||
* for testing.
|
||||
*/
|
||||
JNIEXPORT jboolean JNICALL Java_NativeCredentialCacheHelper_copyCredentialsToInMemoryCache
|
||||
(JNIEnv *env, jclass cls, jstring inMemoryCacheName, jstring sourceCacheName)
|
||||
@ -264,7 +266,3 @@ cleanup:
|
||||
|
||||
return (ret == 0) ? JNI_TRUE : JNI_FALSE;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@ -1,9 +1,9 @@
|
||||
#!/bin/bash
|
||||
# Build script for NativeCacheTest - compiles Java classes and native library
|
||||
# Build script for NativeCacheTest
|
||||
|
||||
set -e
|
||||
|
||||
# Use jtreg environment variables when available, fallback to manual calculation
|
||||
# Use jtreg environment variables when available
|
||||
if [ -n "$TESTJAVA" ]; then
|
||||
# Running under jtreg
|
||||
BUILT_JDK="$TESTJAVA"
|
||||
@ -23,7 +23,7 @@ export PATH="$BUILT_JDK/bin:$PATH"
|
||||
|
||||
# Module exports required for Kerberos internal APIs
|
||||
if [ -n "$TESTCLASSPATH" ]; then
|
||||
# Use jtreg's prepared classpath
|
||||
# Use the jtreg classpath
|
||||
JAVA_CP="$TESTCLASSPATH"
|
||||
else
|
||||
# Manual execution classpath
|
||||
@ -41,9 +41,8 @@ MODULE_EXPORTS="--add-exports java.security.jgss/sun.security.krb5=ALL-UNNAMED \
|
||||
cd "$TEST_DIR"
|
||||
|
||||
# For jtreg, classes are already compiled by the harness
|
||||
# For manual execution, compile what's needed
|
||||
if [ -z "$TESTJAVA" ]; then
|
||||
# Manual execution - compile everything
|
||||
# Manual execution
|
||||
|
||||
# Compile test library classes
|
||||
cd "$LIB_DIR"
|
||||
@ -61,7 +60,7 @@ if [ -z "$TESTJAVA" ]; then
|
||||
NativeCredentialCacheHelper.java NativeCacheTest.java
|
||||
fi
|
||||
|
||||
# Generate JNI header (always needed for native compilation)
|
||||
# Generate JNI header
|
||||
cd "$TEST_DIR"
|
||||
if [ -n "$TESTCLASSPATH" ]; then
|
||||
javac -cp "$TESTCLASSPATH" -h . NativeCredentialCacheHelper.java
|
||||
@ -69,7 +68,7 @@ else
|
||||
javac -cp . -h . NativeCredentialCacheHelper.java
|
||||
fi
|
||||
|
||||
# get the OS
|
||||
# Get the OS to determine the compiler and library extension
|
||||
OS=$(uname -s | tr 'A-Z' 'a-z')
|
||||
if [ "$OS" == "linux" ]; then
|
||||
COMPILER=gcc
|
||||
@ -82,7 +81,7 @@ else
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Compile native library (work from test source directory)
|
||||
# Compile native library
|
||||
cd "$TEST_DIR"
|
||||
${COMPILER} -shared -fPIC -I"$JAVA_HOME/include" -I"$JAVA_HOME/include/${OS}" -lkrb5 \
|
||||
-o libnativecredentialcachehelper.${LIBEXT} NativeCredentialCacheHelper.c
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user