users@glassfish.java.net

Costum login module in glassfish (WARNING: Exception while starting bundle)

From: <glassfish_at_javadesktop.org>
Date: Mon, 19 Jul 2010 01:01:34 PDT

I am trying to implement custom login module in glassfish, but after deploying jar files server does not start. i am in hell for two days :)

//Custom login module

public class LSLoginModule extends AppservPasswordLoginModule {

        // private ConnectionUtilita utilita = new ConnectionUtilita();
        @Override
        protected void authenticateUser()
                        throws javax.security.auth.login.LoginException {
                System.err.println("check login/password");
                commitUserAuthentication(new String[]{"manager","group1","guest"});
        }
}

//Custom Realm

public class LSRealm extends AppservRealm {
        private ConnectionUtilita utilita;
        @Override
        public String getAuthType() {
                return "soft";
        }
        @Override
        public Enumeration<String> getGroupNames(String login)
                        throws InvalidOperationException, NoSuchUserException {
                Vector<String> userGroups = selectUserGroupsFromDB(login);
                if (userGroups != null) {
                        return userGroups.elements();
                }
                return null;
        }
        private Vector<String> selectUserGroupsFromDB(String login) {
                Vector<String> userGroups = new Vector<String>();
                String selectUser = "SELECT GROUPS.GROUP_NAME AS 'USERGROUP' FROM GROUPS INNER JOIN USER_GROUPS ON"
                                + " GROUPS.ID=USER_GROUPS.GROUPSID INNER JOIN USERS ON"
                                + " USER_GROUPS.USERSID=USERS.ID "
                                + " WHERE USERS.LOGIN=? AND GROUPS.ENABLED=1";

                try {
                        PreparedStatement pst = utilita.getConnection().prepareStatement(
                                        selectUser);
                        pst.setString(1, login);
                        ResultSet rs = pst.executeQuery();
                        while (rs.next()) {
                                userGroups.add(rs.getString("USERGROUP"));
                        }
                        return userGroups;
                } catch (SQLException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                }
                return null;
        }
        private Vector<String> showAllGroups() {
                Vector<String> userGroups = new Vector<String>();
                String selectUser = "SELECT GROUPS.GROUP_NAME AS 'USERGROUP' FROM GROUPS INNER JOIN USER_GROUPS ON "
                                + " GROUPS.ID=USER_GROUPS.GROUPSID INNER JOIN USERS ON "
                                + " USER_GROUPS.USERSID=USERS.ID";
                try {
                        PreparedStatement pst = utilita.getConnection().prepareStatement(selectUser);
                        ResultSet rs = pst.executeQuery();
                        while (rs.next()) {
                                userGroups.add(rs.getString("USERGROUP"));
                        }
                        return userGroups;
                } catch (SQLException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();

                }
                return null;
        }
        @Override
        protected void init(Properties props) throws BadRealmException,
                        NoSuchRealmException {

                super.init(props);

                utilita = new ConnectionUtilita();

                System.err.println("soft groups");
                try {
                        System.err.println("isCosed: "+utilita.getConnection().isClosed());
                                Vector<String> groups=showAllGroups();
                                for (int i = 0; i < groups.size(); i++) {
                                System.err.println("LSRealm Group: "+groups.get(i));
                        }
                        
                } catch (SQLException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                }

                if (props.containsKey(JAAS_CONTEXT_PARAM))
                        setProperty(JAAS_CONTEXT_PARAM,
                                        props.getProperty(JAAS_CONTEXT_PARAM));
        }
        @Override
        public AuthenticationHandler getAuthenticationHandler() {
                return null;
        }
}

//Sql server user is hardcoded in ConnectionUtilita class

// Domain XML

<security-service>
                <auth-realm classname="com.app.LSRealm" name="testRealm">
                                        <property name="jaas-context" value="testRealm" />
                                        <property name="auth-type" value="soft" />
                </auth-realm>
....

//login.conf

testRealm{
        com.app.LSLoginModule required;
};

my IDE is Eclipse Helios with glassfish plugin
version 1.0.53

glassfish log in eclipse console is :

<LOG>19-Jul-2010 11:43:03 com.sun.enterprise.admin.launcher.GFLauncherLogger info
INFO: JVM invocation command line:
C:\Program Files\Java\jdk1.6.0_21\bin\java.exe
-cp
F:/Database/glassfishv3/glassfish/modules/glassfish.jar;F:/Database/glassfishv3/glassfish/domains/domain1/lib/mytestrealm.jar
-XX:+UnlockDiagnosticVMOptions
-XX:MaxPermSize=192m
-XX:NewRatio=2
-XX:+LogVMOutput
-XX:LogFile=F:\Database\glassfishv3\glassfish\domains\domain1/logs/jvm.log
                                
