1 package org.starobjects.tested.fitnesse.internal.helpers;
2
3 import org.nakedobjects.applib.fixtures.LogonFixture;
4 import org.nakedobjects.metamodel.authentication.AuthenticationSession;
5 import org.nakedobjects.runtime.authentication.AuthenticationManager;
6 import org.nakedobjects.runtime.authentication.standard.fixture.AuthenticationRequestLogonFixture;
7 import org.nakedobjects.runtime.context.NakedObjectsContext;
8 import org.starobjects.tested.fitnesse.StoryFixture;
9
10 public class OpenSession {
11
12 @SuppressWarnings("unused")
13 private final StoryFixture storyFixture;
14
15 public OpenSession(final StoryFixture storyFixture) {
16 this.storyFixture = storyFixture;
17 }
18
19 public void openSession(final String userName, final String[] roles) {
20 NakedObjectsContext.closeSession();
21 final LogonFixture logonFixture = new LogonFixture(userName, roles);
22 final AuthenticationRequestLogonFixture authRequest = new AuthenticationRequestLogonFixture(
23 logonFixture);
24 final AuthenticationSession authSession = OpenSession
25 .getAuthenticationManager().authenticate(authRequest);
26
27 NakedObjectsContext.openSession(authSession);
28 }
29
30 private static AuthenticationManager getAuthenticationManager() {
31 return NakedObjectsContext.getAuthenticationManager();
32 }
33
34 }