예제 #1
0
  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) {
    }
  }
예제 #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.
    }
  }
예제 #3
0
  @Test
  public void testImportExport() throws Exception {
    clearCache();
    startDeployment();
    Assert.assertEquals(0, app.getCache().size());
    init();
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    new Loader().export(app.getCache(), baos);
    app.getCache().clear();
    stopDeployment();

    startDeployment();
    Assert.assertEquals(0, app.getCache().size());
    ByteArrayInputStream bios = new ByteArrayInputStream(baos.toByteArray());
    new Loader().importStore(bios, app.getCache());
    stopDeployment();
    startDeployment();
    Assert.assertTrue(0 < app.getCache().size());

    ResteasyClient client = new ResteasyClientBuilder().build();
    WebTarget target = client.target(generateBaseUrl());
    SkeletonKeyAdminClient admin =
        new SkeletonKeyClientBuilder().username("wburke").password("geheim").idp(target).admin();

    StoredUser newUser = new StoredUser();
    newUser.setName("John Smith");
    newUser.setUsername("jsmith");
    newUser.setEnabled(true);
    Map creds = new HashMap();
    creds.put("password", "foobar");
    newUser.setCredentials(creds);
    Response response = admin.users().create(newUser);
    User user = response.readEntity(User.class);
    response = admin.roles().create("user");
    Role role = response.readEntity(Role.class);
    Projects projects = admin.projects().query("Skeleton Key");
    Project project = projects.getList().get(0);
    admin.projects().addUserRole(project.getId(), user.getId(), role.getId());

    admin =
        new SkeletonKeyClientBuilder().username("jsmith").password("foobar").idp(target).admin();
    response = admin.roles().create("error");
    Assert.assertEquals(403, response.getStatus());
    stopDeployment();
  }
예제 #4
0
 private static void stopDeployment() throws Exception {
   app.getCache().stop();
   deployment = null;
   app = null;
   EmbeddedContainer.stop();
 }