test_class.declarator: HEADER_NOT_BEARER = "NOT BEARER"
test_class.modifier: private static final
test_class.original_string: private static final String HEADER_NOT_BEARER = "NOT BEARER";
test_class.type: String
test_class.var_name: HEADER_NOT_BEARER
test_class.declarator: HEADER_BAD_BEARER = JwtFilter.BEARER_PREFIX + "GARBAGE"
test_class.modifier: private static final
test_class.original_string: private static final String HEADER_BAD_BEARER = JwtFilter.BEARER_PREFIX + "GARBAGE";
test_class.type: String
test_class.var_name: HEADER_BAD_BEARER
test_class.declarator: HEADER_EMPTY_CREDENTIALS = JwtFilter.BEARER_PREFIX +
          "eyJhbGciOiJIUzI1NiJ9.eyJyb2xlcyI6IiIsImlhdCI6MH0.nEBg6Bj7PLGALFT2rs4wDfhvUfA91b7XLNog029crUA"
test_class.modifier: private static final
test_class.original_string: private static final String HEADER_EMPTY_CREDENTIALS = JwtFilter.BEARER_PREFIX +
          "eyJhbGciOiJIUzI1NiJ9.eyJyb2xlcyI6IiIsImlhdCI6MH0.nEBg6Bj7PLGALFT2rs4wDfhvUfA91b7XLNog029crUA";
test_class.type: String
test_class.var_name: HEADER_EMPTY_CREDENTIALS
test_class.declarator: HEADER_VALID_CREDENTIALS = JwtFilter.BEARER_PREFIX +
          "eyJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJ2YWxpZCIsInJvbGVzIjoiIiwiaWF0IjowfQ.lzdLJW9bdkXZLc57_YcXm0cJL87ZFSrPLEOD1-nYR8Q"
test_class.modifier: private static final
test_class.original_string: private static final String HEADER_VALID_CREDENTIALS = JwtFilter.BEARER_PREFIX +
          "eyJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJ2YWxpZCIsInJvbGVzIjoiIiwiaWF0IjowfQ.lzdLJW9bdkXZLc57_YcXm0cJL87ZFSrPLEOD1-nYR8Q";
test_class.type: String
test_class.var_name: HEADER_VALID_CREDENTIALS
test_class.declarator: VALID_CREDENTIALS_SUBJECT = "valid"
test_class.modifier: private static final
test_class.original_string: private static final String VALID_CREDENTIALS_SUBJECT = "valid";
test_class.type: String
test_class.var_name: VALID_CREDENTIALS_SUBJECT
test_class.declarator: mockHttpServletRequest
test_class.modifier: @Mock
      private
test_class.original_string: @Mock
      private HttpServletRequest mockHttpServletRequest;
test_class.type: HttpServletRequest
test_class.var_name: mockHttpServletRequest
test_class.declarator: mockHttpServletResponse
test_class.modifier: @Mock
      private
test_class.original_string: @Mock
      private HttpServletResponse mockHttpServletResponse;
test_class.type: HttpServletResponse
test_class.var_name: mockHttpServletResponse
test_class.declarator: mockFilterChain
test_class.modifier: @Mock
      private
test_class.original_string: @Mock
      private FilterChain mockFilterChain;
test_class.type: FilterChain
test_class.var_name: mockFilterChain
test_class.declarator: jwtFilter
test_class.modifier: private
test_class.original_string: private JwtFilter jwtFilter;
test_class.type: JwtFilter
test_class.var_name: jwtFilter
test_class.file: application/confagrid-webapp/src/test/java/com/aleggeup/confagrid/auth/JwtFilterTest.java
test_class.identifier: JwtFilterTest
test_case.body: @Test
      public void testEmptyCredentials() throws ServletException, IOException {
          Mockito.when(mockHttpServletRequest.getHeader(JwtFilter.HEADER_AUTHORIZATION))
              .thenReturn(HEADER_EMPTY_CREDENTIALS);
  
          jwtFilter.doFilterInternal(mockHttpServletRequest, mockHttpServletResponse, mockFilterChain);
  
          Mockito.verify(mockHttpServletRequest).getMethod();
          Mockito.verify(mockHttpServletRequest).setAttribute(JwtFilter.JWT_ATTRIBUTE,
              new DefaultClaims().setSubject(JwtFilter.SUBJECT_ANONYMOUS));
          Mockito.verify(mockHttpServletResponse).setHeader(JwtFilter.JWT_TOKEN,
              "eyJhbGciOiJIUzI1NiJ9.eyJyb2xlcyI6IiIsImlhdCI6MH0.nEBg6Bj7PLGALFT2rs4wDfhvUfA91b7XLNog029crUA");
          Mockito.verify(mockHttpServletRequest).getHeader(JwtFilter.HEADER_AUTHORIZATION);
          Mockito.verify(mockHttpServletResponse).setHeader(JwtFilter.HEADER_CLAIMS_SUBJECT, JwtFilter.SUBJECT_ANONYMOUS);
          Mockito.verify(mockFilterChain).doFilter(mockHttpServletRequest, mockHttpServletResponse);
          Mockito.verify(mockHttpServletResponse, Mockito.times(4)).setHeader(ArgumentMatchers.anyString(),
              ArgumentMatchers.any());
      }
