### Question:
JAASLoginInterceptor extends AbstractPhaseInterceptor<Message> { public void handleMessage(final Message message) { if (allowNamedPrincipals) { SecurityContext sc = message.get(SecurityContext.class); if (sc != null && sc.getUserPrincipal() != null && sc.getUserPrincipal().getName() != null) { return; } } CallbackHandler handler = getFirstCallbackHandler(message); if (handler == null && !allowAnonymous) { throw new AuthenticationException("Authentication required but no authentication information was supplied"); } try { LoginContext ctx = new LoginContext(getContextName(), null, handler, loginConfig); ctx.login(); Subject subject = ctx.getSubject(); String name = getUsername(handler); message.put(SecurityContext.class, createSecurityContext(name, subject)); if (useDoAs) { Subject.doAs(subject, new PrivilegedAction<Void>() { @Override public Void run() { InterceptorChain chain = message.getInterceptorChain(); if (chain != null) { message.put("suspend.chain.on.current.interceptor", Boolean.TRUE); chain.doIntercept(message); } return null; } }); } } catch (LoginException ex) { String errorMessage = "Authentication failed: " + ex.getMessage(); LOG.log(Level.FINE, errorMessage, ex); if (reportFault) { AuthenticationException aex = new AuthenticationException(errorMessage); aex.initCause(ex); throw aex; } throw new AuthenticationException("Authentication failed (details can be found in server log)"); } } JAASLoginInterceptor();  JAASLoginInterceptor(String phase); void setContextName(String name); String getContextName(); @Deprecated void setRolePrefix(String name); void setRoleClassifier(String value); String getRoleClassifier(); void setRoleClassifierType(String value); String getRoleClassifierType(); void setReportFault(boolean reportFault); void setUseDoAs(boolean useDoAs); void handleMessage(final Message message); Configuration getLoginConfig(); void setLoginConfig(Configuration loginConfig); List<CallbackHandlerProvider> getCallbackHandlerProviders(); void setCallbackHandlerProviders(List<CallbackHandlerProvider> callbackHandlerProviders); void addCallbackHandlerProviders(List<CallbackHandlerProvider> callbackHandlerProviders2); void setAllowAnonymous(boolean allowAnonymous); void setAllowNamedPrincipals(boolean allowNamedPrincipals); static final String ROLE_CLASSIFIER_PREFIX; static final String ROLE_CLASSIFIER_CLASS_NAME; }### Answer:
@Test(expected = AuthenticationException.class) public void testLoginWithDefaultHandler() { JAASLoginInterceptor jaasInt = createTestJaasLoginInterceptor(); Message message = new MessageImpl(); jaasInt.handleMessage(message); }
@Test public void testLoginWithDefaultHandlerAndAuthPol() { JAASLoginInterceptor jaasInt = createTestJaasLoginInterceptor(); Message message = new MessageImpl(); addAuthPolicy(message, TestUserPasswordLoginModule.TESTUSER, TestUserPasswordLoginModule.TESTPASS); jaasInt.handleMessage(message); }
@Test(expected = AuthenticationException.class) public void testLoginWithDefaultHandlerAndAuthPolWrongPass() { JAASLoginInterceptor jaasInt = createTestJaasLoginInterceptor(); Message message = new MessageImpl(); addAuthPolicy(message, TestUserPasswordLoginModule.TESTUSER, "wrong"); jaasInt.handleMessage(message); }
@Test public void testLoginWithDefaultHandlerAndUsernameToken() { JAASLoginInterceptor jaasInt = createTestJaasLoginInterceptor(); Message message = new MessageImpl(); addUsernameToken(message, TestUserPasswordLoginModule.TESTUSER, TestUserPasswordLoginModule.TESTPASS); jaasInt.handleMessage(message); }
@Test(expected = AuthenticationException.class) public void testLoginWithDefaultHandlerAndUsernameTokenWrongPass() { JAASLoginInterceptor jaasInt = createTestJaasLoginInterceptor(); Message message = new MessageImpl(); addUsernameToken(message, TestUserPasswordLoginModule.TESTUSER, "wrong"); jaasInt.handleMessage(message); }