Commit 6c87ea78 authored by femiadeyemi's avatar femiadeyemi
Browse files

delete the utility controller

Motivation:

At the moment the utility controller is for obtaining
access and refresh token. These are no longer needed
at this time. Since the helmholtz-marketplace-webapp
will is now a dependency of this project, there is no
need for the index.html page.

Modification:

- delete the controller and index.html page

Result:

The server now render the helmholtz-marketplace-webapp
static files.

Target: master
parent ab9fb8ed
Pipeline #42890 passed with stages
in 8 minutes and 13 seconds
package de.helmholtz.marketplace.webappserver.controller;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.springframework.security.oauth2.client.OAuth2AuthorizedClient;
import org.springframework.security.oauth2.client.OAuth2AuthorizedClientService;
import org.springframework.security.oauth2.client.authentication.OAuth2AuthenticationToken;
import org.springframework.security.web.csrf.CsrfToken;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletRequest;
@RestController
public class UtilityController
{
private final OAuth2AuthorizedClientService authorizedClientService;
private final ObjectMapper mapper = new ObjectMapper();
public UtilityController(OAuth2AuthorizedClientService authorizedClientService) {
this.authorizedClientService = authorizedClientService;
}
@GetMapping("/token")
public JsonNode getBearerToken(
OAuth2AuthenticationToken authentication) {
OAuth2AuthorizedClient client = authorizedClientService.loadAuthorizedClient(
authentication.getAuthorizedClientRegistrationId(), authentication.getName());
return mapper.convertValue(client.getAccessToken(), JsonNode.class);
}
@GetMapping("/refresh-token")
public JsonNode getRefreshToken(
OAuth2AuthenticationToken authentication) {
OAuth2AuthorizedClient client = authorizedClientService.loadAuthorizedClient(
authentication.getAuthorizedClientRegistrationId(), authentication.getName());
return mapper.convertValue(client.getRefreshToken(), JsonNode.class);
}
@GetMapping("/error")
@ResponseBody
public String error(HttpServletRequest request) {
String message = (String) request.getSession().getAttribute("error.message");
request.getSession().removeAttribute("error.message");
return message;
}
@GetMapping("/csrf")
public CsrfToken csrf(CsrfToken token) {
return token;
}
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Test Page</title>
</head>
<body>
<div>
<a href="/oauth2/authorization/unity">login</a>
</div>
<div>
<a href="/token">get token</a>
</div>
<div>
<a href="/refresh-token">get refresh token</a>
</div>
<div>
<a href="/csrf">csrf</a>
</div>
<div>
<a href="/logout">logout</a>
</div>
</body>
</html>
\ No newline at end of file
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment