Check access.

@throws EFapsException on error
195737
private void checkAccess()
        throws EFapsException
    {
        // check the access for the given instances
        final Map<Instance, Boolean> accessmap = new HashMap<Instance, Boolean>();
        for (final Entry<Type, List<Instance>> entry : this.typeMapping.entrySet()) {
            accessmap.putAll(entry.getKey().checkAccess(entry.getValue(), AccessTypeEnums.SHOW.getAccessType()));
        }
        this.elements.entrySet().removeIf(entry -> accessmap.size() > 0 && (!accessmap.containsKey(entry.getKey())
                        || !accessmap.get(entry.getKey())));
    }
96934
public void checkAccess(JimfsPath path) throws IOException {
    // just check that the file exists
    lookUpWithLock(path, Options.FOLLOW_LINKS).requireExists(path);
  }
578396
protected boolean hasAccess()
        throws EFapsException
    {
        //Admin_REST
        return Context.getThreadContext().getPerson().isAssigned(Role.get(
                        UUID.fromString("2d142645-140d-46ad-af67-835161a8d732")));
    }
505236
private void readFromDBAttributes()
        throws EFapsException
    {
        Connection con = null;
        try {
            con = Context.getConnection();
            Statement stmt = null;
            try {
                stmt = con.createStatement();

                final StringBuilder cmd = new StringBuilder("select ");
                for (final AttrName attrName : Person.AttrName.values()) {
                    cmd.append(attrName.sqlColumn).append(",");
                }
                cmd.append("0 as DUMMY ").append("from V_USERPERSON ").append("where V_USERPERSON.ID=").append(getId());

                final ResultSet resultset = stmt.executeQuery(cmd.toString());
                if (resultset.next()) {
                    for (final AttrName attrName : Person.AttrName.values()) {
                        final String tmp = resultset.getString(attrName.sqlColumn);
                        setAttrValue(attrName, tmp == null ? null : tmp.trim());
                    }
                }
                resultset.close();
            } catch (final SQLException e) {
                Person.LOG.error("read attributes for person with SQL statement is not " + "possible", e);
                throw new EFapsException(Person.class, "readFromDBAttributes.SQLException", e, getName(), getId());
            } finally {
                try {
                    if (stmt != null) {
                        stmt.close();
                    }
                    con.commit();
                } catch (final SQLException e) {
                    Person.LOG.error("close of SQL statement is not possible", e);
                }
            }
        } finally {
            try {
                if (con != null && !con.isClosed()) {
                    con.close();
                }
            } catch (final SQLException e) {
                throw new CacheReloadException("could not read child type ids", e);
            }
        }
    }
1286028
public function checkAccessToken($access_token = null)
    {
        $token = is_null($access_token) ? $this->access_token : $access_token;
        if (is_null($token)) return false;

        $rs = $this->api('getUserSettings', array('access_token' => $token));
        return isset($rs['response']);
    }
577271
int getAccess(PageContext pc) {
	if (pc == null) return ACCESS_PUBLIC;

	if (isPrivate(pc)) return ACCESS_PRIVATE;
	if (isPackage(pc)) return ACCESS_PACKAGE;
	return ACCESS_PUBLIC;
    }
1094308
def check_io_access(ioobj, access, is_file=False):
    '''  '''
    if ((is_file and not os.path.isfile(ioobj)) or
        (not is_file and not os.path.isdir(ioobj)) or
            not os.access(ioobj, access)):
            _objtype = "File" if is_file else "Directory"
            raise IOError("Error accessing %s: %s" % (_objtype, ioobj))
958919
public function detectAccessDenied(MvcEvent $event)
    {
        $response = $event->getResponse();
        if ($response->getStatusCode() == 403) {
            $event->setError('Access Denied');
            $event->stopPropagation(true);
        }
    }
116025
public static Status getStatus(final Instance _instance)
        throws EFapsException
    {
        Evaluation.LOG.debug("Retrieving Status for {}", _instance);
        long statusId = 0;
        if (_instance.getType().isCheckStatus()) {
            final Cache<String, Long> cache = AccessCache.getStatusCache();
            if (cache.containsKey(_instance.getKey())) {
                statusId = cache.get(_instance.getKey());
            } else {
                final PrintQuery print = new PrintQuery(_instance);
                print.addAttribute(_instance.getType().getStatusAttribute());
                print.executeWithoutAccessCheck();
                final Long statusIdTmp = print.getAttribute(_instance.getType().getStatusAttribute());
                statusId = statusIdTmp == null ? 0 : statusIdTmp;
                cache.put(_instance.getKey(), statusId);
            }
        }
        final Status ret = statusId > 0 ? Status.get(statusId) : null;
        Evaluation.LOG.debug("Retrieve Status: {}", ret);
        return ret;
    }
417736
public static void endAccessContext() {
        AccessContext.clearAccessContextOnThread();
        final AccessContext accessContext = SuspendedAccessContext.getAccessContextOnThread();
        if (accessContext != null) { // resume
            AccessContext.setAccessContextOnThread(accessContext);
            SuspendedAccessContext.clearAccessContextOnThread();
        }
    }
333440
public static boolean isTMMarkedRollback()
        throws EFapsException
    {
        try {
            return Context.TRANSMANAG.getStatus() == Status.STATUS_MARKED_ROLLBACK;
        } catch (final SystemException e) {
            throw new EFapsException(Context.class, "isTMMarkedRollback.SystemException", e);
        }
    }
