示例#1
0
 @Test
 public void testNotAuthenticated() {
   {
     // assuming @RolesAllowed is on class level. Too lazy to test it all!
     String newUser =
         "******"user\" : { \"username\" : \"wburke\", \"name\" : \"Bill Burke\", \"email\" : \"[email protected]\", \"enabled\" : true, \"credentials\" : { \"password\" : \"geheim\" }} }";
     ResteasyClient client = new ResteasyClient(deployment.getProviderFactory());
     Response response = client.target(generateURL("/users")).request().post(Entity.json(newUser));
     Assert.assertEquals(response.getStatus(), 403);
     response.close();
   }
   {
     String newRole = "{ \"role\" : { \"name\" : \"admin\"} }";
     ResteasyClient client = new ResteasyClient(deployment.getProviderFactory());
     Response response = client.target(generateURL("/roles")).request().post(Entity.json(newRole));
     Assert.assertEquals(response.getStatus(), 403);
     response.close();
   }
   {
     String newProject =
         "{ \"project\" : { \"id\" : \"5\", \"name\" : \"Resteasy\", \"description\" : \"The Best of REST\", \"enabled\" : true } }";
     ResteasyClient client = new ResteasyClient(deployment.getProviderFactory());
     Response response =
         client.target(generateURL("/projects")).request().post(Entity.json(newProject));
     Assert.assertEquals(response.getStatus(), 403);
     response.close();
   }
 }
  @Before
  public void setUp() throws Exception {

    if (server != null) {
      return;
    }

    int port =
        testingPropertiesHelper.getPropertyValueAsInt(
            testingProperties, RestTestingProperties.REST_PORT_PROPERTY);
    server = new TJWSEmbeddedJaxrsServer();
    server.setPort(port);
    ResteasyDeployment deployment = server.getDeployment();

    server.start();
    Dispatcher dispatcher = deployment.getDispatcher();
    SpringBeanProcessor processor =
        new SpringBeanProcessor(
            dispatcher, deployment.getRegistry(), deployment.getProviderFactory());
    ((ConfigurableApplicationContext) applicationContext).addBeanFactoryPostProcessor(processor);

    SpringResourceFactory noDefaults =
        new SpringResourceFactory("userService", applicationContext, UserService.class);
    dispatcher.getRegistry().addResourceFactory(noDefaults);
  }
示例#3
0
 public static void before(Hashtable<String, String> contextParams) throws Exception {
   Hashtable<String, String> initParams = new Hashtable<String, String>();
   deployment = EmbeddedContainer.start(initParams, contextParams);
   dispatcher = deployment.getDispatcher();
   deployment.getRegistry().addPerRequestResource(TestResource.class);
   deployment.getProviderFactory().register(TestExceptionMapper.class);
 }
 @Override
 public ResteasyDeployment createDeployment() {
   ResteasyDeployment deployment = super.createDeployment();
   deployment.getDefaultContextObjects().put(ServletConfig.class, config);
   deployment.getDefaultContextObjects().put(ServletContext.class, config.getServletContext());
   return deployment;
 }
  public static void startup() throws Exception {
    deployment = EmbeddedContainer.start();

    manager = new MessageServiceManager();
    manager.start();
    deployment.getRegistry().addSingletonResource(manager.getQueueManager().getDestination());
    deployment.getRegistry().addSingletonResource(manager.getTopicManager().getDestination());

    deployment.getRegistry().addPerRequestResource(Receiver.class);
  }
  @Test
  public void customizedDeploymentConfiguration() {
    this.context = new AnnotationConfigApplicationContext();
    this.context.register(ResteasyAutoConfiguration.class);
    EnvironmentTestUtils.addEnvironment(
        this.context, "resteasy.deployment.async_job_service_enabled:true");
    this.context.refresh();

    ResteasyDeployment deployment = this.context.getBean(ResteasyDeployment.class);
    assertTrue(deployment.isAsyncJobServiceEnabled());
  }
  private static void startDeployment() throws Exception {
    deployment = new ResteasyDeployment();
    deployment.setSecurityEnabled(true);
    deployment.setApplicationClass(SApp.class.getName());
    ResteasyProviderFactory factory = new ResteasyProviderFactory();
    deployment.setProviderFactory(factory);
    factory.setProperty(SkeletonKeyApplication.SKELETON_KEY_INFINISPAN_CONFIG_FILE, "cache.xml");
    factory.setProperty(SkeletonKeyApplication.SKELETON_KEY_INFINISPAN_CACHE_NAME, "idp-store");

    EmbeddedContainer.start(deployment);
    app = ((SApp) deployment.getApplication()).app;
  }
示例#8
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.
    }
  }
 private void deploy() {
   List<ApplicationClass> classes = Play.classes.all();
   deployment = new ResteasyDeployment();
   // classes
   for (ApplicationClass klass : classes) {
     if (!isJAXRSEntity(klass.javaClass, Path.class)) continue;
     log("Found resource class: %s", klass.name);
     resourceClasses.put(klass.name, klass.javaClass);
   }
   deployment.setResourceClasses(new ArrayList<String>(resourceClasses.keySet()));
   // providers
   for (ApplicationClass klass : classes) {
     if (!isJAXRSEntity(klass.javaClass, Provider.class)) continue;
     log("Found provider class: %s", klass.name);
     providerClasses.put(klass.name, klass.javaClass);
   }
   deployment.setProviderClasses(new ArrayList<String>(providerClasses.keySet()));
   deployment.start();
 }
示例#10
0
  public void start() {

    ResteasyDeployment dp = new ResteasyDeployment();

    Collection<Object> providers = ac.getBeansWithAnnotation(Provider.class).values();
    Collection<Object> controllers = ac.getBeansWithAnnotation(Controller.class).values();

    Assert.notEmpty(controllers);

    // extract providers
    if (providers != null) {
      dp.getProviders().addAll(providers);
    }
    // extract only controller annotated beans
    dp.getResources().addAll(controllers);

    netty = new ConfigurableNettyJaxrsServer();
    netty.initBootstrap().setOption("reuseAddress", true);
    netty.setDeployment(dp);
    netty.setPort(port);
    netty.setRootResourcePath(rootResourcePath);
    netty.setSecurityDomain(null);
    netty.start();
  }
 @Before
 public void before() throws Exception {
   deployment = EmbeddedContainer.start();
   deployment.getRegistry().addPerRequestResource(TestResource.class);
 }
 public ResteasyHandlerMapping(ResteasyDeployment deployment) {
   super();
   this.dispatcher = (SynchronousDispatcher) deployment.getDispatcher();
 }
 @BeforeClass
 public static void setup() throws Exception {
   deployment = EmbeddedContainer.start();
   deployment.getRegistry().addPerRequestResource(TestResource.class);
   client = new ResteasyClientBuilder().build();
 }