This repository has been archived by the owner on Oct 21, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #53 from TheThingsNetwork/2.1.2
2.1.2
- Loading branch information
Showing
29 changed files
with
499 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
82 changes: 82 additions & 0 deletions
82
...rc/main/java/org/thethingsnetwork/account/async/auth/grant/AsyncApplicationAccessKey.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,82 @@ | ||
/* | ||
* The MIT License | ||
* | ||
* Copyright (c) 2017 The Things Network | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in | ||
* all copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
* THE SOFTWARE. | ||
*/ | ||
package org.thethingsnetwork.account.async.auth.grant; | ||
|
||
import java.net.URI; | ||
import org.thethingsnetwork.account.async.auth.token.AsyncAccessKey; | ||
import org.thethingsnetwork.account.common.GrantType; | ||
import rx.Observable; | ||
|
||
/** | ||
* This token provider uses application credentials (access-key) to generate a token only usable for the owning application. | ||
* It will always use access keys for authentication. | ||
* | ||
* @author Romain Cambier | ||
*/ | ||
public class AsyncApplicationAccessKey extends GrantType { | ||
|
||
private final String key; | ||
private final URI accountServer; | ||
|
||
/** | ||
* Create an instance of this token provider using fully-customized settings | ||
* | ||
* @param _key The application access-key | ||
* @param _accountServer The account server to be used | ||
*/ | ||
public AsyncApplicationAccessKey(String _key, URI _accountServer) { | ||
if (_key == null) { | ||
throw new IllegalArgumentException("key can not be null"); | ||
} | ||
if (_accountServer == null) { | ||
throw new IllegalArgumentException("accountServer can not be null"); | ||
} | ||
key = _key; | ||
accountServer = _accountServer; | ||
} | ||
|
||
/** | ||
* Create an instance of this token provider using default account server | ||
* | ||
* @param _key The application access-key | ||
*/ | ||
public AsyncApplicationAccessKey(String _key) { | ||
this(_key, GrantType.DEFAULT_ACCOUNT_SERVER); | ||
} | ||
|
||
@Override | ||
public URI getAccountServer() { | ||
return accountServer; | ||
} | ||
|
||
/** | ||
* Create a token using the settings provided in the constructor | ||
* | ||
* @return the AsyncAccessKey as an Observable stream | ||
*/ | ||
public Observable<AsyncAccessKey> getToken() { | ||
return Observable.just(new AsyncAccessKey(key, accountServer)); | ||
} | ||
|
||
} |
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
56 changes: 56 additions & 0 deletions
56
account/src/main/java/org/thethingsnetwork/account/async/auth/token/AsyncAccessKey.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,56 @@ | ||
/* | ||
* To change this license header, choose License Headers in Project Properties. | ||
* To change this template file, choose Tools | Templates | ||
* and open the template in the editor. | ||
*/ | ||
package org.thethingsnetwork.account.async.auth.token; | ||
|
||
import java.net.URI; | ||
import rx.Observable; | ||
|
||
/** | ||
* Async Access Key wrapper | ||
* | ||
* @author Romain Cambier | ||
*/ | ||
public class AsyncAccessKey implements AsyncOAuth2Token { | ||
|
||
private final String accessKey; | ||
private final URI accountServer; | ||
|
||
public AsyncAccessKey(String _accessKey, URI _accountServer) { | ||
accessKey = _accessKey; | ||
accountServer = _accountServer; | ||
} | ||
|
||
@Override | ||
public boolean hasRefresh() { | ||
return false; | ||
} | ||
|
||
@Override | ||
public Observable<? extends AsyncOAuth2Token> refresh() { | ||
return Observable.error(new UnsupportedOperationException("Not supported.")); | ||
} | ||
|
||
@Override | ||
public boolean isExpired() { | ||
return false; | ||
} | ||
|
||
@Override | ||
public String getToken() { | ||
return "Key " + accessKey; | ||
} | ||
|
||
@Override | ||
public String getRawToken() { | ||
return accessKey; | ||
} | ||
|
||
@Override | ||
public URI getAccountServer() { | ||
return accountServer; | ||
} | ||
|
||
} |
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
60 changes: 60 additions & 0 deletions
60
account/src/main/java/org/thethingsnetwork/account/sync/auth/grant/ApplicationAccessKey.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,60 @@ | ||
/* | ||
* To change this license header, choose License Headers in Project Properties. | ||
* To change this template file, choose Tools | Templates | ||
* and open the template in the editor. | ||
*/ | ||
package org.thethingsnetwork.account.sync.auth.grant; | ||
|
||
import java.net.URI; | ||
import org.thethingsnetwork.account.async.auth.grant.AsyncApplicationAccessKey; | ||
import org.thethingsnetwork.account.async.auth.token.AsyncAccessKey; | ||
import org.thethingsnetwork.account.common.GrantType; | ||
import org.thethingsnetwork.account.sync.auth.token.AccessKey; | ||
|
||
/** | ||
* This token provider uses application credentials (access-key) to generate a token only usable for the owning application. | ||
* It will always use access keys for authentication. | ||
* | ||
* @author Romain Cambier | ||
*/ | ||
public class ApplicationAccessKey extends GrantType { | ||
|
||
private final AsyncApplicationAccessKey wrapped; | ||
|
||
/** | ||
* Create an instance of this token provider using fully-customized settings | ||
* | ||
* @param _key The application access-key | ||
* @param _accountServer The account server to be used | ||
*/ | ||
public ApplicationAccessKey(String _key, URI _accountServer) { | ||
wrapped = new AsyncApplicationAccessKey(_key, _accountServer); | ||
} | ||
|
||
/** | ||
* Create an instance of this token provider using default account server | ||
* | ||
* @param _key The application access-key | ||
*/ | ||
public ApplicationAccessKey(String _key) { | ||
wrapped = new AsyncApplicationAccessKey(_key, GrantType.DEFAULT_ACCOUNT_SERVER); | ||
} | ||
|
||
@Override | ||
public URI getAccountServer() { | ||
return wrapped.getAccountServer(); | ||
} | ||
|
||
/** | ||
* Create a token using the settings provided in the constructor | ||
* | ||
* @return the AccessKey | ||
*/ | ||
public AccessKey getToken() { | ||
return wrapped.getToken() | ||
.map((AsyncAccessKey t) -> new AccessKey(t)) | ||
.toBlocking() | ||
.single(); | ||
} | ||
|
||
} |
Oops, something went wrong.