public Request authenticateProxy(Proxy paramProxy, Response paramResponse) {
   List localList = paramResponse.challenges();
   paramResponse = paramResponse.request();
   URL localURL = paramResponse.url();
   int i = 0;
   int j = localList.size();
   while (i < j) {
     Object localObject = (Challenge) localList.get(i);
     if ("Basic".equalsIgnoreCase(((Challenge) localObject).getScheme())) {
       InetSocketAddress localInetSocketAddress = (InetSocketAddress) paramProxy.address();
       localObject =
           java.net.Authenticator.requestPasswordAuthentication(
               localInetSocketAddress.getHostName(),
               getConnectToInetAddress(paramProxy, localURL),
               localInetSocketAddress.getPort(),
               localURL.getProtocol(),
               ((Challenge) localObject).getRealm(),
               ((Challenge) localObject).getScheme(),
               localURL,
               Authenticator.RequestorType.PROXY);
       if (localObject != null) {
         paramProxy =
             Credentials.basic(
                 ((PasswordAuthentication) localObject).getUserName(),
                 new String(((PasswordAuthentication) localObject).getPassword()));
         return paramResponse.newBuilder().header("Proxy-Authorization", paramProxy).build();
       }
     }
     i += 1;
   }
   return null;
 }
 /*
  * Enabled aggressive block sorting
  */
 @Override
 public Request authenticateProxy(Proxy object, Response object2) throws IOException {
   List<Challenge> list = object2.challenges();
   object2 = object2.request();
   URL uRL = object2.url();
   int n2 = 0;
   int n3 = list.size();
   while (n2 < n3) {
     InetSocketAddress inetSocketAddress;
     Object object3 = list.get(n2);
     if ("Basic".equalsIgnoreCase(object3.getScheme())
         && (object3 =
                 java.net.Authenticator.requestPasswordAuthentication(
                     (inetSocketAddress = (InetSocketAddress) object.address()).getHostName(),
                     this.getConnectToInetAddress((Proxy) object, uRL),
                     inetSocketAddress.getPort(),
                     uRL.getProtocol(),
                     object3.getRealm(),
                     object3.getScheme(),
                     uRL,
                     Authenticator.RequestorType.PROXY))
             != null) {
       object = Credentials.basic(object3.getUserName(), new String(object3.getPassword()));
       return object2.newBuilder().header("Proxy-Authorization", (String) object).build();
     }
     ++n2;
   }
   return null;
 }
 @Test(groups = {GROUP})
 public void testBadUserAndPassword() throws Throwable {
   try (TestWebSocketClient testClient =
       TestWebSocketClient.builder()
           .url(baseGwUri + "/ui/ws") //
           .authentication(Credentials.basic("baduser", "bad password")) //
           .expectMessage(ExpectedFailure.UNAUTHORIZED) //
           .build()) {
     testClient.validate(10000);
   }
 }
Esempio n. 4
0
  public BaseApi() {

    String strUserName = CustomPreferences.getPreferences(Constants.PREF_USERNAME, "");
    String strPassword = CustomPreferences.getPreferences(Constants.PREF_PASSWORD, "");
    Gson gson = new GsonBuilder().disableHtmlEscaping().create();
    OkHttpClient httpClient = new OkHttpClient();
    final String credential = Credentials.basic(strUserName, strPassword);
    httpClient
        .interceptors()
        .add(
            new Interceptor() {
              @Override
              public com.squareup.okhttp.Response intercept(Interceptor.Chain chain)
                  throws IOException {

                com.squareup.okhttp.Request original = chain.request();
                com.squareup.okhttp.Request request =
                    original
                        .newBuilder()
                        .header("Authorization", credential)
                        .header("Accept", "application/vnd.textus-v2+json")
                        .method(original.method(), original.body())
                        .build();
                LogUtil.e("Url : ", request.httpUrl().toString());
                com.squareup.okhttp.Response response = chain.proceed(request);
                if (request.body() != null) {

                  Buffer buffer = new Buffer();
                  request.body().writeTo(buffer);
                  String body = buffer.readUtf8();
                  LogUtil.e("body : ", body);
                }

                String strBody = response.body().string();
                LogUtil.e("Response", strBody);
                return response
                    .newBuilder()
                    .body(ResponseBody.create(response.body().contentType(), strBody))
                    .build();
              }
            });

    mRetrofit =
        new Retrofit.Builder()
            .baseUrl(Constants.BASE_URL)
            .client(httpClient)
            .addConverterFactory(GsonConverterFactory.create(gson))
            .build();
  }
 @Override
 public void authenticate(Request request) {
   request.getHeaders().put(Headers.AUTHORIZATION, Credentials.basic(username, password));
 }