use of org.springframework.security.userdetails.User in project gocd by gocd.
the class GoFileConfigDataSourceTest method shouldUse_UserFromSession_asConfigModifyingUserWhenNoneGiven.
@Test
public void shouldUse_UserFromSession_asConfigModifyingUserWhenNoneGiven() throws GitAPIException, IOException {
SecurityContext context = SecurityContextHolder.getContext();
context.setAuthentication(new UsernamePasswordAuthenticationToken(new User("loser_boozer", "pass", true, true, true, true, new GrantedAuthority[] {}), null));
goConfigDao.updateMailHost(getMailHost("mailhost.local"));
CruiseConfig cruiseConfig = goConfigDao.load();
GoConfigRevision revision = configRepository.getRevision(cruiseConfig.getMd5());
assertThat(revision.getUsername(), is("loser_boozer"));
}
use of org.springframework.security.userdetails.User in project gocd by gocd.
the class UserHelperTest method shouldGetNameFromUserDetails.
@Test
public void shouldGetNameFromUserDetails() {
TestingAuthenticationToken authentication = new TestingAuthenticationToken(new User("user", "pass", true, false, true, true, new GrantedAuthority[0]), null, null);
assertThat(UserHelper.getUserName(authentication).getDisplayName(), is("user"));
}
use of org.springframework.security.userdetails.User in project gocd by gocd.
the class GoConfigAdministrationControllerIntegrationTest method setCurrentUser.
private void setCurrentUser(String username) {
SecurityContextImpl context = new SecurityContextImpl();
context.setAuthentication(new UsernamePasswordAuthenticationToken(new User(username, "", true, new GrantedAuthority[] {}), null));
SecurityContextHolder.setContext(context);
}
use of org.springframework.security.userdetails.User in project gocd by gocd.
the class X509AuthoritiesPopulator method getUserDetails.
public UserDetails getUserDetails(X509Certificate clientCert) throws AuthenticationException {
X500Principal principal = clientCert.getSubjectX500Principal();
Matcher cnMatcher = CN_PATTERN.matcher(principal.getName());
Matcher ouMatcher = OU_PATTERN.matcher(principal.getName());
if (cnMatcher.find() && ouMatcher.find()) {
GrantedAuthorityImpl agentAuthority = new GrantedAuthorityImpl(role);
return new User(cnMatcher.group(1), "", true, true, true, true, new GrantedAuthority[] { agentAuthority });
}
throw new BadCredentialsException("Couldn't find CN and/or OU for the certificate");
}
use of org.springframework.security.userdetails.User in project gocd by gocd.
the class OauthAuthenticationProvider method authenticate.
public OauthAuthenticationToken authenticate(Authentication authentication) throws AuthenticationException {
OauthAuthenticationToken authenticationToken = (OauthAuthenticationToken) authentication;
String token = authenticationToken.getCredentials();
OauthDataSource.OauthTokenDTO oauthToken = oauthDataSource.findOauthTokenByAccessToken(token);
if (oauthToken == null) {
throw new BadCredentialsException("No match for OAuth token: " + token);
}
String username = oauthToken.getUserId();
UserDetails user = new User(username, token, true, true, true, true, oauthAuthority());
return new OauthAuthenticationToken(user);
}
Aggregations