Example #1
0
  protected void onSetUpInTransaction() throws Exception {
    System.err.println("onSetUpInTransaction");
    super.onSetUpInTransaction();
    this.nodeService = (NodeService) super.applicationContext.getBean("dbNodeService");
    assertNotNull(this.nodeService);
    final FileFolderService fileFolderService =
        (FileFolderService) super.applicationContext.getBean("fileFolderService");
    assertNotNull(fileFolderService);
    this.formsService = (FormsService) super.applicationContext.getBean("FormsService");
    assertNotNull(this.formsService);
    final MutableAuthenticationService authenticationService =
        (MutableAuthenticationService) applicationContext.getBean("authenticationService");
    authenticationService.clearCurrentSecurityContext();
    final MutableAuthenticationDao authenticationDAO =
        (MutableAuthenticationDao) applicationContext.getBean("authenticationDao");

    // Create a workspace that contains the 'live' nodes
    final StoreRef testStoreRef =
        this.nodeService.createStore(
            StoreRef.PROTOCOL_WORKSPACE, "Test_" + System.currentTimeMillis());

    // Get a reference to the root node
    final NodeRef rootNodeRef = this.nodeService.getRootNode(testStoreRef);

    // Create an authenticate the user
    if (!authenticationDAO.userExists(AuthenticationUtil.getAdminUserName())) {
      authenticationService.createAuthentication(
          AuthenticationUtil.getAdminUserName(), "admin".toCharArray());
    }

    TestWithUserUtils.authenticateUser(
        AuthenticationUtil.getAdminUserName(), "admin", rootNodeRef, authenticationService);

    // set up a faces context
    final MockExternalContext ec =
        new MockExternalContext(
            new MockServletContext(), new MockHttpServletRequest(), new MockHttpServletResponse());
    final StaticWebApplicationContext ac = new StaticWebApplicationContext();
    ac.setParent(this.applicationContext);
    this.applicationContext = ac;
    ec.getApplicationMap()
        .put(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, this.applicationContext);
    new MockFacesContext(ec);

    final FileInfo folderInfo =
        fileFolderService.create(rootNodeRef, "test_form", WCMAppModel.TYPE_FORMFOLDER);
    final HashMap<QName, Serializable> props = new HashMap<QName, Serializable>();
    this.nodeService.addAspect(folderInfo.getNodeRef(), WCMAppModel.ASPECT_FORM, props);
    this.mockForm = new MockForm(folderInfo.getNodeRef(), this.formsService);
  }
 @Override
 protected void onTearDownInTransaction() throws Exception {
   authenticationService.clearCurrentSecurityContext();
   super.onTearDownInTransaction();
 }
Example #3
0
 private void reauthenticate(String name, String password) {
   authenticationService.invalidateTicket(authenticationService.getCurrentTicket());
   authenticationService.clearCurrentSecurityContext();
   authenticationService.authenticate(name, password.toCharArray());
 }