Skip to content
Snippets Groups Projects
Commit 3a075fd0 authored by William Enright's avatar William Enright Committed by Adrien Béraud
Browse files

Added missing annotations for XML parsing errors

Change-Id: Ife15286d955c853d5912df255706ee90a6aed6ec
parent 2bcc453c
No related branches found
No related tags found
No related merge requests found
......@@ -28,6 +28,7 @@ import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import net.jami.jams.common.annotations.JsonContent;
import net.jami.jams.common.authmodule.AuthTokenResponse;
import net.jami.jams.common.serialization.tomcat.TomcatCustomErrorHandler;
import net.jami.jams.server.servlets.api.auth.login.LoginRequest;
......@@ -39,7 +40,8 @@ import static net.jami.jams.server.servlets.api.auth.login.AuthRequestProcessor.
import static net.jami.jams.server.servlets.api.auth.login.AuthRequestProcessor.processX509Auth;
@WebServlet("/api/login")
//This method returns the token which is used for all the next calls to the API.
// This method returns the token which is used for all the next calls to the
// API.
public class LoginServlet extends HttpServlet {
/**
......@@ -49,12 +51,14 @@ public class LoginServlet extends HttpServlet {
* @apiGroup Login
* @apiParam {header} [authorization] classical HTTP auth header
* @apiParam {attribute} [X509Certificate] X509 User certificate
* @apiParam {body} [LoginRequest] username/password sent to server as JSON object
* @apiParam {body} [LoginRequest] username/password sent to server as JSON
* object
*
* @apiSuccess (200) {body} AuthTokenResponse the 0Auth authentication token
* @apiError (403) {null} null The user is unauthorized
*/
@Override
@JsonContent
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws IOException {
AuthTokenResponse res = null;
// Case 1: Authorization header.
......@@ -64,20 +68,16 @@ public class LoginServlet extends HttpServlet {
// Case 2 SSL Certificate
else if (req.getAttribute("jakarta.servlet.request.X509Certificate") != null) {
res = processX509Auth((X509Certificate[]) req.getAttribute("jakarta.servlet.request.X509Certificate"));
}
else{
} else {
// Case 3: form submitted username/password
LoginRequest object = JsonIterator.deserialize(req.getInputStream().readAllBytes(), LoginRequest.class);
if (object.getUsername() != null && object.getPassword() != null) {
res = processUsernamePasswordAuth(object.getUsername(), object.getPassword());
}
}
if(res == null) TomcatCustomErrorHandler.sendCustomError(resp,401,"Invalid credentials provided!");
else resp.getOutputStream().write(JsonStream.serialize(res).getBytes());
}
@Override
protected void doDelete(HttpServletRequest req, HttpServletResponse resp) throws IOException {
resp.setStatus(200);
if (res == null)
TomcatCustomErrorHandler.sendCustomError(resp, 401, "Invalid credentials provided!");
else
resp.getOutputStream().write(JsonStream.serialize(res).getBytes());
}
}
......@@ -29,6 +29,7 @@ import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import net.jami.jams.common.annotations.JsonContent;
import net.jami.jams.common.annotations.ScopedServletMethod;
import net.jami.jams.common.dao.StatementElement;
import net.jami.jams.common.dao.StatementList;
......@@ -70,6 +71,7 @@ public class ContactServlet extends HttpServlet {
*/
@Override
@ScopedServletMethod(securityGroups = {AccessLevel.ADMIN})
@JsonContent
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
StatementList statementList = new StatementList();
statementList.addStatement(new StatementElement("owner","=",req.getParameter("username").toString(),""));
......
......@@ -31,6 +31,7 @@ import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import lombok.extern.slf4j.Slf4j;
import net.jami.jams.common.annotations.JsonContent;
import net.jami.jams.common.annotations.ScopedServletMethod;
import net.jami.jams.common.authentication.AuthenticationSourceType;
import net.jami.jams.common.authmodule.AuthModuleKey;
......@@ -54,6 +55,7 @@ public class DirectoryEntryServlet extends HttpServlet {
@Override
@ScopedServletMethod(securityGroups = {AccessLevel.ADMIN})
@JsonContent
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws IOException {
//Create a user profile.
String realm = "LOCAL";
......
......@@ -57,6 +57,7 @@ public class SubscriptionServlet extends HttpServlet {
// on disk..
@Override
@ScopedServletMethod(securityGroups = {AccessLevel.ADMIN})
@JsonContent
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws IOException {
String license = new String(req.getInputStream().readAllBytes());
final JSONObject obj = new JSONObject(license);
......
......@@ -88,6 +88,7 @@ public class UserServlet extends HttpServlet {
//Create an internal user - this is always technically available, because internal users have the right to exist.
@Override
@ScopedServletMethod(securityGroups = {AccessLevel.ADMIN})
@JsonContent
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
final JSONObject obj = new JSONObject(req.getReader().lines().collect(Collectors.joining(System.lineSeparator())));
String pw = obj.getString("password");
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment