Search in sources :

Example 41 with HttpCookie

use of java.net.HttpCookie in project hadoop by apache.

the class TestHttpCookieFlag method testHttpCookie.

@Test
public void testHttpCookie() throws IOException {
    URL base = new URL("http://" + NetUtils.getHostPortString(server.getConnectorAddress(0)));
    HttpURLConnection conn = (HttpURLConnection) new URL(base, "/echo").openConnection();
    String header = conn.getHeaderField("Set-Cookie");
    List<HttpCookie> cookies = HttpCookie.parse(header);
    Assert.assertTrue(!cookies.isEmpty());
    Assert.assertTrue(header.contains("; HttpOnly"));
    Assert.assertTrue("token".equals(cookies.get(0).getValue()));
}
Also used : HttpURLConnection(java.net.HttpURLConnection) HttpCookie(java.net.HttpCookie) URL(java.net.URL) Test(org.junit.Test)

Example 42 with HttpCookie

use of java.net.HttpCookie in project Hystrix by Netflix.

the class HystrixCommandDemo method executeSimulatedUserRequestForOrderConfirmationAndCreditCardPayment.

public void executeSimulatedUserRequestForOrderConfirmationAndCreditCardPayment() throws InterruptedException, ExecutionException {
    /* fetch user object with http cookies */
    UserAccount user = new GetUserAccountCommand(new HttpCookie("mockKey", "mockValueFromHttpRequest")).execute();
    /* fetch the payment information (asynchronously) for the user so the credit card payment can proceed */
    Future<PaymentInformation> paymentInformation = new GetPaymentInformationCommand(user).queue();
    /* fetch the order we're processing for the user */
    int orderIdFromRequestArgument = 13579;
    Order previouslySavedOrder = new GetOrderCommand(orderIdFromRequestArgument).execute();
    CreditCardCommand credit = new CreditCardCommand(previouslySavedOrder, paymentInformation.get(), new BigDecimal(123.45));
    credit.execute();
}
Also used : HttpCookie(java.net.HttpCookie) BigDecimal(java.math.BigDecimal)

Example 43 with HttpCookie

use of java.net.HttpCookie in project LuaViewSDK by alibaba.

the class CookieManager method updateNetResponseCookies.

/**
     * write net cookies
     *
     * @param cookiesHeader
     */
private static void updateNetResponseCookies(List<String> cookiesHeader) {
    //write net cookie
    final CookieStore cookieStore = getCookieManager().getCookieStore();
    if (cookieStore != null && cookiesHeader != null) {
        HttpCookie cookieStr = null;
        for (String cookieHeader : cookiesHeader) {
            if (cookieHeader != null) {
                List<HttpCookie> cookies = HttpCookie.parse(cookieHeader);
                if (cookies != null && cookies.size() > 0) {
                    cookieStr = cookies.get(0);
                    LogUtil.d(TAG, "write-net", cookieStr);
                    cookieStore.add(null, cookieStr);
                }
            }
        }
    }
}
Also used : CookieStore(java.net.CookieStore) HttpCookie(java.net.HttpCookie)

Example 44 with HttpCookie

use of java.net.HttpCookie in project remusic by aa112901.

the class PersistentCookieStore method decodeCookie.

/**
     * Returns cookie decoded from cookie string
     *
     * @param cookieString string of cookie as returned from http request
     * @return decoded cookie or null if exception occured
     */
protected HttpCookie decodeCookie(String cookieString) {
    byte[] bytes = hexStringToByteArray(cookieString);
    ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(bytes);
    HttpCookie cookie = null;
    try {
        ObjectInputStream objectInputStream = new ObjectInputStream(byteArrayInputStream);
        cookie = ((SerializableHttpCookie) objectInputStream.readObject()).getCookie();
    } catch (IOException e) {
        Log.d(LOG_TAG, "IOException in decodeCookie", e);
    } catch (ClassNotFoundException e) {
        Log.d(LOG_TAG, "ClassNotFoundException in decodeCookie", e);
    }
    return cookie;
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) IOException(java.io.IOException) HttpCookie(java.net.HttpCookie) ObjectInputStream(java.io.ObjectInputStream)

Example 45 with HttpCookie

use of java.net.HttpCookie in project android by cSploit.

the class HijackerWebView method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    SharedPreferences themePrefs = getSharedPreferences("THEME", 0);
    Boolean isDark = themePrefs.getBoolean("isDark", false);
    if (isDark)
        setTheme(R.style.DarkTheme);
    else
        setTheme(R.style.AppTheme);
    super.onCreate(savedInstanceState);
    supportRequestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
    supportRequestWindowFeature(Window.FEATURE_PROGRESS);
    setTitle(System.getCurrentTarget() + " > MITM > Session Hijacker");
    setContentView(R.layout.plugin_mitm_hijacker_webview);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    mWebView = (WebView) findViewById(R.id.webView);
    mWebView.setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY);
    mProgressBar = (ProgressBar) findViewById(R.id.webprogress);
    mURLet = (EditText) findViewById(R.id.url);
    mProgressBar.setVisibility(View.GONE);
    mProgressBar.setMax(100);
    mSettings = mWebView.getSettings();
    mSettings.setJavaScriptEnabled(true);
    mSettings.setJavaScriptCanOpenWindowsAutomatically(true);
    mSettings.setBuiltInZoomControls(true);
    mSettings.setAppCacheEnabled(false);
    mSettings.setUserAgentString(DEFAULT_USER_AGENT);
    mSettings.setUseWideViewPort(true);
    mURLet.setOnEditorActionListener(new EditText.OnEditorActionListener() {

        @Override
        public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
            if (actionId == EditorInfo.IME_ACTION_DONE || actionId == EditorInfo.IME_ACTION_NEXT) {
                mWebView.loadUrl(mURLet.getText().toString());
                InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
                imm.hideSoftInputFromWindow(mWebView.getWindowToken(), 0);
                mWebView.requestFocus();
                return true;
            }
            return false;
        }
    });
    mURLet.setOnKeyListener(new EditText.OnKeyListener() {

        @Override
        public boolean onKey(View v, int keyCode, KeyEvent event) {
            if (event.getAction() == KeyEvent.ACTION_DOWN && event.getKeyCode() == KeyEvent.KEYCODE_ENTER) {
                mWebView.loadUrl(mURLet.getText().toString());
                InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
                imm.hideSoftInputFromWindow(mWebView.getWindowToken(), 0);
                mWebView.requestFocus();
                return true;
            }
            return false;
        }
    });
    mWebView.setWebViewClient(new WebViewClient() {

        @Override
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            view.loadUrl(url);
            mURLet.setText(url);
            return true;
        }
    });
    mWebView.setWebChromeClient(new WebChromeClient() {

        public void onProgressChanged(WebView view, int progress) {
            if ((mWebView != null) && (mURLet != null) && (progress == 0))
                ;
            {
                getSupportActionBar().setSubtitle(mWebView.getUrl());
                mURLet.setText(mWebView.getUrl());
            }
            if (mProgressBar != null) {
                mProgressBar.setVisibility(View.VISIBLE);
                // Normalize our progress along the progress bar's scale
                mProgressBar.setProgress(progress);
                if (progress == 100) {
                    mProgressBar.setVisibility(View.GONE);
                }
            }
        }
    });
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        CookieManager cm = CookieManager.getInstance();
        cm.flush();
    } else {
        CookieSyncManager.createInstance(this);
        CookieManager.getInstance().removeAllCookie();
    }
    Session session = (Session) System.getCustomData();
    if (session != null) {
        String domain = null, rawcookie = null;
        for (HttpCookie cookie : session.mCookies.values()) {
            domain = cookie.getDomain();
            rawcookie = cookie.getName() + "=" + cookie.getValue() + "; domain=" + domain + "; path=/" + (session.mHTTPS ? ";secure" : "");
            CookieManager.getInstance().setCookie(domain, rawcookie);
        }
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            CookieManager cm = CookieManager.getInstance();
            cm.flush();
        } else {
            CookieSyncManager.getInstance().startSync();
        }
        if (session.mUserAgent != null && session.mUserAgent.isEmpty() == false)
            mSettings.setUserAgentString(session.mUserAgent);
        String url = (session.mHTTPS ? "https" : "http") + "://";
        if (domain != null && !Patterns.IP_ADDRESS.matcher(domain).matches())
            url += "www.";
        url += domain;
        mWebView.loadUrl(url);
        mWebView.requestFocus();
    }
}
Also used : EditText(android.widget.EditText) SharedPreferences(android.content.SharedPreferences) InputMethodManager(android.view.inputmethod.InputMethodManager) View(android.view.View) WebView(android.webkit.WebView) TextView(android.widget.TextView) KeyEvent(android.view.KeyEvent) WebChromeClient(android.webkit.WebChromeClient) TextView(android.widget.TextView) WebView(android.webkit.WebView) HttpCookie(java.net.HttpCookie) CookieManager(android.webkit.CookieManager) WebViewClient(android.webkit.WebViewClient)

Aggregations

HttpCookie (java.net.HttpCookie)151 CookieManager (java.net.CookieManager)49 CookieStore (java.net.CookieStore)33 URI (java.net.URI)32 Test (org.junit.Test)31 IOException (java.io.IOException)16 Test (org.testng.annotations.Test)13 MockResponse (com.google.mockwebserver.MockResponse)11 MockWebServer (com.google.mockwebserver.MockWebServer)11 ArrayList (java.util.ArrayList)11 HashMap (java.util.HashMap)6 Map (java.util.Map)6 Project (com.kickstarter.models.Project)5 RestResponse (com.linkedin.r2.message.rest.RestResponse)5 Cookie (javax.servlet.http.Cookie)5 HttpServletResponse (javax.servlet.http.HttpServletResponse)5 MockResponse (okhttp3.mockwebserver.MockResponse)5 MockWebServer (okhttp3.mockwebserver.MockWebServer)5 ContentResponse (org.eclipse.jetty.client.api.ContentResponse)5 ByteString (com.linkedin.data.ByteString)4