oauth.signpost.http.HttpRequest Java Examples

The following examples show how to use oauth.signpost.http.HttpRequest. 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: RsaSha1MessageSigner.java    From jira-steps-plugin with Apache License 2.0 6 votes vote down vote up
@Override
public String sign(HttpRequest request, HttpParameters requestParams)
    throws OAuthMessageSignerException {

  final OAuthRsaSigner signer = new OAuthRsaSigner();
  final byte[] privateBytes = Base64.decodeBase64(getConsumerSecret());
  final PKCS8EncodedKeySpec keySpec = new PKCS8EncodedKeySpec(privateBytes);

  try {
    signer.privateKey = KeyFactory.getInstance("RSA").generatePrivate(keySpec);
    final String signatureBaseString = new SignatureBaseString(request, requestParams).generate();
    return signer.computeSignature(signatureBaseString);
  } catch (GeneralSecurityException e) {
    throw new OAuthMessageSignerException(e);
  }
}
 
Example #2
Source File: BurpExtender.java    From burp-oauth with MIT License 6 votes vote down vote up
@Override
public void processHttpMessage(int toolFlag, boolean messageIsRequest, IHttpRequestResponse messageInfo)
{
	if (messageIsRequest && shouldSign(messageInfo))
	{
		HttpRequest req = new BurpHttpRequestWrapper(messageInfo);
		OAuthConsumer consumer = new DefaultOAuthConsumer(
				OAuthConfig.getConsumerKey(),
				OAuthConfig.getConsumerSecret());
		consumer.setTokenWithSecret(OAuthConfig.getToken(),
				OAuthConfig.getTokenSecret());
		try {
			consumer.sign(req);
		} catch (OAuthException oae) {
			oae.printStackTrace();
		}
	}
}
 
Example #3
Source File: OAuthConsumer.java    From jira-steps-plugin with Apache License 2.0 5 votes vote down vote up
@Override
protected HttpRequest wrap(Object request) {
  if (!(request instanceof Request)) {
    throw new IllegalArgumentException(
        "Accepts only requests of type " + Request.class.getCanonicalName());
  }
  return new RequestAdapter((Request) request);
}
 
Example #4
Source File: OkHttpOAuthProvider.java    From okhttp-signpost with Apache License 2.0 5 votes vote down vote up
@Override
protected void closeConnection(HttpRequest request, HttpResponse response) throws Exception {
    if (response != null) {
        Response r = (Response) response.unwrap();
        r.close();
    }
}
 
Example #5
Source File: OkHttpOAuthConsumer.java    From okhttp-signpost with Apache License 2.0 5 votes vote down vote up
@Override
protected HttpRequest wrap(Object request) {
    if (!(request instanceof Request)) {
        throw new IllegalArgumentException("This consumer expects requests of type " + Request.class.getCanonicalName());
    }
    return new OkHttpRequestAdapter((Request) request);
}
 
Example #6
Source File: OAuthTest.java    From burp-oauth with MIT License 5 votes vote down vote up
@Ignore
public static HttpRequest reqWrapForTestInput(int num) throws IOException {
	RandomAccessFile f = new RandomAccessFile(String.format("test-inputs/%d.txt", num), "r");
	final byte[] req = new byte[(int)f.length()];
	f.read(req);
	IHttpRequestResponse request = new MockRequest(req);
	HttpRequest reqWrap = new BurpHttpRequestWrapper(request);
	request.setHttpService(new MockService(reqWrap.getHeader("Host")));
	return reqWrap;
}
 
Example #7
Source File: OAuthTest.java    From burp-oauth with MIT License 5 votes vote down vote up
@Test
public void testGetMessagePayload() throws IOException {
	HttpRequest hr;
	hr = reqWrapForTestInput(1);
	assertEquals(0, hr.getMessagePayload().available());
	hr = reqWrapForTestInput(2);
	final InputStream is = hr.getMessagePayload();
	final byte[] buf = new byte[is.available()];
	assertEquals(buf.length, is.read(buf));
	assertEquals(SOAP_BODY, new String(buf));
}
 
