Checks access to a class or method based on any {@link controllers.deadbolt.Restrict} or
{@link controllers.deadbolt.Restrictions} annotations.
964698
@Before
    static void checkRestrictions() throws Throwable
    {
        DEADBOLT_HANDLER.beforeRoleCheck();

        RoleHolder roleHolder = getRoleHolder();
        RestrictionType restrictionType = getRestrictionType();
        if (restrictionType == RestrictionType.DYNAMIC)
        {
            handleDynamicChecks(roleHolder);
        }
        else if (restrictionType == RestrictionType.STATIC)
        {
            handleStaticChecks(roleHolder);
        }
        else if (restrictionType == RestrictionType.BASIC)
        {
            handleRoleHolderPresent(roleHolder);
        }
    }
309139
public boolean isMethodAllowed(String method) {

		return HttpMethod.isValidMethod(method) && (allowedMethods.isEmpty() || allowedMethods.contains(method));
	}
1368358
private <T> void check(T t, BiConsumer<T, AddOnModel> specific) {
        if (!shouldCheck()) {
            return;
        }
        secureAccess.doElevated(this::getAddOnModelForClassLoader)
            .ifPresent(addOnModel ->
                    secureAccess.doElevated(() -> specific.accept(t, addOnModel)));
    }
817632
@Override
	public final boolean isLocked(int handle) throws DataStoreException 
    {
        if (SAFE_MODE) checkHandle(handle);
		return locks.get(handle);
	}
888481
@edu.umd.cs.findbugs.annotations.SuppressFBWarnings(value = "EXS_EXCEPTION_SOFTENING_RETURN_FALSE", justification = "No other simple way to determine whether class exists")
    private boolean checkConfusedName(String methodOrVariableName, String signature) {
        try {
            String name = methodOrVariableName.toLowerCase(Locale.ENGLISH);
            if ((name.endsWith("map") || (name.endsWith("set") && !name.endsWith("toset")) || name.endsWith("list") || name.endsWith("queue"))
                    && signature.startsWith("Ljava/util/")) {
                String clsName = SignatureUtils.stripSignature(signature);
                JavaClass cls = Repository.lookupClass(clsName);
                if ((cls.implementationOf(mapInterface) && !name.endsWith("map")) || (cls.implementationOf(setInterface) && !name.endsWith("set"))
                        || ((cls.implementationOf(listInterface) || cls.implementationOf(queueInterface)) && !name.endsWith("list")
                                && !name.endsWith("queue"))) {
                    return true;
                }
            }
        } catch (ClassNotFoundException cnfe) {
            bugReporter.reportMissingClass(cnfe);
        }

        return false;
    }
918959
private int checkSecurity(String strClassResource, String strSecurityMap, int iAccessType, int iLevel)
    {
        int iAccessAllowed = Constants.ACCESS_DENIED;

        if (strSecurityMap == null)
            return iAccessAllowed;  // Denied
        if (LOGIN_REQUIRED.equalsIgnoreCase(strSecurityMap))
            return Constants.LOGIN_REQUIRED;  // Denied
        if (CREATE_USER_REQUIRED.equalsIgnoreCase(strSecurityMap))
            return Constants.CREATE_USER_REQUIRED;  // Denied
    	int startThin = strClassResource.indexOf(Constants.THIN_SUBPACKAGE, 0);
    	if (startThin != -1)	// Remove the ".thin" reference
    		strClassResource = strClassResource.substring(0, startThin) + strClassResource.substring(startThin + Constants.THIN_SUBPACKAGE.length());
        
        if (this.classMatch(strClassResource, BASE_CLASS))
            return Constants.NORMAL_RETURN;   // Allow access to all base classes
        StringTokenizer tokenizer = new StringTokenizer(strSecurityMap, TOKENS);
        try {
            while (tokenizer.hasMoreTokens())
            {
                String strClass = tokenizer.nextToken();
                String strAccess = tokenizer.nextToken();
                int iClassAccessType = Constants.READ_ACCESS;
                iClassAccessType = Integer.parseInt(strAccess);
                String strLevel = tokenizer.nextToken();
                int iClassLevel = Constants.LOGIN_USER;
                iClassLevel = Integer.parseInt(strLevel);
                
                if (this.classMatch(strClassResource, strClass))
                    if (iAccessType <= iClassAccessType)
                        if (iLevel >= iClassLevel)
                {
                    iAccessAllowed = Constants.NORMAL_RETURN;
                }
            }
        } catch (NoSuchElementException ex) {
            // Done
        } catch (NumberFormatException ex) {
            ex.printStackTrace();
        }
        
        if (("1"/*DBConstants.ANON_USER_ID*/.equals(this.getProperty(Params.USER_ID)))
                || (this.getProperty(Params.USER_ID) == null))
            if (iAccessAllowed == Constants.ACCESS_DENIED)
                iAccessAllowed = Constants.LOGIN_REQUIRED;  // For anonymous access, logging in will always get you more
        
        return iAccessAllowed;
    }
