Skip to the content
Krizaka Java
Skip to Content
Krizaka Java

Security

krizaka-security — local session-token verification, one baseline for every filter chain, service tokens.

<dependency>
  <groupId>com.krizaka</groupId>
  <artifactId>krizaka-spring-boot-starter-security</artifactId>
</dependency>

Verify session tokens locally

krizaka:
  security:
    jwt:
      secret: ${IDENTITY_JWT_SECRET} # ≥ 32 characters, or the service refuses to start

With the secret set, the auto-configuration contributes a JwtDecoder (HS256 only, this key only) and a JwtAuthenticationConverter that maps the roles claim to authorities with no prefix: ROLE_USER, ROLE_ADMIN and SERVICE arrive as they were issued. Both back off if you declare your own.

One baseline for every filter chain

@Bean
SecurityFilterChain securityFilterChain(HttpSecurity http, JwtAuthenticationConverter roles) throws Exception {
  return SecurityBaseline.apply(http, auth -> auth.requestMatchers("/api/v1/catalogue/**").permitAll())
      .oauth2ResourceServer(o -> o.jwt(jwt -> jwt.jwtAuthenticationConverter(roles)))
      .build();
}

SecurityBaseline.apply:

  • makes the chain stateless (CSRF off — token-only APIs);
  • opens OPTIONS /** (a CORS preflight never carries a token), /actuator/health, /actuator/info and /error;
  • reserves /internal/v1/** for the SERVICE authority;
  • runs your rules, then ends with anyRequest().authenticated() — nothing is open by omission.

Call another service's internal surface

ServiceTokenProvider tokens = new ServiceTokenProvider(secret, "billing-client");
RestClient.builder()
    .baseUrl(billingUrl)
    .requestInitializer(request -> request.getHeaders().setBearerAuth(tokens.token()))
    .build();

A five-minute HS256 token with roles: ["SERVICE"], minted per call. ServiceTokenProvider needs nothing but the JDK. Any process holding the secret can mint SERVICE: keep the secret where it is needed.

Configuration

Generated from the configuration metadata — the full reference lists every artifact.

PropertyDescription
krizaka.security.jwt.audienceStringdefault Optional with 'jwk-set-uri': when set, the 'aud' that must be present; empty by default.
krizaka.security.jwt.callersMap<String,String>no defaultOptional: the public key (SPKI PEM, P-256) of each calling service by the name it puts in 'sub'. A token signed by one of these keys, carrying exactly the SERVICE role, is accepted beside the sessions; a caller cannot speak for another, an unknown name is refused.
krizaka.security.jwt.hs256-cutoffInstantno defaultOptional, with 'secret': from this instant the shared secret verifies nothing (ISO-8601). Empty keeps it open until the secret is removed.
krizaka.security.jwt.issuerStringdefault Required with 'jwk-set-uri': the only 'iss' accepted; empty by default.
krizaka.security.jwt.jwk-set-uriStringdefault The issuer's JWKS endpoint ('/.well-known/jwks.json'); empty by default, which leaves this mode off. Only ES256 tokens are accepted in this mode; keys are matched by 'kid', and an unknown 'kid' triggers a (rate limited) refresh so rotation needs no restart.
krizaka.security.jwt.secretStringno defaultLegacy shared HMAC-SHA256 secret, at least 32 characters (256 bits). Whoever can verify with it can also mint.

On this page