1
2
3
4
5
6
7
8
9
10
11
12
13 package com.eviware.soapui.impl.wsdl.submit.filters;
14
15 import java.io.IOException;
16
17 import org.apache.commons.httpclient.Credentials;
18 import org.apache.commons.httpclient.NTCredentials;
19 import org.apache.commons.httpclient.UsernamePasswordCredentials;
20 import org.apache.commons.httpclient.auth.AuthScheme;
21 import org.apache.commons.httpclient.auth.CredentialsNotAvailableException;
22 import org.apache.commons.httpclient.auth.CredentialsProvider;
23 import org.apache.commons.httpclient.auth.NTLMScheme;
24 import org.apache.commons.httpclient.auth.RFC2617Scheme;
25 import org.apache.log4j.Logger;
26
27 import com.eviware.soapui.impl.wsdl.WsdlRequest;
28
29 /***
30 * Provided credentials from equivilant WsdlRequest properties
31 *
32 * @author Ole.Matzura
33 */
34
35 public final class WsdlRequestCredentialsProvider implements CredentialsProvider
36 {
37 private boolean checkedCredentials;
38 private final WsdlRequest wsdlRequest;
39 private final static Logger logger = Logger.getLogger( WsdlRequestCredentialsProvider.class );
40
41 public WsdlRequestCredentialsProvider( WsdlRequest wsdlRequest )
42 {
43 this.wsdlRequest = wsdlRequest;
44 }
45
46 public Credentials getCredentials( final AuthScheme authscheme, final String host, int port, boolean proxy )
47 throws CredentialsNotAvailableException
48 {
49 if( checkedCredentials )
50 throw new CredentialsNotAvailableException( "Missing valid credentials" );
51
52 if( authscheme == null )
53 {
54 return null;
55 }
56 try
57 {
58 String password = wsdlRequest.getPassword();
59 if( password == null )
60 password = "";
61
62 if( authscheme instanceof NTLMScheme )
63 {
64 logger.info( host + ":" + port + " requires Windows authentication" );
65 return new NTCredentials( wsdlRequest.getUsername(), password, host, wsdlRequest.getDomain() );
66 }
67 else if( authscheme instanceof RFC2617Scheme )
68 {
69 logger.info( host + ":" + port + " requires authentication with the realm '" + authscheme.getRealm() + "'" );
70 return new UsernamePasswordCredentials( wsdlRequest.getUsername(), password );
71 }
72 else
73 {
74 throw new CredentialsNotAvailableException( "Unsupported authentication scheme: "
75 + authscheme.getSchemeName() );
76 }
77 }
78 catch( IOException e )
79 {
80 throw new CredentialsNotAvailableException( e.getMessage(), e );
81 }
82 finally
83 {
84 checkedCredentials = true;
85 }
86 }
87 }