use of org.springframework.security.Authentication in project gocd by gocd.
the class AuthenticationRequestProcessor method process.
@Override
public GoApiResponse process(GoPluginDescriptor pluginDescriptor, GoApiRequest goPluginApiRequest) {
try {
String version = goPluginApiRequest.apiVersion();
if (!goSupportedVersions.contains(version)) {
throw new RuntimeException(String.format("Unsupported '%s' API version: %s. Supported versions: %s", AUTHENTICATE_USER_REQUEST, version, goSupportedVersions));
}
User user = messageHandlerMap.get(version).responseMessageForAuthenticateUser(goPluginApiRequest.requestBody());
if (user == null) {
throw new RuntimeException(String.format("Could not parse User details. Request Body: %s", goPluginApiRequest.requestBody()));
}
GoUserPrinciple goUserPrincipal = getGoUserPrincipal(user);
Authentication authentication = getAuthenticationToken(goUserPrincipal);
userService.addUserIfDoesNotExist(UserHelper.getUser(authentication));
getSecurityContext().setAuthentication(authentication);
return new DefaultGoApiResponse(200);
} catch (Exception e) {
LOGGER.error("Error occurred while authenticating user", e);
}
return new DefaultGoApiResponse(500);
}
use of org.springframework.security.Authentication in project gocd by gocd.
the class LdapAuthenticationTest method assertFailedAuthentication.
private void assertFailedAuthentication(String userName, String password) {
Authentication authentication = new UsernamePasswordAuthenticationToken(userName, password);
try {
ldapAuthenticationProvider.authenticate(authentication);
fail("Expected authentication to fail for user: " + userName);
} catch (BadCredentialsException e) {
}
}
use of org.springframework.security.Authentication in project gocd by gocd.
the class UserEnabledCheckFilterTest method shouldNotSetUserIdInSessionIfUserServiceReturnANullUser.
@Test
public void shouldNotSetUserIdInSessionIfUserServiceReturnANullUser() throws IOException, ServletException {
String userName = "none";
SecurityContextHelper.setCurrentUser(userName);
Authentication actual = SecurityContextHolder.getContext().getAuthentication();
when(session.getAttribute(USERID_ATTR)).thenReturn(null);
NullUser nullUser = new NullUser();
when(userService.findUserByName(userName)).thenReturn(nullUser);
filter.doFilterHttp(req, res, chain);
assertThat(SecurityContextHolder.getContext().getAuthentication(), is(actual));
verify(session, never()).setAttribute(eq(USERID_ATTR), Matchers.<Object>any());
verify(chain).doFilter(req, res);
}
use of org.springframework.security.Authentication in project gocd by gocd.
the class GoAuthenticationProviderTest method shouldEnforceLicenseLimit.
@Test
public void shouldEnforceLicenseLimit() throws Exception {
Authentication authentication = enforcementProvider.authenticate(auth);
assertThat(authentication, is(resultantAuthorization));
verify(userService).addUserIfDoesNotExist(UserHelper.getUser(resultantAuthorization));
}
use of org.springframework.security.Authentication in project gocd by gocd.
the class PreAuthenticatedAuthenticationProviderTest method authenticate_shouldSupportAuthenticationForPreAuthenticatedAuthenticationTokenOnly.
@Test
public void authenticate_shouldSupportAuthenticationForPreAuthenticatedAuthenticationTokenOnly() {
Authentication authenticate = authenticationProvider.authenticate(new UsernamePasswordAuthenticationToken("p", "c"));
assertNull(authenticate);
verifyZeroInteractions(authorizationExtension);
}
Aggregations