use of com.thoughtworks.go.plugin.api.response.DefaultGoApiResponse 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 com.thoughtworks.go.plugin.api.response.DefaultGoApiResponse in project gocd by gocd.
the class PluginSettingsRequestProcessor method handlePluginSettingsGetRequest.
private GoApiResponse handlePluginSettingsGetRequest(String pluginId, GoApiRequest goPluginApiRequest) {
Plugin plugin = pluginSqlMapDao.findPlugin(pluginId);
PluginSettings pluginSettings = new PluginSettings(pluginId);
if (!(plugin instanceof NullPlugin)) {
pluginSettings.populateSettingsMap(plugin);
}
DefaultGoApiResponse response = new DefaultGoApiResponse(200);
response.setResponseBody(messageHandlerMap.get(goPluginApiRequest.apiVersion()).responseMessagePluginSettingsGet(pluginSettings));
return response;
}
use of com.thoughtworks.go.plugin.api.response.DefaultGoApiResponse in project gocd by gocd.
the class SessionRequestProcessor method handleSessionGetRequest.
private GoApiResponse handleSessionGetRequest(GoApiRequest goPluginApiRequest) {
String pluginId = messageHandlerMap.get(goPluginApiRequest.apiVersion()).requestMessageSessionGetAndRemove(goPluginApiRequest.requestBody());
HttpSession session = getUserSession();
if (session == null) {
throw new RuntimeException("session not found");
}
Map<String, String> sessionDataMap = (Map<String, String>) session.getAttribute(pluginId);
DefaultGoApiResponse response = new DefaultGoApiResponse(200);
response.setResponseBody(JsonHelper.toJsonString(sessionDataMap));
return response;
}
use of com.thoughtworks.go.plugin.api.response.DefaultGoApiResponse in project gocd by gocd.
the class SessionRequestProcessor method handleSessionPutRequest.
private GoApiResponse handleSessionPutRequest(GoApiRequest goPluginApiRequest) {
SessionData sessionData = messageHandlerMap.get(goPluginApiRequest.apiVersion()).requestMessageSessionPut(goPluginApiRequest.requestBody());
HttpSession session = getUserSession();
if (session == null) {
throw new RuntimeException("session not found");
}
session.setAttribute(sessionData.getPluginId(), sessionData.getSessionData());
return new DefaultGoApiResponse(200);
}
use of com.thoughtworks.go.plugin.api.response.DefaultGoApiResponse in project gocd by gocd.
the class SessionRequestProcessor method handleSessionRemoveRequest.
private GoApiResponse handleSessionRemoveRequest(GoApiRequest goPluginApiRequest) {
String pluginId = messageHandlerMap.get(goPluginApiRequest.apiVersion()).requestMessageSessionGetAndRemove(goPluginApiRequest.requestBody());
HttpSession session = getUserSession();
if (session == null) {
throw new RuntimeException("session not found");
}
session.removeAttribute(pluginId);
return new DefaultGoApiResponse(200);
}
Aggregations