public void authenticate ( final PacketOutputStream out , final PacketInputStream in , final AtomicInteger sequence , final String servicePrincipalName , final String mechanisms ) throws IOException { // initialize a security context on the client IWindowsSecurityContext clientContext = WindowsSecurityContextImpl . getCurrent ( mechanisms , servicePrincipalName ) ; do { // Step 1: send token to server byte [ ] tokenForTheServerOnTheClient = clientContext . getToken ( ) ; out . startPacket ( sequence . incrementAndGet ( ) ) ; out . write ( tokenForTheServerOnTheClient ) ; out . flush ( ) ; // Step 2: read server response token if ( clientContext . isContinue ( ) ) { Buffer buffer = in . getPacket ( true ) ; sequence . set ( in . getLastPacketSeq ( ) ) ; byte [ ] tokenForTheClientOnTheServer = buffer . readRawBytes ( buffer . remaining ( ) ) ; Sspi . SecBufferDesc continueToken = new Sspi . SecBufferDesc ( Sspi . SECBUFFER_TOKEN , tokenForTheClientOnTheServer ) ; clientContext . initialize ( clientContext . getHandle ( ) , continueToken , servicePrincipalName ) ; } } while ( clientContext . isContinue ( ) ) ; clientContext . dispose ( ) ; }
Process native windows GSS plugin authentication .