-
Notifications
You must be signed in to change notification settings - Fork 271
/
Manage.java
executable file
·47 lines (42 loc) · 1.77 KB
/
Manage.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package com.ibm.webapi.apis;
import javax.enterprise.context.RequestScoped;
import javax.inject.Inject;
import javax.json.JsonObject;
import javax.ws.rs.*;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.Response.Status;
import javax.json.Json;
import org.eclipse.microprofile.openapi.annotations.Operation;
import org.eclipse.microprofile.openapi.annotations.responses.APIResponses;
import org.eclipse.microprofile.openapi.annotations.responses.APIResponse;
import org.eclipse.microprofile.openapi.annotations.media.Content;
import org.eclipse.microprofile.openapi.annotations.media.Schema;
import org.eclipse.microprofile.jwt.JsonWebToken;
@RequestScoped
@Path("/v1")
public class Manage {
@Inject
private JsonWebToken jwtPrincipal;
@POST
@Path("/manage")
@Produces(MediaType.APPLICATION_JSON)
@APIResponses(value = {
@APIResponse(responseCode = "200", description = "Manage application",
content = @Content(mediaType = "application/json", schema = @Schema(implementation = ManageResponse.class))),
@APIResponse(responseCode = "401", description = "Not authorized") })
@Operation(summary = "Manage application", description = "Manage application")
public Response manage() {
System.out.println("com.ibm.web-api.apis.Manage.manage");
System.out.println(this.jwtPrincipal);
String principalEmail = this.jwtPrincipal.getClaim("email");
if (principalEmail.equalsIgnoreCase("[email protected]")) {
JsonObject output = Json.createObjectBuilder().add("message", "success").build();
return Response.ok(output).build();
}
else {
JsonObject output = Json.createObjectBuilder().add("message", "failure").build();
return Response.status(Status.FORBIDDEN).entity(output).type(MediaType.APPLICATION_JSON).build();
}
}
}