Skip to content

Commit 042a9e3

Browse files
authored
Merge pull request #504 from devicehive/development
Development
2 parents d4b893e + b0976be commit 042a9e3

30 files changed

Lines changed: 106 additions & 46 deletions

File tree

devicehive-auth/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<parent>
66
<artifactId>devicehive-server</artifactId>
77
<groupId>com.devicehive</groupId>
8-
<version>3.4.4</version>
8+
<version>3.4.5</version>
99
</parent>
1010
<modelVersion>4.0.0</modelVersion>
1111
<packaging>jar</packaging>

devicehive-auth/src/main/java/com/devicehive/application/security/WebSecurityConfig.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,8 @@ protected void configure(HttpSecurity http) throws Exception {
6565
.authenticationEntryPoint(unauthorizedEntryPoint());
6666

6767
http
68-
.addFilterBefore(new HttpAuthenticationFilter(authenticationManager()), BasicAuthenticationFilter.class)
69-
.addFilterAfter(new SimpleCORSFilter(), HttpAuthenticationFilter.class);
68+
.addFilterBefore(new SimpleCORSFilter(), BasicAuthenticationFilter.class)
69+
.addFilterAfter(new HttpAuthenticationFilter(authenticationManager()), SimpleCORSFilter.class);
7070
}
7171

7272
@Override

devicehive-backend/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<parent>
66
<artifactId>devicehive-server</artifactId>
77
<groupId>com.devicehive</groupId>
8-
<version>3.4.4</version>
8+
<version>3.4.5</version>
99
</parent>
1010
<modelVersion>4.0.0</modelVersion>
1111

devicehive-common-dao/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<parent>
88
<groupId>com.devicehive</groupId>
99
<artifactId>devicehive-server</artifactId>
10-
<version>3.4.4</version>
10+
<version>3.4.5</version>
1111
</parent>
1212
<artifactId>devicehive-common-dao</artifactId>
1313
<packaging>jar</packaging>

devicehive-common-service/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<parent>
66
<artifactId>devicehive-server</artifactId>
77
<groupId>com.devicehive</groupId>
8-
<version>3.4.4</version>
8+
<version>3.4.5</version>
99
</parent>
1010
<modelVersion>4.0.0</modelVersion>
1111
<packaging>jar</packaging>

devicehive-common/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<parent>
88
<groupId>com.devicehive</groupId>
99
<artifactId>devicehive-server</artifactId>
10-
<version>3.4.4</version>
10+
<version>3.4.5</version>
1111
</parent>
1212
<artifactId>devicehive-common</artifactId>
1313
<packaging>jar</packaging>

devicehive-common/src/main/java/com/devicehive/auth/HiveAction.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,17 @@ public static HiveAction fromString(String text) {
8989
return null;
9090
}
9191

92+
public static HiveAction fromId(Integer id) {
93+
if (id != null) {
94+
for (HiveAction b : HiveAction.values()) {
95+
if (id.equals(b.id)) {
96+
return b;
97+
}
98+
}
99+
}
100+
return null;
101+
}
102+
92103
public static Set<HiveAction> getAllHiveActions() {
93104
return KNOWN_ACTIONS;
94105
}

devicehive-common/src/main/java/com/devicehive/model/DevicePortableFactory.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ public Portable create(int classId) {
4040
return new Filter();
4141
} else if (Subscriber.CLASS_ID == classId) {
4242
return new Subscriber();
43+
} else if (HazelcastEntityComparator.CLASS_ID == classId) {
44+
return new HazelcastEntityComparator();
4345
}
4446

4547
return null;

devicehive-common/src/main/java/com/devicehive/model/HazelcastEntityComparator.java

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,36 @@
2020
* #L%
2121
*/
2222

23+
import com.hazelcast.nio.serialization.Portable;
24+
import com.hazelcast.nio.serialization.PortableReader;
25+
import com.hazelcast.nio.serialization.PortableWriter;
26+
2327
import java.io.Serializable;
2428
import java.util.Comparator;
2529
import java.util.Date;
2630
import java.util.Map;
2731

