-
Notifications
You must be signed in to change notification settings - Fork 0
SecureRestEndpoints
kohlhaas edited this page Jun 20, 2024
·
1 revision
To obtain an access token for the user admin with an empty password, use the following curl command:
curl -X POST "http://localhost:8051/rapla/authentication?username=admin" --data '""'Use the obtained token for secured requests by including it in the Authorization header:
curl -X GET "http://localhost:8051/rapla/pruefungen/secure" -H 'Authorization: Bearer InsertTokenHere'@Inject
RemoteSession session;
private final HttpServletRequest request;
@Inject
public RaplaPruefungen(@Context HttpServletRequest request) {
this.request = request;
}
@GET
@Produces(MediaType.TEXT_HTML)
@Path("secure")
public void generateSecurePage(@Context HttpServletRequest request, @Context HttpServletResponse response) throws Exception {
User user = session.checkAndGetUser(request);
java.io.PrintWriter out = response.getWriter();
out.println("<html>");
out.println("<head>");
out.println("<title>Secured Page</title>");
out.println("</head>");
out.println("<body>");
out.println("Welcome, " + user.getUsername());
out.println("</body>");
out.println("</html>");
}This example demonstrates how to secure a page by verifying the access token and authenticating the user.