11052
public static void checkProxyPackageAccess(Class<?> clazz) {
        SecurityManager s = System.getSecurityManager();
        if (s != null) {
            // check proxy interfaces if the given class is a proxy class
            if (Proxy.isProxyClass(clazz)) {
                for (Class<?> intf : clazz.getInterfaces()) {
                    checkPackageAccess(intf);
                }
            }
        }
    }
515571
private boolean parseClassSecurity(Class<?> cls, SecurityContext sc) {

        // try DenyAll
        DenyAll denyAll = cls.getAnnotation(DenyAll.class);
        if (denyAll != null) {
            if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) {
                Tr.debug(tc, "Found class level @DenyAll - authorization denied for " + cls.getName());
            }
            return false;
        } else { // try RolesAllowed

            RolesAllowed rolesAllowed = cls.getAnnotation(RolesAllowed.class);
            if (rolesAllowed != null) {

                String[] theseroles = rolesAllowed.value();
                if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) {
                    Tr.debug(
                             tc,
                             "found RolesAllowed in class level: {} "
                                 + cls.getName(),
                             new Object[] { theseroles });
                }
                if (!ensureAuthentication(sc)) {
                    return false;
                }
                if (!isUserInRole(sc, Arrays.asList(theseroles), false)) {
                    return false;
                }
                return true;
            } else { // try PermitAll
//				PermitAll permitAll = cls.getAnnotation(PermitAll.class);
                return true;
            }

        }

    }
645222
private boolean checkRestrictorService(RestrictorCheck pCheck, Object ... args) {
        try {
            ServiceReference[] serviceRefs = bundleContext.getServiceReferences(Restrictor.class.getName(),null);
            if (serviceRefs != null) {
                boolean ret = true;
                boolean found = false;
                for (ServiceReference serviceRef : serviceRefs) {
                    Restrictor restrictor = (Restrictor) bundleContext.getService(serviceRef);
                    if (restrictor != null) {
                        ret = ret && pCheck.check(restrictor,args);
                        found = true;
                    }
                }
                return found && ret;
            } else {
                return false;
            }
        } catch (InvalidSyntaxException e) {
            // Will not happen, since we dont use a filter here
            throw new IllegalArgumentException("Impossible exception (we don't use a filter for fetching the services)",e);
        }
    }
394595
private function _checkCurrentLocks()
    {
        foreach ($this->_classHierarchy as $classInfo) {
            // FATAL: If any part of our class hierarchy is already locked ("is
            // being compiled right now", higher up the call stack), then it's a
            // bad map with circular "import"-statements.
            // NOTE: This specifically protects against the dangerous scenario
            // of importing classes derived from our hierarchy but whose
            // classname isn't in the current class hierarchy, so they weren't
            // blocked by the "import-target sanity checks". So when they get
            // to their own sub-compilation, their class hierarchy is checked
            // here and we'll discover their circular inheritance.
            if (isset($this->_propertyMapCache->compilerLocks[$classInfo['className']])) {
                // NOTE: strictClassName goes in "arg1" because it's being
                // compiled earlier than us, so we're definitely the "arg2".
                throw new CircularPropertyMapException(
                    $classInfo['strictClassName'],
                    $this->_strictSolveClassName
                );
            }
        }
    }
1066918
private Map<Method, Class<? extends Annotation>> getControllerMethods(Class<? extends Controller> controllerClass) {
        // collect the annotated methods
        Map<Method, Class<? extends Annotation>> controllerMethods = new LinkedHashMap<>();

        // discover all annotated controllers methods
        for (Method method : ClassUtils.getDeclaredMethods(controllerClass)) {
            for (Annotation annotation : method.getAnnotations()) {
                Class<? extends Annotation> annotationClass = annotation.annotationType();
                if (httpMethodAnnotationClasses.contains(annotationClass)) {
                    controllerMethods.put(method, annotationClass);
                    break;
                }
            }
        }

        return controllerMethods;
    }
222676
@Override
  public Description matchMethodInvocation(MethodInvocationTree tree, VisitorState state) {
    if (!HAS_MUST_BE_CLOSED_ANNOTATION.matches(tree, state)) {
      return NO_MATCH;
    }
    if (CONSTRUCTOR.matches(tree, state)) {
      return NO_MATCH;
    }
    return matchNewClassOrMethodInvocation(tree, state);
  }
