@Test public void filterShouldPassThroughWhenLoginSucceedsWithForwardedHeader() throws Exception { Mockery context = new Mockery() { { setImposteriser(ClassImposteriser.INSTANCE); setThreadingPolicy(new Synchroniser()); } }; context.setThreadingPolicy(new Synchroniser()); final NextFilter nextFilter = context.mock(NextFilter.class); final IoSessionEx session = context.mock(IoSessionEx.class); final ResourceAddress address = context.mock(ResourceAddress.class); final HttpRequestMessage message = new HttpRequestMessage(); message.setMethod(HttpMethod.GET); message.setVersion(HttpVersion.HTTP_1_1); message.setRequestURI(URI.create(BASE_URI)); message.addHeader("Connection", "Upgrade"); message.addHeader("Upgrade", "WebSocket"); message.addHeader("Host", "localhost:8000"); message.addHeader("Forwarded", "for=\"[0:0:0:0:0:0:0:1]:8000\";by=198.51.100.17;proto=http"); message.addHeader("Authorization", "Token gobbledegook"); message.setLocalAddress(address); final ResultAwareLoginContext loginContext = context.mock(ResultAwareLoginContext.class); final LoginContextFactory loginContextFactory = context.mock(DefaultLoginContextFactory.class); final DefaultLoginResult loginResult = context.mock(DefaultLoginResult.class); final Set<Principal> principals = new HashSet<>(); principals.add(AUTHORIZED_PRINCIPAL); final Subject subject = new Subject(false, principals, Collections.EMPTY_SET, Collections.EMPTY_SET); final HttpSubjectSecurityFilter filter = new HttpSubjectSecurityFilter(); filter.setSchedulerProvider(new SchedulerProvider()); final CountDownLatch latch = new CountDownLatch(1); context.checking(new Expectations() { { oneOf(session).getSubject(); will(returnValue(null)); allowing(address).getOption(HttpResourceAddress.REQUIRED_ROLES); will(returnValue(new String[]{"AUTHORIZED"})); allowing(address).getOption(HttpResourceAddress.REALMS); final HttpRealmInfo[] realms = new HttpRealmInfo[1]; realms[0] = new DefaultHttpRealmInfo("demo", "Application Token", null, new String[]{"foo"}, new String[]{}, new String[]{}, loginContextFactory, null); will(returnValue(realms)); oneOf(loginContextFactory).createLoginContext(with(aNonNull(TypedCallbackHandlerMap.class))); will(returnValue(loginContext)); oneOf(session).suspendRead(); oneOf(loginContext).login(); will(VoidAction.INSTANCE); oneOf(loginContext).getLoginResult(); will(returnValue(loginResult)); oneOf(loginResult).getType(); will(returnValue(LoginResult.Type.SUCCESS)); oneOf(loginResult).hasLoginAuthorizationAttachment(); will(returnValue(false)); atMost(2).of(loginContext).getSubject(); will(returnValue(subject)); oneOf(nextFilter).messageReceived(session, message); oneOf(session).getIoExecutor(); will(returnValue(HTTP_SUBJECT_SECURITY_FILTER_TEST_EXECUTOR)); oneOf(session).resumeRead(); will(new LoginContextTaskDoneAction(latch, "login context task done")); } }); filter.messageReceived(nextFilter, session, message); latch.await(200000, TimeUnit.MILLISECONDS); assertNotNull(message.getLoginContext()); context.assertIsSatisfied(); }
public void setSchedulerProvider(SchedulerProvider provider) { this.scheduler = provider.getScheduler("loginmodule", false); }
HttpSubjectSecurityFilter extends HttpLoginSecurityFilter { public void setSchedulerProvider(SchedulerProvider provider) { this.scheduler = provider.getScheduler("loginmodule", false); } }
HttpSubjectSecurityFilter extends HttpLoginSecurityFilter { public void setSchedulerProvider(SchedulerProvider provider) { this.scheduler = provider.getScheduler("loginmodule", false); } HttpSubjectSecurityFilter();  HttpSubjectSecurityFilter(Logger logger);  HttpSubjectSecurityFilter(Logger logger, ExpiringState expiringState); }
HttpSubjectSecurityFilter extends HttpLoginSecurityFilter { public void setSchedulerProvider(SchedulerProvider provider) { this.scheduler = provider.getScheduler("loginmodule", false); } HttpSubjectSecurityFilter();  HttpSubjectSecurityFilter(Logger logger);  HttpSubjectSecurityFilter(Logger logger, ExpiringState expiringState); void setSchedulerProvider(SchedulerProvider provider); @Override void doMessageReceived(NextFilter nextFilter, IoSession session, Object message); @Override void filterWrite(NextFilter nextFilter, IoSession session, WriteRequest writeRequest); @Override void exceptionCaught(NextFilter nextFilter, IoSession session, Throwable cause); @Override void destroy(); }
HttpSubjectSecurityFilter extends HttpLoginSecurityFilter { public void setSchedulerProvider(SchedulerProvider provider) { this.scheduler = provider.getScheduler("loginmodule", false); } HttpSubjectSecurityFilter();  HttpSubjectSecurityFilter(Logger logger);  HttpSubjectSecurityFilter(Logger logger, ExpiringState expiringState); void setSchedulerProvider(SchedulerProvider provider); @Override void doMessageReceived(NextFilter nextFilter, IoSession session, Object message); @Override void filterWrite(NextFilter nextFilter, IoSession session, WriteRequest writeRequest); @Override void exceptionCaught(NextFilter nextFilter, IoSession session, Throwable cause); @Override void destroy(); static final String AUTH_SCHEME_APPLICATION_PREFIX; static final String AUTH_SCHEME_BASIC; static final String AUTH_SCHEME_NEGOTIATE; }