@Test public void shouldLoadContextWithoutAuthenticationIfAuthorizationHeaderValueNotBearerToken() throws Exception { BearerSecurityContextRepository repository = new BearerSecurityContextRepository(); HttpServletRequest request = mock(HttpServletRequest.class); HttpRequestResponseHolder holder = new HttpRequestResponseHolder(request, null); when(request.getHeader("Authorization")).thenReturn("Basic somevalue"); SecurityContext context = repository.loadContext(holder); assertThat(context, is(notNullValue())); assertThat(context.getAuthentication(), is(nullValue())); }
@Override public SecurityContext loadContext(HttpRequestResponseHolder requestResponseHolder) { SecurityContext context = SecurityContextHolder.createEmptyContext(); String token = tokenFromRequest(requestResponseHolder.getRequest()); Authentication authentication = PreAuthenticatedAuthenticationJsonWebToken.usingToken(token); if (authentication != null) { context.setAuthentication(authentication); logger.debug("Found bearer token in request. Saving it in SecurityContext"); } return context; }
BearerSecurityContextRepository implements SecurityContextRepository { @Override public SecurityContext loadContext(HttpRequestResponseHolder requestResponseHolder) { SecurityContext context = SecurityContextHolder.createEmptyContext(); String token = tokenFromRequest(requestResponseHolder.getRequest()); Authentication authentication = PreAuthenticatedAuthenticationJsonWebToken.usingToken(token); if (authentication != null) { context.setAuthentication(authentication); logger.debug("Found bearer token in request. Saving it in SecurityContext"); } return context; } }
BearerSecurityContextRepository implements SecurityContextRepository { @Override public SecurityContext loadContext(HttpRequestResponseHolder requestResponseHolder) { SecurityContext context = SecurityContextHolder.createEmptyContext(); String token = tokenFromRequest(requestResponseHolder.getRequest()); Authentication authentication = PreAuthenticatedAuthenticationJsonWebToken.usingToken(token); if (authentication != null) { context.setAuthentication(authentication); logger.debug("Found bearer token in request. Saving it in SecurityContext"); } return context; }  }
BearerSecurityContextRepository implements SecurityContextRepository { @Override public SecurityContext loadContext(HttpRequestResponseHolder requestResponseHolder) { SecurityContext context = SecurityContextHolder.createEmptyContext(); String token = tokenFromRequest(requestResponseHolder.getRequest()); Authentication authentication = PreAuthenticatedAuthenticationJsonWebToken.usingToken(token); if (authentication != null) { context.setAuthentication(authentication); logger.debug("Found bearer token in request. Saving it in SecurityContext"); } return context; }  @Override SecurityContext loadContext(HttpRequestResponseHolder requestResponseHolder); @Override void saveContext(SecurityContext context, HttpServletRequest request, HttpServletResponse response); @Override boolean containsContext(HttpServletRequest request); }
BearerSecurityContextRepository implements SecurityContextRepository { @Override public SecurityContext loadContext(HttpRequestResponseHolder requestResponseHolder) { SecurityContext context = SecurityContextHolder.createEmptyContext(); String token = tokenFromRequest(requestResponseHolder.getRequest()); Authentication authentication = PreAuthenticatedAuthenticationJsonWebToken.usingToken(token); if (authentication != null) { context.setAuthentication(authentication); logger.debug("Found bearer token in request. Saving it in SecurityContext"); } return context; }  @Override SecurityContext loadContext(HttpRequestResponseHolder requestResponseHolder); @Override void saveContext(SecurityContext context, HttpServletRequest request, HttpServletResponse response); @Override boolean containsContext(HttpServletRequest request);  }