458430
public static Method getAccessibleMethodByName(final Class clazz, final String methodName) {
		Validate.notNull(clazz, "clazz can't be null");
		Validate.notEmpty(methodName, "methodName can't be blank");

		for (Class<?> searchType = clazz; searchType != Object.class; searchType = searchType.getSuperclass()) {
			Method[] methods = searchType.getDeclaredMethods();
			for (Method method : methods) {
				if (method.getName().equals(methodName)) {
					makeAccessible(method);
					return method;
				}
			}
		}
		return null;
	}
318593
@Override
    public boolean hasAccessToWebResource(String resource, String... methods) {

        String appName = getApplicationName();
        SecurityMetadata securityMetadata = WebConfigUtils.getSecurityMetadata();
        SecurityConstraintCollection collection = null;
        if (securityMetadata != null) {
            collection = securityMetadata.getSecurityConstraintCollection();
        }
        if (null != collection) {

            AuthorizationService authService = SecurityContextHelper.getAuthorizationService();
            Subject callerSubject = getCallerSubject();

            List<MatchResponse> matchResponses = collection.getMatchResponses(resource, methods);

            for (MatchResponse response : matchResponses) {

                if (response.equals(MatchResponse.NO_MATCH_RESPONSE)) {
                    // There are no constraints so user has access
                    return true;
                }

                if (response.isAccessPrecluded()) {
                    //This methods access is precluded proceed to next method
                    continue;
                }

                List<String> roles = response.getRoles();

                if (roles != null && !roles.isEmpty()) {
                    if (authService.isAuthorized(appName, roles, callerSubject)) {
                        return true;
                    }
                } else {
                    // there are no roles and access is not precluded the user has access
                    return true;
                }
            }
        }
        return false;
    }
1373676
private List<Class<?>> getValidJPAAnnotationsFromMethod(Class<?> clazz, Method method, int numberOfParams,
            Class<?> entityClazz)
    {
        List<Class<?>> annotations = new ArrayList<Class<?>>();

        for (Annotation methodAnnotation : method.getAnnotations())
        {
            Class<?> methodAnnotationType = methodAnnotation.annotationType();

            if (isValidJPAEntityListenerAnnotation(methodAnnotationType))
            {

                // verify method signature

                // verify exceptions
                boolean hasUncheckedExceptions = false;
                for (Class<?> exception : method.getExceptionTypes())
                {
                    if (!ReflectUtils.hasSuperClass(RuntimeException.class, exception))
                    {
                        hasUncheckedExceptions = true;
                        break;
                    }
                }

                if (hasUncheckedExceptions)
                {
                    log.info("Skipped method(" + clazz.getName() + "." + method.getName()
                            + ") Must not throw unchecked exceptions.");
                    continue;
                }

                // return type must be "void"
                if (!method.getReturnType().getSimpleName().equals("void"))
                {
                    log.info("Skipped method(" + clazz.getName() + "." + method.getName()
                            + ") Must have \"void\" return type.");
                    continue;
                }
                // argument must be an Entity or Object
                Class<?>[] paramTypes = method.getParameterTypes();
                if (paramTypes.length != numberOfParams)
                {
                    log.info("Skipped method(" + clazz.getName() + "." + method.getName() + ") Must have "
                            + numberOfParams + " parameter.");
                    continue;
                }

                if (numberOfParams == 1)
                {
                    Class<?> parameter = paramTypes[0];
                    if (!(parameter != null && parameter.isAssignableFrom(entityClazz)))
                    {
                        log.info("Skipped method(" + clazz.getName() + "." + method.getName()
                                + ") Must have only 1 \"Object\" type parameter.");
                        continue;
                    }
                }

                annotations.add(methodAnnotationType);
            }
        }
        return annotations;
    }
450823
private void checkAnonymous(FieldDescriptorDef fieldDef, String checkLevel) throws ConstraintException
    {
        if (CHECKLEVEL_NONE.equals(checkLevel))
        {
            return;
        }

        String access = fieldDef.getProperty(PropertyHelper.OJB_PROPERTY_ACCESS);

        if (!"anonymous".equals(access))
        {
            throw new ConstraintException("The access property of the field "+fieldDef.getName()+" defined in class "+fieldDef.getOwner().getName()+" cannot be changed");
        }

        if ((fieldDef.getName() == null) || (fieldDef.getName().length() == 0))
        {
            throw new ConstraintException("An anonymous field defined in class "+fieldDef.getOwner().getName()+" has no name");
        }
    }
966867
public static boolean hasMethod(Class<?> targetClass, String methodName, Class... parameterTypes) {
        try {
            targetClass.getMethod(methodName, parameterTypes);
            return true;
        } catch (NoSuchMethodException e) {
            return false;
        }
    }