com.formkiq.server.api.OAuthClientsController Maven / Gradle / Ivy
package com.formkiq.server.api;
import java.io.IOException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.transaction.Transactional;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.annotation.Secured;
import org.springframework.security.core.userdetails.UserDetails;
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.ClientDTO;
import com.formkiq.server.domain.type.ClientListDTO;
import com.formkiq.server.service.OAuthService;
/**
* Form Group Rest Services.
*
*/
@RestController
public class OAuthClientsController extends AbstractRestController {
/** Client Create URL. */
public static final String API_CLIENT = "/api/clients";
/** Client GET URL. */
public static final String API_CLIENT_GET = API_CLIENT + "/get";
/** Client Save URL. */
public static final String API_CLIENT_SAVE = API_CLIENT + "/save";
/** Client Create URL. */
public static final String API_CLIENT_LIST = API_CLIENT + "/list";
/** Client Delete URL. */
public static final String API_CLIENT_DELETE = API_CLIENT + "/delete";
/** OAuthService. */
@Autowired
private OAuthService oauthservice;
/**
* Gets a Client.
* @param request {@link HttpServletRequest}
* @param response {@link HttpServletResponse}
* @param client {@link String}
* @throws IOException IOException
* @return {@link ClientDTO}
*/
@Transactional
@RequestMapping(API_CLIENT_GET)
public ClientDTO get(
final HttpServletRequest request,
final HttpServletResponse response,
@RequestParam(value = "client", required = true)
final String client) throws IOException {
getApiVersion(request);
UserDetails user = getUserDetails();
return this.oauthservice.findClient(user, client);
}
/**
* Creates Form Group.
* @param request {@link HttpServletRequest}
* @param name String
* @param client String
* @param secret String
* @return ApiStringResponse
*/
@Transactional
@Secured({ "ROLE_ADMIN" })
@RequestMapping(API_CLIENT_SAVE)
public ApiMessageResponse save(
final HttpServletRequest request,
@RequestParam(value = "clientname", required = false)
final String name,
@RequestParam(value = "client", required = true)
final String client,
@RequestParam(value = "clientsecret", required = false)
final String secret) {
this.oauthservice.save(name, client, secret);
return new ApiMessageResponse("Client saved");
}
/**
* List Apps.
* @param request {@link HttpServletRequest}
* @param token {@link String}
* @return ClientListDTO
*/
@Transactional
@Secured({ "ROLE_ADMIN" })
@RequestMapping(API_CLIENT_LIST)
public ClientListDTO list(final HttpServletRequest request,
@RequestParam(value = "token", required = false)
final String token) {
getApiVersion(request);
return this.oauthservice.list(token);
}
/**
* Delete Client.
* @param request {@link HttpServletRequest}
* @param client {@link String}
* @return ApiStringResponse
*/
@Transactional
@Secured({ "ROLE_ADMIN" })
@RequestMapping(API_CLIENT_DELETE)
public ApiMessageResponse delete(final HttpServletRequest request,
@RequestParam(value = "client", required = true)
final String client) {
getApiVersion(request);
this.oauthservice.deleteClient(client);
return new ApiMessageResponse("Client deleted");
}
}