How to configure JAAS for JBoss

  1. In jboss.xml, add <security-domain>java:/jaas/jboss-secure</security-domain>
  2. In JBoss install directorty, C:\jboss-4.2.1.GA\server\default\conf, add users.properties and roles.properties
  3. In users.properties, add user=pass
  4. In roles.properties, add user=role
  5. Deploy ejb, restart jboss
  6. In your ejb client, your initialContext should look like this
  7. properties.put(Context.INITIAL_CONTEXT_FACTORY , "org.jboss.security.jndi.JndiLoginInitialContextFactory");
    properties.put("java.naming.provider.url", "jnp://localhost:1099");
    properties.put(Context.SECURITY_PRINCIPAL, "user");
    properties.put(Context.SECURITY_CREDENTIALS, "pass");

    Context ic = new InitialContext(properties);
Or alternatively,
Application Server side:
NO CHANGES
EJB side:
  1. In jboss.xml add domain
  2. Add users.properties, roles.properties to ejb jar above META-INF
This is probably the simplest tutorial on JAAS (that actually works!)

How to get 1Password working on Snow Leopard

  1. Locate 1Password in /Applications
  2. Right click...Show Package Contents
  3. Traverse and open Contents/Resources/SupportedBrowsers.plist
  4. Set Safari.MaxBundleVersion to 6532
  5. Restart Safari, you should have your 1Password button back

Exception in thread "main" javax.naming.CommunicationException [Root exception is java.lang.ClassNotFoundException: org.jboss.ejb3.JBossProxy (no secu

Exception in thread "main" javax.naming.CommunicationException [Root exception is java.lang.ClassNotFoundException: org.jboss.ejb3.JBossProxy (no security manager: RMI class loader disabled)]

Cause:
Client library missing

Solution:
Add jbossall-client.jar to classpath

NoInitialContextException when calling an EJB from a java client

Exception in thread "main" javax.naming.NoInitialContextException: Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file: java.naming.factory.initial
at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:645)
at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:247)
at javax.naming.InitialContext.getURLOrDefaultInitCtx(InitialContext.java:284)
at javax.naming.InitialContext.lookup(InitialContext.java:351)
at helloworldclient.Main.main(Main.java:34)

Cause
:
The initial context is not set.

Solution:
Set the initial context via jndi.properties or programatically:
properties.put("java.naming.factory.initial","org.jnp.interfaces.NamingContextFactory");
properties.put("java.naming.provider.url","jnp://localhost:1099");
Context ic = new InitialContext(properties );

How to run JBoss 5.1 within Netbeans 6.5 and Netbeans 6.7

  1. Download JBoss 5.x and extract it to C: (Don't put it inside 'Program Files')
  2. In the Services tab, select Servers..Add Server and select JBoss


  3. Leave everything at the default setting
  4. JBoss should be registered with netbeans
  5. Right click on JBoss and click start server
  6. If there were no issues, JBoss will start within Netbeans BUT it is never that simple is it? :)
Ok so here are some of the issues I encountered and how I went about solving them.
  1. First make sure your JBOSS_HOME environment variable is pointing to the correct path. I upgraded from JBoss 4.05 and had to update this. Check your PATH variable as well
  2. On trying to register JBoss with Netbeans I kept getting this error:
    ALL [null]: Cannot rename file J2EE/InstalledServers/.nbattrs~ in C:\Documents and Settings\g\.netbeans\6.7\config to J2EE/InstalledServers/.nbattrs
    This is basically netbeans trying to create a file called .nbattrs but not being able to do so. In XP a file name cannot begin with a dot. Go ahead try it! But Netbeans tries to create one. Slopppy implementation by Netbeans (or Netbeans engineers are not big windows fans!). Here's what I did. Went to DOS (cmd) and renamed it. Yeah Microsoft, consistency is not thy forte! (No pun intended - Netbeans used to be called Forte)
  3. Close Netbeans and start is again. You should be able to see JBoss listed under servers
  4. When I tried to start Netbeans, the first error I got was:
    Port already in use: 8080
  5. To fix this, I went to C:\jboss-5.1.0.GA\server\default\deploy\jbossweb.sar\server.xml and changed the port from 8080 to 7075 (select any unused port).
  6. Once that was fixed the next error on a restart was:
    java.rmi.server.ExportException: Port already in use: 1098; nested exception is: java.net.BindException: Address already in use: JVM_Bind

  7. To fix this, I edited C:\jboss-5.1.0.GA\server\default\conf\bindingservice.beans\META-INF\bindings-jboss-beans.xml and updated 1098 to 11098
  8. In the same xml file I updated Remote classloading service port as well as this too was giving a port already in use error
  9. Now a restart of JBoss was successful!

You are welcome!

NullPointerException during authentication in JSecurity

WARNING: Authentication failed for token submission [org.jsecurity.authc.UsernamePasswordToken - lonestarr, rememberMe=true]. Possible unexpected error? (Typical or expected login exceptions should extend from AuthenticationException).
java.lang.NullPointerException
at org.jsecurity.realm.SimpleAccountRealm.doGetAuthenticationInfo(SimpleAccountRealm.java:141)
at org.jsecurity.realm.AuthenticatingRealm.getAuthenticationInfo(AuthenticatingRealm.java:170)
at org.jsecurity.authc.pam.ModularRealmAuthenticator.doSingleRealmAuthentication(ModularRealmAuthenticator.java:213)
at org.jsecurity.authc.pam.ModularRealmAuthenticator.doAuthenticate(ModularRealmAuthenticator.java:303)
at org.jsecurity.authc.AbstractAuthenticator.authenticate(AbstractAuthenticator.java:180)
at org.jsecurity.mgt.AuthenticatingSecurityManager.authenticate(AuthenticatingSecurityManager.java:209)
at org.jsecurity.mgt.DefaultSecurityManager.login(DefaultSecurityManager.java:314)
at org.jsecurity.subject.DelegatingSubject.login(DelegatingSubject.java:239)
at Quickstart.main(Quickstart.java:71)


Cause:
Probably a bug in JSecurity. I'm using version 0.9. This might've been fixed in the latest release. JSecurity is looking for
the cache manager but is unable to find one.

Solution:
Try downloading the latest version
Place ehcache.jar and backport-util-concurrent.jar in the classpath and run again

How to resolve UnresolvedExternal exceptions while deploying jni apps in Tomcat

Cause:
UnresolvedExternal errors are caused in JNI applications when the class files tries to reference a native method in a shared object or dll and is unable to find the dll.

Solution:
  • Find out Tomcat's current java.library.path
  • Copy your application dlls to this path
  • The jars would remain within the application's war file
  • The dlls need not be along with the application jars