Spring

Spring

BitSensor Spring Plugin

BitSensor Spring Plugin

The BitSensor plugin for Spring. Works with any Spring application using MVC or Spring Security.

Getting started

This shows how to intercept request and send them to a BitSensor server for analysis.

  1. Follow the README of the BitSensor core plugin

  2. Add java-spring dependencies to pom.xml

        <dependency>
            <groupId>io.bitsensor.plugins</groupId>
            <artifactId>core-spring</artifactId>
            <version>2.0-RC3</version>
        </dependency>
        <dependency>
            <groupId>io.bitsensor.plugins</groupId>
            <artifactId>java-spring-http</artifactId>
            <version>2.0-RC3</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-aop</artifactId>
            <optional>true</optional>
        </dependency>
    
  3. Add @EnableBitSensor to your io.bitsensor.spring.configuration:

    @SpringBootApplication
    @Configuration
    @EnableAspectJAutoProxy
    @EnableBitSensor
    public class Application extends SpringBootServletInitializer {
    
        public static void main(String[] args) throws Exception {
            SpringApplication.run(Application.class, args);
        }
    
    
  4. Add your configuration to application.yml:

    bitsensor:
        username: webgoat
        apiKey: apikey_java
        #URI for protobuf gRPC connector
        uri: dev.bitsensor.io
        #URI for http connector
        uri: http://dev.bitsensor.io:8080        
        queueSize: 1000
        poolSize: 1000
    spring:
        application:
            name: username
    profiles:
        active: bitsensor-test
    endpoints:
        shutdown:
            enabled: true
            sensitive: false
    logging:
        level: trace
    
  5. Get the BitSensor instance to add additional information:

    @Autowired
    BitSensor mBitSensor;
    

Writing handlers

It is possible to add easily add some data to a DataPoint. Just create a bean that implements the Handler interface and you will be able to manipulate every DataPoint that gets collected.

import io.bitsensor.plugins.java.spring.BitSensor;

import javax.inject.Inject;
import javax.inject.Named;

@Named
public class CustomHandler implements CoreHandler {

    @Inject
    BitSensor bitSensor;

    @Override
    public void handle() {

    }

    @Override
    public ExecutionMoment getExecutionMoment() {

    }

}