Search in sources :

Example 1 with DefaultGoApiResponse

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);
}
Also used : DefaultGoApiResponse(com.thoughtworks.go.plugin.api.response.DefaultGoApiResponse) User(com.thoughtworks.go.plugin.access.authentication.models.User) Authentication(org.springframework.security.Authentication) GoUserPrinciple(com.thoughtworks.go.server.security.userdetail.GoUserPrinciple)

Example 2 with DefaultGoApiResponse

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;
}
Also used : DefaultGoApiResponse(com.thoughtworks.go.plugin.api.response.DefaultGoApiResponse) PluginSettings(com.thoughtworks.go.server.domain.PluginSettings) NullPlugin(com.thoughtworks.go.domain.NullPlugin) Plugin(com.thoughtworks.go.domain.Plugin) NullPlugin(com.thoughtworks.go.domain.NullPlugin)

Example 3 with DefaultGoApiResponse

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;
}
Also used : DefaultGoApiResponse(com.thoughtworks.go.plugin.api.response.DefaultGoApiResponse) HttpSession(javax.servlet.http.HttpSession) HashMap(java.util.HashMap) Map(java.util.Map)

Example 4 with DefaultGoApiResponse

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);
}
Also used : DefaultGoApiResponse(com.thoughtworks.go.plugin.api.response.DefaultGoApiResponse) HttpSession(javax.servlet.http.HttpSession)

Example 5 with DefaultGoApiResponse

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);
}
Also used : DefaultGoApiResponse(com.thoughtworks.go.plugin.api.response.DefaultGoApiResponse) HttpSession(javax.servlet.http.HttpSession)

Aggregations

DefaultGoApiResponse (com.thoughtworks.go.plugin.api.response.DefaultGoApiResponse)5 HttpSession (javax.servlet.http.HttpSession)3 NullPlugin (com.thoughtworks.go.domain.NullPlugin)1 Plugin (com.thoughtworks.go.domain.Plugin)1 User (com.thoughtworks.go.plugin.access.authentication.models.User)1 PluginSettings (com.thoughtworks.go.server.domain.PluginSettings)1 GoUserPrinciple (com.thoughtworks.go.server.security.userdetail.GoUserPrinciple)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Authentication (org.springframework.security.Authentication)1