152962
private void evalAccess()
        throws EFapsException
    {
        final List<Instance> instances = new ArrayList<>();
        while (step(this.selection.getInstSelects().values())) {
            for (final Entry<String, Select> entry : this.selection.getInstSelects().entrySet()) {
                final Object object = entry.getValue().getCurrent();
                if (object != null) {
                    if (object instanceof List) {
                        ((List<?>) object).stream()
                            .filter(Objects::nonNull)
                            .forEach(e -> instances.add((Instance) e));
                    } else {
                        instances.add((Instance) object);
                    }
                }
            }
        }
        for (final Entry<String, Select> entry : this.selection.getInstSelects().entrySet()) {
            entry.getValue().reset();
        }
        this.access = Access.get(AccessTypeEnums.READ.getAccessType(), instances);
    }
351083
public boolean checkAccess(AccessFlags flags){

        boolean isPublic = flags.is(AccessFlags.ACC_PUBLIC);
        boolean isProtected = flags.is(AccessFlags.ACC_PROTECTED);
        boolean isPrivate = flags.is(AccessFlags.ACC_PRIVATE);
        boolean isPackage = !(isPublic || isProtected || isPrivate);

        if ((showAccess == AccessFlags.ACC_PUBLIC) && (isProtected || isPrivate || isPackage))
            return false;
        else if ((showAccess == AccessFlags.ACC_PROTECTED) && (isPrivate || isPackage))
            return false;
        else if ((showAccess == 0) && (isPrivate))
            return false;
        else
            return true;
    }
875683
public static void stop()
        throws EFapsException
    {
        for (final QueueConnection queCon : JmsHandler.QUEUE2QUECONN.values()) {
            try {
                queCon.close();
            } catch (final JMSException e) {
                throw new EFapsException("JMSException", e);
            }
        }
        for (final TopicConnection queCon : JmsHandler.TOPIC2QUECONN.values()) {
            try {
                queCon.close();
            } catch (final JMSException e) {
                throw new EFapsException("JMSException", e);
            }
        }
        JmsHandler.TOPIC2QUECONN.clear();
        JmsHandler.QUEUE2QUECONN.clear();
        JmsHandler.NAME2DEF.clear();
    }
326369
public boolean hasAccess(final Instance _instance)
    {
        try {
            initialize();
        } catch (final EFapsException e) {
            LOG.error("Problems while evaluation access.", e);
        }
        return this.accessMap.containsKey(_instance) ? this.accessMap.get(_instance) : false;
    }
580200
public void execute(final OutputStream _out)
        throws EFapsException
    {
        final boolean hasAccess = super.getInstance().getType().hasAccess(super.getInstance(),
                                                                          AccessTypeEnums.CHECKOUT.getAccessType());
        if (!hasAccess) {
            throw new EFapsException(this.getClass(), "execute.NoAccess");
        }
        this.executeWithoutAccessCheck(_out);
    }
597887
protected function checkAccessPolicy($access_policy_name, Reference $ref)
	{
		// Allow by default
		if (empty($access_policy_name)) {
			return true;
		}

		if (!isset($this->access_policies[$access_policy_name])) {
			throw new \InvalidArgumentException('Unknown policy: '.$access_policy_name);
		}
		$access_policy = $this->access_policies[$access_policy_name];

		//debug_dump($access_policy, 'POLICY: '.$access_policy_name.' @ '.get_class($this));

		if ($this->auth->isAllMighty()) {
			return true;
		}

		switch ($access_policy['type']) {

			// anyone: Completely open for anyone
			case 'anyone':
				return true;

			// nobody: Nobody is allowed, except all mighty users.
			case 'nobody':
				return false;

			// anonymous: Only anonymous users allowed (not logged in)
			case 'anonymous':
				$user_id = $this->auth->getUserId();
				return $user_id === null;

			// user: All logged-in users allowed
			case 'user':
				$user_id = $this->auth->getUserId();
				return $user_id !== null;

			// owner: Owner must match current user
			case 'owner':
				if ($ref->isNullRef()) {
					// Everyone owns nothing :)
					return true;
				}
				$properties = $ref->properties;
				$user_id = $this->auth->getUserId();
				$owner_property = $access_policy['owner_property'];
				if (isset($access_policy['session_state'])) {
					$session_machine = $this->auth->getSessionMachine();
					if (!$session_machine || $session_machine->state != $access_policy['session_state']) {
						return false;
					}
				}
				return $user_id !== null ? $user_id == $properties[$owner_property] : $properties[$owner_property] === null;

			// role: Current user must have specified role ($ref is ignored)
			case 'role':
				return $this->auth->hasUserRoles($access_policy['required_role']);

			// These are done by SQL select.
			case 'condition':
				if ($ref->isNullRef()) {
					// Nonexistent entity has nulls everywhere
					// FIXME: Are we sure?
					return false;
				}
				$properties = $ref->properties;
				return !empty($properties['_access_policy_'.$access_policy_name]);

			// These are done by SQL select.
			case 'user_relation':
				if ($ref->isNullRef()) {
					// No relation to nonexistent entity.
					return false;
				}
				$properties = $ref->properties;
				return !empty($properties['_access_policy_'.$access_policy_name]);

			// unknown policies are considered unsafe
			default:
				return false;
		}

		// This should not happen.
		throw new \RuntimeException('Policy '.$policy.' did not decide.');
	}