-Xmx512m
-javaagent:F:/Database/glassfishv3/glassfish/lib/monitor/btrace-agent.jar=unsafe=true,noServer=true
-client
-Dosgi.shell.telnet.maxconn=1
-Djdbc.drivers=org.apache.derby.jdbc.ClientDriver
                                
-Dfelix.fileinstall.dir=F:\Database\glassfishv3\glassfish/modules/autostart/
                                
-Djavax.net.ssl.keyStore=F:\Database\glassfishv3\glassfish\domains\domain1/config/keystore.jks
                                
-Dosgi.shell.telnet.port=6666
-Djava.security.policy=F:\Database\glassfishv3\glassfish\domains\domain1/config/server.policy
                                
-Dfelix.fileinstall.poll=5000
-Dcom.sun.aas.instanceRoot=F:\Database\glassfishv3\glassfish\domains\domain1
-Dcom.sun.enterprise.config.config_environment_factory_class=com.sun.enterprise.config.serverbeans.AppserverConfigEnvironmentFactory
                                
-Dosgi.shell.telnet.ip=127.0.0.1
-Djava.endorsed.dirs=F:\Database\glassfishv3\glassfish/modules/endorsed;F:\Database\glassfishv3\glassfish/lib/endorsed
                                
-Dcom.sun.aas.installRoot=F:\Database\glassfishv3\glassfish
-Djava.ext.dirs=C:\Program Files\Java\jdk1.6.0_21/lib/ext;C:\Program Files\Java\jdk1.6.0_21/jre/lib/ext;F:\Database\glassfishv3\glassfish\domains\domain1/lib/ext
                                
-Dfelix.fileinstall.bundles.new.start=true
                                
-Djavax.net.ssl.trustStore=F:\Database\glassfishv3\glassfish\domains\domain1/config/cacerts.jks
                                
-Dcom.sun.enterprise.security.httpsOutboundKeyAlias=s1as
                                
-Djava.security.auth.login.config=F:\Database\glassfishv3\glassfish\domains\domain1/config/login.conf
                                
-DANTLR_USE_DIRECT_CLASS_LOADING=true
-Dfelix.fileinstall.debug=1
-Dorg.glassfish.web.rfc2109_cookie_names_enforced=false
                                
-Djava.library.path=F:/Database/glassfishv3/glassfish/lib;C:/Program Files/Java/jdk1.6.0_21/bin;F:/Database/glassfishv3/glassfish;C:/WINDOWS/Sun/Java/bin;C:/WINDOWS/system32;C:/WINDOWS;C:/Program Files/Java/jre6/bin/client;C:/Program Files/Java/jre6/bin;C:/Program Files/Java/jre6/lib/i386;C:/Program Files/Borland/Delphi5/bin;C:/WINDOWS/system32/wbem;C:/Program Files/Common Files/Adobe/AGL;F:/Database/mysql/bin;F:/Database/SqlServer/100/Tools/Binn;F:/Database/SqlServer/100/DTS/Binn;F:/Database/SqlServer/100/Tools/Binn/VSShell/Common7/IDE;C:/WINDOWS/system32/windowspowershell/v1.0;C:/Program Files/Microsoft SQL Server/80/Tools/Binn;C:/Program Files/Java/jdk1.6.0_19/bin
com.sun.enterprise.glassfish.bootstrap.ASMain
-domainname
domain1
-asadmin-args
start-domain,,,--domaindir,,,F:/Database/glassfishv3/glassfish/domains,,,--debug=false,,,--verbose=false,,,domain1
-instancename
server
-verbose
false
-debug
false
-asadmin-classpath
F:/Database/glassfishv3/glassfish/modules/admin-cli.jar
-asadmin-classname
com.sun.enterprise.admin.cli.AsadminMain
-upgrade
false
-domaindir
F:/Database/glassfishv3/glassfish/domains/domain1
-read-stdin
true
19-Jul-2010 11:43:03 com.sun.enterprise.admin.launcher.GFLauncherLogger info
INFO: Successfully launched in 16 msec.
INFO: Running GlassFish Version: GlassFish v3 (build 74.2)
INFO: Perform lazy SSL initialization for the listener 'http-listener-2'
INFO: Starting Grizzly Framework 1.9.18-k - Mon Jul 19 11:43:05 GMT+04:00 2010
INFO: Grizzly Framework 1.9.18-k started in: 47ms listening on port 4848
INFO: Grizzly Framework 1.9.18-k started in: 110ms listening on port 8080
INFO: Grizzly Framework 1.9.18-k started in: 63ms listening on port 8181
INFO: Grizzly Framework 1.9.18-k started in: 31ms listening on port 3700
INFO: Starting Grizzly Framework 1.9.18-k - Mon Jul 19 11:43:05 GMT+04:00 2010
INFO: Grizzly Framework 1.9.18-k started in: 15ms listening on port 7676
INFO: The Admin Console is already installed, but not yet loaded.
INFO: GlassFish v3 (74.2) startup time : Felix(1875ms) startup services(609ms) total(2484ms)
INFO: javassist.util.proxy.ProxyFactory.classLoaderProvider = org.glassfish.weld.WeldActivator$GlassFishClassLoaderProvider_at_138933d
INFO: Binding RMI port to *:8686
INFO: JMXStartupService: Started JMXConnector, JMXService URL = service:jmx:rmi://leasingd-dima.leasing.tbc:8686/jndi/rmi://leasingd-dima.leasing.tbc:8686/jmxrmi
INFO: Using com.sun.enterprise.transaction.jts.JavaEETransactionManagerJTSDelegate as the delegate
INFO: [Thread[GlassFish Kernel Main Thread,5,main]] started
INFO: Cannot create folder F:\Database\glassfishv3\glassfish\modules\autostart\
                                . Is the folder write-protected?
