final int rc = Secur32.INSTANCE.AcquireCredentialsHandle(username, scheme, Sspi.SECPKG_CRED_OUTBOUND, null, null, null, null, clientCred, lifetime);
public void dispose() { if (clientCred != null && !clientCred.isNull()) { final int rc = Secur32.INSTANCE.FreeCredentialsHandle(clientCred); if (WinError.SEC_E_OK != rc) { throw new Win32Exception(rc); } } if (sspiContext != null && !sspiContext.isNull()) { final int rc = Secur32.INSTANCE.DeleteSecurityContext(sspiContext); if (WinError.SEC_E_OK != rc) { throw new Win32Exception(rc); } } continueNeeded = true; // waiting clientCred = null; sspiContext = null; }
String getToken( final CtxtHandle continueCtx, final SecBufferDesc continueToken, final String targetName) { final IntByReference attr = new IntByReference(); final ManagedSecBufferDesc token = new ManagedSecBufferDesc( Sspi.SECBUFFER_TOKEN, Sspi.MAX_TOKEN_SIZE); sspiContext = new CtxtHandle(); final int rc = Secur32.INSTANCE.InitializeSecurityContext(clientCred, continueCtx, targetName, Sspi.ISC_REQ_DELEGATE | Sspi.ISC_REQ_MUTUAL_AUTH, 0, Sspi.SECURITY_NATIVE_DREP, continueToken, 0, sspiContext, token, attr, null); switch (rc) { case WinError.SEC_I_CONTINUE_NEEDED: continueNeeded = true; break; case WinError.SEC_E_OK: dispose(); // Don't keep the context continueNeeded = false; break; default: dispose(); throw new Win32Exception(rc); } return Base64.encodeBase64String(token.getBuffer(0).getBytes()); }
/** * Dispose of the credentials handle. */ @Override public void dispose() { if (this.handle != null && !this.handle.isNull()) { final int rc = Secur32.INSTANCE.FreeCredentialsHandle(this.handle); if (WinError.SEC_E_OK != rc) { throw new Win32Exception(rc); } } }
/** * Dispose a security context. * * @param ctx * Security context. * @return True if a context was disposed. */ public static boolean dispose(final CtxtHandle ctx) { if (ctx != null && !ctx.isNull()) { final int rc = Secur32.INSTANCE.DeleteSecurityContext(ctx); if (WinError.SEC_E_OK != rc) { throw new Win32Exception(rc); } return true; } return false; }
/** * 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]); } }
public synchronized void free() { if(SessionKey != null) { Secur32.INSTANCE.FreeContextBuffer(SessionKey); SessionKey = null; } } }
@Override public IWindowsIdentity getIdentity() { final HANDLEByReference phContextToken = new HANDLEByReference(); final int rc = Secur32.INSTANCE.QuerySecurityContextToken(this.ctx, phContextToken); if (WinError.SEC_E_OK != rc) { throw new Win32Exception(rc); } return new WindowsIdentityImpl(phContextToken.getValue()); }
/** * Instantiates a new windows security context impersonation context impl. * * @param newCtx * the new ctx */ public WindowsSecurityContextImpersonationContextImpl(final CtxtHandle newCtx) { final int rc = Secur32.INSTANCE.ImpersonateSecurityContext(newCtx); if (rc != WinError.SEC_E_OK) { throw new Win32Exception(rc); } this.ctx = newCtx; }
rc = Secur32.INSTANCE.AcceptSecurityContext(serverCredential.getHandle(), continueHandle, pbClientToken, Sspi.ISC_REQ_CONNECTION, Sspi.SECURITY_NATIVE_DREP, phNewServerContext, pbServerToken, pfClientContextAttr, null);
char[] buffer = new char[128]; IntByReference len = new IntByReference(buffer.length); boolean result = Secur32.INSTANCE.GetUserNameEx(format, buffer, len); result = Secur32.INSTANCE.GetUserNameEx(format, buffer, len);
/** * Dispose of the credentials handle. */ @Override public void dispose() { if (this.handle != null && !this.handle.isNull()) { final int rc = Secur32.INSTANCE.FreeCredentialsHandle(this.handle); if (WinError.SEC_E_OK != rc) { throw new Win32Exception(rc); } } }
/** * Dispose a security context. * * @param ctx * Security context. * @return True if a context was disposed. */ public static boolean dispose(final CtxtHandle ctx) { if (ctx != null && !ctx.isNull()) { final int rc = Secur32.INSTANCE.DeleteSecurityContext(ctx); if (WinError.SEC_E_OK != rc) { throw new Win32Exception(rc); } return true; } return false; }
/** * 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.ByReference pPackageInfo = new PSecPkgInfo.ByReference(); 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]); } }
public synchronized void free() { if(sSignatureAlgorithmName != null) { Secur32.INSTANCE.FreeContextBuffer(sSignatureAlgorithmName); sSignatureAlgorithmName = null; } if(sEncryptAlgorithmName != null) { Secur32.INSTANCE.FreeContextBuffer(sEncryptAlgorithmName); sEncryptAlgorithmName = null; } } }
@Override public IWindowsIdentity getIdentity() { final HANDLEByReference phContextToken = new HANDLEByReference(); final int rc = Secur32.INSTANCE.QuerySecurityContextToken(this.ctx, phContextToken); if (WinError.SEC_E_OK != rc) { throw new Win32Exception(rc); } return new WindowsIdentityImpl(phContextToken.getValue()); }
/** * Instantiates a new windows security context impersonation context impl. * * @param newCtx * the new ctx */ public WindowsSecurityContextImpersonationContextImpl(final CtxtHandle newCtx) { final int rc = Secur32.INSTANCE.ImpersonateSecurityContext(newCtx); if (rc != WinError.SEC_E_OK) { throw new Win32Exception(rc); } this.ctx = newCtx; }
rc = Secur32.INSTANCE.AcceptSecurityContext(serverCredential.getHandle(), continueHandle, pbClientToken, Sspi.ISC_REQ_CONNECTION, Sspi.SECURITY_NATIVE_DREP, phNewServerContext, pbServerToken, pfClientContextAttr, null);
char[] buffer = new char[128]; IntByReference len = new IntByReference(buffer.length); boolean result = Secur32.INSTANCE.GetUserNameEx(format, buffer, len); result = Secur32.INSTANCE.GetUserNameEx(format, buffer, len);
public void dispose() { if (clientCred != null && !clientCred.isNull()) { final int rc = Secur32.INSTANCE.FreeCredentialsHandle(clientCred); if (WinError.SEC_E_OK != rc) { throw new Win32Exception(rc); } } if (sspiContext != null && !sspiContext.isNull()) { final int rc = Secur32.INSTANCE.DeleteSecurityContext(sspiContext); if (WinError.SEC_E_OK != rc) { throw new Win32Exception(rc); } } continueNeeded = true; // waiting clientCred = null; sspiContext = null; }