use of com.thoughtworks.go.config.SecurityAuthConfig in project gocd by gocd.
the class SecurityAuthConfigServiceTest method verifyConnection_shouldSendConnectionFailedResponseOnUnSuccessfulVerification.
@Test
public void verifyConnection_shouldSendConnectionFailedResponseOnUnSuccessfulVerification() throws Exception {
VerifyConnectionResponse success = new VerifyConnectionResponse("failure", "Connection check failed", new ValidationResult());
SecurityAuthConfig ldap = new SecurityAuthConfig("ldap", "cd.go.ldap");
when(extension.verifyConnection("cd.go.ldap", ldap.getConfigurationAsMap(true))).thenReturn(success);
VerifyConnectionResponse response = securityAuthConfigService.verifyConnection(ldap);
assertThat(response, is(success));
}
use of com.thoughtworks.go.config.SecurityAuthConfig in project gocd by gocd.
the class RevokeStaleAccessTokenServiceTest method setUp.
@BeforeEach
void setUp() {
service = new RevokeStaleAccessTokenService(goConfigService, accessTokenService);
authConfig1 = new SecurityAuthConfig("authConfig1", "ldap");
authConfig2 = new SecurityAuthConfig("authConfig2", "ldap");
authConfig1_token1 = AccessToken.create(null, null, "authConfig1", new TestingClock());
authConfig1_token1.setId(0);
authConfig1_token2 = AccessToken.create(null, null, "authConfig1", new TestingClock());
authConfig1_token2.setId(1);
authConfig2_token1 = AccessToken.create(null, null, "authConfig2", new TestingClock());
authConfig2_token1.setId(2);
}
use of com.thoughtworks.go.config.SecurityAuthConfig in project gocd by gocd.
the class AccessTokenAuthenticationFilterTest method setUp.
@BeforeEach
void setUp() throws Exception {
clock = new TestingClock();
securityService = mock(SecurityService.class);
accessTokenService = mock(AccessTokenService.class);
authenticationProvider = mock(AccessTokenBasedPluginAuthenticationProvider.class);
securityAuthConfigService = mock(SecurityAuthConfigService.class);
response = new MockHttpServletResponse();
filterChain = mock(FilterChain.class);
filter = new AccessTokenAuthenticationFilter(securityService, accessTokenService, securityAuthConfigService, authenticationProvider);
accessToken = randomAccessTokenForUser(BOB);
when(accessTokenService.findByAccessToken(TOKEN)).thenReturn(accessToken);
authConfig = new SecurityAuthConfig(accessToken.getAuthConfigId(), PLUGIN_ID);
when(securityAuthConfigService.findProfile(accessToken.getAuthConfigId())).thenReturn(authConfig);
}
use of com.thoughtworks.go.config.SecurityAuthConfig in project gocd by gocd.
the class AccessTokenAuthenticationFilter method filterWhenSecurityEnabled.
private void filterWhenSecurityEnabled(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain, AccessTokenCredential accessTokenCredential) throws IOException, ServletException {
if (accessTokenCredential == null) {
LOGGER.debug("Bearer auth credentials are not provided in request.");
filterChain.doFilter(request, response);
} else {
accessTokenService.updateLastUsedCacheWith(accessTokenCredential.getAccessToken());
ACCESS_TOKEN_LOGGER.debug("[Bearer Token Authentication] Authenticating bearer token for: " + "GoCD User: '{}'. " + "GoCD API endpoint: '{}', " + "API Client: '{}', " + "Is Admin Scoped Token: '{}', " + "Current Time: '{}'.", accessTokenCredential.getAccessToken().getUsername(), request.getRequestURI(), request.getHeader("User-Agent"), securityService.isUserAdmin(new Username(accessTokenCredential.getAccessToken().getUsername())), new Timestamp(System.currentTimeMillis()));
try {
String authConfigId = accessTokenCredential.getAccessToken().getAuthConfigId();
SecurityAuthConfig authConfig = securityAuthConfigService.findProfile(authConfigId);
if (authConfig == null) {
String errorMessage = String.format("Can not find authorization configuration \"%s\" to which the requested personal access token belongs. Authorization Configuration \"%s\" might have been renamed or deleted. Please revoke the existing token and create a new one for the same.", authConfigId, authConfigId);
onAuthenticationFailure(request, response, errorMessage);
return;
}
final AuthenticationToken<AccessTokenCredential> authenticationToken = authenticationProvider.authenticateUser(accessTokenCredential, authConfig);
if (authenticationToken == null) {
onAuthenticationFailure(request, response, BAD_CREDENTIALS_MSG);
} else {
SessionUtils.setAuthenticationTokenAfterRecreatingSession(authenticationToken, request);
filterChain.doFilter(request, response);
}
} catch (AuthenticationException e) {
LOGGER.debug("Failed to authenticate user.", e);
onAuthenticationFailure(request, response, e.getMessage());
}
}
}
use of com.thoughtworks.go.config.SecurityAuthConfig in project gocd by gocd.
the class AbstractPluginAuthenticationProvider method reauthenticate.
@Override
public AuthenticationToken<T> reauthenticate(AuthenticationToken<T> authenticationToken) {
final String authConfigId = authenticationToken.getAuthConfigId();
final T credentials = authenticationToken.getCredentials();
final SecurityAuthConfig authConfig = goConfigService.security().securityAuthConfigs().find(authConfigId);
AuthenticationToken<T> reAuthenticatedToken;
if (authConfig == null) {
reAuthenticatedToken = authenticate(credentials, authenticationToken.getPluginId());
} else {
reAuthenticatedToken = authenticateUser(credentials, authConfig);
}
if (reAuthenticatedToken == null) {
removeAnyAssociatedPluginRolesFor(getUsername(authenticationToken));
}
return reAuthenticatedToken;
}
Aggregations