All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.formkiq.server.api.OAuthClientsController Maven / Gradle / Ivy

There is a newer version: 0.6.1
Show newest version
package com.formkiq.server.api;

import javax.servlet.http.HttpServletRequest;
import javax.transaction.Transactional;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.annotation.Secured;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.formkiq.server.domain.type.ClientListDTO;
import com.formkiq.server.service.OAuthService;

/**
 * Form Group Rest Services.
 *
 */
@RestController
public class OAuthClientsController extends AbstractRestController {

    /** Form Group Create URL. */
    public static final String API_CLIENT = "/api/clients";

    /** Form Group Create URL. */
    public static final String API_CLIENT_CREATE = API_CLIENT + "/create";

    /** Form Group Create URL. */
    public static final String API_CLIENT_LIST = API_CLIENT + "/list";

    /** OAuthService. */
    @Autowired
    private OAuthService oauthservice;

    /**
     * Creates Form Group.
     * @param request {@link HttpServletRequest}
     * @param name String
     * @param client String
     * @param clientSecret String
     * @return ApiStringResponse
     */
    @Transactional
    @Secured({ "ROLE_ADMIN" })
    @RequestMapping(API_CLIENT_CREATE)
    public ApiMessageResponse createApp(
            final HttpServletRequest request,
            @RequestParam(value = "clientname", required = true)
            final String name,
            @RequestParam(value = "client", required = true)
            final String client,
            @RequestParam(value = "clientsecret", required = true)
            final String clientSecret) {

        ApiMessageResponse msg = null;

        if (this.oauthservice.isValidClient(client)) {

            msg = new ApiMessageResponse("Client already exists");

        } else {

            this.oauthservice.addClientDetails(name, client,
                    clientSecret);
            msg = new ApiMessageResponse("Client created");
        }

        return msg;
    }

    /**
     * List Apps.
     * @param request {@link HttpServletRequest}
     * @return ApiStringResponse
     */
    @Transactional
    @Secured({ "ROLE_ADMIN" })
    @RequestMapping(API_CLIENT_LIST)
    public ClientListDTO list(final HttpServletRequest request) {
        getApiVersion(request);
        return this.oauthservice.list();
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy