use of com.google.fleetengine.auth.token.factory.signer.SigningTokenException in project java-on-demand-rides-deliveries-stub-provider by googlemaps.
the class TokenServlet method doGet.
@Override
public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException {
ServletUtils.setStandardResponseHeaders(response);
String tokenType = request.getPathInfo().substring(1);
FleetEngineTokenType tokenTypeEnum;
try {
tokenTypeEnum = FleetEngineTokenType.valueOf(Ascii.toUpperCase(tokenType));
} catch (IllegalArgumentException e) {
logger.warning(String.format("Requested token for tokenType [%s], but did not find token.", tokenType));
response.sendError(HttpServletResponse.SC_BAD_REQUEST, String.format("Could not find token for the given type: %s", tokenType));
return;
}
FleetEngineToken authToken;
try {
switch(tokenTypeEnum) {
case DRIVER:
authToken = this.minter.getDriverToken(VehicleClaims.create());
break;
case CONSUMER:
authToken = this.minter.getConsumerToken(TripClaims.create());
break;
default:
logger.severe("Requested token for tokenType [%s], but it should not get here.");
response.sendError(HttpServletResponse.SC_BAD_REQUEST, String.format("Could not find token for the given type: %s", tokenType));
return;
}
} catch (SigningTokenException exception) {
throw new SampleProviderException("Error signing token", exception);
}
logger.info(String.format("Found token for type %s: %s", tokenType, authToken.jwt()));
response.getWriter().print(GsonProvider.get().toJson(authToken));
response.getWriter().flush();
}
use of com.google.fleetengine.auth.token.factory.signer.SigningTokenException in project java-fleetengine-auth by googlemaps.
the class FleetEngineAuthClientInterceptor method addAuthorizationHeader.
/**
* Adds the signed base64 encode JWT to the header.
*/
@VisibleForTesting
void addAuthorizationHeader(Metadata headers) {
try {
FleetEngineToken token = tokenProvider.getSignedToken();
headers.put(AUTHORIZATION_HEADER, String.format("Bearer %s", token.jwt()));
} catch (SigningTokenException e) {
throw new WritingAuthorizationHeaderException("Exception while getting token.", e);
}
}
Aggregations