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; }
/** * Invokes {@link #closeHandle(WinNT.HANDLE)} on each handle. If an exception * is thrown for a specific handle, then it is accumulated until all * handles have been closed. If more than one exception occurs, then it * is added as a suppressed exception to the first one. Once closed all * handles, the accumulated exception (if any) is thrown * * @param handles The handles to be closed * @see Throwable#getSuppressed() */ public static void closeHandles(HANDLE... handles) { Win32Exception err = null; for (HANDLE h : handles) { try { closeHandle(h); } catch(Win32Exception e) { if (err == null) { err = e; } else { err.addSuppressedReflected(e); } } } if (err != null) { throw err; } }
public String resolveFolder(FolderId folderId) { try { logger.debug("Invoking SHGetKnownFolderPath"); return Shell32Util.getKnownFolderPath(convertFolderIdToGuid(folderId)); } catch (Win32Exception e) { logger.error("SHGetKnownFolderPath returns an error: {}", e.getErrorCode()); throw new AppDirsException( "SHGetKnownFolderPath returns an error: " + e.getErrorCode()); } catch (UnsatisfiedLinkError e) { // Fallback for pre-vista OSes. #5 try { logger.debug("SHGetKnownFolderPath failed. Trying SHGetFolderPath."); int folder = convertFolderIdToCsidl(folderId); return Shell32Util.getFolderPath(folder); } catch (Win32Exception e2) { logger.error("SHGetFolderPath returns an error: {}", e2); throw new AppDirsException( "SHGetFolderPath returns an error: " + e2.getErrorCode()); } } }
securityContext = this.auth.acceptSecurityToken(connectionId, tokenBuffer, securityPackage); } catch (final Win32Exception e) { this.log.warn("error logging in user: {}", e.getMessage()); this.log.trace("", e); this.sendUnauthorized(response);
HANDLE snapshot = Kernel32.INSTANCE.CreateToolhelp32Snapshot(Tlhelp32.TH32CS_SNAPMODULE, new DWORD(processID)); if (snapshot == null) { throw new Win32Exception(Kernel32.INSTANCE.GetLastError()); throw new Win32Exception(Kernel32.INSTANCE.GetLastError()); throw new Win32Exception(lastError); we = e; } else { we.addSuppressedReflected(e);
securityContext = this.auth.acceptSecurityToken(connectionId, tokenBuffer, securityPackage); } catch (final Win32Exception e) { this.log.warn("error logging in user: {}", e.getMessage()); this.log.trace("", e); this.sendUnauthorized(response);
throw new Win32Exception(Kernel32.INSTANCE.GetLastError()); try { if (!Kernel32.INSTANCE.EnumResourceTypes(target, ertp, null)) { throw new Win32Exception(Kernel32.INSTANCE.GetLastError()); throw new Win32Exception(Kernel32.INSTANCE.GetLastError()); Win32Exception we = new Win32Exception(Kernel32.INSTANCE.GetLastError()); if (err != null) { we.addSuppressedReflected(err);
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()); }
securityContext = this.auth.acceptSecurityToken(connectionId, tokenBuffer, securityPackage); } catch (final Win32Exception e) { this.log.warn("error logging in user: {}", e.getMessage()); this.log.trace("", e); this.sendUnauthorized(response);
throw new Win32Exception(Kernel32.INSTANCE.GetLastError()); break; default: throw new Win32Exception(rc); err = e; } else { err.addSuppressedReflected(e);
/** * Closes all referenced handles. If an exception is thrown for * a specific handle, then it is accumulated until all * handles have been closed. If more than one exception occurs, * then it is added as a suppressed exception to the first one. * Once closed all handles, the accumulated exception (if any) is thrown * * @param refs The references to close * @see #closeHandleRef(WinNT.HANDLEByReference) */ public static void closeHandleRefs(HANDLEByReference... refs) { Win32Exception err = null; for (HANDLEByReference r : refs) { try { closeHandleRef(r); } catch(Win32Exception e) { if (err == null) { err = e; } else { err.addSuppressedReflected(e); } } } if (err != null) { throw err; } } /**
throw new Win32Exception(rc);
securityContext = this.auth.acceptSecurityToken(connectionId, tokenBuffer, securityPackage); } catch (final Win32Exception e) { this.log.warn("error logging in user: {}", e.getMessage()); this.log.trace("", e); this.sendUnauthorized(response);
RECT rect = new RECT(); if (!User32.INSTANCE.GetWindowRect(target, rect)) { throw new Win32Exception(Native.getLastError()); throw new Win32Exception(Native.getLastError()); hdcTargetMem = GDI32.INSTANCE.CreateCompatibleDC(hdcTarget); if (hdcTargetMem == null) { throw new Win32Exception(Native.getLastError()); throw new Win32Exception(Native.getLastError()); throw new Win32Exception(Native.getLastError()); throw new Win32Exception(Native.getLastError()); WinGDI.DIB_RGB_COLORS); if (resultOfDrawing == 0 || resultOfDrawing == WinError.ERROR_INVALID_PARAMETER) { throw new Win32Exception(Native.getLastError()); Win32Exception ex = new Win32Exception(Native.getLastError()); if (we != null) { ex.addSuppressedReflected(we); Win32Exception ex = new Win32Exception(Native.getLastError()); if (we != null) { ex.addSuppressedReflected(we); Win32Exception ex = new Win32Exception(Native.getLastError());
@Override public void revertToSelf() { final int rc = Secur32.INSTANCE.RevertSecurityContext(this.ctx); if (rc != WinError.SEC_E_OK) { throw new Win32Exception(rc); } } }
securityContext = this.auth.acceptSecurityToken(connectionId, tokenBuffer, securityPackage); } catch (final Win32Exception e) { this.log.warn("error logging in user: {}", e.getMessage()); this.log.trace("", e); this.sendUnauthorized(response);
throw new Win32Exception(Kernel32.INSTANCE.GetLastError()); throw new Win32Exception(Kernel32.INSTANCE.GetLastError()); throw new Win32Exception(Kernel32.INSTANCE.GetLastError()); throw new Win32Exception(Kernel32.INSTANCE.GetLastError()); Win32Exception we = new Win32Exception(Kernel32.INSTANCE.GetLastError()); if (err != null) { we.addSuppressedReflected(err);
/** * Close the registry key * * @param hKey * Registry key. */ public static void registryCloseKey(HKEY hKey) { int rc = Advapi32.INSTANCE.RegCloseKey(hKey); if (rc != W32Errors.ERROR_SUCCESS) { throw new Win32Exception(rc); } }
securityContext = this.auth.acceptSecurityToken(connectionId, tokenBuffer, securityPackage); } catch (final Win32Exception e) { this.log.warn("error logging in user: {}", e.getMessage()); this.log.trace("", e); this.sendUnauthorized(response);
return cacheItems; } else if (lastError != WinError.ERROR_SUCCESS && lastError != WinError.ERROR_INSUFFICIENT_BUFFER) { throw new Win32Exception(lastError); throw new Win32Exception(Native.getLastError()); break; } else if (lastError != WinError.ERROR_SUCCESS && lastError != WinError.ERROR_INSUFFICIENT_BUFFER) { throw new Win32Exception(lastError); break; } else if (lastError != WinError.ERROR_SUCCESS && lastError != WinError.ERROR_INSUFFICIENT_BUFFER) { throw new Win32Exception(lastError); if (!Wininet.INSTANCE.FindCloseUrlCache(cacheHandle)) { if (we != null) { Win32Exception e = new Win32Exception(Native.getLastError()); e.addSuppressedReflected(we); we = e;