[jboss-user] [EJB 3.0] - Re: Programmatically query @RolesAllowed or if caller can ac

wolfc do-not-reply at jboss.com
Mon Aug 7 09:49:02 EDT 2006


This works for me:
package test;
  | 
  | import java.lang.annotation.Annotation;
  | import java.lang.reflect.Method;
  | 
  | import javax.annotation.security.RolesAllowed;
  | import javax.ejb.Remote;
  | import javax.ejb.Stateless;
  | 
  | @Stateless
  | @Remote(MyStateless.class)
  | public class MyStatelessBean implements MyStateless {
  | 
  | 	@RolesAllowed("user")
  | 	public String sayHelloTo(String name) {
  | //		Annotation as[] = MyStatelessBean.class.getAnnotations();
  | //		for(Annotation a : as) {
  | //			System.err.println(a.toString());
  | //		}
  | 		Method ms[] = getClass().getMethods();
  | 		for(Method m : ms) {
  | 			Annotation as[] = m.getAnnotations();
  | 			for (Annotation a : as) {
  | 				System.err.println(a.toString());
  | 			}
  | 			RolesAllowed rolesAllowed = m.getAnnotation(RolesAllowed.class);
  | 			if(rolesAllowed != null) {
  | 				for(String role : rolesAllowed.value()) {
  | 					if(role.equals("user"))
  | 						System.err.println("method " + m + " is allowed for user");
  | 				}
  | 			}
  | 		}
  | 		return "Hi " + name;
  | 	}
  | 	
  | 	@RolesAllowed("admin")
  | 	public void notAllowed()
  | 	{
  | 		
  | 	}
  | 	
  | 	@RolesAllowed("user")
  | 	public void allowed()
  | 	{
  | 		
  | 	}
  | }
  | 

View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=3963575#3963575

Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=3963575



More information about the jboss-user mailing list