Skip to content
This repository was archived by the owner on Oct 21, 2020. It is now read-only.

Commit 030904c

Browse files
Merge pull request #53 from TheThingsNetwork/2.1.2
2.1.2
2 parents a932120 + 1247100 commit 030904c

File tree

29 files changed

+499
-49
lines changed

29 files changed

+499
-49
lines changed

account/pom.xml

+4-4
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<parent>
55
<groupId>org.thethingsnetwork</groupId>
66
<artifactId>app-sdk</artifactId>
7-
<version>2.1.1</version>
7+
<version>2.1.2</version>
88
</parent>
99
<artifactId>account</artifactId>
1010
<packaging>jar</packaging>
@@ -24,17 +24,17 @@
2424
<dependency>
2525
<groupId>io.reactivex</groupId>
2626
<artifactId>rxjava</artifactId>
27-
<version>1.2.3</version>
27+
<version>1.2.9</version>
2828
</dependency>
2929
<dependency>
3030
<groupId>com.fasterxml.jackson.core</groupId>
3131
<artifactId>jackson-databind</artifactId>
32-
<version>2.8.5</version>
32+
<version>2.8.7</version>
3333
</dependency>
3434
<dependency>
3535
<groupId>com.squareup.okhttp3</groupId>
3636
<artifactId>okhttp</artifactId>
37-
<version>3.5.0</version>
37+
<version>3.6.0</version>
3838
</dependency>
3939
</dependencies>
4040
</project>

account/src/main/java/org/thethingsnetwork/account/async/AsyncApplication.java

+10-10
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
import okhttp3.Response;
2929
import org.thethingsnetwork.account.async.auth.token.AsyncOAuth2Token;
3030
import org.thethingsnetwork.account.common.AbstractApplication;
31-
import org.thethingsnetwork.account.common.AccessKey;
31+
import org.thethingsnetwork.account.common.ExtendedAccessKey;
3232
import org.thethingsnetwork.account.common.ApplicationRights;
3333
import org.thethingsnetwork.account.common.Collaborator;
3434
import org.thethingsnetwork.account.sync.Application;
@@ -349,16 +349,16 @@ public Observable<AsyncApplication> removeCollaborator(Collaborator _collaborato
349349
*
350350
* @return the list of AccessKey of this AsyncApplication as an Observable stream.
351351
*/
352-
public Observable<AccessKey> getAccessKeys() {
352+
public Observable<ExtendedAccessKey> getAccessKeys() {
353353
/**
354354
* GET /applications/{app_id}/access-keys
355355
*/
356356
return HttpRequest
357357
.from(creds.getAccountServer() + "/applications/" + getId() + "/access-keys")
358358
.flatMap((HttpRequest t) -> t.inject(creds))
359359
.doOnNext((HttpRequest t) -> t.getBuilder().get())
360-
.flatMap((HttpRequest t) -> t.doExecuteForType(AccessKey[].class))
361-
.flatMap((AccessKey[] cs) -> Observable.from(cs));
360+
.flatMap((HttpRequest t) -> t.doExecuteForType(ExtendedAccessKey[].class))
361+
.flatMap((ExtendedAccessKey[] cs) -> Observable.from(cs));
362362
}
363363

364364
/**
@@ -367,15 +367,15 @@ public Observable<AccessKey> getAccessKeys() {
367367
* @param _keyname the name of the AccessKey
368368
* @return the AccessKey as an Observable stream.
369369
*/
370-
public Observable<AccessKey> findOneAccessKey(String _keyname) {
370+
public Observable<ExtendedAccessKey> findOneAccessKey(String _keyname) {
371371
/**
372372
* GET /applications/{app_id}/access-keys/{keyname}
373373
*/
374374
return HttpRequest
375375
.from(creds.getAccountServer() + "/applications/" + getId() + "/access-keys/" + _keyname)
376376
.flatMap((HttpRequest t) -> t.inject(creds))
377377
.doOnNext((HttpRequest t) -> t.getBuilder().get())
378-
.flatMap((HttpRequest t) -> t.doExecuteForType(AccessKey.class));
378+
.flatMap((HttpRequest t) -> t.doExecuteForType(ExtendedAccessKey.class));
379379
}
380380

381381
/**
@@ -384,7 +384,7 @@ public Observable<AccessKey> findOneAccessKey(String _keyname) {
384384
* @param _key the AccessKey template
385385
* @return the new AccessKey as an Observable stream.
386386
*/
387-
public Observable<AccessKey> addAccessKey(AccessKey _key) {
387+
public Observable<ExtendedAccessKey> addAccessKey(ExtendedAccessKey _key) {
388388
/**
389389
* POST /applications/{app_id}/access-keys
390390
*/
@@ -398,8 +398,8 @@ public Observable<AccessKey> addAccessKey(AccessKey _key) {
398398
return t;
399399
})
400400
)
401-
.flatMap((HttpRequest t) -> t.doExecuteForType(AccessKey.class))
402-
.map((AccessKey c) -> c);
401+
.flatMap((HttpRequest t) -> t.doExecuteForType(ExtendedAccessKey.class))
402+
.map((ExtendedAccessKey c) -> c);
403403
}
404404

405405
/**
@@ -408,7 +408,7 @@ public Observable<AccessKey> addAccessKey(AccessKey _key) {
408408
* @param _key the AccessKey
409409
* @return the updated AsyncApplication as an Observable stream.
410410
*/
411-
public Observable<AsyncApplication> removeAccessKey(AccessKey _key) {
411+
public Observable<AsyncApplication> removeAccessKey(ExtendedAccessKey _key) {
412412
/**
413413
* DELETE /applications/{app_id}/access-keys/{keyname}
414414
*/
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
/*
2+
* The MIT License
3+
*
4+
* Copyright (c) 2017 The Things Network
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be included in
14+
* all copies or substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22+
* THE SOFTWARE.
23+
*/
24+
package org.thethingsnetwork.account.async.auth.grant;
25+
26+
import java.net.URI;
27+
import org.thethingsnetwork.account.async.auth.token.AsyncAccessKey;
28+
import org.thethingsnetwork.account.common.GrantType;
29+
import rx.Observable;
30+
31+
/**
32+
* This token provider uses application credentials (access-key) to generate a token only usable for the owning application.
33+
* It will always use access keys for authentication.
34+
*
35+
* @author Romain Cambier
36+
*/
37+
public class AsyncApplicationAccessKey extends GrantType {
38+
39+
private final String key;
40+
private final URI accountServer;
41+
42+
/**
43+
* Create an instance of this token provider using fully-customized settings
44+
*
45+
* @param _key The application access-key
46+
* @param _accountServer The account server to be used
47+
*/
48+
public AsyncApplicationAccessKey(String _key, URI _accountServer) {
49+
if (_key == null) {
50+
throw new IllegalArgumentException("key can not be null");
51+
}
52+
if (_accountServer == null) {
53+
throw new IllegalArgumentException("accountServer can not be null");
54+
}
55+
key = _key;
56+
accountServer = _accountServer;
57+
}
58+
59+
/**
60+
* Create an instance of this token provider using default account server
61+
*
62+
* @param _key The application access-key
63+
*/
64+
public AsyncApplicationAccessKey(String _key) {
65+
this(_key, GrantType.DEFAULT_ACCOUNT_SERVER);
66+
}
67+
68+
@Override
69+
public URI getAccountServer() {
70+
return accountServer;
71+
}
72+
73+
/**
74+
* Create a token using the settings provided in the constructor
75+
*
76+
* @return the AsyncAccessKey as an Observable stream
77+
*/
78+
public Observable<AsyncAccessKey> getToken() {
79+
return Observable.just(new AsyncAccessKey(key, accountServer));
80+
}
81+
82+
}

account/src/main/java/org/thethingsnetwork/account/async/auth/grant/AsyncApplicationPassword.java

+1
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535

3636
/**
3737
* This token provider uses application credentials (id + access-key) to generate a token only usable for the owning application
38+
* It will exchange the access key for an access token using client credentials.
3839
*
3940
* @author Romain Cambier
4041
*/
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
/*
2+
* To change this license header, choose License Headers in Project Properties.
3+
* To change this template file, choose Tools | Templates
4+
* and open the template in the editor.
5+
*/
6+
package org.thethingsnetwork.account.async.auth.token;
7+
8+
import java.net.URI;
9+
import rx.Observable;
10+
11+
/**
12+
* Async Access Key wrapper
13+
*
14+
* @author Romain Cambier
15+
*/
16+
public class AsyncAccessKey implements AsyncOAuth2Token {
17+
18+
private final String accessKey;
19+
private final URI accountServer;
20+
21+
public AsyncAccessKey(String _accessKey, URI _accountServer) {
22+
accessKey = _accessKey;
23+
accountServer = _accountServer;
24+
}
25+
26+
@Override
27+
public boolean hasRefresh() {
28+
return false;
29+
}
30+
31+
@Override
32+
public Observable<? extends AsyncOAuth2Token> refresh() {
33+
return Observable.error(new UnsupportedOperationException("Not supported."));
34+
}
35+
36+
@Override
37+
public boolean isExpired() {
38+
return false;
39+
}
40+
41+
@Override
42+
public String getToken() {
43+
return "Key " + accessKey;
44+
}
45+
46+
@Override
47+
public String getRawToken() {
48+
return accessKey;
49+
}
50+
51+
@Override
52+
public URI getAccountServer() {
53+
return accountServer;
54+
}
55+
56+
}

account/src/main/java/org/thethingsnetwork/account/common/AccessKey.java renamed to account/src/main/java/org/thethingsnetwork/account/common/ExtendedAccessKey.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
* @author Romain Cambier
3333
*/
3434
@JsonIgnoreProperties(ignoreUnknown = true)
35-
public class AccessKey {
35+
public class ExtendedAccessKey {
3636

3737
private String name;
3838
private String key;
@@ -41,7 +41,7 @@ public class AccessKey {
4141
/**
4242
* Create an empty AccessKey. Only used by jackson.
4343
*/
44-
public AccessKey() {
44+
public ExtendedAccessKey() {
4545

4646
}
4747

@@ -51,7 +51,7 @@ public AccessKey() {
5151
* @param _name The key name
5252
* @param _rights The key rights
5353
*/
54-
public AccessKey(String _name, List<ApplicationRights> _rights) {
54+
public ExtendedAccessKey(String _name, List<ApplicationRights> _rights) {
5555
name = _name;
5656
rights = _rights;
5757
}

account/src/main/java/org/thethingsnetwork/account/common/GrantType.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public abstract class GrantType {
3636

3737
static {
3838
try {
39-
DEFAULT_ACCOUNT_SERVER = new URI("https://account.thethingsnetwork.org");
39+
DEFAULT_ACCOUNT_SERVER = new URI("https://account.thethingsnetwork.org/api/v2");
4040
} catch (URISyntaxException ex) {
4141
throw new RuntimeException(ex);
4242
}

account/src/main/java/org/thethingsnetwork/account/sync/Application.java

+5-5
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
import java.util.List;
2727
import org.thethingsnetwork.account.async.AsyncApplication;
2828
import org.thethingsnetwork.account.common.AbstractApplication;
29-
import org.thethingsnetwork.account.common.AccessKey;
29+
import org.thethingsnetwork.account.common.ExtendedAccessKey;
3030
import org.thethingsnetwork.account.common.ApplicationRights;
3131
import org.thethingsnetwork.account.common.Collaborator;
3232
import org.thethingsnetwork.account.sync.auth.token.OAuth2Token;
@@ -224,7 +224,7 @@ public Application removeCollaborator(Collaborator _collaborator) {
224224
*
225225
* @return the list of AccessKey of this Application
226226
*/
227-
public List<AccessKey> getAccessKeys() {
227+
public List<ExtendedAccessKey> getAccessKeys() {
228228
return wrapped.getAccessKeys()
229229
.toList()
230230
.toBlocking()
@@ -237,7 +237,7 @@ public List<AccessKey> getAccessKeys() {
237237
* @param _keyname the name of the AccessKey
238238
* @return the AccessKey
239239
*/
240-
public AccessKey findOneAccessKey(String _keyname) {
240+
public ExtendedAccessKey findOneAccessKey(String _keyname) {
241241
return wrapped.findOneAccessKey(_keyname)
242242
.toBlocking()
243243
.singleOrDefault(null);
@@ -249,7 +249,7 @@ public AccessKey findOneAccessKey(String _keyname) {
249249
* @param _key the AccessKey template
250250
* @return the new AccessKey
251251
*/
252-
public AccessKey addAccessKey(AccessKey _key) {
252+
public ExtendedAccessKey addAccessKey(ExtendedAccessKey _key) {
253253
return wrapped.addAccessKey(_key)
254254
.toBlocking()
255255
.single();
@@ -261,7 +261,7 @@ public AccessKey addAccessKey(AccessKey _key) {
261261
* @param _key the AccessKey
262262
* @return the updated Application
263263
*/
264-
public Application removeAccessKey(AccessKey _key) {
264+
public Application removeAccessKey(ExtendedAccessKey _key) {
265265
return wrapped.removeAccessKey(_key)
266266
.map((i) -> this)
267267
.toBlocking()
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
/*
2+
* To change this license header, choose License Headers in Project Properties.
3+
* To change this template file, choose Tools | Templates
4+
* and open the template in the editor.
5+
*/
6+
package org.thethingsnetwork.account.sync.auth.grant;
7+
8+
import java.net.URI;
9+
import org.thethingsnetwork.account.async.auth.grant.AsyncApplicationAccessKey;
10+
import org.thethingsnetwork.account.async.auth.token.AsyncAccessKey;
11+
import org.thethingsnetwork.account.common.GrantType;
12+
import org.thethingsnetwork.account.sync.auth.token.AccessKey;
13+
14+
/**
15+
* This token provider uses application credentials (access-key) to generate a token only usable for the owning application.
16+
* It will always use access keys for authentication.
17+
*
18+
* @author Romain Cambier
19+
*/
20+
public class ApplicationAccessKey extends GrantType {
21+
22+
private final AsyncApplicationAccessKey wrapped;
23+
24+
/**
25+
* Create an instance of this token provider using fully-customized settings
26+
*
27+
* @param _key The application access-key
28+
* @param _accountServer The account server to be used
29+
*/
30+
public ApplicationAccessKey(String _key, URI _accountServer) {
31+
wrapped = new AsyncApplicationAccessKey(_key, _accountServer);
32+
}
33+
34+
/**
35+
* Create an instance of this token provider using default account server
36+
*
37+
* @param _key The application access-key
38+
*/
39+
public ApplicationAccessKey(String _key) {
40+
wrapped = new AsyncApplicationAccessKey(_key, GrantType.DEFAULT_ACCOUNT_SERVER);
41+
}
42+
43+
@Override
44+
public URI getAccountServer() {
45+
return wrapped.getAccountServer();
46+
}
47+
48+
/**
49+
* Create a token using the settings provided in the constructor
50+
*
51+
* @return the AccessKey
52+
*/
53+
public AccessKey getToken() {
54+
return wrapped.getToken()
55+
.map((AsyncAccessKey t) -> new AccessKey(t))
56+
.toBlocking()
57+
.single();
58+
}
59+
60+
}

0 commit comments

Comments
 (0)