Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
* Copyright (c) 2018, 2020 Oracle and/or its affiliates. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.helidon.security;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import java.util.Optional;
import java.util.function.Supplier;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.stream.Collectors;
import io.helidon.security.util.AbacSupport;
/**
* A request sent to security providers.
* Contains all information that may be needed to authenticate or authorize a request:
*
*
User's subject: {@link #subject()} - if user is authenticated
*
Service subject: {@link #service()} - if service is authenticated
*
Environment information: {@link #env()} - path, method etc.
*
Object: {@link #getObject()} - target resource, if provided by user
*
Security context: {@link #securityContext()} - current subjects and information about security context of this
* request
*/
public class ProviderRequest implements AbacSupport {
private static final Logger LOGGER = Logger.getLogger(ProviderRequest.class.getName());
private final Map contextRoot = new HashMap<>();
private final Optional subject;
private final Optional service;
private final SecurityEnvironment env;
private final Optional resource;
private final SecurityContext context;
private final EndpointConfig epConfig;
ProviderRequest(SecurityContext context,
Map> resources) {
ObjectWrapper object = null;
for (Map.Entry> entry : resources.entrySet()) {
ObjectWrapper wrapper = new ObjectWrapper(entry.getValue());
contextRoot.put(entry.getKey(), wrapper);
if ("object".equals(entry.getKey())) {
object = wrapper;
}
}
this.env = context.env();
this.epConfig = context.endpointConfig();
this.context = context;
this.resource = Optional.ofNullable(object);
this.subject = context.user();
this.service = context.service();
contextRoot.put("env", env);
subject.ifPresent(user -> contextRoot.put("subject", user));
service.ifPresent(svc -> contextRoot.put("service", svc));
}
/**
* Get a value of a property from an object.
* If object implements {@link AbacSupport} the value is obtained through {@link AbacSupport#abacAttribute(String)}, if not,
* the value is obtained by reflection from a public field or a public getter method.
* The method name may be (for attribute called for example "audit"):
*
*
audit
*
getAudit
*
isAudit
*
shouldAudit
*
hasAudit
*
*
* @param object object to get attribute from
* @param key key of the attribute
* @return value of the attribute if found
*/
public static Optional