AccessControlInterceptor extends AbstractPhaseInterceptor<Message> { protected Session authenticateAccess( Message message, HttpServletRequest request ) { String sptoken; if ( message == null ) { return identityManager.loginSystemUser(); } else { String bearerToken = getBearerToken( request ); if ( bearerToken != null ) { return identityManager.login( request, message ); } else { sptoken = request.getParameter( "sptoken" ); if ( StringUtils.isBlank( sptoken ) ) { HttpHeaders headers = new HttpHeadersImpl( message.getExchange().getInMessage() ); sptoken = headers.getHeaderString( "sptoken" ); } if ( StringUtils.isBlank( sptoken ) ) { Cookie[] cookies = request.getCookies(); for ( final Cookie cookie : cookies ) { if ( "sptoken".equals( cookie.getName() ) ) { sptoken = cookie.getValue(); } } } if ( StringUtils.isBlank( sptoken ) ) { return null; } else { return identityManager.login( IdentityManager.TOKEN_ID, sptoken ); } } } } AccessControlInterceptor( IdentityManager identityManager ); @Override void handleMessage( final Message message );  }
@Test public void testAuthenticateAccess() throws Exception { accessControlInterceptor.authenticateAccess( null, request ); verify( identityManager ).loginSystemUser(); }
@Test public void testAuthenticateAccess2() throws Exception { assertNull( accessControlInterceptor.authenticateAccess( message, request ) ); }
@Test public void testAuthenticateAccess3() throws Exception { doReturn( "sptoken" ).when( cookie ).getName(); doReturn( "sptoken" ).when( cookie ).getValue(); accessControlInterceptor.authenticateAccess( message, request ); verify( identityManager ).login( "token", "sptoken" ); }