com.formkiq.server.api.OAuthClientsController Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of formkiq-server Show documentation
Show all versions of formkiq-server Show documentation
Server-side integration for the FormKiQ ios application
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();
}
}