-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Updated authorisation to use token and implemented deserialiser for e…
…poch seconds (#27) * Updated authentication implementation to use token with client_id and scope for more granular access control * Made scope configuration mandatory without a default value * Implemented converters for epoch second to use for auth response
- Loading branch information
Showing
20 changed files
with
359 additions
and
92 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
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
39 changes: 39 additions & 0 deletions
39
...main/java/com/opencredo/connect/venafi/tpp/log/Deserializer/EpochSecondsDeserializer.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,39 @@ | ||
package com.opencredo.connect.venafi.tpp.log.Deserializer; | ||
|
||
import com.google.gson.JsonDeserializationContext; | ||
import com.google.gson.JsonDeserializer; | ||
import com.google.gson.JsonElement; | ||
import com.google.gson.JsonParseException; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import java.lang.reflect.Type; | ||
import java.time.Instant; | ||
import java.time.ZoneOffset; | ||
import java.time.ZonedDateTime; | ||
import java.time.format.DateTimeParseException; | ||
|
||
public class EpochSecondsDeserializer implements JsonDeserializer<ZonedDateTime> { | ||
private static final Logger log = LoggerFactory.getLogger(EpochSecondsDeserializer.class); | ||
|
||
private ZonedDateTime getParsedDate(String dateTimeString) { | ||
ZonedDateTime zonedDateTime; | ||
try { | ||
Instant instant = Instant.ofEpochSecond(Long.parseLong(dateTimeString)); | ||
zonedDateTime = ZonedDateTime.ofInstant(instant, ZoneOffset.UTC.normalized()); | ||
} catch (DateTimeParseException e) { | ||
log.debug("Failed to parse to ZonedDateTime format", e); | ||
throw new JsonParseException("Unable to deserialize [" + dateTimeString + "] to a ZoneDateTime.", e); | ||
} | ||
return zonedDateTime; | ||
} | ||
|
||
@Override | ||
public ZonedDateTime deserialize(JsonElement jsonElement, Type type, JsonDeserializationContext jsonDeserializationContext) throws JsonParseException { | ||
if (jsonElement.isJsonNull() || jsonElement.getAsString().isEmpty() || !jsonElement.getAsString().chars().allMatch(Character::isDigit)) { | ||
throw new JsonParseException("Unable to deserialize [" + jsonElement + "] to a ZoneDateTime."); | ||
} | ||
String json = jsonElement.getAsString(); | ||
return getParsedDate(json); | ||
} | ||
} |
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
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
8 changes: 5 additions & 3 deletions
8
src/main/java/com/opencredo/connect/venafi/tpp/log/api/TppPlatformAuthorization.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 |
---|---|---|
@@ -1,16 +1,18 @@ | ||
package com.opencredo.connect.venafi.tpp.log.api; | ||
|
||
import com.opencredo.connect.venafi.tpp.log.model.Credentials; | ||
import com.opencredo.connect.venafi.tpp.log.model.TppRefreshToken; | ||
import com.opencredo.connect.venafi.tpp.log.model.TppToken; | ||
import feign.Headers; | ||
import feign.RequestLine; | ||
|
||
public interface TppPlatformAuthorization { | ||
|
||
|
||
@RequestLine("POST /vedsdk/authorize/") | ||
@RequestLine("POST /vedauth/authorize/") | ||
@Headers("Content-Type: application/json") | ||
TppToken getToken(Credentials credentials); | ||
|
||
|
||
@RequestLine("POST /vedauth/authorize/token") | ||
@Headers("Content-Type: application/json") | ||
TppToken refreshToken(TppRefreshToken refreshToken); | ||
} |
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
17 changes: 11 additions & 6 deletions
17
src/main/java/com/opencredo/connect/venafi/tpp/log/model/Credentials.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 |
---|---|---|
@@ -1,12 +1,17 @@ | ||
package com.opencredo.connect.venafi.tpp.log.model; | ||
|
||
public class Credentials { | ||
//These are uppercase currently to allow GSON to auto convert them to JSON without needing annotations. | ||
private String Username; | ||
private String Password; | ||
//client_id to allow GSON to auto convert them to JSON without needing annotations. | ||
|
||
public Credentials(String username, String password) { | ||
Username = username; | ||
Password = password; | ||
private String username; | ||
private String password; | ||
private String client_id; | ||
private String scope; | ||
|
||
public Credentials(String username, String password, String scope, String client_id) { | ||
this.username = username; | ||
this.password = password; | ||
this.client_id = client_id; | ||
this.scope = scope; | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
src/main/java/com/opencredo/connect/venafi/tpp/log/model/TppRefreshToken.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,12 @@ | ||
package com.opencredo.connect.venafi.tpp.log.model; | ||
|
||
public class TppRefreshToken { | ||
|
||
private String refresh_token; | ||
private String client_id; | ||
|
||
public TppRefreshToken(String refresh_token, String client_id) { | ||
this.refresh_token = refresh_token; | ||
this.client_id = client_id; | ||
} | ||
} |
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
Oops, something went wrong.