@Test public void filterShouldPassThroughIfMessageIsNotHttpRequestMessage() throws Exception { Mockery context = new Mockery() {{setImposteriser(ClassImposteriser.INSTANCE);}}; context.setThreadingPolicy(new Synchroniser()); final NextFilter nextFilter = context.mock(NextFilter.class); final IoSession session = context.mock(IoSession.class); final HttpResponseMessage message = new HttpResponseMessage(); context.checking(new Expectations() { { oneOf(nextFilter).messageReceived(session, message); } }); HttpSubjectSecurityFilter filter = new HttpSubjectSecurityFilter(); filter.securityMessageReceived(nextFilter, session, message); context.assertIsSatisfied(); }
void securityMessageReceived(NextFilter nextFilter, IoSession session, Object message) throws Exception { final boolean loggerIsEnabled = logger != null && logger.isTraceEnabled(); if (! httpRequestMessageReceived(nextFilter, session, message)) return; HttpRequestMessage httpRequest = (HttpRequestMessage) message; ResourceAddress httpAddress = httpRequest.getLocalAddress(); if (alreadyLoggedIn(httpRequest)) { if (httpRequest.getLoginContext() == null) { setUnprotectedLoginContext(httpRequest); } if (loggerIsEnabled) { logger.trace("HttpSubjectSecurityFilter skipped because we are already allowed or logged in."); } super.doMessageReceived(nextFilter, session, message); return; } HttpRealmInfo[] realms = httpAddress.getOption(HttpResourceAddress.REALMS); if (realms.length == 0) { setUnprotectedLoginContext(httpRequest); if (loggerIsEnabled) { logger.trace("HttpSecurityStandardFilter skipped because no realm is configured."); } super.doMessageReceived(nextFilter, session, message); return; } String challengeIdentity = httpRequest.getHeader(HEADER_SEC_CHALLENGE_IDENTITY); LoginContext[] loginContexts = getLoginContexts(challengeIdentity); int realmIndex = findCurrentRealm(loginContexts); HttpRealmInfo realm = realms[realmIndex]; AuthenticationTokenExtractor tokenExtractor = DefaultAuthenticationTokenExtractor.INSTANCE; DefaultAuthenticationToken authToken = (DefaultAuthenticationToken) tokenExtractor.extract(httpRequest, realm); String expectedChallengeScheme = getBaseAuthScheme(realm.getChallengeScheme()); if(authToken.getScheme() == null) { authToken.setScheme(expectedChallengeScheme); } suspendIncoming(session); TypedCallbackHandlerMap additionalCallbacks = null; if (realmIndex > 0) { additionalCallbacks = new TypedCallbackHandlerMap(); Function<String, Subject> subjects = name -> findNamedSubject(name, realms, realmIndex, loginContexts); NamedSubjectCallbackHandler callbackHandler = new NamedSubjectCallbackHandler(subjects); additionalCallbacks.put(NamedSubjectCallback.class, callbackHandler); } LoginContextTask loginContextTask = new LoginContextTask(nextFilter, session, httpRequest, authToken, additionalCallbacks, realms, realmIndex, loginContexts); scheduler.execute(loginContextTask); }
HttpSubjectSecurityFilter extends HttpLoginSecurityFilter { void securityMessageReceived(NextFilter nextFilter, IoSession session, Object message) throws Exception { final boolean loggerIsEnabled = logger != null && logger.isTraceEnabled(); if (! httpRequestMessageReceived(nextFilter, session, message)) return; HttpRequestMessage httpRequest = (HttpRequestMessage) message; ResourceAddress httpAddress = httpRequest.getLocalAddress(); if (alreadyLoggedIn(httpRequest)) { if (httpRequest.getLoginContext() == null) { setUnprotectedLoginContext(httpRequest); } if (loggerIsEnabled) { logger.trace("HttpSubjectSecurityFilter skipped because we are already allowed or logged in."); } super.doMessageReceived(nextFilter, session, message); return; } HttpRealmInfo[] realms = httpAddress.getOption(HttpResourceAddress.REALMS); if (realms.length == 0) { setUnprotectedLoginContext(httpRequest); if (loggerIsEnabled) { logger.trace("HttpSecurityStandardFilter skipped because no realm is configured."); } super.doMessageReceived(nextFilter, session, message); return; } String challengeIdentity = httpRequest.getHeader(HEADER_SEC_CHALLENGE_IDENTITY); LoginContext[] loginContexts = getLoginContexts(challengeIdentity); int realmIndex = findCurrentRealm(loginContexts); HttpRealmInfo realm = realms[realmIndex]; AuthenticationTokenExtractor tokenExtractor = DefaultAuthenticationTokenExtractor.INSTANCE; DefaultAuthenticationToken authToken = (DefaultAuthenticationToken) tokenExtractor.extract(httpRequest, realm); String expectedChallengeScheme = getBaseAuthScheme(realm.getChallengeScheme()); if(authToken.getScheme() == null) { authToken.setScheme(expectedChallengeScheme); } suspendIncoming(session); TypedCallbackHandlerMap additionalCallbacks = null; if (realmIndex > 0) { additionalCallbacks = new TypedCallbackHandlerMap(); Function<String, Subject> subjects = name -> findNamedSubject(name, realms, realmIndex, loginContexts); NamedSubjectCallbackHandler callbackHandler = new NamedSubjectCallbackHandler(subjects); additionalCallbacks.put(NamedSubjectCallback.class, callbackHandler); } LoginContextTask loginContextTask = new LoginContextTask(nextFilter, session, httpRequest, authToken, additionalCallbacks, realms, realmIndex, loginContexts); scheduler.execute(loginContextTask); } }
HttpSubjectSecurityFilter extends HttpLoginSecurityFilter { void securityMessageReceived(NextFilter nextFilter, IoSession session, Object message) throws Exception { final boolean loggerIsEnabled = logger != null && logger.isTraceEnabled(); if (! httpRequestMessageReceived(nextFilter, session, message)) return; HttpRequestMessage httpRequest = (HttpRequestMessage) message; ResourceAddress httpAddress = httpRequest.getLocalAddress(); if (alreadyLoggedIn(httpRequest)) { if (httpRequest.getLoginContext() == null) { setUnprotectedLoginContext(httpRequest); } if (loggerIsEnabled) { logger.trace("HttpSubjectSecurityFilter skipped because we are already allowed or logged in."); } super.doMessageReceived(nextFilter, session, message); return; } HttpRealmInfo[] realms = httpAddress.getOption(HttpResourceAddress.REALMS); if (realms.length == 0) { setUnprotectedLoginContext(httpRequest); if (loggerIsEnabled) { logger.trace("HttpSecurityStandardFilter skipped because no realm is configured."); } super.doMessageReceived(nextFilter, session, message); return; } String challengeIdentity = httpRequest.getHeader(HEADER_SEC_CHALLENGE_IDENTITY); LoginContext[] loginContexts = getLoginContexts(challengeIdentity); int realmIndex = findCurrentRealm(loginContexts); HttpRealmInfo realm = realms[realmIndex]; AuthenticationTokenExtractor tokenExtractor = DefaultAuthenticationTokenExtractor.INSTANCE; DefaultAuthenticationToken authToken = (DefaultAuthenticationToken) tokenExtractor.extract(httpRequest, realm); String expectedChallengeScheme = getBaseAuthScheme(realm.getChallengeScheme()); if(authToken.getScheme() == null) { authToken.setScheme(expectedChallengeScheme); } suspendIncoming(session); TypedCallbackHandlerMap additionalCallbacks = null; if (realmIndex > 0) { additionalCallbacks = new TypedCallbackHandlerMap(); Function<String, Subject> subjects = name -> findNamedSubject(name, realms, realmIndex, loginContexts); NamedSubjectCallbackHandler callbackHandler = new NamedSubjectCallbackHandler(subjects); additionalCallbacks.put(NamedSubjectCallback.class, callbackHandler); } LoginContextTask loginContextTask = new LoginContextTask(nextFilter, session, httpRequest, authToken, additionalCallbacks, realms, realmIndex, loginContexts); scheduler.execute(loginContextTask); } HttpSubjectSecurityFilter();  HttpSubjectSecurityFilter(Logger logger);  HttpSubjectSecurityFilter(Logger logger, ExpiringState expiringState); }
HttpSubjectSecurityFilter extends HttpLoginSecurityFilter { void securityMessageReceived(NextFilter nextFilter, IoSession session, Object message) throws Exception { final boolean loggerIsEnabled = logger != null && logger.isTraceEnabled(); if (! httpRequestMessageReceived(nextFilter, session, message)) return; HttpRequestMessage httpRequest = (HttpRequestMessage) message; ResourceAddress httpAddress = httpRequest.getLocalAddress(); if (alreadyLoggedIn(httpRequest)) { if (httpRequest.getLoginContext() == null) { setUnprotectedLoginContext(httpRequest); } if (loggerIsEnabled) { logger.trace("HttpSubjectSecurityFilter skipped because we are already allowed or logged in."); } super.doMessageReceived(nextFilter, session, message); return; } HttpRealmInfo[] realms = httpAddress.getOption(HttpResourceAddress.REALMS); if (realms.length == 0) { setUnprotectedLoginContext(httpRequest); if (loggerIsEnabled) { logger.trace("HttpSecurityStandardFilter skipped because no realm is configured."); } super.doMessageReceived(nextFilter, session, message); return; } String challengeIdentity = httpRequest.getHeader(HEADER_SEC_CHALLENGE_IDENTITY); LoginContext[] loginContexts = getLoginContexts(challengeIdentity); int realmIndex = findCurrentRealm(loginContexts); HttpRealmInfo realm = realms[realmIndex]; AuthenticationTokenExtractor tokenExtractor = DefaultAuthenticationTokenExtractor.INSTANCE; DefaultAuthenticationToken authToken = (DefaultAuthenticationToken) tokenExtractor.extract(httpRequest, realm); String expectedChallengeScheme = getBaseAuthScheme(realm.getChallengeScheme()); if(authToken.getScheme() == null) { authToken.setScheme(expectedChallengeScheme); } suspendIncoming(session); TypedCallbackHandlerMap additionalCallbacks = null; if (realmIndex > 0) { additionalCallbacks = new TypedCallbackHandlerMap(); Function<String, Subject> subjects = name -> findNamedSubject(name, realms, realmIndex, loginContexts); NamedSubjectCallbackHandler callbackHandler = new NamedSubjectCallbackHandler(subjects); additionalCallbacks.put(NamedSubjectCallback.class, callbackHandler); } LoginContextTask loginContextTask = new LoginContextTask(nextFilter, session, httpRequest, authToken, additionalCallbacks, realms, realmIndex, loginContexts); scheduler.execute(loginContextTask); } 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 { void securityMessageReceived(NextFilter nextFilter, IoSession session, Object message) throws Exception { final boolean loggerIsEnabled = logger != null && logger.isTraceEnabled(); if (! httpRequestMessageReceived(nextFilter, session, message)) return; HttpRequestMessage httpRequest = (HttpRequestMessage) message; ResourceAddress httpAddress = httpRequest.getLocalAddress(); if (alreadyLoggedIn(httpRequest)) { if (httpRequest.getLoginContext() == null) { setUnprotectedLoginContext(httpRequest); } if (loggerIsEnabled) { logger.trace("HttpSubjectSecurityFilter skipped because we are already allowed or logged in."); } super.doMessageReceived(nextFilter, session, message); return; } HttpRealmInfo[] realms = httpAddress.getOption(HttpResourceAddress.REALMS); if (realms.length == 0) { setUnprotectedLoginContext(httpRequest); if (loggerIsEnabled) { logger.trace("HttpSecurityStandardFilter skipped because no realm is configured."); } super.doMessageReceived(nextFilter, session, message); return; } String challengeIdentity = httpRequest.getHeader(HEADER_SEC_CHALLENGE_IDENTITY); LoginContext[] loginContexts = getLoginContexts(challengeIdentity); int realmIndex = findCurrentRealm(loginContexts); HttpRealmInfo realm = realms[realmIndex]; AuthenticationTokenExtractor tokenExtractor = DefaultAuthenticationTokenExtractor.INSTANCE; DefaultAuthenticationToken authToken = (DefaultAuthenticationToken) tokenExtractor.extract(httpRequest, realm); String expectedChallengeScheme = getBaseAuthScheme(realm.getChallengeScheme()); if(authToken.getScheme() == null) { authToken.setScheme(expectedChallengeScheme); } suspendIncoming(session); TypedCallbackHandlerMap additionalCallbacks = null; if (realmIndex > 0) { additionalCallbacks = new TypedCallbackHandlerMap(); Function<String, Subject> subjects = name -> findNamedSubject(name, realms, realmIndex, loginContexts); NamedSubjectCallbackHandler callbackHandler = new NamedSubjectCallbackHandler(subjects); additionalCallbacks.put(NamedSubjectCallback.class, callbackHandler); } LoginContextTask loginContextTask = new LoginContextTask(nextFilter, session, httpRequest, authToken, additionalCallbacks, realms, realmIndex, loginContexts); scheduler.execute(loginContextTask); } 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; }