Advertisement
Guest User

Untitled

a guest
May 22nd, 2009
407
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 6.93 KB | None | 0 0
  1. SECURITY DOMAIN DEFINITION in login-config.xml------------------------------------------
  2. <application-policy name="mySecurityDomain">
  3.     <authentication>
  4.       <login-module code="org.jboss.security.auth.spi.UsersRolesLoginModule"
  5.         flag="required">
  6.         <module-option name="usersProperties">props/myProps/users.properties</module-option>
  7.         <module-option name="rolesProperties">props/myProps/roles.properties</module-option>
  8.       </login-module>
  9.     </authentication>
  10.   </application-policy>
  11.  
  12. props/myProps/roles.properties----------------------------------------------------------
  13. guest=guestRole
  14. user=userRole,guestRole
  15. admin=adminRole,userRole,guestRole
  16.  
  17. props/myProps/users.properties----------------------------------------------------------
  18. admin=adminpas
  19. user=userpas
  20. guest=guestpas
  21.  
  22. BEANINTERFACE----------------------------------------------------------------------------
  23. package ejb;
  24.  
  25. import javax.ejb.Remote;
  26.  
  27. @Remote
  28. public interface Secure {
  29.     public String forAll();
  30.     public String forUsers();
  31.     public String forAdmins();
  32.     public String forNoOne();
  33. }
  34.  
  35.  
  36. BEAN-------------------------------------------------------------------------------------
  37. package ejb;
  38.  
  39. import javax.annotation.security.DenyAll;
  40. import javax.annotation.security.PermitAll;
  41. import javax.annotation.security.RolesAllowed;
  42. import javax.ejb.Stateless;
  43.  
  44. import org.jboss.ejb3.annotation.SecurityDomain;
  45.  
  46. //import org.jboss.security.annotation.SecurityDomain;
  47.  
  48.  
  49. @Stateless
  50. @SecurityDomain("mySecurityDomain")
  51. @RolesAllowed({"guestRole", "userRole", "adminRole"})
  52. public class SecureBean implements Secure {
  53.  
  54.     @RolesAllowed("adminRole")
  55.     public String forAdmins() {
  56.         return "forAdmins";
  57.     }
  58.  
  59.     @PermitAll
  60.     public String forAll() {
  61.         return "forAll";
  62.     }
  63.     @DenyAll
  64.     public String forNoOne() {
  65.         return "forNoOne";
  66.     }
  67.     @RolesAllowed("userRole")
  68.     public String forUsers() {
  69.         return "forUsers";
  70.     }
  71. }
  72.  
  73. CLIENT-------------------------------------------------------------------------------------
  74. package client;
  75.  
  76. import java.util.Properties;
  77.  
  78. import javax.naming.Context;
  79. import javax.naming.InitialContext;
  80. import javax.naming.NamingException;
  81.  
  82. import ejb.Secure;
  83.  
  84. public class SecureClient {
  85.     public static void main(String[] args) {
  86.         Context ctx;
  87.         try {
  88.             Properties props = new Properties();
  89.             props.put(Context.SECURITY_PRINCIPAL, "guest");
  90.             props.put(Context.SECURITY_CREDENTIALS, "guestpas");
  91.             ctx = new InitialContext(props);
  92.             Secure bean = (Secure)ctx.lookup("SecureBean/remote");
  93.             System.out.println(bean.forAll());
  94.         } catch (NamingException e) {
  95.             e.printStackTrace();
  96.         }
  97.     }
  98. }
  99.  
  100. EXCEPTION-------------------------------------------------------------------------------------
  101. Exception in thread "main" javax.ejb.EJBAccessException: Invalid User
  102.     at org.jboss.ejb3.security.Ejb3AuthenticationInterceptorv2.invoke(Ejb3AuthenticationInterceptorv2.java:165)
  103.     at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
  104.     at org.jboss.ejb3.ENCPropagationInterceptor.invoke(ENCPropagationInterceptor.java:41)
  105.     at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
  106.     at org.jboss.ejb3.asynchronous.AsynchronousInterceptor.invoke(AsynchronousInterceptor.java:106)
  107.     at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
  108.     at org.jboss.ejb3.BlockContainerShutdownInterceptor.invoke(BlockContainerShutdownInterceptor.java:67)
  109.     at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
  110.     at org.jboss.aspects.currentinvocation.CurrentInvocationInterceptor.invoke(CurrentInvocationInterceptor.java:67)
  111.     at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
  112.     at org.jboss.ejb3.stateless.StatelessContainer.dynamicInvoke(StatelessContainer.java:487)
  113.     at org.jboss.ejb3.session.InvokableContextClassProxyHack._dynamicInvoke(InvokableContextClassProxyHack.java:53)
  114.     at org.jboss.aop.Dispatcher.invoke(Dispatcher.java:91)
  115.     at org.jboss.aspects.remoting.AOPRemotingInvocationHandler.invoke(AOPRemotingInvocationHandler.java:82)
  116.     at org.jboss.remoting.ServerInvoker.invoke(ServerInvoker.java:908)
  117.     at org.jboss.remoting.transport.socket.ServerThread.completeInvocation(ServerThread.java:742)
  118.     at org.jboss.remoting.transport.socket.ServerThread.processInvocation(ServerThread.java:695)
  119.     at org.jboss.remoting.transport.socket.ServerThread.dorun(ServerThread.java:522)
  120.     at org.jboss.remoting.transport.socket.ServerThread.run(ServerThread.java:230)
  121.     at org.jboss.remoting.MicroRemoteClientInvoker.invoke(MicroRemoteClientInvoker.java:206)
  122.     at org.jboss.remoting.Client.invoke(Client.java:1708)
  123.     at org.jboss.remoting.Client.invoke(Client.java:612)
  124.     at org.jboss.aspects.remoting.InvokeRemoteInterceptor.invoke(InvokeRemoteInterceptor.java:60)
  125.     at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
  126.     at org.jboss.aspects.tx.ClientTxPropagationInterceptor.invoke(ClientTxPropagationInterceptor.java:61)
  127.     at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
  128.     at org.jboss.ejb3.security.client.SecurityClientInterceptor.invoke(SecurityClientInterceptor.java:65)
  129.     at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
  130.     at org.jboss.ejb3.remoting.IsLocalInterceptor.invoke(IsLocalInterceptor.java:74)
  131.     at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
  132.     at org.jboss.aspects.remoting.PojiProxy.invoke(PojiProxy.java:62)
  133.     at $Proxy3.invoke(Unknown Source)
  134.     at org.jboss.ejb3.proxy.handler.ProxyInvocationHandlerBase.invoke(ProxyInvocationHandlerBase.java:261)
  135.     at org.jboss.ejb3.proxy.handler.session.SessionSpecProxyInvocationHandlerBase.invoke(SessionSpecProxyInvocationHandlerBase.java:101)
  136.     at $Proxy2.forAll(Unknown Source)
  137.     at client.SecureClient.main(SecureClient.java:21)
  138.     at org.jboss.aspects.remoting.InvokeRemoteInterceptor.invoke(InvokeRemoteInterceptor.java:72)
  139.     at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
  140.     at org.jboss.aspects.tx.ClientTxPropagationInterceptor.invoke(ClientTxPropagationInterceptor.java:61)
  141.     at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
  142.     at org.jboss.ejb3.security.client.SecurityClientInterceptor.invoke(SecurityClientInterceptor.java:65)
  143.     at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
  144.     at org.jboss.ejb3.remoting.IsLocalInterceptor.invoke(IsLocalInterceptor.java:74)
  145.     at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
  146.     at org.jboss.aspects.remoting.PojiProxy.invoke(PojiProxy.java:62)
  147.     at $Proxy3.invoke(Unknown Source)
  148.     at org.jboss.ejb3.proxy.handler.ProxyInvocationHandlerBase.invoke(ProxyInvocationHandlerBase.java:261)
  149.     at org.jboss.ejb3.proxy.handler.session.SessionSpecProxyInvocationHandlerBase.invoke(SessionSpecProxyInvocationHandlerBase.java:101)
  150.     at $Proxy2.forAll(Unknown Source)
  151.     at client.SecureClient.main(SecureClient.java:21)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement