users@glassfish.java.net

Re: Embedded Glassfish and security questions

From: <forums_at_java.net>
Date: Wed, 4 May 2011 05:58:23 -0500 (CDT)

[quote]Ok, I see. This particular command seems to be having an issue. There
is an issue filed already for this -
http://java.net/jira/browse/GLASSFISH-16277 [1]. Please have a watch on that
issue.[/quote]

I saw that you closed the JIRA ticket. It still doesn't work, though. I must
be doing it wrong.

I'm not really sure how to use it. I got a password.txt file with

AS_ADMIN_MASTERPASSWORD=changeit AS_ADMIN_PASSWORD=adminadmin
AS_ADMIN_USERPASSWORD=xxx
and my command is *final CommandResult result =
runner.run("create-file-user", "--passwordfile=passwords.txt",
"--groups=role1", "user1");*

What needs to be in the password file? How can I assign passwords to the
users I create?

Thank you for your patience.

JUnit test case:

public class TestCase { private static GlassFish glassFish; @BeforeClass
public static void setup() throws Exception { glassFish =
GlassFishRuntime.bootstrap().newGlassFish(); glassFish.start(); final
CommandRunner runner = glassFish.getCommandRunner();
        *final CommandResult result = runner.run("create-file-user",
"--passwordfile=passwords.txt", "--groups=role1", "user1");*
        if ((result.getExitStatus() !=
CommandResult.ExitStatus.SUCCESS) && (result.getFailureCause() != null)) {
            throw new Exception(String.format("Failed to create
user : message %s ", result.getOutput()), result.getFailureCause());
        }
    }
    @AfterClass
    public static void cleanup() throws GlassFishException {
        if (glassFish != null) {
            glassFish.stop();
            glassFish.dispose();
        }
    }
    @Test
    public void testUserHasRole() throws Exception {
        final ProgrammaticLogin programmaticLogin = new
ProgrammaticLogin();
        final boolean loggedIn = programmaticLogin.login("user1",
"xxx".toCharArray());
        Assert.assertEquals(true, loggedIn);
        System.out.println("Logged in!");
    }
} Maven console output: Running test.ejb.TestCase 04-May-2011 12:51:43
com.sun.enterprise.v3.server.CommonClassLoaderServiceImpl findDerbyClient
INFO: Cannot find javadb client jar file, derby jdbc driver will not be
available by default. 04-May-2011 12:51:43
com.sun.enterprise.v3.services.impl.GrizzlyService createNetworkProxy INFO:
Network listener http-listener on port 0 disabled per domain.xml 04-May-2011
12:51:43 com.sun.enterprise.v3.services.impl.GrizzlyService
createNetworkProxy INFO: Network listener https-listener on port 0 disabled
per domain.xml 04-May-2011 12:51:43
com.sun.enterprise.v3.server.AppServerStartup run INFO: GlassFish Server Open
Source Edition 3.2-b05 (java_re-private) startup time : Embedded (566ms),
startup services(279ms), total(845ms) 04-May-2011 12:51:44
org.glassfish.admin.mbeanserver.JMXStartupService$JMXConnectorsStarterThread
run INFO: JMXStartupService: JMXConnector system is disabled, skipping.
04-May-2011 12:51:44 org.glassfish.admin.mbeanserver.JMXStartupService
shutdown INFO: JMXStartupService and JMXConnectors have been shut down.
04-May-2011 12:51:44 com.sun.enterprise.v3.server.AppServerStartup stop INFO:
Shutdown procedure finished 04-May-2011 12:51:44 AppServerStartup run INFO:
[Thread[GlassFish Kernel Main Thread,5,main]] exiting
Surefire report:

-------------------------------------------------------------------------------
Test set: test.ejb.TestCase
-------------------------------------------------------------------------------
Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 1.462 sec <<<
FAILURE! test.ejb.TestCase Time elapsed: 0 sec <<< ERROR!
java.lang.Exception: Failed to create user : message Exception while
executing command. at test.ejb.TestCase.setup(TestCase.java:27) at
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597) at
org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
at
org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
at
org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
at
org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:27)
at
org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:31)
at org.junit.runners.ParentRunner.run(ParentRunner.java:236) at
org.apache.maven.surefire.junit4.JUnit4TestSet.execute(JUnit4TestSet.java:53)
at
org.apache.maven.surefire.junit4.JUnit4Provider.executeTestSet(JUnit4Provider.java:119)
at
org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:101)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597) at
org.apache.maven.surefire.booter.ProviderFactory$ClassLoaderProxy.invoke(ProviderFactory.java:103)
at $Proxy0.invoke(Unknown Source) at
org.apache.maven.surefire.booter.SurefireStarter.invokeProvider(SurefireStarter.java:150)
at
org.apache.maven.surefire.booter.SurefireStarter.runSuitesInProcess(SurefireStarter.java:91)
at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:69)
*Caused by: org.glassfish.api.admin.CommandValidationException: **Invalid
option: --passwordfile=passwords.txt* at
com.sun.enterprise.admin.cli.Parser.parseCommandLine(Parser.java:204) at
com.sun.enterprise.admin.cli.Parser.<init>(Parser.java:92) at
com.sun.enterprise.admin.cli.embeddable.CommandExecutorImpl.getParameters(CommandExecutorImpl.java:97)
at
com.sun.enterprise.admin.cli.embeddable.CommandExecutorImpl.executeCommand(CommandExecutorImpl.java:112)
at
com.sun.enterprise.admin.cli.embeddable.CommandExecutorImpl.run(CommandExecutorImpl.java:85)
at test.ejb.TestCase.setup(TestCase.java:25) ... 22 more
Maven dependecies:

[INFO] --- maven-dependency-plugin:2.2:list (default-cli) @ glassfish.tests
--- [INFO] [INFO] The following files have been resolved: [INFO]
org.apache.geronimo.specs:geronimo-annotation_1.1_spec:jar:1.0.1:compile
[INFO] org.glassfish.extras:glassfish-embedded-all:jar:3.2-b05:provided
[INFO] junit:junit:jar:4.8.2:test [INFO]

[1] http://java.net/jira/browse/GLASSFISH-16277

--
[Message sent by forum member 'nickdegraeve']
View Post: http://forums.java.net/node/793586