test_case.class_method_signature: JwtFilterTest.testEmptyCredentials()
test_case.full_signature: @Test public void testEmptyCredentials()
test_case.identifier: testEmptyCredentials
test_case.invocations: thenReturn when getHeader doFilterInternal getMethod verify setAttribute verify setSubject setHeader verify getHeader verify setHeader verify doFilter verify setHeader verify times anyString any
test_case.modifiers: @Test public
test_case.parameters: ()
test_case.return: void
test_case.signature: void testEmptyCredentials()
focal_class.declarator: ATTRIBUTE_CLAIMS = "claims"
focal_class.modifier: public static final
focal_class.original_string: public static final String ATTRIBUTE_CLAIMS = "claims";
focal_class.type: String
focal_class.var_name: ATTRIBUTE_CLAIMS
focal_class.declarator: BEARER_PREFIX = "Bearer "
focal_class.modifier: public static final
focal_class.original_string: public static final String BEARER_PREFIX = "Bearer ";
focal_class.type: String
focal_class.var_name: BEARER_PREFIX
focal_class.declarator: HEADER_AUTHORIZATION = "Authorization"
focal_class.modifier: public static final
focal_class.original_string: public static final String HEADER_AUTHORIZATION = "Authorization";
focal_class.type: String
focal_class.var_name: HEADER_AUTHORIZATION
focal_class.declarator: HEADER_CLAIMS = "x-claims"
focal_class.modifier: public static final
focal_class.original_string: public static final String HEADER_CLAIMS = "x-claims";
focal_class.type: String
focal_class.var_name: HEADER_CLAIMS
focal_class.declarator: HEADER_CLAIMS_SUBJECT = "x-claims-subject"
focal_class.modifier: public static final
focal_class.original_string: public static final String HEADER_CLAIMS_SUBJECT = "x-claims-subject";
focal_class.type: String
focal_class.var_name: HEADER_CLAIMS_SUBJECT
focal_class.declarator: HEADER_CLAIMS_USER_ID = "x-claims-user-id"
focal_class.modifier: public static final
focal_class.original_string: public static final String HEADER_CLAIMS_USER_ID = "x-claims-user-id";
focal_class.type: String
focal_class.var_name: HEADER_CLAIMS_USER_ID
focal_class.declarator: SECRET_KEY = "secretkey"
focal_class.modifier: public static final
focal_class.original_string: public static final String SECRET_KEY = "secretkey";
focal_class.type: String
focal_class.var_name: SECRET_KEY
focal_class.declarator: SUBJECT_ANONYMOUS = "anonymous"
focal_class.modifier: public static final
focal_class.original_string: public static final String SUBJECT_ANONYMOUS = "anonymous";
focal_class.type: String
focal_class.var_name: SUBJECT_ANONYMOUS
focal_class.declarator: JWT_TOKEN = "x-jwt-token"
focal_class.modifier: public static final
focal_class.original_string: public static final String JWT_TOKEN = "x-jwt-token";
focal_class.type: String
focal_class.var_name: JWT_TOKEN
focal_class.declarator: JWT_ATTRIBUTE = "x-jwt-attribute"
focal_class.modifier: public static final
focal_class.original_string: public static final String JWT_ATTRIBUTE = "x-jwt-attribute";
focal_class.type: String
focal_class.var_name: JWT_ATTRIBUTE
focal_class.declarator: ANONYMOUS_USER_ID = "b5a2918e-bd3f-48f5-8437-daf40fd3f323"
focal_class.modifier: public static final
focal_class.original_string: public static final String ANONYMOUS_USER_ID = "b5a2918e-bd3f-48f5-8437-daf40fd3f323";
focal_class.type: String
focal_class.var_name: ANONYMOUS_USER_ID
focal_class.declarator: LOGGER = LoggerFactory.getLogger(JwtFilter.class)
focal_class.modifier: private static final
focal_class.original_string: private static final Logger LOGGER = LoggerFactory.getLogger(JwtFilter.class);
focal_class.type: Logger
focal_class.var_name: LOGGER
focal_class.file: application/confagrid-webapp/src/main/java/com/aleggeup/confagrid/auth/JwtFilter.java
focal_class.identifier: JwtFilter
focal_class.class_method_signature: JwtFilter.doFilterInternal(@NonNull final HttpServletRequest request,
          @NonNull final HttpServletResponse response, @NonNull final FilterChain chain)
