Skip to content

Commit

Permalink
PubNub SDK v5.1.0 release.
Browse files Browse the repository at this point in the history
  • Loading branch information
client-engineering-bot committed May 20, 2021
1 parent f6c9190 commit 26f9cbb
Show file tree
Hide file tree
Showing 28 changed files with 650 additions and 262 deletions.
11 changes: 9 additions & 2 deletions .pubnub.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
name: java
version: 5.0.0
version: 5.1.0
schema: 1
scm: github.com/pubnub/java
files:
- build/libs/pubnub-gson-5.0.0-all.jar
- build/libs/pubnub-gson-5.1.0-all.jar
sdks:
-
type: library
Expand Down Expand Up @@ -234,6 +234,13 @@ sdks:
is-required: Required

changelog:
- version: v5.1.0
date: 2021-05-20
changes:
- type: feature
text: "Method grantToken has beed added. It allows generation of signed token with permissions for channels and channel groups."
- type: bug
text: "UUID is now exposed as PNMembership field which make is accessible from PNMembershipResult argument of SubscribeCallback.membership() method."
- version: v5.0.0
date: 2021-05-12
changes:
Expand Down
10 changes: 8 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
## [v5.1.0](https://github.com/pubnub/java/releases/tag/v5.1.0)
May-20-2021

