List of usage examples for org.apache.commons.httpclient NTCredentials getDomain
public String getDomain()
From source file:com.gargoylesoftware.htmlunit.DefaultCredentialsProviderTest.java
/** * Test for NTLM credentials./*from w w w . java 2 s . c om*/ * @throws Exception if the test fails */ @Test public void addNTLMCredentials() throws Exception { final String username = "foo"; final String domain = "myDomain"; final String password = "password"; final String host = "my.host"; final String clientHost = "client.host"; final int port = 1234; final DefaultCredentialsProvider provider = new DefaultCredentialsProvider(); provider.addNTLMCredentials(username, password, host, port, clientHost, domain); final NTLMScheme scheme = new NTLMScheme("NTLM"); final Credentials credentials = provider.getCredentials(scheme, host, port, false); assertNotNull(credentials); assertTrue(NTCredentials.class.isInstance(credentials)); final NTCredentials ntCredentials = (NTCredentials) credentials; assertEquals(username, ntCredentials.getUserName()); assertEquals(password, ntCredentials.getPassword()); assertEquals(clientHost, ntCredentials.getHost()); assertEquals(domain, ntCredentials.getDomain()); }
From source file:it.greenvulcano.gvesb.http.auth.impl.NTLMHttpAuth.java
@SuppressWarnings({ "rawtypes", "unchecked" }) @Override//w w w . j a v a 2s .c om public void setAuthentication(Options options, String host, GVBuffer gvBuffer, Map<String, Object> props) throws HttpAuthException { try { if (props == null) { props = GVBufferPropertiesHelper.getPropertiesMapSO(gvBuffer, true); } String currUser = PropertiesHandler.expand(userName, props, gvBuffer); String currPassword = XMLConfig.getDecrypted(PropertiesHandler.expand(password, props, gvBuffer)); String currDomain = PropertiesHandler.expand(domain, props, gvBuffer); List ntlmPref = new ArrayList(); ntlmPref.add(HttpTransportProperties.Authenticator.NTLM); NTCredentials creds = new NTCredentials(currUser, currPassword, host, currDomain); Authenticator ntlmAuth = new HttpTransportProperties.Authenticator(); ntlmAuth.setUsername(creds.getUserName()); ntlmAuth.setPassword(creds.getPassword()); ntlmAuth.setDomain(creds.getDomain()); ntlmAuth.setHost(creds.getHost()); ntlmAuth.setAuthSchemes(ntlmPref); ntlmAuth.setPreemptiveAuthentication(true); options.setProperty(HTTPConstants.AUTHENTICATE, ntlmAuth); } catch (Exception exc) { throw new HttpAuthException("Error using NTLM authenticator", exc); } }
From source file:it.greenvulcano.gvesb.http.ntlm.JCIFS_NTLMScheme.java
@Override public String authenticate(Credentials credentials, HttpMethod method) throws AuthenticationException { if (this.state == UNINITIATED) { throw new IllegalStateException("NTLM authentication process has not been initiated"); }/*from ww w . j a va 2s . c o m*/ NTCredentials ntcredentials = null; try { ntcredentials = (NTCredentials) credentials; } catch (ClassCastException e) { throw new InvalidCredentialsException( "Credentials cannot be used for NTLM authentication: " + credentials.getClass().getName()); } NTLM ntlm = new NTLM(); ntlm.setCredentialCharset(method.getParams().getCredentialCharset()); String response = null; if ((this.state == INITIATED) || (this.state == FAILED)) { response = ntlm.generateType1Msg(ntcredentials.getHost(), ntcredentials.getDomain()); this.state = TYPE1_MSG_GENERATED; } else { response = ntlm.generateType3Msg(ntcredentials.getUserName(), ntcredentials.getPassword(), ntcredentials.getHost(), ntcredentials.getDomain(), this.ntlmchallenge); this.state = TYPE3_MSG_GENERATED; } return "NTLM " + response; }
From source file:com.mobilehelix.appserver.auth.JCIFS_NTLMScheme.java
@Override public String authenticate(Credentials credentials, HttpMethod method) throws AuthenticationException { LOG.log(Level.FINEST, "Enter JCIFS_NTLMScheme.authenticate(Credentials, HttpMethod)"); if (this.state == UNINITIATED) { throw new IllegalStateException("NTLM authentication process has not been initiated"); }/*from ww w .java 2 s. c o m*/ NTCredentials ntcredentials = null; try { ntcredentials = (NTCredentials) credentials; } catch (ClassCastException e) { throw new InvalidCredentialsException( "Credentials cannot be used for NTLM authentication: " + credentials.getClass().getName()); } NTLM ntlm = new NTLM(); ntlm.setCredentialCharset(method.getParams().getCredentialCharset()); String response = null; if (this.state == INITIATED || this.state == FAILED) { response = ntlm.generateType1Msg(ntcredentials.getHost(), ntcredentials.getDomain()); this.state = TYPE1_MSG_GENERATED; } else { response = ntlm.generateType3Msg(ntcredentials.getUserName(), ntcredentials.getPassword(), ntcredentials.getHost(), ntcredentials.getDomain(), this.ntlmchallenge); this.state = TYPE3_MSG_GENERATED; } return "NTLM " + response; }
From source file:davmail.http.NTLMv2Scheme.java
/** * Produces NTLM authorization string for the given set of * {@link Credentials}./*from ww w . j a v a 2 s.c om*/ * * @param credentials The set of credentials to be used for authentication * @param httpMethod The method being authenticated * @return an NTLM authorization string * @throws InvalidCredentialsException if authentication credentials * are not valid or not applicable for this authentication scheme * @throws AuthenticationException if authorization string cannot * be generated due to an authentication failure */ public String authenticate(Credentials credentials, HttpMethod httpMethod) throws AuthenticationException { if (this.state == UNINITIATED) { throw new IllegalStateException("NTLM authentication process has not been initiated"); } NTCredentials ntcredentials; try { ntcredentials = (NTCredentials) credentials; } catch (ClassCastException e) { throw new InvalidCredentialsException( "Credentials cannot be used for NTLM authentication: " + credentials.getClass().getName()); } String response; if (this.state == INITIATED || this.state == FAILED) { int flags = NtlmFlags.NTLMSSP_NEGOTIATE_NTLM2 | NtlmFlags.NTLMSSP_NEGOTIATE_ALWAYS_SIGN | NtlmFlags.NTLMSSP_NEGOTIATE_OEM_WORKSTATION_SUPPLIED | NtlmFlags.NTLMSSP_NEGOTIATE_OEM_DOMAIN_SUPPLIED | NtlmFlags.NTLMSSP_NEGOTIATE_NTLM | NtlmFlags.NTLMSSP_REQUEST_TARGET | NtlmFlags.NTLMSSP_NEGOTIATE_OEM | NtlmFlags.NTLMSSP_NEGOTIATE_UNICODE | NtlmFlags.NTLMSSP_NEGOTIATE_56 | NtlmFlags.NTLMSSP_NEGOTIATE_128; Type1Message type1Message = new Type1Message(flags, ntcredentials.getDomain(), ntcredentials.getHost()); response = EncodingUtil.getAsciiString(Base64.encodeBase64(type1Message.toByteArray())); this.state = TYPE1_MSG_GENERATED; } else { int flags = NtlmFlags.NTLMSSP_NEGOTIATE_NTLM2 | NtlmFlags.NTLMSSP_NEGOTIATE_ALWAYS_SIGN | NtlmFlags.NTLMSSP_NEGOTIATE_NTLM | NtlmFlags.NTLMSSP_NEGOTIATE_UNICODE; Type3Message type3Message = new Type3Message(type2Message, ntcredentials.getPassword(), ntcredentials.getDomain(), ntcredentials.getUserName(), ntcredentials.getHost(), flags); response = EncodingUtil.getAsciiString(Base64.encodeBase64(type3Message.toByteArray())); this.state = TYPE3_MSG_GENERATED; } return "NTLM " + response; }
From source file:org.apache.maven.wagon.providers.webdav.AbstractHttpClientWagonTest.java
public void testNTCredentialsWithNTDomain() throws AuthenticationException, ConnectionException { TestWagon wagon = new TestWagon(); AuthenticationInfo authenticationInfo = new AuthenticationInfo(); String myNTDomain = "myNTDomain"; String myUsername = "myUsername"; String myNTDomainAndUser = myNTDomain + "\\" + myUsername; authenticationInfo.setUserName(myNTDomainAndUser); String myPassword = "myPassword"; authenticationInfo.setPassword(myPassword); Repository repository = new Repository("mockRepoId", "mockRepoURL"); wagon.connect(repository, authenticationInfo, (ProxyInfo) null); wagon.openConnection();/* w ww.jav a 2s . com*/ assertEquals(myNTDomainAndUser, wagon.getAuthenticationInfo().getUserName()); assertEquals(myPassword, wagon.getAuthenticationInfo().getPassword()); Credentials credentials = wagon.getClient().getState().getCredentials(new AuthScope(null, 0)); assertTrue(credentials instanceof NTCredentials); NTCredentials ntCredentials = (NTCredentials) credentials; assertEquals(myNTDomain, ntCredentials.getDomain()); assertEquals(myUsername, ntCredentials.getUserName()); assertEquals(myPassword, ntCredentials.getPassword()); }
From source file:org.jetbrains.tfsIntegration.webservice.auth.NTLM2Scheme.java
protected String getType1MessageResponse(NTCredentials ntcredentials, HttpMethodParams params) { // we cannot put local computer name into credentials, as HttpMethodDirector.authenticateHost() expects it to be server's name Type1Message t1m = new Type1Message(MESSAGE_1_DEFAULT_FLAGS, ntcredentials.getDomain(), Workstation.getComputerName()); return Base64.encode(t1m.toByteArray()); }
From source file:org.jetbrains.tfsIntegration.webservice.auth.NTLM2Scheme.java
protected String getType3MessageResponse(String type2message, NTCredentials ntcredentials, HttpMethodParams params) throws AuthenticationException { Type2Message t2m;/*from ww w .j a va 2s . c om*/ try { t2m = new Type2Message(Base64.decode(type2message)); } catch (IOException ex) { throw new AuthenticationException("Invalid Type2 message", ex); } Type3Message t3m = new Type3Message(t2m, ntcredentials.getPassword(), ntcredentials.getDomain(), ntcredentials.getUserName(), Workstation.getComputerName(), MESSAGE_3_DEFAULT_FLAGS); return Base64.encode(t3m.toByteArray()); }
From source file:org.wso2.carbon.mediator.ntlm.CustomNTLMAuthScheme.java
/** * Produces NTLM authorization string for the given set of * {@link Credentials}./*from ww w. j a v a2s . c o m*/ * * @param credentials * The set of credentials to be used for athentication * @param method * The method being authenticated * * @throws InvalidCredentialsException * if authentication credentials are not valid or not applicable * for this authentication scheme * @throws AuthenticationException * if authorization string cannot be generated due to an * authentication failure * * @return an NTLM authorization string * * @since 3.0 */ public String authenticate(Credentials credentials, HttpMethod method) throws AuthenticationException { LOG.trace("enter NTLMScheme.authenticate (Credentials, HttpMethod)"); if (this.state == UNINITIATED) { throw new IllegalStateException("NTLM authentication process has not been initiated"); } NTCredentials ntcredentials = null; try { ntcredentials = (NTCredentials) credentials; } catch (ClassCastException e) { throw new InvalidCredentialsException( "Credentials cannot be used for NTLM authentication: " + credentials.getClass().getName()); } byte[] msgBytes = null; String response = null; if (this.state == INITIATED) { Type1Message msg = new Type1Message(); // @see http://davenport.sourceforge.net/ntlm.html#theType1Message // dont' support Unicode // negotiate OEM // request authentication realm in Type2 response // not signed // not encrypted // not authenticated // no lan manager key // negotiate NTLM msg.setFlags(0x5206); msg.setSuppliedWorkstation(ntcredentials.getHost()); msg.setSuppliedDomain(ntcredentials.getDomain()); msgBytes = msg.toByteArray(); this.state = TYPE1_MSG_GENERATED; } else if (this.state == TYPE2_MSG_RECEIVED) { byte[] msg2Bytes = Base64.decodeBase64( EncodingUtil.getBytes(this.ntlmChallenge, method.getParams().getCredentialCharset())); try { Type2Message msg2 = new Type2Message(msg2Bytes); int flags = Type3Message.NTLMSSP_NEGOTIATE_OEM | Type3Message.NTLMSSP_NEGOTIATE_LM_KEY; Type3Message msg3 = new Type3Message(msg2, ntcredentials.getPassword(), ntcredentials.getDomain(), ntcredentials.getUserName(), ntcredentials.getHost(), flags); msgBytes = msg3.toByteArray(); } catch (IOException ex) { throw new AuthenticationException("unable to parse Type2Message", ex); } this.state = TYPE3_MSG_GENERATED; } else { throw new RuntimeException("failed to authenticate"); } response = EncodingUtil.getAsciiString(Base64.encodeBase64(msgBytes)); return "NTLM " + response; }
From source file:org.zaproxy.zap.network.ZapNTLMScheme.java
@Override public String authenticate(Credentials credentials, HttpMethod method) throws AuthenticationException { NTCredentials ntcredentials = null; try {//from w ww. j a va2 s . c o m ntcredentials = (NTCredentials) credentials; } catch (final ClassCastException e) { throw new AuthenticationException( "Credentials cannot be used for NTLM authentication: " + credentials.getClass().getName()); } String response = null; if (this.state == State.FAILED) { throw new AuthenticationException("NTLM authentication failed"); } else if (this.state == State.CHALLENGE_RECEIVED) { response = this.engine.generateType1Msg(ntcredentials.getDomain(), ntcredentials.getHost()); this.state = State.MSG_TYPE1_GENERATED; } else if (this.state == State.MSG_TYPE2_RECEVIED) { response = this.engine.generateType3Msg(ntcredentials.getUserName(), ntcredentials.getPassword(), ntcredentials.getDomain(), ntcredentials.getHost(), this.challenge); this.state = State.MSG_TYPE3_GENERATED; } else { throw new AuthenticationException("Unexpected state: " + this.state); } return "NTLM " + response; }