private Set<String> expectedScopes(ProviderRequest request) { List<ScopeValidator.Scopes> expectedScopes = request.endpointConfig() .combineAnnotations(ScopeValidator.Scopes.class, EndpointConfig.AnnotationScope.values()); Set<String> result = new HashSet<>(); expectedScopes.stream() .map(ScopeValidator.Scopes::value) .map(Arrays::asList) .map(List::stream) .forEach(stream -> stream.map(ScopeValidator.Scope::value) .forEach(result::add)); return result; }
@Override public ScopesConfig fromAnnotations(EndpointConfig endpointConfig) { List<Scope> scopes = new ArrayList<>(); for (EndpointConfig.AnnotationScope value : EndpointConfig.AnnotationScope.values()) { List<Annotation> annotations = new ArrayList<>(); for (Class<? extends Annotation> annotation : supportedAnnotations()) { List<? extends Annotation> list = endpointConfig.combineAnnotations(annotation, value); annotations.addAll(list); } for (Annotation annot : annotations) { if (annot instanceof Scopes) { scopes.addAll(Arrays.asList(((Scopes) annot).value())); } else if (annot instanceof Scope) { scopes.add((Scope) annot); } } } return ScopesConfig.create(scopes); }
@Override protected AuthenticationResponse syncAuthenticate(ProviderRequest providerRequest) { if (!authenticate) { return AuthenticationResponse.abstain(); } List<LoginConfig> loginConfigs = providerRequest.endpointConfig() .combineAnnotations(LoginConfig.class, EndpointConfig.AnnotationScope.APPLICATION); try { return loginConfigs.stream() .filter(JwtAuthAnnotationAnalyzer::isMpJwt) .findFirst() .map(loginConfig -> authenticate(providerRequest, loginConfig)) .orElseGet(AuthenticationResponse::abstain); } catch (java.lang.SecurityException e) { return AuthenticationResponse.failed("Failed to process authentication header", e); } }
@Override public PolicyConfig fromAnnotations(EndpointConfig endpointConfig) { PolicyConfig.Builder resultBuilder = PolicyConfig.builder(); for (EndpointConfig.AnnotationScope value : EndpointConfig.AnnotationScope.values()) { List<Annotation> annotations = new ArrayList<>(); for (Class<? extends Annotation> annotation : supportedAnnotations()) { List<? extends Annotation> list = endpointConfig.combineAnnotations(annotation, value); annotations.addAll(list); } for (Annotation annotation : annotations) { if (annotation instanceof PolicyStatement) { PolicyStatement statement = (PolicyStatement) annotation; resultBuilder.from(PolicyConfig.builder().from(statement).build()); } } } return resultBuilder.build(); }
@Override public TimeConfig fromAnnotations(EndpointConfig endpointConfig) { TimeConfig.Builder builder = TimeConfig.builder(); for (EndpointConfig.AnnotationScope value : EndpointConfig.AnnotationScope.values()) { List<Annotation> annotations = new ArrayList<>(); for (Class<? extends Annotation> annotation : supportedAnnotations()) { List<? extends Annotation> list = endpointConfig.combineAnnotations(annotation, value); annotations.addAll(list); } for (Annotation annotation : annotations) { if (annotation instanceof DaysOfWeek) { DaysOfWeek daw = (DaysOfWeek) annotation; for (DayOfWeek dayOfWeek : daw.value()) { builder.addDaysOfWeek(dayOfWeek); } } else if (annotation instanceof TimesOfDay) { TimesOfDay tods = (TimesOfDay) annotation; for (TimeOfDay tod : tods.value()) { builder.addBetween(LocalTime.parse(tod.from()), LocalTime.parse(tod.to())); } } else if (annotation instanceof TimeOfDay) { TimeOfDay tod = (TimeOfDay) annotation; builder.addBetween(LocalTime.parse(tod.from()), LocalTime.parse(tod.to())); } } } return builder.build(); }
annotations.addAll(endpointConfig.combineAnnotations(annotation, value));
for (Class<? extends Annotation> annotation : annotations) { List<? extends Annotation> list = epConfig .combineAnnotations(annotation, EndpointConfig.AnnotationScope.values()); annotationConfig.addAll(list);
@Override protected AuthenticationResponse syncAuthenticate(ProviderRequest providerRequest) { if (!authenticate) { return AuthenticationResponse.abstain(); } List<LoginConfig> loginConfigs = providerRequest.endpointConfig() .combineAnnotations(LoginConfig.class, EndpointConfig.AnnotationScope.APPLICATION); try { return loginConfigs.stream() .filter(JwtAuthAnnotationAnalyzer::isMpJwt) .findFirst() .map(loginConfig -> authenticate(providerRequest, loginConfig)) .orElseGet(AuthenticationResponse::abstain); } catch (java.lang.SecurityException e) { return AuthenticationResponse.failed("Failed to process authentication header", e); } }
for (Class<? extends Annotation> annotation : annotations) { List<? extends Annotation> list = epConfig .combineAnnotations(annotation, EndpointConfig.AnnotationScope.values()); annotationConfig.addAll(list);