use of com.google.fleetengine.auth.token.FleetEngineToken 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.FleetEngineToken in project java-fleetengine-auth by googlemaps.
the class FleetEngineTokenFactoryTest method createCustomToken_returnsCustomTokenType.
@Test
public void createCustomToken_returnsCustomTokenType() {
FleetEngineTokenFactory factory = new FleetEngineTokenFactory(clock, FleetEngineTokenFactorySettings.builder().build());
FleetEngineToken signedToken = factory.createCustomToken(TripClaims.create(TEST_TRIP_ID));
assertThat(signedToken.tokenType()).isEqualTo(CUSTOM);
}
use of com.google.fleetengine.auth.token.FleetEngineToken in project java-fleetengine-auth by googlemaps.
the class FleetEngineTokenFactoryTest method createTrustedDriverToken_whenVehicleClaimsWildAndTaskClaimsNOTWild_claimIsNOTWild.
@Test
public void createTrustedDriverToken_whenVehicleClaimsWildAndTaskClaimsNOTWild_claimIsNOTWild() {
FleetEngineTokenFactorySettings settings = FleetEngineTokenFactorySettings.builder().setAudience(FAKE_AUDIENCE).build();
FleetEngineTokenFactory factory = new FleetEngineTokenFactory(clock, settings);
FleetEngineToken token = factory.createTrustedDeliveryDriverToken(DeliveryVehicleClaims.create(), TaskClaims.create(TEST_TASK_ID));
assertThat(token.authorizationClaims().isWildcard()).isFalse();
}
use of com.google.fleetengine.auth.token.FleetEngineToken in project java-fleetengine-auth by googlemaps.
the class FleetEngineTokenFactoryTest method createTrustedDriverToken_whenVehicleClaimsNOTWildAndTaskClaimsWild_claimIsNOTWild.
@Test
public void createTrustedDriverToken_whenVehicleClaimsNOTWildAndTaskClaimsWild_claimIsNOTWild() {
FleetEngineTokenFactorySettings settings = FleetEngineTokenFactorySettings.builder().setAudience(FAKE_AUDIENCE).build();
FleetEngineTokenFactory factory = new FleetEngineTokenFactory(clock, settings);
FleetEngineToken token = factory.createTrustedDeliveryDriverToken(DeliveryVehicleClaims.create(TEST_VEHICLE_ID), TaskClaims.create());
assertThat(token.authorizationClaims().isWildcard()).isFalse();
}
use of com.google.fleetengine.auth.token.FleetEngineToken in project java-fleetengine-auth by googlemaps.
the class FleetEngineTokenFactoryTest method createVehicleToken_returnsVehicleTokenType.
@Test
public void createVehicleToken_returnsVehicleTokenType() {
FleetEngineTokenFactory factory = new FleetEngineTokenFactory(clock, FleetEngineTokenFactorySettings.builder().build());
FleetEngineToken token = factory.createDriverToken(VehicleClaims.create(TEST_VEHICLE_ID));
assertThat(token.tokenType()).isEqualTo(DRIVER);
}
Aggregations