Package com.sun.jna.platform.win32

Examples of com.sun.jna.platform.win32.Win32Exception


                dispose(); // Don't keep the context
                continueNeeded = false;
                break;
            default:
                dispose();
                throw new Win32Exception(rc);
        }
        return Base64.encodeBase64String(token.getBytes());
    }
View Full Code Here


        }

        @Override
        String getToken(final CtxtHandle continueCtx, final SecBufferDesc continueToken, final String targetName) {
            dispose();
            throw new Win32Exception(WinError.SEC_E_DOWNGRADE_DETECTED);
        }
View Full Code Here

    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 (sppicontext != null && !sppicontext.isNull()) {
            final int rc = Secur32.INSTANCE.DeleteSecurityContext(sppicontext);
            if (WinError.SEC_E_OK != rc) {
                throw new Win32Exception(rc);
            }
        }
        continueNeeded = true; // waiting
        clientCred = null;
        sppicontext = null;
View Full Code Here

                final int rc = Secur32.INSTANCE.AcquireCredentialsHandle(username,
                        scheme, Sspi.SECPKG_CRED_OUTBOUND, null, null, null, null,
                        clientCred, lifetime);

                if (WinError.SEC_E_OK != rc) {
                    throw new Win32Exception(rc);
                }

                final String targetName = getServicePrincipalName(context);
                response = getToken(null, null, targetName);
            } catch (RuntimeException ex) {
View Full Code Here

                dispose(); // Don't keep the context
                continueNeeded = false;
                break;
            default:
                dispose();
                throw new Win32Exception(rc);
        }
        return Base64.encodeBase64String(token.getBytes());
    }
View Full Code Here

    if (lpType.getValue() == WinNT.REG_NONE)
      return null;

    if (rc != W32Errors.ERROR_SUCCESS
        && rc != W32Errors.ERROR_INSUFFICIENT_BUFFER) {
      throw new Win32Exception(rc);
    }

    Memory byteData = new Memory(lpcbData.getValue());
    byteData.write(0, lpData, 0, lpcbData.getValue());
View Full Code Here

    public IWindowsSecurityContext acceptSecurityToken(final String connectionId, final byte[] token,
            final String securityPackage) {

        if (token == null || token.length == 0) {
            this.continueContexts.asMap().remove(connectionId);
            throw new Win32Exception(WinError.SEC_E_INVALID_TOKEN);
        }

        final IWindowsCredentialsHandle serverCredential = new WindowsCredentialsHandleImpl(null,
                Sspi.SECPKG_CRED_INBOUND, securityPackage);
        serverCredential.initialize();

        WindowsSecurityContextImpl sc;

        int rc;
        int tokenSize = Sspi.MAX_TOKEN_SIZE;

        CtxtHandle continueContext;
        SecBufferDesc pbServerToken;
        SecBufferDesc pbClientToken;
        final IntByReference pfClientContextAttr = new IntByReference();
        final CtxtHandle phNewServerContext = new CtxtHandle();
        do {
            pbServerToken = new SecBufferDesc(Sspi.SECBUFFER_TOKEN, tokenSize);
            pbClientToken = new SecBufferDesc(Sspi.SECBUFFER_TOKEN, token);

            continueContext = this.continueContexts.asMap().get(connectionId);

            rc = Secur32.INSTANCE.AcceptSecurityContext(serverCredential.getHandle(), continueContext, pbClientToken,
                    Sspi.ISC_REQ_CONNECTION, Sspi.SECURITY_NATIVE_DREP, phNewServerContext, pbServerToken,
                    pfClientContextAttr, null);

            sc = new WindowsSecurityContextImpl();
            sc.setCredentialsHandle(serverCredential.getHandle());
            sc.setSecurityPackage(securityPackage);
            sc.setSecurityContext(phNewServerContext);

            switch (rc) {
                case WinError.SEC_E_BUFFER_TOO_SMALL:
                    tokenSize += Sspi.MAX_TOKEN_SIZE;
                    sc.dispose();
                    WindowsSecurityContextImpl.dispose(continueContext);
                    break;
                case WinError.SEC_E_OK:
                    // the security context received from the client was accepted
                    this.continueContexts.asMap().remove(connectionId);
                    // if an output token was generated by the function, it must be sent to the client process
                    if (pbServerToken.pBuffers != null && pbServerToken.cBuffers == 1
                            && pbServerToken.pBuffers[0].cbBuffer > 0) {
                        sc.setToken(pbServerToken.getBytes() == null ? new byte[0] : pbServerToken.getBytes().clone());
                    }
                    sc.setContinue(false);
                    break;
                case WinError.SEC_I_CONTINUE_NEEDED:
                    // the server must send the output token to the client and wait for a returned token
                    this.continueContexts.put(connectionId, phNewServerContext);
                    sc.setToken(pbServerToken.getBytes() == null ? new byte[0] : pbServerToken.getBytes().clone());
                    sc.setContinue(true);
                    break;
                default:
                    sc.dispose();
                    WindowsSecurityContextImpl.dispose(continueContext);
                    this.continueContexts.asMap().remove(connectionId);
                    throw new Win32Exception(rc);
            }
        } while (rc == WinError.SEC_E_BUFFER_TOO_SMALL);

        return sc;
    }
View Full Code Here

    @Override
    public IWindowsIdentity logonDomainUserEx(final String username, final String domain, final String password,
            final int logonType, final int logonProvider) {
        final HANDLEByReference phUser = new HANDLEByReference();
        if (!Advapi32.INSTANCE.LogonUser(username, domain, password, logonType, logonProvider, phUser)) {
            throw new Win32Exception(Kernel32.INSTANCE.GetLastError());
        }
        return new WindowsIdentityImpl(phUser.getValue());
    }
View Full Code Here

     * @param windowsIdentity
     *            Windows identity obtained via LogonUser.
     */
    public WindowsIdentityImpersonationContextImpl(final HANDLE windowsIdentity) {
        if (!Advapi32.INSTANCE.ImpersonateLoggedOnUser(windowsIdentity)) {
            throw new Win32Exception(Kernel32.INSTANCE.GetLastError());
        }
    }
View Full Code Here

    private CtxtHandle 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;
    }
View Full Code Here

TOP

Related Classes of com.sun.jna.platform.win32.Win32Exception

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.