use of org.springframework.security.core.userdetails.User in project spring-security by spring-projects.
the class UserDeserializerTests method serializeUserTest.
// @formatter:on
@Test
public void serializeUserTest() throws JsonProcessingException, JSONException {
User user = createDefaultUser();
String userJson = mapper.writeValueAsString(user);
JSONAssert.assertEquals(userWithPasswordJson(user.getPassword()), userJson, true);
}
use of org.springframework.security.core.userdetails.User in project spring-security by spring-projects.
the class UserDeserializerTests method deserializeUserWithClassIdInAuthoritiesTest.
@Test
public void deserializeUserWithClassIdInAuthoritiesTest() throws IOException {
User user = mapper.readValue(userJson(), User.class);
assertThat(user).isNotNull();
assertThat(user.getUsername()).isEqualTo("admin");
assertThat(user.getPassword()).isEqualTo("1234");
assertThat(user.getAuthorities()).hasSize(1).contains(new SimpleGrantedAuthority("ROLE_USER"));
}
use of org.springframework.security.core.userdetails.User in project spring-security by spring-projects.
the class AuthenticationPrincipalArgumentResolverTests method resolveArgumentUserDetails.
@Test
public void resolveArgumentUserDetails() throws Exception {
setAuthenticationPrincipal(new User("user", "password", AuthorityUtils.createAuthorityList("ROLE_USER")));
assertThat(resolver.resolveArgument(showUserAnnotationUserDetails(), null, null, null)).isEqualTo(expectedPrincipal);
}
use of org.springframework.security.core.userdetails.User in project vaadin-samples by xpoft.
the class MainView method enter.
@Override
public void enter(ViewChangeListener.ViewChangeEvent event) {
User user = (User) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
List<String> roles = new ArrayList<String>();
for (GrantedAuthority grantedAuthority : user.getAuthorities()) {
roles.add(grantedAuthority.getAuthority());
}
usernameLabel.setValue(user.getUsername());
rolesLabel.setValue(StringUtils.join(roles, ","));
}
use of org.springframework.security.core.userdetails.User in project opennms by OpenNMS.
the class KerberosServiceLdapAuthenticationProvider method authenticate.
@Override
public Authentication authenticate(Authentication authentication) throws AuthenticationException {
KerberosServiceRequestToken auth = (KerberosServiceRequestToken) authentication;
byte[] token = auth.getToken();
LOG.debug("Try to validate Kerberos Token");
KerberosTicketValidation ticketValidation = m_kerberosTicketValidator.validateTicket(token);
LOG.debug("Succesfully validated " + ticketValidation.username());
/*
* The incoming username will be in the form of a Kerberos user principal name,
* e.g. user@EXAMPLE.ORG. We typically need to strip off the realm name before
* doing any LDAP operations with the username.
*/
String validatedUsername = trimRealmFromUsername(ticketValidation.username());
DirContextOperations ldapUserEntry = m_ldapUserSearch.searchForUser(validatedUsername);
Collection<? extends GrantedAuthority> grantedAuthorities = m_ldapAuthoritiesPopulator.getGrantedAuthorities(ldapUserEntry, validatedUsername);
UserDetails userDetails = new User(validatedUsername, "notUsed", true, true, true, true, grantedAuthorities);
m_userDetailsChecker.check(userDetails);
additionalAuthenticationChecks(userDetails, auth);
KerberosServiceRequestToken responseAuth = new KerberosServiceRequestToken(userDetails, ticketValidation, userDetails.getAuthorities(), token);
return responseAuth;
}
Aggregations