Skip to content

Commit 68c1647

Browse files
author
Max Presman
committed
move signing into utils
1 parent 66f3553 commit 68c1647

4 files changed

Lines changed: 12 additions & 64 deletions

File tree

‎docs/com/pubnub/api/endpoints/vendor/AppEngineFactory.Factory.html‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ <h3>Constructor Summary</h3>
136136
<th class="colOne" scope="col">Constructor and Description</th>
137137
</tr>
138138
<tr class="altColor">
139-
<td class="colOne"><code><span class="memberNameLink"><a href="../../../../../com/pubnub/api/endpoints/vendor/AppEngineFactory.Factory.html#Factory--">Factory</a></span>()</code>&nbsp;</td>
139+
<td class="colOne"><code><span class="memberNameLink"><a href="../../../../../com/pubnub/api/endpoints/vendor/AppEngineFactory.Factory.html#Factory-com.pubnub.api.PubNub-">Factory</a></span>(<a href="../../../../../com/pubnub/api/PubNub.html" title="class in com.pubnub.api">PubNub</a>&nbsp;pubNub)</code>&nbsp;</td>
140140
</tr>
141141
</table>
142142
</li>
@@ -179,13 +179,13 @@ <h3>Methods inherited from class&nbsp;java.lang.Object</h3>
179179
<!-- -->
180180
</a>
181181
<h3>Constructor Detail</h3>
182-
<a name="Factory--">
182+
<a name="Factory-com.pubnub.api.PubNub-">
183183
<!-- -->
184184
</a>
185185
<ul class="blockListLast">
186186
<li class="blockList">
187187
<h4>Factory</h4>
188-
<pre>public&nbsp;Factory()</pre>
188+
<pre>public&nbsp;Factory(<a href="../../../../../com/pubnub/api/PubNub.html" title="class in com.pubnub.api">PubNub</a>&nbsp;pubNub)</pre>
189189
</li>
190190
</ul>
191191
</li>

‎docs/com/pubnub/api/enums/package-tree.html‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,12 +81,12 @@ <h2 title="Enum Hierarchy">Enum Hierarchy</h2>
8181
<ul>
8282
<li type="circle">java.lang.Enum&lt;E&gt; (implements java.lang.Comparable&lt;T&gt;, java.io.Serializable)
8383
<ul>
84-
<li type="circle">com.pubnub.api.enums.<a href="../../../../com/pubnub/api/enums/PNLogVerbosity.html" title="enum in com.pubnub.api.enums"><span class="typeNameLink">PNLogVerbosity</span></a></li>
8584
<li type="circle">com.pubnub.api.enums.<a href="../../../../com/pubnub/api/enums/PNHeartbeatNotificationOptions.html" title="enum in com.pubnub.api.enums"><span class="typeNameLink">PNHeartbeatNotificationOptions</span></a></li>
86-
<li type="circle">com.pubnub.api.enums.<a href="../../../../com/pubnub/api/enums/PNStatusCategory.html" title="enum in com.pubnub.api.enums"><span class="typeNameLink">PNStatusCategory</span></a></li>
87-
<li type="circle">com.pubnub.api.enums.<a href="../../../../com/pubnub/api/enums/PNReconnectionPolicy.html" title="enum in com.pubnub.api.enums"><span class="typeNameLink">PNReconnectionPolicy</span></a></li>
8885
<li type="circle">com.pubnub.api.enums.<a href="../../../../com/pubnub/api/enums/PNOperationType.html" title="enum in com.pubnub.api.enums"><span class="typeNameLink">PNOperationType</span></a></li>
8986
<li type="circle">com.pubnub.api.enums.<a href="../../../../com/pubnub/api/enums/PNPushType.html" title="enum in com.pubnub.api.enums"><span class="typeNameLink">PNPushType</span></a></li>
87+
<li type="circle">com.pubnub.api.enums.<a href="../../../../com/pubnub/api/enums/PNLogVerbosity.html" title="enum in com.pubnub.api.enums"><span class="typeNameLink">PNLogVerbosity</span></a></li>
88+
<li type="circle">com.pubnub.api.enums.<a href="../../../../com/pubnub/api/enums/PNStatusCategory.html" title="enum in com.pubnub.api.enums"><span class="typeNameLink">PNStatusCategory</span></a></li>
89+
<li type="circle">com.pubnub.api.enums.<a href="../../../../com/pubnub/api/enums/PNReconnectionPolicy.html" title="enum in com.pubnub.api.enums"><span class="typeNameLink">PNReconnectionPolicy</span></a></li>
9090
</ul>
9191
</li>
9292
</ul>

