Search in sources :

Example 36 with SecurityLevel

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

the class TimeValidatorTest method initClass.

@BeforeAll
public static void initClass() {
    validator = TimeValidator.create();
    EndpointConfig ep = mock(EndpointConfig.class);
    TimeValidator.TimeOfDay tod = mock(TimeValidator.TimeOfDay.class);
    when(tod.from()).thenReturn("08:15:00");
    when(tod.to()).thenReturn("12:00");
    annotations.add(tod);
    TimeValidator.TimeOfDay tod2 = mock(TimeValidator.TimeOfDay.class);
    when(tod2.from()).thenReturn("12:30:00");
    when(tod2.to()).thenReturn("17:30");
    annotations.add(tod2);
    SecurityLevel appSecurityLevel = mock(SecurityLevel.class);
    SecurityLevel classSecurityLevel = mock(SecurityLevel.class);
    List<SecurityLevel> securityLevels = new ArrayList<>();
    securityLevels.add(appSecurityLevel);
    securityLevels.add(classSecurityLevel);
    when(ep.securityLevels()).thenReturn(securityLevels);
    when(classSecurityLevel.filterAnnotations(TimeValidator.TimeOfDay.class, EndpointConfig.AnnotationScope.CLASS)).thenReturn(List.of(tod, tod2));
    TimeValidator.DaysOfWeek dow = mock(TimeValidator.DaysOfWeek.class);
    when(dow.value()).thenReturn(new DayOfWeek[] { DayOfWeek.MONDAY, DayOfWeek.TUESDAY, DayOfWeek.WEDNESDAY, DayOfWeek.THURSDAY, DayOfWeek.FRIDAY });
    annotations.add(dow);
    when(classSecurityLevel.filterAnnotations(TimeValidator.DaysOfWeek.class, EndpointConfig.AnnotationScope.CLASS)).thenReturn(List.of(dow));
    timeConfig = validator.fromAnnotations(ep);
}
Also used : SecurityLevel(io.helidon.security.SecurityLevel) ArrayList(java.util.ArrayList) EndpointConfig(io.helidon.security.EndpointConfig) BeforeAll(org.junit.jupiter.api.BeforeAll)

Aggregations

SecurityLevel (io.helidon.security.SecurityLevel)36 EndpointConfig (io.helidon.security.EndpointConfig)30 ArrayList (java.util.ArrayList)26 ProviderRequest (io.helidon.security.ProviderRequest)25 Test (org.junit.jupiter.api.Test)22 Errors (io.helidon.common.Errors)17 Annotation (java.lang.annotation.Annotation)9 RolesAllowed (jakarta.annotation.security.RolesAllowed)8 DenyAll (jakarta.annotation.security.DenyAll)7 PermitAll (jakarta.annotation.security.PermitAll)6 AuthorizationResponse (io.helidon.security.AuthorizationResponse)5 LinkedList (java.util.LinkedList)5 List (java.util.List)5 SecurityEnvironment (io.helidon.security.SecurityEnvironment)3 AbacAnnotation (io.helidon.security.providers.abac.AbacAnnotation)3 Config (io.helidon.config.Config)2 AuthenticationResponse (io.helidon.security.AuthenticationResponse)2 Subject (io.helidon.security.Subject)2 Audited (io.helidon.security.annotations.Audited)2 Authenticated (io.helidon.security.annotations.Authenticated)2