focal_class.full_signature: @Override protected void doFilterInternal(@NonNull final HttpServletRequest request,
          @NonNull final HttpServletResponse response, @NonNull final FilterChain chain)
focal_class.identifier: doFilterInternal
focal_class.modifiers: @Override protected
focal_class.parameters: (@NonNull final HttpServletRequest request,
          @NonNull final HttpServletResponse response, @NonNull final FilterChain chain)
focal_class.return: void
focal_class.signature: void doFilterInternal(@NonNull final HttpServletRequest request,
          @NonNull final HttpServletResponse response, @NonNull final FilterChain chain)
focal_class.superclass: extends OncePerRequestFilter
focal_method.body: @Override
      protected void doFilterInternal(@NonNull final HttpServletRequest request,
          @NonNull final HttpServletResponse response, @NonNull final FilterChain chain)
          throws ServletException, IOException {
  
          Claims claims = null;
          String token = "";
  
          if (!RequestMethod.OPTIONS.toString().equals(request.getMethod())) {
  
              final String authHeader = request.getHeader(HEADER_AUTHORIZATION);
  
              if (authHeader == null || !authHeader.startsWith(BEARER_PREFIX)) {
                  LOGGER.info("Missing or invalid Authorization header.");
                  claims = new DefaultClaims().setSubject(SUBJECT_ANONYMOUS);
              } else {
                  try {
                      token = authHeader.substring(BEARER_PREFIX.length());
                      claims = Jwts.parser().setSigningKey(SECRET_KEY).parseClaimsJws(token).getBody();
                  } catch (final JwtException e) {
                      LOGGER.warn("Unable to get claims from bearer token: {}", e.getMessage());
                  }
  
                  if (claims == null || claims.getSubject() == null) {
                      claims = new DefaultClaims().setSubject(SUBJECT_ANONYMOUS);
                  }
              }
  
              request.setAttribute(JWT_ATTRIBUTE, claims);
              response.setHeader(JWT_TOKEN, token);
              response.setHeader(HEADER_CLAIMS, claims.toString());
              response.setHeader(HEADER_CLAIMS_SUBJECT, claims.getSubject());
              response.setHeader(HEADER_CLAIMS_USER_ID, claims.getId());
          }
  
          chain.doFilter(request, response);
      }
focal_method.class_method_signature: JwtFilter.doFilterInternal(@NonNull final HttpServletRequest request,
          @NonNull final HttpServletResponse response, @NonNull final FilterChain chain)
focal_method.full_signature: @Override protected void doFilterInternal(@NonNull final HttpServletRequest request,
          @NonNull final HttpServletResponse response, @NonNull final FilterChain chain)
focal_method.identifier: doFilterInternal
focal_method.invocations: equals toString getMethod getHeader startsWith info setSubject substring length getBody parseClaimsJws setSigningKey parser warn getMessage getSubject setSubject setAttribute setHeader setHeader toString setHeader getSubject setHeader getId doFilter
focal_method.modifiers: @Override protected
focal_method.parameters: (@NonNull final HttpServletRequest request,
          @NonNull final HttpServletResponse response, @NonNull final FilterChain chain)
focal_method.return: void
focal_method.signature: void doFilterInternal(@NonNull final HttpServletRequest request,
          @NonNull final HttpServletResponse response, @NonNull final FilterChain chain)