package at.acdp.opcur.opc; /* * Copyright (c) 2016 Kevin Herron * * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * and Eclipse Distribution License v1.0 which accompany this distribution. * * The Eclipse Public License is available at * http://www.eclipse.org/legal/epl-v10.html * and the Eclipse Distribution License is available at * http://www.eclipse.org/org/documents/edl-v10.html. */ import java.util.Optional; import java.util.Set; import java.util.function.Function; import org.eclipse.milo.opcua.sdk.core.AccessLevel; import org.eclipse.milo.opcua.sdk.server.Session; import org.eclipse.milo.opcua.sdk.server.api.nodes.VariableNode; import org.eclipse.milo.opcua.sdk.server.nodes.AttributeContext; import org.eclipse.milo.opcua.sdk.server.nodes.delegates.AttributeDelegate; import org.eclipse.milo.opcua.sdk.server.nodes.delegates.DelegatingAttributeDelegate; import org.eclipse.milo.opcua.stack.core.UaException; import org.eclipse.milo.opcua.stack.core.types.builtin.unsigned.UByte; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import static org.eclipse.milo.opcua.stack.core.types.builtin.unsigned.Unsigned.ubyte; public class RestrictedAccessDelegate extends DelegatingAttributeDelegate { private static final Set INTERNAL_ACCESS = AccessLevel.READ_WRITE; private final Logger logger = LoggerFactory.getLogger(getClass()); private final Function> accessLevelsFn; public RestrictedAccessDelegate(Function> accessLevelsFn) { this(null, accessLevelsFn); } public RestrictedAccessDelegate(AttributeDelegate parent, Function> accessLevelsFn) { super(parent); this.accessLevelsFn = accessLevelsFn; } @Override public UByte getUserAccessLevel(AttributeContext context, VariableNode node) throws UaException { Optional identity = context.getSession().map(Session::getIdentityObject); Set accessLevels = identity.map(accessLevelsFn).orElse(INTERNAL_ACCESS); return ubyte(AccessLevel.getMask(accessLevels)); } }