Internal API Module is helper for Blibli Internal API
<dependency>
<groupId>com.blibli.oss</groupId>
<artifactId>blibli-backend-framework-internal-api</artifactId>
</dependency>
External Session is represented by InternalSession
class. There are some information on that class,
like userId, userName and roles.
public class InternalSession {
private String userId;
private String userName;
private List<String> roles;
}
To Get Internal Session on Controller, we can add on method parameter. InternalSessionArgumentResolver
will automatically get the data from HTTP Header
@RestController
public class ExampleController {
@GetMapping(value = "/backend-internal/your-api", produces = MediaType.APPLICATION_JSON_VALUE)
public Mono<Response<SomeResponse>> member(InternalSession internalSession) {
// do something
}
To add Internal Session to swagger, we can use @InternalSessionAtHeader
annotation in controller method.
@RestController
public class ExampleController {
@InternalSessionAtHeader
@GetMapping(value = "/backend-internal/only-member", produces = MediaType.APPLICATION_JSON_VALUE)
public Mono<Response<MemberData>> member(InternalSession internalSession) {
// do something
}
If we are using sleuth, we can also get InternalSession
from sleuth using InternalSessionHelper
.
@Service
public class ExampleService {
@Autowired
private Tracer tracer;
public InternalSession getInternalSession() {
return InternalSessionHelper.fromSleuth(tracer.currentSpan().context());
}
}