use of io.helidon.security.ProviderRequest in project helidon by oracle.
the class TimeValidatorTest method testDayOfWeekDeny.
@Test
public void testDayOfWeekDeny() {
// explicitly set time to 10:00
SecurityTime time = SecurityTime.builder().value(ChronoField.HOUR_OF_DAY, 12).value(ChronoField.MINUTE_OF_HOUR, 15).value(ChronoField.DAY_OF_WEEK, DayOfWeek.SUNDAY.getValue()).build();
Errors.Collector collector = Errors.collector();
SecurityEnvironment env = SecurityEnvironment.builder().time(time).build();
ProviderRequest request = mock(ProviderRequest.class);
when(request.env()).thenReturn(env);
validator.validate(timeConfig, collector, request);
if (collector.collect().isValid()) {
fail("Should have failed, as 12:15 is not in supported times");
}
}
use of io.helidon.security.ProviderRequest in project helidon by oracle.
the class TimeValidatorTest method testBetweenTimesAndDayOfWekPermit.
@Test
public void testBetweenTimesAndDayOfWekPermit() {
// explicitly set time to 10:00
SecurityTime time = SecurityTime.builder().value(ChronoField.HOUR_OF_DAY, 10).value(ChronoField.MINUTE_OF_HOUR, 0).value(ChronoField.DAY_OF_WEEK, DayOfWeek.TUESDAY.getValue()).build();
Errors.Collector collector = Errors.collector();
SecurityEnvironment env = SecurityEnvironment.builder().time(time).build();
ProviderRequest request = mock(ProviderRequest.class);
when(request.env()).thenReturn(env);
validator.validate(timeConfig, collector, request);
collector.collect().checkValid();
}
use of io.helidon.security.ProviderRequest in project helidon by oracle.
the class TimeValidatorTest method testBetweenTimesDeny.
@Test
public void testBetweenTimesDeny() {
// explicitly set time to 10:00
SecurityTime time = SecurityTime.builder().value(ChronoField.HOUR_OF_DAY, 12).value(ChronoField.MINUTE_OF_HOUR, 15).value(ChronoField.DAY_OF_WEEK, DayOfWeek.TUESDAY.getValue()).build();
Errors.Collector collector = Errors.collector();
SecurityEnvironment env = SecurityEnvironment.builder().time(time).build();
ProviderRequest request = mock(ProviderRequest.class);
when(request.env()).thenReturn(env);
validator.validate(timeConfig, collector, request);
if (collector.collect().isValid()) {
fail("Should have failed, as 12:15 is not in supported times");
}
}
use of io.helidon.security.ProviderRequest in project helidon by oracle.
the class GoogleTokenProvider method syncAuthenticate.
@Override
protected AuthenticationResponse syncAuthenticate(ProviderRequest providerRequest) {
Optional<String> maybeToken;
try {
maybeToken = tokenHandler.extractToken(providerRequest.env().headers());
} catch (Exception e) {
return failInvalidRequest(e);
}
SecurityContext sContext = providerRequest.securityContext();
return maybeToken.map(token -> cachedResponse(token, sContext.tracer(), sContext.tracingSpan())).orElseGet(this::failNoToken);
}
use of io.helidon.security.ProviderRequest in project helidon by oracle.
the class GoogleTokenProviderTest method testInboundMissingToken.
@Test
public void testInboundMissingToken() throws ExecutionException, InterruptedException {
ProviderRequest inboundRequest = createInboundRequest("OtherHeader", "tearer " + TOKEN_VALUE);
AuthenticationResponse response = provider.authenticate(inboundRequest).toCompletableFuture().get();
assertThat(response.status(), is(SecurityResponse.SecurityStatus.FAILURE));
assertThat(response.statusCode().orElse(200), is(401));
assertThat(response.responseHeaders().get("WWW-Authenticate"), notNullValue());
}
Aggregations