use of org.springframework.security.authentication.AuthenticationManager in project spring-boot by spring-projects.
the class SampleSecureApplicationTests method init.
@Before
public void init() {
AuthenticationManager authenticationManager = this.context.getBean(AuthenticationManager.class);
this.authentication = authenticationManager.authenticate(new UsernamePasswordAuthenticationToken("user", "password"));
}
use of org.springframework.security.authentication.AuthenticationManager in project spring-boot by spring-projects.
the class SecurityAutoConfigurationTests method testDefaultUsernamePassword.
@Test
public void testDefaultUsernamePassword() throws Exception {
this.context = new AnnotationConfigWebApplicationContext();
this.context.setServletContext(new MockServletContext());
this.context.register(SecurityAutoConfiguration.class);
this.context.refresh();
SecurityProperties security = this.context.getBean(SecurityProperties.class);
AuthenticationManager manager = this.context.getBean(AuthenticationManager.class);
UsernamePasswordAuthenticationToken token = new UsernamePasswordAuthenticationToken(security.getUser().getName(), security.getUser().getPassword());
assertThat(manager.authenticate(token)).isNotNull();
}
use of org.springframework.security.authentication.AuthenticationManager in project spring-boot by spring-projects.
the class SecurityAutoConfigurationTests method testCustomAuthenticationDoesNotAuthenticateWithBootSecurityUser.
@Test
public void testCustomAuthenticationDoesNotAuthenticateWithBootSecurityUser() throws Exception {
this.context = new AnnotationConfigWebApplicationContext();
this.context.setServletContext(new MockServletContext());
this.context.register(AuthenticationManagerCustomizer.class, SecurityAutoConfiguration.class);
this.context.refresh();
SecurityProperties security = this.context.getBean(SecurityProperties.class);
AuthenticationManager manager = this.context.getBean(AuthenticationManager.class);
UsernamePasswordAuthenticationToken token = new UsernamePasswordAuthenticationToken(security.getUser().getName(), security.getUser().getPassword());
try {
manager.authenticate(token);
fail("Expected Exception");
} catch (AuthenticationException success) {
// Expected
}
token = new UsernamePasswordAuthenticationToken("foo", "bar");
assertThat(manager.authenticate(token)).isNotNull();
}
use of org.springframework.security.authentication.AuthenticationManager in project spring-security-oauth by spring-projects.
the class ResourceServerBeanDefinitionParserTests method testAuthenticationManager.
@Test
public void testAuthenticationManager() {
GenericXmlApplicationContext context = new GenericXmlApplicationContext(getClass(), "resource-server-authmanager-context.xml");
// System.err.println(Arrays.asList(context.getBeanDefinitionNames()));
assertTrue(context.containsBeanDefinition("oauth2ProviderFilter"));
OAuth2AuthenticationProcessingFilter filter = context.getBean(OAuth2AuthenticationProcessingFilter.class);
assertEquals(context.getBean(AuthenticationManager.class), ReflectionTestUtils.getField(filter, "authenticationManager"));
assertNotNull(ReflectionTestUtils.getField(filter, "tokenExtractor"));
context.close();
}
use of org.springframework.security.authentication.AuthenticationManager in project spring-security by spring-projects.
the class AuthenticationConfigurationGh3935Tests method delegateUsesExisitingAuthentication.
@Test
public void delegateUsesExisitingAuthentication() {
String username = "user";
String password = "password";
User user = new User(username, password, AuthorityUtils.createAuthorityList("ROLE_USER"));
when(this.uds.loadUserByUsername(username)).thenReturn(user);
AuthenticationManager authenticationManager = this.adapter.authenticationManager;
assertThat(authenticationManager).isNotNull();
Authentication auth = authenticationManager.authenticate(new UsernamePasswordAuthenticationToken(username, password));
verify(this.uds).loadUserByUsername(username);
assertThat(auth.getPrincipal()).isEqualTo(user);
}
Aggregations