use of com.thoughtworks.go.plugin.domain.authorization.AuthenticationResponse in project gocd by gocd.
the class AbstractPluginAuthenticationProvider method authenticateUser.
public AuthenticationToken<T> authenticateUser(T credentials, SecurityAuthConfig authConfig) {
String pluginId = authConfig.getPluginId();
try {
if (!doesPluginSupportAuthentication(pluginId)) {
return null;
}
final List<PluginRoleConfig> roleConfigs = goConfigService.security().getRoles().pluginRoleConfigsFor(authConfig.getId());
LOGGER.debug("Authenticating user using the authorization plugin: `{}`", pluginId);
AuthenticationResponse response = authenticateWithExtension(pluginId, credentials, authConfig, roleConfigs);
User user = ensureDisplayNamePresent(response.getUser());
if (user != null) {
userService.addOrUpdateUser(toDomainUser(user), authConfig);
pluginRoleService.updatePluginRoles(pluginId, user.getUsername(), CaseInsensitiveString.list(response.getRoles()));
LOGGER.debug("Successfully authenticated user: `{}` using the authorization plugin: `{}`", user.getUsername(), pluginId);
final GoUserPrinciple goUserPrinciple = new GoUserPrinciple(user.getUsername(), user.getDisplayName(), authorityGranter.authorities(user.getUsername()));
return createAuthenticationToken(goUserPrinciple, credentials, pluginId, authConfig.getId());
}
} catch (OnlyKnownUsersAllowedException e) {
LOGGER.info("User {} is successfully authenticated. Auto register new user is disabled. Please refer {}", e.getUsername(), CurrentGoCDVersion.docsUrl("configuration/dev_authentication.html#controlling-user-access"));
throw e;
} catch (InvalidAccessTokenException e) {
LOGGER.error("Error while authenticating user using auth_config: {} with the authorization plugin: {} ", authConfig.getId(), pluginId);
throw e;
} catch (Exception e) {
LOGGER.error("Error while authenticating user using auth_config: {} with the authorization plugin: {} ", authConfig.getId(), pluginId);
}
LOGGER.debug("Authentication failed using the authorization plugin: `{}`", pluginId);
return null;
}
Aggregations