Skip to content

Commit

Permalink
Fixed REST method loginPostJSON in RestAuthClient and AuthService
Browse files Browse the repository at this point in the history
  • Loading branch information
gasparez15 committed May 5, 2023
1 parent 972f9df commit 5c4b48d
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 18 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.logicaldoc.webservice.model;

import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlType;

@XmlRootElement(name = "credentials")
@XmlType(name = "WSCredentials")
public class WSCredentials {

private String username;
private String password;

public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.MediaType;

import com.logicaldoc.webservice.model.WSCredentials;

/**
* Auth Web Service definition interface for Rest Services
*
Expand All @@ -32,7 +34,7 @@ public interface AuthService {
@POST
@Path("/login")
@Consumes(MediaType.APPLICATION_JSON)
public String loginPostJSON(String jsonstr) throws Exception;
public String loginPostJSON(WSCredentials wscred) throws Exception;

@DELETE
@Path("/logout")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import org.slf4j.LoggerFactory;

import com.logicaldoc.core.security.authentication.AuthenticationException;
import com.logicaldoc.webservice.model.WSCredentials;
import com.logicaldoc.webservice.rest.AuthService;

/**
Expand Down Expand Up @@ -34,8 +35,8 @@ public void logout(String sid) {
}

@Override
public String loginPostJSON(String jsonstr) throws Exception {
return proxy.loginPostJSON(jsonstr);
public String loginPostJSON(WSCredentials wscred) throws Exception {
return proxy.loginPostJSON(wscred);
}

@Override
Expand All @@ -47,4 +48,5 @@ public String getSid() {
public String loginForm(String username, String password) throws Exception {
return proxy.loginForm(username, password);
}

}
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package com.logicaldoc.webservice.rest.endpoint;

import java.util.HashMap;

import javax.ws.rs.Consumes;
import javax.ws.rs.DELETE;
import javax.ws.rs.FormParam;
Expand All @@ -17,9 +15,8 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.logicaldoc.core.security.authentication.AuthenticationException;
import com.logicaldoc.webservice.model.WSCredentials;
import com.logicaldoc.webservice.rest.AuthService;
import com.logicaldoc.webservice.soap.endpoint.SoapAuthService;

Expand Down Expand Up @@ -61,17 +58,8 @@ public String loginForm(@FormParam("username") String username, @FormParam("pass
@Path("/login")
@Operation(operationId = "loginPostJSON", summary = "Login with POST in JSON format", description = "Login posting the credentials in JSON format")
@Consumes(MediaType.APPLICATION_JSON)
public String loginPostJSON(String jsonstr) throws Exception {
log.debug("loginPostJSON({})", jsonstr);

ObjectMapper mapper = new ObjectMapper();
TypeReference<HashMap<String, String>> typeRef = new TypeReference<HashMap<String, String>>() {};
HashMap<String, String> hm = mapper.readValue(jsonstr, typeRef);

String username = hm.get("username");
String password = hm.get("password");

return super.login(username, password);
public String loginPostJSON(WSCredentials cred) throws Exception {
return super.login(cred.getUsername(), cred.getPassword());
}

@DELETE
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,9 @@
<aop:scoped-proxy />
</bean>
</jaxrs:serviceBeans>
<jaxrs:providers>
<ref bean="jsonProvider" />
</jaxrs:providers>
</jaxrs:server>

<jaxrs:server id="restDocument" address="/rest/document">
Expand Down

0 comments on commit 5c4b48d

Please sign in to comment.