public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException { for (JaasAuthenticationCallbackHandler handler : AbstractJaasAuthenticationProvider.this.callbackHandlers) { for (Callback callback : callbacks) { handler.handle(callback, this.authentication); } } } }
public void onApplicationEvent(SessionDestroyedEvent event) { handleLogout(event); }
/** * Creates a LoginContext using the Configuration that was specified in * {@link #setConfiguration(Configuration)}. */ @Override protected LoginContext createLoginContext(CallbackHandler handler) throws LoginException { return new LoginContext(getLoginContextName(), null, handler, getConfiguration()); }
private void testConfigureJaasCase(JaasAuthenticationProvider p1, JaasAuthenticationProvider p2) throws Exception { p1.setLoginConfig(new ClassPathResource(resolveConfigFile("/test1.conf"))); p1.setLoginContextName("test1"); p1.setCallbackHandlers(new JaasAuthenticationCallbackHandler[] { new TestCallbackHandler(), new JaasNameCallbackHandler(), new JaasPasswordCallbackHandler() }); p1.setAuthorityGranters(new AuthorityGranter[] { new TestAuthorityGranter() }); p1.afterPropertiesSet(); testAuthenticate(p1); p2.setLoginConfig(new ClassPathResource(resolveConfigFile("/test2.conf"))); p2.setLoginContextName("test2"); p2.setCallbackHandlers(new JaasAuthenticationCallbackHandler[] { new TestCallbackHandler(), new JaasNameCallbackHandler(), new JaasPasswordCallbackHandler() }); p2.setAuthorityGranters(new AuthorityGranter[] { new TestAuthorityGranter() }); p2.afterPropertiesSet(); testAuthenticate(p2); }
/** * Validates the required properties are set. In addition, if * {@link #setCallbackHandlers(JaasAuthenticationCallbackHandler[])} has not been * called with valid handlers, initializes to use {@link JaasNameCallbackHandler} and * {@link JaasPasswordCallbackHandler}. */ public void afterPropertiesSet() throws Exception { Assert.hasLength(this.loginContextName, "loginContextName cannot be null or empty"); Assert.notEmpty(this.authorityGranters, "authorityGranters cannot be null or empty"); if (ObjectUtils.isEmpty(this.callbackHandlers)) { setCallbackHandlers(new JaasAuthenticationCallbackHandler[] { new JaasNameCallbackHandler(), new JaasPasswordCallbackHandler() }); } Assert.notNull(this.loginExceptionResolver, "loginExceptionResolver cannot be null"); }
@Override protected LoginContext createLoginContext(CallbackHandler handler) throws LoginException { return new LoginContext(getLoginContextName(), handler); }
@Override public void afterPropertiesSet() throws Exception { super.afterPropertiesSet(); Assert.notNull(this.configuration, "configuration cannot be null."); }
@Test(expected = IllegalArgumentException.class) public void afterPropertiesSetNullAuthorityGranters() throws Exception { provider.setAuthorityGranters(null); provider.afterPropertiesSet(); }
@Test(expected = IllegalArgumentException.class) public void afterPropertiesSetNullConfiguration() throws Exception { provider.setConfiguration(null); provider.afterPropertiesSet(); }
/** * Hook method for configuring Jaas. * * @param loginConfig URL to Jaas login configuration * * @throws IOException if there is a problem reading the config resource. */ protected void configureJaas(Resource loginConfig) throws IOException { configureJaasUsingLoop(); if (this.refreshConfigurationOnStartup) { // Overcome issue in SEC-760 Configuration.getConfiguration().refresh(); } }
@Test public void authenticateBadPassword() { try { provider.authenticate(new UsernamePasswordAuthenticationToken("user", "asdf")); fail("LoginException should have been thrown for the bad password"); } catch (AuthenticationException success) { } verifyFailedLogin(); }
@Test public void testConfigureJaas() throws Exception { testConfigureJaasCase(new JaasAuthenticationProvider(), new JaasAuthenticationProvider()); }
@Test public void publishNullPublisher() { provider.setApplicationEventPublisher(null); AuthenticationException ae = new BadCredentialsException("Failed to login"); provider.publishFailureEvent(token, ae); provider.publishSuccessEvent(token); }
@Before public void setUp() throws Exception { this.module = new SecurityContextLoginModule(); this.module.initialize(this.subject, null, null, null); SecurityContextHolder.clearContext(); }
/** * Creates a LoginContext using the Configuration that was specified in * {@link #setConfiguration(Configuration)}. */ @Override protected LoginContext createLoginContext(CallbackHandler handler) throws LoginException { return new LoginContext(getLoginContextName(), null, handler, getConfiguration()); }
@Override protected LoginContext createLoginContext(CallbackHandler handler) throws LoginException { return new LoginContext(getLoginContextName(), handler); }
public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException { for (JaasAuthenticationCallbackHandler handler : AbstractJaasAuthenticationProvider.this.callbackHandlers) { for (Callback callback : callbacks) { handler.handle(callback, this.authentication); } } } }
public void onApplicationEvent(SessionDestroyedEvent event) { handleLogout(event); }
@Override public void afterPropertiesSet() throws Exception { super.afterPropertiesSet(); Assert.notNull(this.configuration, "configuration cannot be null."); }
@Test public void authenticateBadUser() { try { provider.authenticate(new UsernamePasswordAuthenticationToken("asdf", "password")); fail("LoginException should have been thrown for the bad user"); } catch (AuthenticationException success) { } verifyFailedLogin(); }