Search in sources :

Example 81 with SecurityContext

use of io.helidon.security.SecurityContext in project helidon by oracle.

the class PolicyValidatorTest method testSimplePolicyExecutor.

@Test
public void testSimplePolicyExecutor() {
    PolicyValidator pv = PolicyValidator.builder().addExecutor(new MyPolicyExecutor()).build();
    SecurityContext sc = mock(SecurityContext.class);
    when(sc.isAuthenticated()).thenReturn(true);
    ProviderRequest request = mock(ProviderRequest.class);
    when(request.securityContext()).thenReturn(sc);
    when(request.getObject()).thenReturn(Optional.empty());
    PolicyValidator.PolicyConfig pc = PolicyValidator.PolicyConfig.builder().statement(PolicyClass.class.getName() + ".isAuthenticated").build();
    Errors.Collector collector = Errors.collector();
    pv.validate(pc, collector, request);
    collector.collect().checkValid();
}
Also used : Errors(io.helidon.common.Errors) SecurityContext(io.helidon.security.SecurityContext) ProviderRequest(io.helidon.security.ProviderRequest) Test(org.junit.jupiter.api.Test)

Aggregations

SecurityContext (io.helidon.security.SecurityContext)81 Test (org.junit.jupiter.api.Test)47 SecurityEnvironment (io.helidon.security.SecurityEnvironment)38 ProviderRequest (io.helidon.security.ProviderRequest)32 EndpointConfig (io.helidon.security.EndpointConfig)30 Subject (io.helidon.security.Subject)25 AuthenticationResponse (io.helidon.security.AuthenticationResponse)23 Security (io.helidon.security.Security)22 Config (io.helidon.config.Config)21 OutboundSecurityResponse (io.helidon.security.OutboundSecurityResponse)19 Routing (io.helidon.webserver.Routing)17 Principal (io.helidon.security.Principal)16 Optional (java.util.Optional)15 WebSecurity (io.helidon.security.integration.webserver.WebSecurity)14 List (java.util.List)13 AuthorizationResponse (io.helidon.security.AuthorizationResponse)11 Map (java.util.Map)11 MediaType (io.helidon.common.http.MediaType)10 WebServer (io.helidon.webserver.WebServer)10 HashMap (java.util.HashMap)10