Search in sources :

Example 1 with SecurityPackage

use of com.sun.jna.platform.win32.Secur32Util.SecurityPackage in project jna by java-native-access.

the class Secur32Util method getSecurityPackages.

/**
	 * Get the security packages installed on the current computer.
	 * @return
	 *  An array of SSPI security packages.
	 */
public static SecurityPackage[] getSecurityPackages() {
    IntByReference pcPackages = new IntByReference();
    PSecPkgInfo pPackageInfo = new PSecPkgInfo();
    int rc = Secur32.INSTANCE.EnumerateSecurityPackages(pcPackages, pPackageInfo);
    if (W32Errors.SEC_E_OK != rc) {
        throw new Win32Exception(rc);
    }
    SecPkgInfo[] packagesInfo = pPackageInfo.toArray(pcPackages.getValue());
    ArrayList<SecurityPackage> packages = new ArrayList<SecurityPackage>(pcPackages.getValue());
    for (SecPkgInfo packageInfo : packagesInfo) {
        SecurityPackage securityPackage = new SecurityPackage();
        securityPackage.name = packageInfo.Name.toString();
        securityPackage.comment = packageInfo.Comment.toString();
        packages.add(securityPackage);
    }
    rc = Secur32.INSTANCE.FreeContextBuffer(pPackageInfo.pPkgInfo.getPointer());
    if (W32Errors.SEC_E_OK != rc) {
        throw new Win32Exception(rc);
    }
    return packages.toArray(new SecurityPackage[0]);
}
Also used : IntByReference(com.sun.jna.ptr.IntByReference) SecPkgInfo(com.sun.jna.platform.win32.Sspi.SecPkgInfo) PSecPkgInfo(com.sun.jna.platform.win32.Sspi.PSecPkgInfo) ArrayList(java.util.ArrayList) PSecPkgInfo(com.sun.jna.platform.win32.Sspi.PSecPkgInfo)

Example 2 with SecurityPackage

use of com.sun.jna.platform.win32.Secur32Util.SecurityPackage in project jna by java-native-access.

the class Secur32UtilTest method main.

public static void main(String[] args) {
    junit.textui.TestRunner.run(Secur32UtilTest.class);
    System.out.println("Current user: " + Secur32Util.getUserNameEx(EXTENDED_NAME_FORMAT.NameSamCompatible));
    System.out.println("Security packages:");
    for (SecurityPackage sp : Secur32Util.getSecurityPackages()) {
        System.out.println(" " + sp.name + ": " + sp.comment);
    }
}
Also used : SecurityPackage(com.sun.jna.platform.win32.Secur32Util.SecurityPackage)

Example 3 with SecurityPackage

use of com.sun.jna.platform.win32.Secur32Util.SecurityPackage in project jna by java-native-access.

the class Secur32UtilTest method testGetSecurityPackages.

public void testGetSecurityPackages() {
    SecurityPackage[] sps = Secur32Util.getSecurityPackages();
    for (SecurityPackage sp : sps) {
        assertTrue(sp.name.length() > 0);
        assertTrue(sp.comment.length() >= 0);
    }
}
Also used : SecurityPackage(com.sun.jna.platform.win32.Secur32Util.SecurityPackage)

Aggregations

SecurityPackage (com.sun.jna.platform.win32.Secur32Util.SecurityPackage)2 PSecPkgInfo (com.sun.jna.platform.win32.Sspi.PSecPkgInfo)1 SecPkgInfo (com.sun.jna.platform.win32.Sspi.SecPkgInfo)1 IntByReference (com.sun.jna.ptr.IntByReference)1 ArrayList (java.util.ArrayList)1