forked from ringcentral/pubnub-jtools
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Revoke Token
- Loading branch information
Showing
26 changed files
with
338 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,9 @@ | ||
## v5.3.0 | ||
December 16 2021 | ||
|
||
#### Added | ||
- Add revoke token feature. | ||
|
||
## v5.2.4 | ||
December 09 2021 | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,7 +12,7 @@ plugins { | |
} | ||
group = 'com.pubnub' | ||
|
||
version = '5.2.4' | ||
version = '5.3.0' | ||
|
||
description = """""" | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
103 changes: 103 additions & 0 deletions
103
src/main/java/com/pubnub/api/endpoints/access/RevokeToken.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
package com.pubnub.api.endpoints.access; | ||
|
||
import com.pubnub.api.PubNub; | ||
import com.pubnub.api.PubNubException; | ||
import com.pubnub.api.builder.PubNubErrorBuilder; | ||
import com.pubnub.api.endpoints.Endpoint; | ||
import com.pubnub.api.enums.PNOperationType; | ||
import com.pubnub.api.managers.RetrofitManager; | ||
import com.pubnub.api.managers.TelemetryManager; | ||
import com.pubnub.api.managers.token_manager.TokenManager; | ||
import com.pubnub.api.models.consumer.access_manager.v3.PNRevokeTokenResult; | ||
import com.pubnub.api.models.server.access_manager.v3.RevokeTokenResponse; | ||
import lombok.Setter; | ||
import lombok.experimental.Accessors; | ||
import retrofit2.Call; | ||
import retrofit2.Response; | ||
|
||
import java.io.UnsupportedEncodingException; | ||
import java.net.URLEncoder; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
@Accessors(chain = true, fluent = true) | ||
public class RevokeToken extends Endpoint<RevokeTokenResponse, PNRevokeTokenResult> { | ||
|
||
@Setter | ||
private String token; | ||
|
||
public RevokeToken(PubNub pubnub, | ||
TelemetryManager telemetryManager, | ||
RetrofitManager retrofit, | ||
TokenManager tokenManager) { | ||
super(pubnub, telemetryManager, retrofit, tokenManager); | ||
} | ||
|
||
@Override | ||
protected List<String> getAffectedChannels() { | ||
return null; | ||
} | ||
|
||
@Override | ||
protected List<String> getAffectedChannelGroups() { | ||
return null; | ||
} | ||
|
||
@Override | ||
protected void validateParams() throws PubNubException { | ||
if (this.getPubnub().getConfiguration().getSecretKey() == null || this.getPubnub() | ||
.getConfiguration() | ||
.getSecretKey() | ||
.isEmpty()) { | ||
throw PubNubException.builder().pubnubError(PubNubErrorBuilder.PNERROBJ_SECRET_KEY_MISSING).build(); | ||
} | ||
if (this.getPubnub().getConfiguration().getSubscribeKey() == null || this.getPubnub() | ||
.getConfiguration() | ||
.getSubscribeKey() | ||
.isEmpty()) { | ||
throw PubNubException.builder().pubnubError(PubNubErrorBuilder.PNERROBJ_SUBSCRIBE_KEY_MISSING).build(); | ||
} | ||
if (this.token == null) { | ||
throw PubNubException.builder() | ||
.pubnubError(PubNubErrorBuilder.PNERROBJ_TOKEN_MISSING) | ||
.build(); | ||
} | ||
} | ||
|
||
@Override | ||
protected Call<RevokeTokenResponse> doWork(Map<String, String> baseParams) throws PubNubException { | ||
return getRetrofit() | ||
.getAccessManagerService() | ||
.revokeToken(getPubnub().getConfiguration().getSubscribeKey(), repairEncoding(token), baseParams); | ||
} | ||
|
||
@Override | ||
protected PNRevokeTokenResult createResponse(Response<RevokeTokenResponse> input) throws PubNubException { | ||
if (input.body() == null) { | ||
return null; | ||
} | ||
|
||
return new PNRevokeTokenResult(); | ||
} | ||
|
||
@Override | ||
protected PNOperationType getOperationType() { | ||
return PNOperationType.PNAccessManagerRevokeToken; | ||
} | ||
|
||
@Override | ||
protected boolean isAuthRequired() { | ||
return false; | ||
} | ||
|
||
private String repairEncoding(String token) throws PubNubException { | ||
try { | ||
return URLEncoder.encode(token, "utf-8").replace("+", "%20"); | ||
} catch (UnsupportedEncodingException e) { | ||
throw PubNubException.builder() | ||
.pubnubError(PubNubErrorBuilder.PNERROBJ_PUBNUB_ERROR) | ||
.cause(e) | ||
.build(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
src/main/java/com/pubnub/api/models/consumer/access_manager/v3/PNRevokeTokenResult.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package com.pubnub.api.models.consumer.access_manager.v3; | ||
|
||
import lombok.Data; | ||
|
||
@Data | ||
public class PNRevokeTokenResult { | ||
} |
18 changes: 18 additions & 0 deletions
18
src/main/java/com/pubnub/api/models/server/access_manager/v3/RevokeTokenResponse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package com.pubnub.api.models.server.access_manager.v3; | ||
|
||
import lombok.Data; | ||
|
||
@Data | ||
public class RevokeTokenResponse { | ||
|
||
private final int status; | ||
private final RevokeTokenData data; | ||
private final String service; | ||
|
||
@Data | ||
public static class RevokeTokenData { | ||
private final String message; | ||
private final String token; | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -56,4 +56,4 @@ class Hooks { | |
} | ||
.firstOrNull() | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.