Problem in using our own authentication cache policy
rajesh_sp Nov 26, 2001 11:27 PMI am using JBoss-2.4.3 vorsion.
First I am telling my requirement and then my work on that and what problem I am facing. I dont know what I have done is right or wrong. I request you to help me out.
and thanks a lot in advance.
First, My requirement is to write a authentication cache service which is in my control ie
1) Flush on request
2) Remove a single user on request
3) Know the number of users logged in.
4) Allow Specified number of users to login.
Second, what I have done to achive it.
I am facing a problem while using the class files present in jars
Like I have written a cache policy service Mbean called
package com.velankani.security.cache;
public class SCECachePolicy extends ServiceMBeanSupport implements SCECachePolicyMBean
I have registered in the jboss.jcml in this fashion.
security/CachePolicy
when I start run.bat
I will get following exception
[Configuration] Could not create MBean DefaultDomain:service=security/CachePolic
y(com.velankani.security.cache.SCECachePolicy)
[Configuration] java.lang.NoClassDefFoundError: org/jboss/util/ServiceMBeanSupport
[Configuration]at java.lang.ClassLoader.defineClass0(Native Method)
[Configuration]at java.lang.ClassLoader.defineClass(Unknown Source)
and in starnge way, if I put jboss.jar in the classpath in run.bat file it gave lot of other exceptions but all were class not found exceptions.
So to get rid of this problem what I did is changed the package of my service MBean to
package org.jboss.util;
extracted jboss.jar and placed the class files related to my service MBean in proper folder and again jared
jboss.jar accordingly changed jboss.jcml
and the cache class that I am registering to JNDI in the serevice MBean SCECachePolicy class as shown in the following code.(at the end)
The TimedCachePolicy1(cache class ) That I am using as authentication cache policy is also put in jboss.jar similar to the earlier one. In this case I got exception as.
[Configuration] java.lang.NoClassDefFoundError: org/jboss/util/CachePolicy
with this set up of jboss.jar I am able to start the jboss server with my service bean also starting with out any problem while starting,
piece of app server out put is below
.
.
.
[SCECachePolicy] Initializing
[SCECachePolicy] Initialized
.
.
[JaasSecurityManagerService] Starting
[JaasSecurityManagerService] startService, cachePolicy=org.jboss.util.TimedCachePolicy1@5a6bf4
[JaasSecurityManagerService] startService, SecurityProxyFactory=org.jboss.security.SubjectSecurityProxyFactory@658cb8
.
.
[JaasSecurityManagerService] Created securityMgr=org.jboss.security.plugins.JaasSecurityManager@55d3a3
[JaasSecurityManagerService] setCachePolicy, c=org.jboss.util.TimedCachePolicy1@5a6bf4
[JaasSecurityManagerService] Added ems, org.jboss.security.plugins.JaasSecurityManager@55d3a3 to map
.
.
[Service Control] Started 51 services
JBoss 2.4.3 Started in 0m:26s
till this tis ok when I give a request from the client I am getting following exception on client window and nothing on server window
Creating LoginContext
Created LoginContext
ini context created
Got reference
Got Home ----object
java.rmi.ServerException: RemoteException occurred in server thread; nested exception is: java.rmi.ServerException: Exception occurred; nested exception is: java.lang.NullPointerException
java.rmi.ServerException: Exception occurred; nested exception is: java.lang.NullPointerException
java.lang.NullPointerException
at sun.rmi.transport.StreamRemoteCall.exceptionReceivedFromServer(Unknown Source)
at sun.rmi.transport.StreamRemoteCall.executeCall(Unknown Source)
at sun.rmi.server.UnicastRef.invoke(Unknown Source)
at org.jboss.ejb.plugins.jrmp.server.JRMPContainerInvoker_Stub.invokeHome(Unknown Source)
at org.jboss.ejb.plugins.jrmp.interfaces.HomeProxy.invokeHome(HomeProxy.java:258)
at org.jboss.ejb.plugins.jrmp.interfaces.HomeProxy.invoke(HomeProxy.java:182)
at $Proxy0.create(Unknown Source)
at InterestClientLC.main(InterestClientLC.java:108)
java.rmi.ServerException: RemoteException occurred in server thread; nested exception is:
java.rmi.ServerException: Exception occurred; nested exception is: java.lang.NullPointerException
TimedCachePolicy1 is same as TimedCachePolicy
The code is as follows
public void startService() throws Exception
{
// Finally create a mail session
TimedCachePolicy1 cache = new TimedCachePolicy1();
bind(cache);
}
private void bind(TimedCachePolicy1 cache) throws NamingException
{
Context ctx = new InitialContext();
String name = getJNDIName();
if (name == null) {name = "java:/security/CachePolicy";}
else if (!name.startsWith("java:/")) {name = "java:/" + name;}
m_bindName = name;
// Ah ! Session isn't serializable, so we use a helper class
NonSerializableFactory.bind(m_bindName, cache);
Name n = ctx.getNameParser("").parse(m_bindName);
while (n.size() > 1)
{
String ctxName = n.get(0);
try
{
ctx = (Context)ctx.lookup(ctxName);
}
catch (NameNotFoundException e)
{
ctx = ctx.createSubcontext(ctxName);
}
n = n.getSuffix(1);
}
// The helper class NonSerializableFactory uses address type nns, we go on to
// use the helper class to bind the javax.mail.Session object in JNDI
StringRefAddr addr = new StringRefAddr("nns", m_bindName);
Reference ref = new Reference(TimedCachePolicy1.class.getName(), addr, NonSerializableFactory.class.getName(), null);
ctx.bind(n.get(0), ref);
System.out.println("Cache Service '" + getJNDIName() + "' bound to " + m_bindName);
}
Thanking you very much.