[Full Changelog](https://github.com/pubnub/java/compare/v5.0.0...v5.1.0)

- 🌟️ Method grantToken has beed added. It allows generation of signed token with permissions for channels and channel groups.
- 🐛 UUID is now exposed as PNMembership field which make is accessible from PNMembershipResult argument of SubscribeCallback.membership() method.

## [v5.0.0](https://github.com/pubnub/java/releases/tag/v5.0.0)
May-12-2021

[Full Changelog](https://github.com/pubnub/java/compare/v4.36.0...v5.0.0)

- 🌟️ Now random initialisation vector used when encryption enabled is now default behaviour.
- 🐛 There were some non daemon threads running in background preventing VM from exiting. Now they are daemon threads.

Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@ You will need the publish and subscribe keys to authenticate your app. Get your
<dependency>
<groupId>com.pubnub</groupId>
<artifactId>pubnub-gson</artifactId>
<version>5.0.0</version>
<version>5.1.0</version>
</dependency>
```

* for Gradle, add the following dependency in your `gradle.build`:
```groovy
compile group: 'com.pubnub', name: 'pubnub-gson', version: '5.0.0'
compile group: 'com.pubnub', name: 'pubnub-gson', version: '5.1.0'
```

2. Configure your keys:
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ plugins {
}
group = 'com.pubnub'

version = '5.0.0'
version = '5.1.0'

description = """"""

Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,29 @@
package com.pubnub.api.integration.objects.memberships;

import com.pubnub.api.PubNub;
import com.pubnub.api.PubNubException;
import com.pubnub.api.integration.managers.subscription.SubscribeCallbackAdapter;
import com.pubnub.api.integration.objects.ObjectsApiBaseIT;
import com.pubnub.api.models.consumer.objects_api.channel.PNSetChannelMetadataResult;
import com.pubnub.api.models.consumer.objects_api.membership.PNChannelMembership;
import com.pubnub.api.models.consumer.objects_api.membership.PNGetMembershipsResult;
import com.pubnub.api.models.consumer.objects_api.membership.PNMembershipResult;
import com.pubnub.api.models.consumer.objects_api.membership.PNSetMembershipResult;
import org.awaitility.core.ThrowingRunnable;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;

import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.concurrent.TimeUnit;

import static com.pubnub.api.endpoints.objects_api.utils.Include.PNChannelDetailsLevel.CHANNEL;
import static com.pubnub.api.endpoints.objects_api.utils.Include.PNChannelDetailsLevel.CHANNEL_WITH_CUSTOM;
import static org.awaitility.Awaitility.await;
import static org.hamcrest.Matchers.allOf;
import static org.hamcrest.Matchers.hasItem;
import static org.hamcrest.Matchers.hasProperty;
Expand All @@ -39,6 +47,22 @@ public class CustomMetadataInMembershipPropagationIT extends ObjectsApiBaseIT {
private PNSetMembershipResult setMembershipResult;


private CopyOnWriteArrayList<PNMembershipResult> pnMembershipResults = new CopyOnWriteArrayList<>();

@Before
public void setCallbackListener() {
pubNubUnderTest.addListener(new SubscribeCallbackAdapter() {
@Override
public void membership(final PubNub pubnub, final PNMembershipResult pnMembershipResult) {
pnMembershipResults.add(pnMembershipResult);
}
});

pubNubUnderTest.subscribe()
.channels(Collections.singletonList(testChannelMetadataId))
.execute();
}

@Test
public void setMembershipCustomHappyPath() throws PubNubException {
final String testChannelName = "The Name of the Channel";
Expand Down Expand Up @@ -86,6 +110,14 @@ public void setMembershipCustomHappyPath() throws PubNubException {
hasProperty("name", is(testChannelName)),
hasProperty("description", is(testDescription)),
hasProperty("custom", nullValue()))))))));

await().atMost(1, TimeUnit.SECONDS).untilAsserted(new ThrowingRunnable() {
@Override
public void run() throws Throwable {
assertThat(pnMembershipResults, hasItem(
hasProperty("data", hasProperty("uuid", is(pubNubUnderTest.getConfiguration().getUuid())))));
}
});
}

@After
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package com.pubnub.api.integration.pam;

import com.pubnub.api.PNConfiguration;
import com.pubnub.api.PubNub;
import com.pubnub.api.PubNubException;
import com.pubnub.api.integration.util.BaseIntegrationTest;
import com.pubnub.api.models.consumer.access_manager.v3.ChannelGrant;
import com.pubnub.api.models.consumer.access_manager.v3.ChannelGroupGrant;
import com.pubnub.api.models.consumer.access_manager.v3.PNGrantTokenResult;
import com.pubnub.api.models.consumer.access_manager.v3.PNToken;
import org.junit.Test;

import java.util.Arrays;
import static org.junit.Assert.assertEquals;


public class GrantTokenIT extends BaseIntegrationTest {
private final PubNub pubNubUnderTest = getServer();

@Test
public void happyPath() throws PubNubException {
//given
final int expectedTTL = 1337;
final String expectedChannelResourceName = "channelResource";
final String expectedChannelPattern = "channel.*";
final String expectedChannelGroupResourceId = "channelGroup";
final String expectedChannelGroupPattern = "channelGroup.*";

//when
final PNGrantTokenResult grantTokenResponse = pubNubUnderTest
.grantToken()
.ttl(expectedTTL)
.channels(Arrays.asList(ChannelGrant.name(expectedChannelResourceName).delete(),
ChannelGrant.pattern(expectedChannelPattern).write()))
.channelGroups(Arrays.asList(ChannelGroupGrant.id(expectedChannelGroupResourceId).read(),
ChannelGroupGrant.pattern(expectedChannelGroupPattern).manage()))
.sync();

final PNToken pnToken = pubNubUnderTest.parseToken(grantTokenResponse.getToken());

//then
assertEquals(expectedTTL, pnToken.getTtl());
assertEquals(new PNToken.PNResourcePermissions(false, false, false, false, true),
pnToken.getResources().getChannels().get(expectedChannelResourceName));
assertEquals(new PNToken.PNResourcePermissions(false, true, false, false, false),
pnToken.getResources().getChannelGroups().get(expectedChannelGroupResourceId));
assertEquals(new PNToken.PNResourcePermissions(false, false, true, false, false),
pnToken.getPatterns().getChannels().get(expectedChannelPattern));
assertEquals(new PNToken.PNResourcePermissions(false, false, false, true, false),
pnToken.getPatterns().getChannelGroups().get(expectedChannelGroupPattern));
}

}
17 changes: 16 additions & 1 deletion src/main/java/com/pubnub/api/PubNub.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import com.pubnub.api.endpoints.MessageCounts;
import com.pubnub.api.endpoints.Time;
import com.pubnub.api.endpoints.access.Grant;
import com.pubnub.api.endpoints.access.GrantToken;
import com.pubnub.api.endpoints.channel_groups.AddChannelChannelGroup;
import com.pubnub.api.endpoints.channel_groups.AllChannelsChannelGroup;
import com.pubnub.api.endpoints.channel_groups.DeleteChannelGroup;
Expand Down Expand Up @@ -62,6 +63,8 @@
import com.pubnub.api.managers.StateManager;
import com.pubnub.api.managers.SubscriptionManager;
import com.pubnub.api.managers.TelemetryManager;
import com.pubnub.api.managers.token_manager.TokenParser;
import com.pubnub.api.models.consumer.access_manager.v3.PNToken;
import com.pubnub.api.vendor.Crypto;
import com.pubnub.api.vendor.FileEncryptionUtil;
import lombok.Getter;
Expand Down Expand Up @@ -94,10 +97,12 @@ public class PubNub {

private RetrofitManager retrofitManager;

private final TokenParser tokenParser;

private static final int TIMESTAMP_DIVIDER = 1000;
private static final int MAX_SEQUENCE = 65535;

private static final String SDK_VERSION = "5.0.0";
private static final String SDK_VERSION = "5.1.0";
private final ListenerManager listenerManager;
private final StateManager stateManager;

Expand All @@ -121,6 +126,7 @@ public PubNub(@NotNull PNConfiguration initialConfig) {
delayedReconnectionManager,
duplicationManager);
this.publishSequenceManager = new PublishSequenceManager(MAX_SEQUENCE);
this.tokenParser = new TokenParser();
instanceId = UUID.randomUUID().toString();
}

Expand Down Expand Up @@ -217,6 +223,11 @@ public Grant grant() {
return new Grant(this, this.telemetryManager, this.retrofitManager);
}

@NotNull
public GrantToken grantToken() {
return new GrantToken(this, this.telemetryManager, this.retrofitManager);
}

@NotNull
public GetState getPresenceState() {
return new GetState(this, this.telemetryManager, this.retrofitManager);
Expand Down Expand Up @@ -575,4 +586,8 @@ public List<String> getSubscribedChannelGroups() {
public void unsubscribeAll() {
subscriptionManager.unsubscribeAll();
}

public PNToken parseToken(String token) throws PubNubException {
return tokenParser.unwrapToken(token);
}
}
7 changes: 7 additions & 0 deletions src/main/java/com/pubnub/api/PubNubException.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,12 @@ public PubNubException(final String errormsg,
this.affectedCall = affectedCall;
}

@Override
@ToString.Include
public Throwable getCause() {
return super.getCause();
}

@Override
public String getMessage() {
return errormsg;
Expand All @@ -42,3 +48,4 @@ public String getMessage() {
@ToString.Exclude
private Call affectedCall;
}

5 changes: 5 additions & 0 deletions src/main/java/com/pubnub/api/PubNubUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import java.net.URLEncoder;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -285,4 +286,8 @@ public static byte[] readBytes(final InputStream inputStream) throws IOException
}
}

public static <T> boolean isNullOrEmpty(final Collection<T> collection) {
return collection == null || collection.isEmpty();
}

}
Loading

0 comments on commit 26f9cbb

Please sign in to comment.