INFO: {felix.fileinstall.poll (ms) = 5000, felix.fileinstall.dir = F:\Database\glassfishv3\glassfish\domains\domain1\autodeploy\bundles, felix.fileinstall.debug = 1, felix.fileinstall.bundles.new.start = true, felix.fileinstall.tmpdir = C:\DOCUME~1\DCHKHA~1\LOCALS~1\Temp\fileinstall--1285608269854123872, felix.fileinstall.filter = null}
SEVERE: Exception in thread "{felix.fileinstall.poll=5000, service.pid=org.apache.felix.fileinstall.d58a4f2d-18de-40ad-b6d2-cb6617963de8, felix.fileinstall.bundles.new.start=true, felix.fileinstall.dir=F:\Database\glassfishv3\glassfish\domains\domain1/autodeploy/bundles/, service.factorypid=org.apache.felix.fileinstall, felix.fileinstall.filename=org.apache.felix.fileinstall-autodeploy-bundles.cfg, felix.fileinstall.debug=1}"
WARNING: Exception while starting bundle org.apache.felix.fileinstall [45]
org.osgi.framework.BundleException: Activator start error in bundle org.apache.felix.fileinstall [45].
        at org.apache.felix.framework.Felix.activateBundle(Felix.java:1751)
        at org.apache.felix.framework.Felix.startBundle(Felix.java:1622)
        at org.apache.felix.framework.BundleImpl.start(BundleImpl.java:915)
        at org.jvnet.hk2.osgimain.Main.start(Main.java:140)
        at org.apache.felix.framework.util.SecureAction.startActivator(SecureAction.java:640)
        at org.apache.felix.framework.Felix.activateBundle(Felix.java:1700)
        at org.apache.felix.framework.Felix.startBundle(Felix.java:1622)
        at org.apache.felix.framework.Felix.setActiveStartLevel(Felix.java:1077)
        at org.apache.felix.framework.StartLevelImpl.run(StartLevelImpl.java:264)
        at java.lang.Thread.run(Thread.java:619)
Caused by: java.lang.RuntimeException: Cannot create folder: F:\Database\glassfishv3\glassfish\modules\autostart\
                                
        at org.apache.felix.fileinstall.internal.DirectoryWatcher.prepareDir(DirectoryWatcher.java:512)
        at org.apache.felix.fileinstall.internal.DirectoryWatcher.<init>(DirectoryWatcher.java:127)
        at org.apache.felix.fileinstall.internal.FileInstall.updated(FileInstall.java:192)
        at org.apache.felix.fileinstall.internal.FileInstall.start(FileInstall.java:111)
        at org.apache.felix.framework.util.SecureAction.startActivator(SecureAction.java:640)
        at org.apache.felix.framework.Felix.activateBundle(Felix.java:1700)
        ... 9 more

SEVERE: java.lang.IllegalStateException: Invalid BundleContext.
        at org.apache.felix.framework.BundleContextImpl.checkValidity(BundleContextImpl.java:393)
        at org.apache.felix.framework.BundleContextImpl.getBundles(BundleContextImpl.java:145)
        at org.apache.felix.fileinstall.internal.DirectoryWatcher.initializeCurrentManagedBundles(DirectoryWatcher.java:649)
        at org.apache.felix.fileinstall.internal.DirectoryWatcher.run(DirectoryWatcher.java:186)
</LOG>

thanks !
[Message sent by forum member 'dimitrichkhartishvili']

http://forums.java.net/jive/thread.jspa?messageID=477936