Example #8
Source File: OAuthTest.java    From burp-oauth with MIT License 5 votes vote down vote up
@Test
public void testSignature() throws Exception {
	HttpRequest hr = reqWrapForTestInput(1);
	OAuthConsumer consumer = new DefaultOAuthConsumer("1234", "5678");
	consumer.setTokenWithSecret("9ABC", "DEF0");
	consumer.sign(hr);
}
 
Example #9
Source File: OAuthTest.java    From burp-oauth with MIT License 5 votes vote down vote up
@Test
public void testUpdateHeader() throws IOException {
	HttpRequest hr = reqWrapForTestInput(1);
	assertEquals(hr.getHeader(UPDATE_HEADER_NAME), UPDATE_HEADER_OLD);
	hr.setHeader(UPDATE_HEADER_NAME, UPDATE_HEADER_VALUE);
	assertEquals(hr.getHeader(UPDATE_HEADER_NAME), UPDATE_HEADER_VALUE);
	assertEquals(hr.getHeader("Connection"), "Keep-Alive"); // next one
}
 
Example #10
Source File: OAuthTest.java    From burp-oauth with MIT License 5 votes vote down vote up
@Test
public void testInsertHeader() throws IOException {
	HttpRequest hr = reqWrapForTestInput(1);
	assertEquals(hr.getHeader(INSERT_HEADER_NAME), null);
	hr.setHeader(INSERT_HEADER_NAME, INSERT_HEADER_VALUE);
	assertEquals(hr.getHeader(INSERT_HEADER_NAME), INSERT_HEADER_VALUE);
}
 
Example #11
Source File: OAuthTest.java    From burp-oauth with MIT License 5 votes vote down vote up
@Test
public void testGetHeader() throws IOException {
	HttpRequest hr;
	hr = reqWrapForTestInput(1);
	assertEquals(hr.getHeader("Accept"), "application/json");
	assertEquals(hr.getHeader("Host"), "silentsignal.hu");
	assertEquals(hr.getHeader("Connection"), "Keep-Alive");
	assertEquals(hr.getHeader("User-Agent"), "Silent Signal");
	assertEquals(hr.getHeader("Non-Existent"), null);
	hr = reqWrapForTestInput(2);
	assertEquals(hr.getHeader("Host"), "weirdport.foo.bar:8081");
}
 
Example #12
Source File: OAuthTest.java    From burp-oauth with MIT License 5 votes vote down vote up
@Test
public void testGetContentType() throws IOException {
	HttpRequest hr;
	hr = reqWrapForTestInput(1);
	assertEquals(hr.getContentType(), null);
	hr = reqWrapForTestInput(2);
	assertEquals(hr.getContentType(), "text/xml; charset=utf-8");
}
 
Example #13
Source File: OAuthTest.java    From burp-oauth with MIT License 5 votes vote down vote up
@Test
public void testGetMethod() throws IOException {
	HttpRequest hr;
	hr = reqWrapForTestInput(1);
	assertEquals(hr.getMethod(), "GET");
	hr = reqWrapForTestInput(2);
	assertEquals(hr.getMethod(), "POST");
}
 
Example #14
Source File: WSAsync.java    From restcommander with Apache License 2.0 5 votes vote down vote up
@Override
protected HttpRequest wrap(Object request) {
    if (!(request instanceof WSRequest)) {
        throw new IllegalArgumentException("WSOAuthConsumer expects requests of type play.libs.WS.WSRequest");
    }
    return new WSRequestAdapter((WSRequest)request);
}
 
Example #15
Source File: OkHttpOAuthConsumer.java    From Woodmin with Apache License 2.0 5 votes vote down vote up
@Override
protected HttpRequest wrap(Object request) {
    if (!(request instanceof Request)) {
        throw new IllegalArgumentException("This consumer expects requests of type " + Request.class.getCanonicalName());
    }
    return new OkHttpRequestAdapter((Request) request);
}
 
Example #16
Source File: SigningInterceptor.java    From Woodmin with Apache License 2.0 5 votes vote down vote up
@Override
public Response intercept(Chain chain) throws IOException {
    Request request = chain.request();
    try {
        HttpRequest httpRequest = consumer.sign(request);
        Request authenticateRequest = (Request) httpRequest.unwrap();
        return chain.proceed(authenticateRequest);
    } catch (OAuthException e) {
        Log.e(LOG_TAG, "Error " + e.getMessage());
        throw new IOException("Could not sign request", e);
    }
}
 
Example #17
Source File: OkHttpOAuthConsumer.java    From Woodmin with Apache License 2.0 5 votes vote down vote up
@Override
protected HttpRequest wrap(Object request) {
    if (!(request instanceof Request)) {
        throw new IllegalArgumentException("This consumer expects requests of type " + Request.class.getCanonicalName());
    }
    return new OkHttpRequestAdapter((Request) request);
}
 
Example #18
Source File: SigningInterceptor.java    From Woodmin with Apache License 2.0 5 votes vote down vote up
@Override
public Response intercept(Chain chain) throws IOException {
    Request request = chain.request();
    try {
        HttpRequest httpRequest = consumer.sign(request);
        Request authenticateRequest = (Request) httpRequest.unwrap();
        return chain.proceed(authenticateRequest);
    } catch (OAuthException e) {
        Log.e(LOG_TAG, "Error " + e.getMessage());
        throw new IOException("Could not sign request", e);
    }
}
 
Example #19
Source File: XOAuthProvider.java    From RxUploader with Apache License 2.0 5 votes vote down vote up
@Override
protected HttpRequest createRequest(String endpointUrl) throws Exception {
    final Request.Builder builder =
            new Request.Builder()
                    .url(endpointUrl)
                    .post(Util.EMPTY_REQUEST);
    if (endpointUrl.contains(Config.ACCESS_TOKEN_URL)) {
        final MediaType mediaType = MediaType.parse("application/x-www-form-urlencoded");
        final String body =
                String.format("x_auth_mode=%s&x_auth_password=%s&x_auth_username=%s",
                        Config.X_AUTH_MODE, Config.X_AUTH_PASSWORD, Config.X_AUTH_USERNAME);
        builder.post(RequestBody.create(mediaType, body));
    }
    return new OkHttpRequestAdapter(builder.build());
}
 
Example #20
Source File: OAuthTest.java    From burp-oauth with MIT License 4 votes vote down vote up
@Test
public void testGetRequestUrl() throws IOException {
	HttpRequest hr = reqWrapForTestInput(1);
	assertEquals(hr.getRequestUrl(), "http://silentsignal.hu:1337/foo/bar");
}
 
Example #21
Source File: XOAuthProvider.java    From RxUploader with Apache License 2.0 4 votes vote down vote up
@Override
protected HttpResponse sendRequest(HttpRequest request) throws Exception {
    Response response = okHttpClient.newCall((Request) request.unwrap()).execute();
    return new OkHttpResponseAdapter(response);
}
 
Example #22
Source File: OkHttpOAuthProvider.java    From okhttp-signpost with Apache License 2.0 4 votes vote down vote up
@Override
protected HttpRequest createRequest(String endpointUrl) throws Exception {
    Request request = new Request.Builder().url(endpointUrl).build();
    return new OkHttpRequestAdapter(request);
}
 
Example #23
Source File: OkHttpOAuthProvider.java    From okhttp-signpost with Apache License 2.0 4 votes vote down vote up
@Override
protected HttpResponse sendRequest(HttpRequest request) throws Exception {
    Response response = okHttpClient.newCall((Request) request.unwrap()).execute();
    return new OkHttpResponseAdapter(response);
}
 
Example #24
Source File: OkOAuthConsumer.java    From uservoice-android-sdk with MIT License 4 votes vote down vote up
@Override
protected HttpRequest wrap(Object request) {
    return new OkRequestAdapter((Request) request);
}