use of org.springframework.security.core.userdetails.User in project spring-security by spring-projects.
the class SecurityMockMvcRequestPostProcessorsDigestTests method setup.
@Before
public void setup() {
this.password = "password";
request = new MockHttpServletRequest();
entryPoint = new DigestAuthenticationEntryPoint();
entryPoint.setKey("key");
entryPoint.setRealmName("Spring Security");
filter = new DigestAuthenticationFilter();
filter.setUserDetailsService(new UserDetailsService() {
public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
return new User(username, password, AuthorityUtils.createAuthorityList("ROLE_USER"));
}
});
filter.setAuthenticationEntryPoint(entryPoint);
filter.afterPropertiesSet();
}
use of org.springframework.security.core.userdetails.User 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);
}
use of org.springframework.security.core.userdetails.User in project spring-security by spring-projects.
the class AbstractPreAuthenticatedProcessingFilterTests method requiresAuthenticationFalsePrincipalUser.
@Test
public void requiresAuthenticationFalsePrincipalUser() throws Exception {
User currentPrincipal = new User("user", "password", AuthorityUtils.createAuthorityList("ROLE_USER"));
UsernamePasswordAuthenticationToken currentAuthentication = new UsernamePasswordAuthenticationToken(currentPrincipal, currentPrincipal.getPassword(), currentPrincipal.getAuthorities());
SecurityContextHolder.getContext().setAuthentication(currentAuthentication);
MockHttpServletRequest request = new MockHttpServletRequest();
MockHttpServletResponse response = new MockHttpServletResponse();
MockFilterChain chain = new MockFilterChain();
ConcretePreAuthenticatedProcessingFilter filter = new ConcretePreAuthenticatedProcessingFilter();
filter.setCheckForPrincipalChanges(true);
filter.principal = new User(currentPrincipal.getUsername(), currentPrincipal.getPassword(), AuthorityUtils.NO_AUTHORITIES);
AuthenticationManager am = mock(AuthenticationManager.class);
filter.setAuthenticationManager(am);
filter.afterPropertiesSet();
filter.doFilter(request, response, chain);
verifyZeroInteractions(am);
}
use of org.springframework.security.core.userdetails.User in project spring-security by spring-projects.
the class AbstractRememberMeServicesTests method autoLoginShouldFailIfUserAccountIsLocked.
@Test
public void autoLoginShouldFailIfUserAccountIsLocked() {
MockRememberMeServices services = new MockRememberMeServices(uds);
services.setUserDetailsChecker(new AccountStatusUserDetailsChecker());
uds.toReturn = new User("joe", "password", false, true, true, true, joe.getAuthorities());
MockHttpServletRequest request = new MockHttpServletRequest();
request.setCookies(createLoginCookie("cookie:1:2"));
MockHttpServletResponse response = new MockHttpServletResponse();
Authentication result = services.autoLogin(request, response);
assertThat(result).isNull();
assertCookieCancelled(response);
}
use of org.springframework.security.core.userdetails.User in project spring-security by spring-projects.
the class PreAuthenticatedAuthenticationProviderTests method authenticateUnknownUserThrowsException.
@Test(expected = UsernameNotFoundException.class)
public final void authenticateUnknownUserThrowsException() throws Exception {
UserDetails ud = new User("dummyUser1", "dummyPwd", true, true, true, true, AuthorityUtils.NO_AUTHORITIES);
PreAuthenticatedAuthenticationProvider provider = getProvider(ud);
Authentication request = new PreAuthenticatedAuthenticationToken("dummyUser2", "dummyPwd");
provider.authenticate(request);
}
Aggregations