use of org.springframework.security.core.userdetails.User in project spring-security by spring-projects.
the class PreAuthenticatedAuthenticationProviderTests method authenticateKnownUser.
@Test
public final void authenticateKnownUser() throws Exception {
UserDetails ud = new User("dummyUser", "dummyPwd", true, true, true, true, AuthorityUtils.NO_AUTHORITIES);
PreAuthenticatedAuthenticationProvider provider = getProvider(ud);
Authentication request = new PreAuthenticatedAuthenticationToken("dummyUser", "dummyPwd");
Authentication result = provider.authenticate(request);
assertThat(result).isNotNull();
assertThat(ud).isEqualTo(result.getPrincipal());
// @TODO: Add more asserts?
}
use of org.springframework.security.core.userdetails.User in project spring-security by spring-projects.
the class PreAuthenticatedAuthenticationProviderTests method authenticateIgnoreCredentials.
@Test
public final void authenticateIgnoreCredentials() throws Exception {
UserDetails ud = new User("dummyUser1", "dummyPwd1", true, true, true, true, AuthorityUtils.NO_AUTHORITIES);
PreAuthenticatedAuthenticationProvider provider = getProvider(ud);
Authentication request = new PreAuthenticatedAuthenticationToken("dummyUser1", "dummyPwd2");
Authentication result = provider.authenticate(request);
assertThat(result).isNotNull();
assertThat(ud).isEqualTo(result.getPrincipal());
// @TODO: Add more asserts?
}
use of org.springframework.security.core.userdetails.User in project spring-security by spring-projects.
the class SecurityContextHolderAwareRequestWrapperTests method testCorrectOperationWithUserDetailsBasedPrincipal.
@Test
public void testCorrectOperationWithUserDetailsBasedPrincipal() throws Exception {
Authentication auth = new TestingAuthenticationToken(new User("rodAsUserDetails", "koala", true, true, true, true, AuthorityUtils.NO_AUTHORITIES), "koala", "ROLE_HELLO", "ROLE_FOOBAR");
SecurityContextHolder.getContext().setAuthentication(auth);
MockHttpServletRequest request = new MockHttpServletRequest();
request.setRequestURI("/");
SecurityContextHolderAwareRequestWrapper wrapper = new SecurityContextHolderAwareRequestWrapper(request, "");
assertThat(wrapper.getRemoteUser()).isEqualTo("rodAsUserDetails");
assertThat(wrapper.isUserInRole("ROLE_FOO")).isFalse();
assertThat(wrapper.isUserInRole("ROLE_NOT_GRANTED")).isFalse();
assertThat(wrapper.isUserInRole("ROLE_FOOBAR")).isTrue();
assertThat(wrapper.isUserInRole("ROLE_HELLO")).isTrue();
assertThat(wrapper.getUserPrincipal()).isEqualTo(auth);
}
use of org.springframework.security.core.userdetails.User in project spring-security-oauth by spring-projects.
the class ClientDetailsUserDetailsService method loadUserByUsername.
public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
ClientDetails clientDetails;
try {
clientDetails = clientDetailsService.loadClientByClientId(username);
} catch (NoSuchClientException e) {
throw new UsernameNotFoundException(e.getMessage(), e);
}
String clientSecret = clientDetails.getClientSecret();
if (clientSecret == null || clientSecret.trim().length() == 0) {
clientSecret = emptyPassword;
}
return new User(username, clientSecret, clientDetails.getAuthorities());
}
use of org.springframework.security.core.userdetails.User in project spring-security-oauth by spring-projects.
the class DefaultUserAuthenticationConverterTests method shouldExtractAuthenticationWhenUserDetailsProvided.
@Test
public void shouldExtractAuthenticationWhenUserDetailsProvided() throws Exception {
Map<String, Object> map = new HashMap<String, Object>();
map.put(UserAuthenticationConverter.USERNAME, "test_user");
UserDetailsService userDetailsService = Mockito.mock(UserDetailsService.class);
Mockito.when(userDetailsService.loadUserByUsername("test_user")).thenReturn(new User("foo", "bar", AuthorityUtils.commaSeparatedStringToAuthorityList("ROLE_SPAM")));
converter.setUserDetailsService(userDetailsService);
Authentication authentication = converter.extractAuthentication(map);
assertEquals("ROLE_SPAM", authentication.getAuthorities().iterator().next().toString());
}
Aggregations