Package javax.annotation.security

Examples of javax.annotation.security.RolesAllowed


      if (method.isAnnotationPresent(RolesAllowed.class)) {
        UserRole userPrincipal = securityContext.getUserPrincipal();
        if (userPrincipal == null && request.getUserPrincipal() == null)
          throw new UserNotLoginException("没有登录或者已经超时");
       
        RolesAllowed annotation = method
            .getAnnotation(RolesAllowed.class);
        String[] roles = annotation.value();

        boolean hasPermission = securityContext.isUserInRole(roles);

        if (!hasPermission)
          throw new AccessDeniedException("拒绝访问");
View Full Code Here


    */
    private int checkPermission(AnnotatedElement targetObject) {
        int perm = -1;
        if (log.isDebugEnabled()) log.debug("Checking user credentials to execute " + targetObject);
        if (targetObject != null) {
            RolesAllowed rolesAllowed = targetObject.getAnnotation(RolesAllowed.class);
            if (rolesAllowed != null) {
                if (log.isDebugEnabled()) log.debug("Detected roles for object " + rolesAllowed);
                for (String role : rolesAllowed.value()) {
                    if (perm != 1) {
                        perm = this.roleMembershipManagement.isInRole(role) ? 1 : 0;
                        if (log.isDebugEnabled() & (perm == 1)) log.debug("Authenticated user is member of role: " + role);
                    }
                }
View Full Code Here

      final Iterator<WebServiceDeclaration> ejbContainers = wsDeployment.getServiceEndpoints().iterator();

      while (ejbContainers.hasNext())
      {
         final WebServiceDeclaration ejbContainer = ejbContainers.next();
         final RolesAllowed allowedRoles = ejbContainer.getAnnotation(RolesAllowed.class);
         final boolean hasAllowedRoles = allowedRoles != null;

         if (hasAllowedRoles)
         {
            for (final String roleName : allowedRoles.value())
            {
               final SecurityRoleMetaData securityRoleMD = new SecurityRoleMetaData();

               securityRoleMD.setRoleName(roleName);
               securityRolesMD.add(securityRoleMD);
View Full Code Here

      // class not here, therefore not on method either
      return true;
    }
    // From now on we can use this class since it's there. I (Stef Epardaud) don't think we need to
    // remove the reference here and use reflection.
    RolesAllowed rolesAllowed = m.getAnnotation(RolesAllowed.class);
    if(rolesAllowed == null)
      return true;
    SecurityContext context = ResteasyProviderFactory.getContextData(SecurityContext.class);
    for(String role : rolesAllowed.value())
      if(context.isUserInRole(role))
        return true;
    return false;
  }
View Full Code Here

   protected boolean denyAll;

   public boolean accept(Class declaring, Method method)
   {
      if (declaring == null || method == null) return false;
      RolesAllowed allowed = (RolesAllowed) declaring.getAnnotation(RolesAllowed.class);
      RolesAllowed methodAllowed = method.getAnnotation(RolesAllowed.class);
      if (methodAllowed != null) allowed = methodAllowed;
      if (allowed != null)
      {
         rolesAllowed = allowed.value();
      }
View Full Code Here

    _lazyGenerator = lazyGenerator;
   
    DeclareRoles declareRoles
      = annotatedType.getJavaClass().getAnnotation(DeclareRoles.class);

    RolesAllowed rolesAllowed
      = annotatedType.getJavaClass().getAnnotation(RolesAllowed.class);
   
    if (declareRoles != null && rolesAllowed != null) {
      _declaredRoles = new String[declareRoles.value().length +
                                  rolesAllowed.value().length];

      System.arraycopy(declareRoles.value(), 0,
                       _declaredRoles, 0,
                       declareRoles.value().length);

      System.arraycopy(rolesAllowed.value(), 0,
                       _declaredRoles, declareRoles.value().length,
                       rolesAllowed.value().length);
    }
    else if (declareRoles != null) {
      _declaredRoles = declareRoles.value();
    }
    else if (rolesAllowed != null) {
      _declaredRoles = rolesAllowed.value();
    }
  }
View Full Code Here

            for (Class<?> clazz : ancestors(beanClass)) {

                if (!classPermissions.contains("*") || !classPermissions.contains(clazz.getName())){

                    RolesAllowed rolesAllowed = clazz.getAnnotation(RolesAllowed.class);
                    PermitAll permitAll = clazz.getAnnotation(PermitAll.class);

                    if (rolesAllowed != null && permitAll != null){
                        ejbModule.getValidation().fail(ejbName, "permitAllAndRolesAllowedOnClass", clazz.getName());
                    }

                    if (rolesAllowed != null) {
                        MethodPermission methodPermission = new MethodPermission();
                        methodPermission.getRoleName().addAll(asList(rolesAllowed.value()));
                        methodPermission.getMethod().add(new org.apache.openejb.jee.Method(ejbName, clazz.getName(), "*"));
                        assemblyDescriptor.getMethodPermission().add(methodPermission);

                        // Automatically add a role ref for any role listed in RolesAllowed
                        RemoteBean remoteBean = (RemoteBean) bean;
                        List<SecurityRoleRef> securityRoleRefs = remoteBean.getSecurityRoleRef();
                        for (String role : rolesAllowed.value()) {
                            securityRoleRefs.add(new SecurityRoleRef(role));
                        }
                    }

                    if (permitAll != null) {
                        MethodPermission methodPermission = new MethodPermission();
                        methodPermission.setUnchecked(true);
                        methodPermission.getMethod().add(new org.apache.openejb.jee.Method(ejbName, clazz.getName(), "*"));
                        assemblyDescriptor.getMethodPermission().add(methodPermission);
                    }
                }

                RunAs runAs = clazz.getAnnotation(RunAs.class);
                if (runAs != null && bean.getSecurityIdentity() == null) {
                    SecurityIdentity securityIdentity = new SecurityIdentity();
                    securityIdentity.setRunAs(runAs.value());
                    bean.setSecurityIdentity(securityIdentity);
                }

                DeclareRoles declareRoles = clazz.getAnnotation(DeclareRoles.class);
                if (declareRoles != null && bean instanceof RemoteBean){
                    RemoteBean remoteBean = (RemoteBean) bean;
                    List<SecurityRoleRef> securityRoleRefs = remoteBean.getSecurityRoleRef();
                    for (String role : declareRoles.value()) {
                        securityRoleRefs.add(new SecurityRoleRef(role));
                    }
                }
            }

            List<Method> seen = new ArrayList<Method>();

            for (Method method : classFinder.findAnnotatedMethods(RolesAllowed.class)) {
                checkConflictingSecurityAnnotations(method, ejbName, ejbModule, seen);
                RolesAllowed rolesAllowed = method.getAnnotation(RolesAllowed.class);
                MethodPermission methodPermission = new MethodPermission();
                methodPermission.getRoleName().addAll(asList(rolesAllowed.value()));
                methodPermission.getMethod().add(new org.apache.openejb.jee.Method(ejbName, method));
                assemblyDescriptor.getMethodPermission().add(methodPermission);

                // Automatically add a role ref for any role listed in RolesAllowed
                RemoteBean remoteBean = (RemoteBean) bean;
                List<SecurityRoleRef> securityRoleRefs = remoteBean.getSecurityRoleRef();
                for (String role : rolesAllowed.value()) {
                    securityRoleRefs.add(new SecurityRoleRef(role));
                }
            }

            for (Method method : classFinder.findAnnotatedMethods(PermitAll.class)) {
View Full Code Here

                /*
                 * Process annotations at the class level
                 */
                if (!classPermissions.contains("*") || !classPermissions.contains(clazz.getName())) {

                    RolesAllowed rolesAllowed = clazz.getAnnotation(RolesAllowed.class);
                    PermitAll permitAll = clazz.getAnnotation(PermitAll.class);

                    /*
                     * @RolesAllowed
                     */
                    if (rolesAllowed != null && permitAll != null) {
                        ejbModule.getValidation().fail(ejbName, "permitAllAndRolesAllowedOnClass", clazz.getName());
                    }

                    if (rolesAllowed != null) {
                        MethodPermission methodPermission = new MethodPermission();
                        methodPermission.getRoleName().addAll(asList(rolesAllowed.value()));
                        methodPermission.getMethod().add(new org.apache.openejb.jee.Method(ejbName, clazz.getName(), "*"));
                        assemblyDescriptor.getMethodPermission().add(methodPermission);

                        // Automatically add a role ref for any role listed in RolesAllowed
                        RemoteBean remoteBean = (RemoteBean) bean;
                        List<SecurityRoleRef> securityRoleRefs = remoteBean.getSecurityRoleRef();
                        for (String role : rolesAllowed.value()) {
                            securityRoleRefs.add(new SecurityRoleRef(role));
                        }
                    }

                    /*
                     * @PermitAll
                     */
                    if (permitAll != null) {
                        MethodPermission methodPermission = new MethodPermission();
                        methodPermission.setUnchecked(true);
                        methodPermission.getMethod().add(new org.apache.openejb.jee.Method(ejbName, clazz.getName(), "*"));
                        assemblyDescriptor.getMethodPermission().add(methodPermission);
                    }
                }

                /*
                 * @RunAs
                 */
                RunAs runAs = clazz.getAnnotation(RunAs.class);
                if (runAs != null && bean.getSecurityIdentity() == null) {
                    SecurityIdentity securityIdentity = new SecurityIdentity();
                    securityIdentity.setRunAs(runAs.value());
                    bean.setSecurityIdentity(securityIdentity);
                }

                /*
                 * @DeclareRoles
                 */
                DeclareRoles declareRoles = clazz.getAnnotation(DeclareRoles.class);
                if (declareRoles != null && bean instanceof RemoteBean) {
                    RemoteBean remoteBean = (RemoteBean) bean;
                    List<SecurityRoleRef> securityRoleRefs = remoteBean.getSecurityRoleRef();
                    for (String role : declareRoles.value()) {
                        securityRoleRefs.add(new SecurityRoleRef(role));
                    }
                }
            }

            /*
             * Process annotations at the method level
             */
            List<Method> seen = new ArrayList<Method>();

            /*
             * @RolesAllowed
             */
            for (Annotated<Method> method : annotationFinder.findMetaAnnotatedMethods(RolesAllowed.class)) {
                checkConflictingSecurityAnnotations(method, ejbName, ejbModule, seen);
                RolesAllowed rolesAllowed = method.getAnnotation(RolesAllowed.class);
                MethodPermission methodPermission = new MethodPermission();
                methodPermission.getRoleName().addAll(asList(rolesAllowed.value()));
                methodPermission.getMethod().add(new org.apache.openejb.jee.Method(ejbName, method.get()));
                assemblyDescriptor.getMethodPermission().add(methodPermission);

                // Automatically add a role ref for any role listed in RolesAllowed
                RemoteBean remoteBean = (RemoteBean) bean;
                List<SecurityRoleRef> securityRoleRefs = remoteBean.getSecurityRoleRef();
                for (String role : rolesAllowed.value()) {
                    securityRoleRefs.add(new SecurityRoleRef(role));
                }
            }

            /*
 
View Full Code Here

   }

  
   public void process(MethodPermissionsMetaData metaData, T type)
   {
      RolesAllowed allowed = finder.getAnnotation(type, RolesAllowed.class);
      if(allowed == null)
         return;

      Method method = null;
      if(type instanceof Method)
         method = (Method) type;

      String ejbName = EjbNameThreadLocal.ejbName.get();
      MethodMetaData mmd = ProcessorUtils.createMethod(ejbName, method);
      MethodPermissionMetaData perm = new MethodPermissionMetaData();
      MethodsMetaData methods = perm.getMethods();
      if(methods == null)
      {
         methods = new MethodsMetaData();
         perm.setMethods(methods);
      }
      HashSet<String> roles = new HashSet<String>();
      for(String role : allowed.value())
         roles.add(role);
      perm.setRoles(roles);
      Descriptions descriptions = ProcessorUtils.getDescription("@RolesAllowed for: "+type);
      mmd.setDescriptions(descriptions);
      methods.add(mmd);
View Full Code Here

            if (a instanceof PermitAll) {
                attributes.add(Jsr250SecurityConfig.PERMIT_ALL_ATTRIBUTE);
                return attributes;
            }
            if (a instanceof RolesAllowed) {
                RolesAllowed ra = (RolesAllowed) a;

                for (String allowed : ra.value()) {
                    attributes.add(new Jsr250SecurityConfig(allowed));
                }
                return attributes;
            }
        }
View Full Code Here

TOP

Related Classes of javax.annotation.security.RolesAllowed

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.