users@glassfish.java.net

Re: Embedded Glassfish and security questions

From: <forums_at_java.net>
Date: Tue, 26 Apr 2011 05:32:20 -0500 (CDT)

Ok, I checked the latest APIs and examples you suggested and came up with a
new test.

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", "userpassword", "xxx",
"groups", "role1", "username", "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!");     } }
It still doesn't work, though. This is the stacktrace:

java.lang.Exception: Failed to create user : message
PlainTextActionReporterFAILUREorg.jvnet.hk2.component.UnsatisfiedDependencyException:
injection failed on
com.sun.enterprise.security.cli.CreateFileUser.userpassword with class
java.lang.StringDescription: create-file-user commandCannot find userpassword
in create-file-user command model, file a bug Usage: create-file-user
[--authrealmname <authrealm_name>] [--target target] [--groups
user_groups[:user_groups]*] [-?|--help[=<help(default:false)>]] username 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.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:49)
at
org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
Caused by: org.jvnet.hk2.component.UnsatisfiedDependencyException: injection
failed on com.sun.enterprise.security.cli.CreateFileUser.userpassword with
class java.lang.String at
org.jvnet.hk2.component.InjectionManager.inject(InjectionManager.java:155) at
org.jvnet.hk2.component.InjectionManager.inject(InjectionManager.java:78) at
com.sun.enterprise.v3.admin.CommandRunnerImpl.injectParameters(CommandRunnerImpl.java:259)
at
com.sun.enterprise.v3.admin.CommandRunnerImpl.doCommand(CommandRunnerImpl.java:885)
at
com.sun.enterprise.v3.admin.CommandRunnerImpl.access$1200(CommandRunnerImpl.java:96)
at
com.sun.enterprise.v3.admin.CommandRunnerImpl$ExecutionContext.execute(CommandRunnerImpl.java:1247)
at
com.sun.enterprise.v3.admin.CommandRunnerImpl$ExecutionContext.execute(CommandRunnerImpl.java:1235)
at
com.sun.enterprise.admin.cli.embeddable.CommandExecutorImpl.executeCommand(CommandExecutorImpl.java:118)
at
com.sun.enterprise.admin.cli.embeddable.CommandExecutorImpl.run(CommandExecutorImpl.java:85)
at test.ejb.TestCase.setup(TestCase.java:25) ... 16 more
After some googling I found this JIRA entry:
http://java.net/jira/browse/GLASSFISH-16277. If I interpreted it correctly
the new embeddable API doesn't allow setting passwords on newly created
users. In that case, I'm stuck.

Possible workaround: can I create the realm files somehow (preferably without
installing a full GF) that I then read in my JUnit tests?

 


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