28-
public class HazelcastEntityComparator implements Comparator<Map.Entry<String, HazelcastEntity>>, Serializable {
32+
33+
public class HazelcastEntityComparator implements Comparator<Map.Entry<String, HazelcastEntity>>, Serializable, Portable {
2934
private static final long serialVersionUID = 5413354955792888308L;
35+
public static final int FACTORY_ID = 1;
36+
public static final int CLASS_ID = 7;
37+
38+
@Override
39+
public int getFactoryId() {
40+
return FACTORY_ID;
41+
}
42+
43+
@Override
44+
public int getClassId() {
45+
return CLASS_ID;
46+
}
47+
48+
@Override
49+
public void writePortable(PortableWriter out) {}
50+
51+
@Override
52+
public void readPortable(PortableReader in) {}
3053

3154
@Override
3255
public int compare(Map.Entry<String, HazelcastEntity> o1, Map.Entry<String, HazelcastEntity> o2) {

devicehive-common/src/main/java/com/devicehive/security/jwt/JwtUserPayloadView.java

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import io.swagger.annotations.ApiModelProperty;
2929

3030
import javax.validation.constraints.NotNull;
31+
import javax.ws.rs.BadRequestException;
3132
import java.util.Date;
3233
import java.util.Objects;
3334
import java.util.Optional;
@@ -36,7 +37,7 @@
3637

3738
import static com.devicehive.auth.HiveAction.NONE;
3839

39-
public class JwtUserPayloadView implements HiveEntity {
40+
public class JwtUserPayloadView<T> implements HiveEntity {
4041

4142
private static final long serialVersionUID = 9015868660504625526L;
4243

@@ -54,7 +55,7 @@ public class JwtUserPayloadView implements HiveEntity {
5455

5556
@JsonProperty(ACTIONS)
5657
@SerializedName(ACTIONS)
57-
private Set<String> actions;
58+
private Set<T> actions;
5859

5960
@JsonProperty(NETWORK_IDS)
6061
@SerializedName(NETWORK_IDS)
@@ -72,7 +73,7 @@ public class JwtUserPayloadView implements HiveEntity {
7273
@SerializedName(TOKEN_TYPE)
7374
private TokenType tokenType;
7475

75-
public JwtUserPayloadView(Long userId, Set<String> actions, Set<String> networkIds,
76+
public JwtUserPayloadView(Long userId, Set<T> actions, Set<String> networkIds,
7677
Set<String> deviceTypeIds, Date expiration, TokenType tokenType) {
7778
this.userId = userId;
7879
this.actions = actions;
@@ -90,11 +91,11 @@ public void setUserId(Long userId) {
9091
this.userId = userId;
9192
}
9293

93-
public Set<String> getActions() {
94+
public Set<T> getActions() {
9495
return actions;
9596
}
9697

97-
public void setActions(Set<String> actions) {
98+
public void setActions(Set<T> actions) {
9899
this.actions = actions;
99100
}
100101

@@ -134,7 +135,13 @@ public JwtUserPayload convertTo() {
134135
Set<Integer> actionIds = Optional.ofNullable(actions)
135136
.map(value -> value.stream()
136137
//Here the compatibility with old behavior is provided to ignore not valid actions
137-
.map(action -> HiveAction.fromString(action))
138+
.map(action -> {
139+
if (action instanceof String) {
140+
return HiveAction.fromString((String) action);
141+
} else if (action instanceof Number && ((Double) action - ((Double) action).intValue() == 0)) {
142+
return HiveAction.fromId(((Double) action).intValue());
143+
} else throw new BadRequestException("Actions list should contain only Strings or Integers");
144+
})
138145
.filter(Objects::nonNull)
139146
.mapToInt(HiveAction::getId)
140147
.boxed()
@@ -148,15 +155,15 @@ public static Builder newBuilder() {
148155
return new Builder();
149156
}
150157

151-
public static class Builder {
158+
public static class Builder<T> {
152159
private Long userId;
153-
private Set<String> actions;
160+
private Set<T> actions;
154161
private Set<String> networkIds;
155162
private Set<String> deviceTypeIds;
156163
private Date expiration;
157164
private TokenType tokenType;
158165

159-
public Builder withPublicClaims(Long userId, Set<String> actions,
166+
public Builder withPublicClaims(Long userId, Set<T> actions,
160167
Set<String> networkIds, Set<String> deviceTypeIds) {
161168
this.userId = userId;
162169
this.actions = actions;
@@ -165,7 +172,7 @@ public Builder withPublicClaims(Long userId, Set<String> actions,
165172
return this;
166173
}
167174

168-
public Builder withPayload(JwtUserPayloadView payload) {
175+
public Builder withPayload(JwtUserPayloadView<T> payload) {
169176
this.userId = payload.getUserId();
170177
this.actions = payload.getActions();
171178
this.networkIds = payload.getNetworkIds();
@@ -179,7 +186,7 @@ public Builder withUserId(Long userId) {
179186
return this;
180187
}
181188

182-
public Builder withActions(Set<String> actions) {
189+
public Builder withActions(Set<T> actions) {
183190
this.actions = actions;
184191
return this;
185192
}
@@ -204,8 +211,8 @@ public Builder withExpirationDate(Date expiration) {
204211
return this;
205212
}
206213

207-
public JwtUserPayloadView buildPayload() {
208-
return new JwtUserPayloadView(userId, actions, networkIds, deviceTypeIds, expiration, tokenType);
214+
public JwtUserPayloadView<T> buildPayload() {
215+
return new JwtUserPayloadView<T>(userId, actions, networkIds, deviceTypeIds, expiration, tokenType);
209216
}
210217
}
211218
}

0 commit comments

Comments
 (0)