public static void init() throws Exception {

    StoredUser admin = new StoredUser();
    admin.setName("Bill");
    admin.setUsername("wburke");
    HashMap<String, String> creds = new HashMap<String, String>();
    creds.put("password", "geheim");
    admin.setCredentials(creds);
    app.getUsers().create(admin);

    Project project = new Project();
    project.setName("Skeleton Key");
    project.setEnabled(true);
    app.getProjects().createProject(project);

    Role adminRole = new Role();
    adminRole.setName("admin");
    app.getRoles().create(adminRole);

    app.getProjects().addUserRole(project.getId(), admin.getId(), adminRole.getId());

    // Test export/import
    System.out.println(new Loader().export(app.getCache()));

    try {
      ByteArrayOutputStream baos = new ByteArrayOutputStream();
      new Loader().export(app.getCache(), baos);
      ByteArrayInputStream bios = new ByteArrayInputStream(baos.toByteArray());
      app.getCache().clear();
      new Loader().importStore(bios, app.getCache());
    } catch (Exception e) {
    }
  }
Beispiel #2
0
  @BeforeClass
  public static void before() throws Exception {
    deployment = new ResteasyDeployment();
    deployment.setSecurityEnabled(true);
    deployment.setApplicationClass(SApp.class.getName());

    EmbeddedContainer.start(deployment);
    SkeletonKeyApplication app = ((SApp) deployment.getApplication()).app;

    KeyPair keyPair = KeyPairGenerator.getInstance("RSA", "BC").generateKeyPair();
    privateKey = keyPair.getPrivate();
    certificate = KeyTools.generateTestCertificate(keyPair);
    app.getTokenService().setCertificate(certificate);
    app.getTokenService().setPrivateKey(privateKey);

    StoredUser admin = new StoredUser();
    admin.setName("Bill");
    admin.setUsername("wburke");
    HashMap<String, String> creds = new HashMap<String, String>();
    creds.put("password", "geheim");
    admin.setCredentials(creds);
    app.getUsers().create(admin);

    Project project = new Project();
    project.setName("Skeleton Key");
    project.setEnabled(true);
    app.getProjects().createProject(project);

    Role adminRole = new Role();
    adminRole.setName("admin");
    app.getRoles().create(adminRole);

    app.getProjects().addUserRole(project.getId(), admin.getId(), adminRole.getId());

    // Test export/import
    System.out.println(new Loader().export(app.getCache()));

    try {
      ByteArrayOutputStream baos = new ByteArrayOutputStream();
      new Loader().export(app.getCache(), baos);
      ByteArrayInputStream bios = new ByteArrayInputStream(baos.toByteArray());
      app.getCache().clear();
      new Loader().importStore(bios, app.getCache());
    } catch (Exception e) {
      e
          .printStackTrace(); // To change body of catch statement use File | Settings | File
                              // Templates.
    }
  }