@Override public Collection<Class<? extends Annotation>> supportedAnnotations() { //Order of the annotations matters because of annotation handling. return CollectionsHelper.listOf(RolesAllowed.class, Roles.class, RolesContainer.class, PermitAll.class, DenyAll.class); }
/** * Add a single-value header. Note that if method {@link #requestHeaders(Map)} is called after * this method, it will remove changes by this method. * * @param header header name * @param value header value * @return this instance */ public T requestHeader(String header, String value) { requestHeaders.put(header, CollectionsHelper.listOf(value)); return myInstance; }
/** * Add a single-value header. Note that if method {@link #headers(Map)} is called after * this method, it will remove changes by this method. * * @param header header name * @param value header value * @return this instance */ public Builder header(String header, String value) { this.headers.put(header, CollectionsHelper.listOf(value)); return this; }
/** * Add a single-value header. Note that if method {@link #responseHeaders(Map)} is called after * this method, it will remove changes by this method. * * @param header header name * @param value header value * @return this instance */ public T responseHeader(String header, String value) { responseHeaders.put(header, CollectionsHelper.listOf(value)); return myInstance; }
/** * Get all grants of a specific type determined by type's name. * * @param grantType type of grant (e.g. "role" or "scope") * @return list of grants of the specific type associated with this subject (may be empty) */ public List<Grant> grantsByType(String grantType) { return Collections.unmodifiableList(grantsByType.getOrDefault(grantType, CollectionsHelper.listOf())); }
/** * Create a config with no signed headers (e.g. signatures disabled) * * @return instance with no required headers */ public static HeadersConfig create() { return create(CollectionsHelper.listOf()); }
/** * Creates an {@code OverrideData} object containing no overrides. * * @return an empty object */ public static OverrideData empty() { return new OverrideData(CollectionsHelper.listOf()); }
/** * Create an instance from an array of scopes. * * @param scopes scopes required * @return configuration based on this list of scopes */ public static ScopesConfig create(String... scopes) { return new ScopesConfig(CollectionsHelper.listOf(scopes)); }
/** * Create a config with required headers only (e.g. no "if-present" headers). * * @param requiredHeaders headers that must be signed * @return instance with required headers */ public static HeadersConfig create(List<String> requiredHeaders) { return create(requiredHeaders, CollectionsHelper.listOf()); }
private String origUri(ProviderRequest providerRequest) { List<String> origUri = providerRequest.env().headers() .getOrDefault(Security.HEADER_ORIG_URI, CollectionsHelper.listOf()); if (origUri.isEmpty()) { origUri = CollectionsHelper.listOf(providerRequest.env().targetUri().getPath()); } try { return URLEncoder.encode(origUri.get(0), "UTF-8"); } catch (UnsupportedEncodingException e) { throw new SecurityException("UTF-8 must be supported for security to work", e); } }
private Map<String, List<String>> tracingHeaders(Tracer tracer, Span currentSpan) { Map<String, String> tracerHeaders = new HashMap<>(); tracer.inject(currentSpan.context(), Format.Builtin.HTTP_HEADERS, new TextMapInjectAdapter(tracerHeaders)); return new HashMap<>(tracerHeaders.entrySet() .stream() .collect(Collectors.toMap(Map.Entry::getKey, entry -> CollectionsHelper .listOf(entry.getValue())))); }
List<? extends OutboundSecurityProvider> resolveOutboundProvider(String providerName) { if (null != providerName) { return resolveProvider(OutboundSecurityProvider.class, providerName).map(CollectionsHelper::listOf) .orElse(CollectionsHelper.listOf()); } return providerSelectionPolicy.selectOutboundProviders(); }
private void register() throws IOException { Path target = target(path); Path dir = parentDir(target); WatchKey oldWatchKey = watchKey; watchKey = dir.register(watchService, CollectionsHelper.listOf(ENTRY_CREATE, ENTRY_DELETE, ENTRY_MODIFY) .toArray(new WatchEvent.Kind[0]), watchServiceModifiers.toArray(new WatchEvent.Modifier[0])); if (oldWatchKey != null) { oldWatchKey.cancel(); } }
private static OutboundSecurityResponse toBasicAuthOutbound(UserStore.User user) { String b64 = Base64.getEncoder() .encodeToString((user.login() + ":" + new String(user.password())).getBytes(StandardCharsets.UTF_8)); String basicAuthB64 = "basic " + b64; return OutboundSecurityResponse .withHeaders(CollectionsHelper.mapOf("Authorization", CollectionsHelper.listOf(basicAuthB64))); }
static OutboundConfig createFromConfig(Config providerConfig, OutboundTarget[] defaults) { Config config = providerConfig.get(CONFIG_OUTBOUND); List<OutboundTarget> configuredTargets = config.asList(OutboundTarget::create).orElse(CollectionsHelper.listOf()); boolean useDefaults = configuredTargets.stream().noneMatch(targetConfig -> "default".equals(targetConfig.name())) && (null != defaults); Builder builder = OutboundConfig.builder(); if (useDefaults) { //first add default values Arrays.stream(defaults).forEach(builder::addTarget); } //then add configured values configuredTargets.forEach(builder::addTarget); return builder.build(); }
/** * Create an instance from configuration (of endpoint). * * @param config config located on the key of this validator * @return configuration based on the config */ public static ScopesConfig create(Config config) { return new ScopesConfig(config.asList(String.class).orElse(CollectionsHelper.listOf())); }
/** * Create a new instance from configuration. * * @param config configuration located at header config * @return instance configured from config */ public static HeadersConfig create(Config config) { return create(config.get("always").asList(String.class).orElse(CollectionsHelper.listOf()), config.get("if-present").asList(String.class).orElse(CollectionsHelper.listOf())); }
static OutboundTarget create(Config c) { Builder builder = new Builder(); builder.config(c); builder.name(c.get(CONFIG_NAME).asString().get()); c.get(CONFIG_TRANSPORTS).asList(String.class).orElse(CollectionsHelper.listOf()) .forEach(builder::addTransport); c.get(CONFIG_HOSTS).asList(String.class).orElse(CollectionsHelper.listOf()) .forEach(builder::addHost); c.get(CONFIG_PATHS).asList(String.class).orElse(CollectionsHelper.listOf()) .forEach(builder::addPath); return builder.build(); }
private CompletionStage<AuthenticationResponse> enhance(Subject subject, AuthenticationResponse previousResponse) { String username = subject.principal().getName(); List<? extends Grant> grants = roleCache.computeValue(username, () -> getGrantsFromServer(username)) .orElse(CollectionsHelper.listOf()); AuthenticationResponse.Builder builder = AuthenticationResponse.builder(); builder.user(buildSubject(subject, grants)); previousResponse.service().ifPresent(builder::service); previousResponse.description().ifPresent(builder::description); builder.requestHeaders(previousResponse.requestHeaders()); AuthenticationResponse response = builder.build(); return CompletableFuture.completedFuture(response); }
static ConfigUser create(Config config) { ConfigUser cu = new ConfigUser(); cu.login = config.get("login").asString().get(); cu.password = config.get("password").asString().orElse("").toCharArray(); cu.roles.addAll(config.get("roles").asList(String.class).orElse(CollectionsHelper.listOf())); return cu; }