Skip to content
Snippets Groups Projects
Commit 3415fd5d authored by Felix Sidokhine's avatar Felix Sidokhine
Browse files

added api documentation inside methods

parent 739743f0
No related branches found
No related tags found
No related merge requests found
......@@ -521,6 +521,69 @@ define({ "api": [
"filename": "src/main/java/net/jami/jams/server/servlets/api/auth/directory/SearchDirectoryServlet.java",
"groupTitle": "Directory_Search"
},
{
"version": "1.0.0",
"type": "post",
"url": "/api/login",
"title": "Obtain an 0Auth token",
"name": "postLogin",
"group": "Login",
"parameter": {
"fields": {
"Parameter": [
{
"group": "Parameter",
"type": "header",
"optional": true,
"field": "authorization",
"description": "<p>classical HTTP auth header</p>"
},
{
"group": "Parameter",
"type": "attribute",
"optional": true,
"field": "X509Certificate",
"description": "<p>X509 User certificate</p>"
},
{
"group": "Parameter",
"type": "body",
"optional": true,
"field": "LoginRequest",
"description": "<p>username/password sent to server as JSON object</p>"
}
]
}
},
"success": {
"fields": {
"200": [
{
"group": "200",
"type": "body",
"optional": false,
"field": "AuthTokenResponse",
"description": "<p>the 0Auth authentication token</p>"
}
]
}
},
"error": {
"fields": {
"403": [
{
"group": "403",
"type": "null",
"optional": false,
"field": "null",
"description": "<p>The user is unauthorized</p>"
}
]
}
},
"filename": "src/main/java/net/jami/jams/server/servlets/LoginServlet.java",
"groupTitle": "Login"
},
{
"version": "1.0.0",
"type": "get",
......
......@@ -521,6 +521,69 @@
"filename": "src/main/java/net/jami/jams/server/servlets/api/auth/directory/SearchDirectoryServlet.java",
"groupTitle": "Directory_Search"
},
{
"version": "1.0.0",
"type": "post",
"url": "/api/login",
"title": "Obtain an 0Auth token",
"name": "postLogin",
"group": "Login",
"parameter": {
"fields": {
"Parameter": [
{
"group": "Parameter",
"type": "header",
"optional": true,
"field": "authorization",
"description": "<p>classical HTTP auth header</p>"
},
{
"group": "Parameter",
"type": "attribute",
"optional": true,
"field": "X509Certificate",
"description": "<p>X509 User certificate</p>"
},
{
"group": "Parameter",
"type": "body",
"optional": true,
"field": "LoginRequest",
"description": "<p>username/password sent to server as JSON object</p>"
}
]
}
},
"success": {
"fields": {
"200": [
{
"group": "200",
"type": "body",
"optional": false,
"field": "AuthTokenResponse",
"description": "<p>the 0Auth authentication token</p>"
}
]
}
},
"error": {
"fields": {
"403": [
{
"group": "403",
"type": "null",
"optional": false,
"field": "null",
"description": "<p>The user is unauthorized</p>"
}
]
}
},
"filename": "src/main/java/net/jami/jams/server/servlets/LoginServlet.java",
"groupTitle": "Login"
},
{
"version": "1.0.0",
"type": "get",
......
......@@ -7,7 +7,7 @@ define({
"apidoc": "0.3.0",
"generator": {
"name": "apidoc",
"time": "2020-06-05T15:49:17.635Z",
"time": "2020-06-05T16:00:10.907Z",
"url": "http://apidocjs.com",
"version": "0.23.0"
}
......
......@@ -7,7 +7,7 @@
"apidoc": "0.3.0",
"generator": {
"name": "apidoc",
"time": "2020-06-05T15:49:17.635Z",
"time": "2020-06-05T16:00:10.907Z",
"url": "http://apidocjs.com",
"version": "0.23.0"
}
......
......@@ -31,6 +31,7 @@ import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import net.jami.jams.common.authmodule.AuthTokenResponse;
import net.jami.jams.common.objects.user.UserProfile;
import net.jami.jams.server.servlets.api.auth.login.LoginRequest;
import net.minidev.json.JSONObject;
import java.io.IOException;
......@@ -43,14 +44,26 @@ import static net.jami.jams.server.servlets.api.auth.login.AuthRequestProcessor.
//This method returns the token which is used for all the next calls to the API.
public class LoginServlet extends HttpServlet {
/**
* @apiVersion 1.0.0
* @api {post} /api/login Obtain an 0Auth token
* @apiName postLogin
* @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
*
* @apiSuccess (200) {body} AuthTokenResponse the 0Auth authentication token
* @apiError (403) {null} null The user is unauthorized
*/
@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws IOException {
//There are 3 possible cases here.
//Case 1: form submitted username/password
AuthTokenResponse res = null;
JSONObject object = JsonIterator.deserialize(req.getInputStream().readAllBytes(), JSONObject.class);
if(object.get("username") != null && object.get("password") != null){
res = processUsernamePasswordAuth(object.get("username").toString(), object.get("password").toString());
LoginRequest object = JsonIterator.deserialize(req.getInputStream().readAllBytes(), LoginRequest.class);
if(object.getUsername() != null && object.getPassword() != null){
res = processUsernamePasswordAuth(object.getUsername(), object.getPassword());
}
//Case 2: Authorization header.
if(req.getHeader("authorization") != null){
......
package net.jami.jams.server.servlets.api.auth.login;
import lombok.Getter;
import lombok.Setter;
@Getter
@Setter
public class LoginRequest {
private String username;
private String password;
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment