-
Notifications
You must be signed in to change notification settings - Fork 2
Module authorizationserver #51
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
e4642ab
Added Authorization Server logic as Manager Module
PatrykMilewski 5b3835e
Fixed all problmes, fully working version
PatrykMilewski f0cf12a
Merge remote-tracking branch 'origin/master' into module-authorizatio…
PatrykMilewski 16f13dd
Merged with current master
PatrykMilewski 598326d
The code is passing tests, functionally working
PatrykMilewski 45009c4
Renamed HttpClient classes to ApacheHttpClient
PatrykMilewski f1be534
Fixed class names
PatrykMilewski 35f0672
Merge with actual master
PatrykMilewski File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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
24 changes: 24 additions & 0 deletions
24
Manager/src/main/java/io/raspberrywallet/manager/common/http/ApacheHttpClient.java
This file contains hidden or 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,24 @@ | ||
| package io.raspberrywallet.manager.common.http; | ||
|
|
||
| import org.apache.http.HttpResponse; | ||
| import org.apache.http.NameValuePair; | ||
| import org.apache.http.client.fluent.Form; | ||
| import org.json.JSONObject; | ||
|
|
||
| import java.io.IOException; | ||
| import java.util.List; | ||
|
|
||
| public abstract class ApacheHttpClient { | ||
|
|
||
| public abstract HttpResponse sendPOSTRequest(Form body, String endpoint) throws IOException; | ||
|
|
||
| public abstract HttpResponse sendGETRequest(Form body, String endpoint); | ||
|
|
||
| JSONObject convert(Form body) { | ||
| List<NameValuePair> keyValuesList = body.build(); | ||
| JSONObject convertedJson = new JSONObject(); | ||
| keyValuesList.forEach(pair -> convertedJson.put(pair.getName(), pair.getValue())); | ||
| return convertedJson; | ||
| } | ||
|
|
||
| } |
20 changes: 20 additions & 0 deletions
20
...er/src/main/java/io/raspberrywallet/manager/common/http/SecureApacheApacheHttpClient.java
This file contains hidden or 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,20 @@ | ||
| package io.raspberrywallet.manager.common.http; | ||
|
|
||
| import org.apache.commons.lang.NotImplementedException; | ||
| import org.apache.http.HttpResponse; | ||
| import org.apache.http.client.fluent.Form; | ||
|
|
||
| import java.io.IOException; | ||
|
|
||
| public class SecureApacheApacheHttpClient extends ApacheHttpClient { | ||
|
|
||
| @Override | ||
| public HttpResponse sendPOSTRequest(Form body, String endpoint) throws IOException { | ||
| throw new NotImplementedException(); | ||
| } | ||
|
|
||
| @Override | ||
| public HttpResponse sendGETRequest(Form body, String endpoint) { | ||
| throw new NotImplementedException(); | ||
| } | ||
| } |
56 changes: 56 additions & 0 deletions
56
.../src/main/java/io/raspberrywallet/manager/common/http/UnsecureApacheApacheHttpClient.java
This file contains hidden or 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 @@ | ||
| package io.raspberrywallet.manager.common.http; | ||
|
|
||
| import org.apache.commons.lang.NotImplementedException; | ||
| import org.apache.http.Header; | ||
| import org.apache.http.HttpResponse; | ||
| import org.apache.http.NameValuePair; | ||
| import org.apache.http.client.fluent.Form; | ||
| import org.apache.http.client.methods.HttpPost; | ||
| import org.apache.http.entity.StringEntity; | ||
| import org.apache.http.impl.client.HttpClients; | ||
| import org.apache.http.message.BasicHeader; | ||
| import org.json.JSONObject; | ||
|
|
||
| import java.io.IOException; | ||
| import java.util.ArrayList; | ||
| import java.util.List; | ||
|
|
||
| public class UnsecureApacheApacheHttpClient extends ApacheHttpClient { | ||
|
|
||
| private Header[] defaultHeaders; | ||
|
|
||
| public UnsecureApacheApacheHttpClient(Form defaultHeaders) { | ||
| this.defaultHeaders = toHeadersArray(defaultHeaders); | ||
| } | ||
|
|
||
| @Override | ||
| public HttpResponse sendPOSTRequest(Form body, String endpoint) throws IOException { | ||
| org.apache.http.client.HttpClient client = HttpClients.createDefault(); | ||
|
|
||
| JSONObject jsonObject = convert(body); | ||
| StringEntity stringEntity = new StringEntity(jsonObject.toString()); | ||
|
|
||
| HttpPost httpRequest = new HttpPost(endpoint); | ||
| httpRequest.setEntity(stringEntity); | ||
| httpRequest.setHeaders(defaultHeaders); | ||
|
|
||
| return client.execute(httpRequest); | ||
| } | ||
|
|
||
| @Override | ||
| public HttpResponse sendGETRequest(Form body, String endpoint) { | ||
| throw new NotImplementedException(); | ||
| } | ||
|
|
||
| private Header[] toHeadersArray(Form form) { | ||
| List<NameValuePair> list = form.build(); | ||
| List<Header> result = new ArrayList<>(list.size()); | ||
| list.forEach(nameValuePair -> { | ||
| BasicHeader basicHeader = new BasicHeader(nameValuePair.getName(), nameValuePair.getValue()); | ||
| result.add(basicHeader); | ||
| }); | ||
|
|
||
| Header[] headers = new Header[result.size()]; | ||
| return result.toArray(headers); | ||
| } | ||
| } |
2 changes: 1 addition & 1 deletion
2
...rrywallet/manager/common/Destroyable.java → ...anager/common/interfaces/Destroyable.java
This file contains hidden or 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
52 changes: 52 additions & 0 deletions
52
Manager/src/main/java/io/raspberrywallet/manager/common/readers/Reader.java
This file contains hidden or 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,52 @@ | ||
| package io.raspberrywallet.manager.common.readers; | ||
|
|
||
| import org.apache.commons.lang.SerializationUtils; | ||
|
|
||
| import java.io.IOException; | ||
| import java.io.Serializable; | ||
| import java.net.URL; | ||
| import java.nio.file.Files; | ||
| import java.nio.file.Path; | ||
| import java.nio.file.Paths; | ||
| import java.nio.file.StandardOpenOption; | ||
|
|
||
| abstract class Reader <T extends Serializable> { | ||
|
|
||
| final static String WALLET_DIR = "/opt/wallet/"; | ||
|
|
||
| private Path pathToFile; | ||
|
|
||
| abstract String getFilePath(); | ||
|
|
||
| T read() { | ||
| try { | ||
| return (T)SerializationUtils.deserialize(Files.readAllBytes(pathToFile)); | ||
| } catch (IOException e) { | ||
| throw new IllegalStateException(e); | ||
| } | ||
| } | ||
|
|
||
| void write(T input) { | ||
| if (pathToFile == null) | ||
| readFilePath(); | ||
|
|
||
| try { | ||
| byte[] serializedData = SerializationUtils.serialize(input); | ||
| Files.write(pathToFile, serializedData, | ||
| StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING ); | ||
| } catch (IOException e) { | ||
| e.printStackTrace(); | ||
| } | ||
| } | ||
|
|
||
| boolean fileExists() { | ||
| if (pathToFile == null) | ||
| readFilePath(); | ||
|
|
||
| return Files.exists(pathToFile); | ||
| } | ||
|
|
||
| private void readFilePath() { | ||
| pathToFile = Paths.get(getFilePath()); | ||
| } | ||
| } |
46 changes: 46 additions & 0 deletions
46
Manager/src/main/java/io/raspberrywallet/manager/common/readers/WalletUUIDReader.java
This file contains hidden or 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,46 @@ | ||
| package io.raspberrywallet.manager.common.readers; | ||
|
|
||
| import lombok.Synchronized; | ||
|
|
||
| import java.io.IOException; | ||
| import java.net.URL; | ||
| import java.nio.file.Files; | ||
| import java.nio.file.Path; | ||
| import java.nio.file.Paths; | ||
| import java.nio.file.StandardOpenOption; | ||
| import java.util.UUID; | ||
|
|
||
| public class WalletUUIDReader extends Reader<UUID> { | ||
|
|
||
| private final static String UUID_FILE_NAME = "wallet.uuid"; | ||
| private final static WalletUUIDReader INSTANCE = new WalletUUIDReader(); | ||
|
|
||
| private UUID walletUUID; | ||
|
|
||
| private WalletUUIDReader() {} | ||
|
|
||
| public static WalletUUIDReader getInstance() { | ||
| return INSTANCE; | ||
| } | ||
|
|
||
| @Synchronized | ||
| public UUID get() { | ||
| if (walletUUID != null) | ||
| return walletUUID; | ||
|
|
||
| if (fileExists()) { | ||
| walletUUID = read(); | ||
| return walletUUID; | ||
| } | ||
|
|
||
| walletUUID = UUID.randomUUID(); | ||
| write(walletUUID); | ||
| return walletUUID; | ||
| } | ||
|
|
||
| @Override | ||
| String getFilePath() { | ||
| return WALLET_DIR + UUID_FILE_NAME; | ||
| } | ||
|
|
||
| } | ||
12 changes: 12 additions & 0 deletions
12
Manager/src/main/java/io/raspberrywallet/manager/common/wrappers/Base64Secret.java
This file contains hidden or 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,12 @@ | ||
| package io.raspberrywallet.manager.common.wrappers; | ||
|
|
||
| import java.util.Base64; | ||
|
|
||
| public class Base64Secret extends Secret { | ||
|
|
||
| public Base64Secret(byte[] data) { | ||
| byte[] dataConverted = Base64.getEncoder().encode(data); | ||
| byteWrapper = new ByteWrapper(dataConverted); | ||
| } | ||
|
|
||
| } |
This file contains hidden or 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
19 changes: 19 additions & 0 deletions
19
Manager/src/main/java/io/raspberrywallet/manager/common/wrappers/Credentials.java
This file contains hidden or 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,19 @@ | ||
| package io.raspberrywallet.manager.common.wrappers; | ||
|
|
||
| import lombok.AllArgsConstructor; | ||
| import lombok.Getter; | ||
|
|
||
| import java.util.Base64; | ||
|
|
||
| @AllArgsConstructor | ||
| @Getter | ||
| public class Credentials { | ||
|
|
||
| private String name; | ||
| private String password; | ||
|
|
||
| public String getPasswordBase64() { | ||
| return Base64.getEncoder().encodeToString(password.getBytes()); | ||
| } | ||
|
|
||
| } |
35 changes: 35 additions & 0 deletions
35
Manager/src/main/java/io/raspberrywallet/manager/common/wrappers/Secret.java
This file contains hidden or 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,35 @@ | ||
| package io.raspberrywallet.manager.common.wrappers; | ||
|
|
||
| import io.raspberrywallet.manager.common.interfaces.Destroyable; | ||
|
|
||
| import java.util.Base64; | ||
|
|
||
| public class Secret implements Destroyable { | ||
|
|
||
| ByteWrapper byteWrapper; | ||
|
|
||
| public byte[] getData() { | ||
| return byteWrapper.getData(); | ||
| } | ||
|
|
||
| Secret() {} | ||
|
|
||
| /** | ||
| * Warning, this constructor assumes, that given data is encoded in Base64 | ||
| * @param base64Data base64 encoded data | ||
| */ | ||
| public Secret(String base64Data) { | ||
| byte[] decodedData = Base64.getDecoder().decode(base64Data); | ||
| byteWrapper = new ByteWrapper(decodedData); | ||
| } | ||
|
|
||
| @Override | ||
| public void destroy() { | ||
| byteWrapper.destroy(); | ||
| } | ||
|
|
||
| @Override | ||
| public int hashCode() { | ||
| return byteWrapper.hashCode(); | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.