jcifs.ntlmssp.NtlmMessage Java Examples
The following examples show how to use
jcifs.ntlmssp.NtlmMessage.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: NtlmHttpURLConnection.java From jcifs with GNU Lesser General Public License v2.1 | 4 votes |
private void doHandshake () throws IOException, GeneralSecurityException { connect(); try { int response = parseResponseCode(); if ( response != HTTP_UNAUTHORIZED && response != HTTP_PROXY_AUTH ) { return; } NtlmMessage type1 = attemptNegotiation(response); if ( type1 == null ) return; // no NTLM int attempt = 0; while ( attempt < MAX_REDIRECTS ) { this.connection.setRequestProperty(this.authProperty, this.authMethod + ' ' + Base64.toBase64String(type1.toByteArray())); this.connection.connect(); // send type 1 response = parseResponseCode(); if ( response != HTTP_UNAUTHORIZED && response != HTTP_PROXY_AUTH ) { return; } NtlmMessage type3 = attemptNegotiation(response); if ( type3 == null ) return; this.connection.setRequestProperty(this.authProperty, this.authMethod + ' ' + Base64.toBase64String(type3.toByteArray())); this.connection.connect(); // send type 3 if ( this.cachedOutput != null && this.doOutput ) { @SuppressWarnings ( "resource" ) OutputStream output = this.connection.getOutputStream(); this.cachedOutput.writeTo(output); output.flush(); } response = parseResponseCode(); if ( response != HTTP_UNAUTHORIZED && response != HTTP_PROXY_AUTH ) { return; } attempt++; if ( this.allowUserInteraction && attempt < MAX_REDIRECTS ) { reconnect(); } else { break; } } throw new IOException("Unable to negotiate NTLM authentication."); } finally { this.cachedOutput = null; } }
Example #2
Source File: NtlmHttpURLConnection.java From jcifs-ng with GNU Lesser General Public License v2.1 | 4 votes |
private void doHandshake () throws IOException, GeneralSecurityException { connect(); try { int response = parseResponseCode(); if ( response != HTTP_UNAUTHORIZED && response != HTTP_PROXY_AUTH ) { return; } NtlmMessage type1 = attemptNegotiation(response); if ( type1 == null ) return; // no NTLM int attempt = 0; while ( attempt < MAX_REDIRECTS ) { this.connection.setRequestProperty(this.authProperty, this.authMethod + ' ' + Base64.toBase64String(type1.toByteArray())); this.connection.connect(); // send type 1 response = parseResponseCode(); if ( response != HTTP_UNAUTHORIZED && response != HTTP_PROXY_AUTH ) { return; } NtlmMessage type3 = attemptNegotiation(response); if ( type3 == null ) return; this.connection.setRequestProperty(this.authProperty, this.authMethod + ' ' + Base64.toBase64String(type3.toByteArray())); this.connection.connect(); // send type 3 if ( this.cachedOutput != null && this.doOutput ) { @SuppressWarnings ( "resource" ) OutputStream output = this.connection.getOutputStream(); this.cachedOutput.writeTo(output); output.flush(); } response = parseResponseCode(); if ( response != HTTP_UNAUTHORIZED && response != HTTP_PROXY_AUTH ) { return; } attempt++; if ( this.allowUserInteraction && attempt < MAX_REDIRECTS ) { reconnect(); } else { break; } } throw new IOException("Unable to negotiate NTLM authentication."); } finally { this.cachedOutput = null; } }