‎docs/index-all.html‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -757,7 +757,7 @@ <h2 class="title">E</h2>
757757
</a>
758758
<h2 class="title">F</h2>
759759
<dl>
760-
<dt><span class="memberNameLink"><a href="com/pubnub/api/endpoints/vendor/AppEngineFactory.Factory.html#Factory--">Factory()</a></span> - Constructor for class com.pubnub.api.endpoints.vendor.<a href="com/pubnub/api/endpoints/vendor/AppEngineFactory.Factory.html" title="class in com.pubnub.api.endpoints.vendor">AppEngineFactory.Factory</a></dt>
760+
<dt><span class="memberNameLink"><a href="com/pubnub/api/endpoints/vendor/AppEngineFactory.Factory.html#Factory-com.pubnub.api.PubNub-">Factory(PubNub)</a></span> - Constructor for class com.pubnub.api.endpoints.vendor.<a href="com/pubnub/api/endpoints/vendor/AppEngineFactory.Factory.html" title="class in com.pubnub.api.endpoints.vendor">AppEngineFactory.Factory</a></dt>
761761
<dd>&nbsp;</dd>
762762
<dt><a href="com/pubnub/api/endpoints/FetchMessages.html" title="class in com.pubnub.api.endpoints"><span class="typeNameLink">FetchMessages</span></a> - Class in <a href="com/pubnub/api/endpoints/package-summary.html">com.pubnub.api.endpoints</a></dt>
763763
<dd>&nbsp;</dd>

‎src/main/java/com/pubnub/api/endpoints/vendor/AppEngineFactory.java‎

Lines changed: 5 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,11 @@
11
package com.pubnub.api.endpoints.vendor;
22

33
import com.pubnub.api.PubNub;
4-
import com.pubnub.api.PubNubException;
54
import com.pubnub.api.PubNubUtil;
6-
7-
import java.io.IOException;
8-
import java.net.HttpURLConnection;
9-
import java.net.URL;
10-
import java.util.HashMap;
11-
import java.util.Map;
12-
135
import lombok.extern.java.Log;
146
import okhttp3.Call;
157
import okhttp3.Callback;
168
import okhttp3.Headers;
17-
import okhttp3.HttpUrl;
189
import okhttp3.MediaType;
1910
import okhttp3.Protocol;
2011
import okhttp3.Request;
@@ -24,6 +15,10 @@
2415
import okio.BufferedSource;
2516
import okio.Okio;
2617

18+
import java.io.IOException;
19+
import java.net.HttpURLConnection;
20+
import java.net.URL;
21+
2722
@Log
2823
public class AppEngineFactory implements Call {
2924
private Request request;
@@ -41,7 +36,7 @@ public Request request() {
4136

4237
@Override
4338
public Response execute() throws IOException {
44-
request = signIfNecessary(request); // We need this since we bypass the signature interceptor
39+
request = PubNubUtil.requestSigner(request, pubNub.getConfiguration(), pubNub.getTimestamp());
4540

4641
URL url = request.url().url();
4742
final HttpURLConnection connection = (HttpURLConnection) url.openConnection();
@@ -95,53 +90,6 @@ public BufferedSource source() {
9590
return response;
9691
}
9792

98-
// TODO: This should probably go in a util file so we don't have copied code from SignatureInterceptor
99-
public Request signIfNecessary(Request request) {
100-
// only sign if we have a secret key in place.
101-
if (this.pubNub.getConfiguration().getSecretKey() == null) {
102-
return request;
103-
}
104-
105-
HttpUrl url = request.url();
106-
String requestURL = url.encodedPath();
107-
int timestamp = this.pubNub.getTimestamp();
108-
Map<String, String> queryParams = new HashMap<>();
109-
String signature = "";
110-
111-
for (String queryKey: url.queryParameterNames()) {
112-
queryParams.put(queryKey, url.queryParameter(queryKey));
113-
}
114-
115-
queryParams.put("timestamp", String.valueOf(timestamp));
116-
117-
String signInput = pubNub.getConfiguration().getSubscribeKey() + "\n"
118-
+ pubNub.getConfiguration().getPublishKey() + "\n";
119-
120-
if (requestURL.startsWith("/v1/auth/audit")) {
121-
signInput += "audit" + "\n";
122-
} else if (requestURL.startsWith("/v1/auth/grant")) {
123-
signInput += "grant" + "\n";
124-
} else {
125-
signInput += requestURL + "\n";
126-
}
127-
128-
signInput += PubNubUtil.preparePamArguments(queryParams);
129-
130-
try {
131-
signature = PubNubUtil.signSHA256(pubNub.getConfiguration().getSecretKey(), signInput);
132-
} catch (PubNubException e) {
133-
log.warning("signature failed on SignatureInterceptor: " + e.toString());
134-
}
135-
136-
HttpUrl rebuiltUrl = url.newBuilder()
137-
.addQueryParameter("timestamp", String.valueOf(timestamp))
138-
.addQueryParameter("signature", signature)
139-
.build();
140-
141-
request = request.newBuilder().url(rebuiltUrl).build();
142-
return request;
143-
}
144-
14593
@Override
14694
public void enqueue(Callback responseCallback) {
14795

0 commit comments

Comments
 (0)