From 296054cf55a13eb45ab0c2c2ef9490db6334c764 Mon Sep 17 00:00:00 2001 From: Robert von Burg Date: Tue, 17 Mar 2015 21:40:08 +0100 Subject: [PATCH] [Major] refactored LoginResult - now return sessionId as well - thus the previous sessionId was renamed to authToken, which is what it is from certificate - added sessionId to as we need it to handle session specific data - also return firstname and lastname on LoginResult --- .../rest/endpoint/AuthenticationService.java | 5 +- .../li/strolch/rest/model/LoginResult.java | 54 +++++++++++++++++++ .../inspector/test/AuthenticationTest.java | 10 ++-- 3 files changed, 63 insertions(+), 6 deletions(-) diff --git a/li.strolch.rest/src/main/java/li/strolch/rest/endpoint/AuthenticationService.java b/li.strolch.rest/src/main/java/li/strolch/rest/endpoint/AuthenticationService.java index 6b36abf9d..d98994260 100644 --- a/li.strolch.rest/src/main/java/li/strolch/rest/endpoint/AuthenticationService.java +++ b/li.strolch.rest/src/main/java/li/strolch/rest/endpoint/AuthenticationService.java @@ -87,8 +87,11 @@ public class AuthenticationService { PrivilegeHandler privilegeHandler = restfulStrolchComponent.getContainer().getPrivilegeHandler(); PrivilegeContext privilegeContext = privilegeHandler.getPrivilegeContext(certificate); - loginResult.setSessionId(certificate.getAuthToken()); + loginResult.setSessionId(certificate.getSessionId()); + loginResult.setAuthToken(certificate.getAuthToken()); loginResult.setUsername(certificate.getUsername()); + loginResult.setFirstname(certificate.getFirstname()); + loginResult.setLastname(certificate.getLastname()); loginResult.setLocale(certificate.getLocale()); loginResult.setParameters(certificate.getPropertyMap()); loginResult.setRoles(new ArrayList<>(certificate.getUserRoles())); diff --git a/li.strolch.rest/src/main/java/li/strolch/rest/model/LoginResult.java b/li.strolch.rest/src/main/java/li/strolch/rest/model/LoginResult.java index 27ce9e31c..e5e5831ba 100644 --- a/li.strolch.rest/src/main/java/li/strolch/rest/model/LoginResult.java +++ b/li.strolch.rest/src/main/java/li/strolch/rest/model/LoginResult.java @@ -38,6 +38,15 @@ public class LoginResult { @XmlAttribute(name = "username") private String username; + @XmlAttribute(name = "firstname") + private String firstname; + + @XmlAttribute(name = "lastname") + private String lastname; + + @XmlAttribute(name = "authToken") + private String authToken; + @XmlAttribute(name = "sessionId") private String sessionId; @@ -74,6 +83,51 @@ public class LoginResult { this.username = username; } + /** + * @return the firstname + */ + public String getFirstname() { + return this.firstname; + } + + /** + * @param firstname + * the firstname to set + */ + public void setFirstname(String firstname) { + this.firstname = firstname; + } + + /** + * @return the lastname + */ + public String getLastname() { + return this.lastname; + } + + /** + * @param lastname + * the lastname to set + */ + public void setLastname(String lastname) { + this.lastname = lastname; + } + + /** + * @return the sessionId + */ + public String getAuthToken() { + return this.authToken; + } + + /** + * @param authToken + * the authToken to set + */ + public void setAuthToken(String authToken) { + this.authToken = authToken; + } + /** * @return the sessionId */ diff --git a/li.strolch.rest/src/test/java/li/strolch/rest/inspector/test/AuthenticationTest.java b/li.strolch.rest/src/test/java/li/strolch/rest/inspector/test/AuthenticationTest.java index f9b1f7af8..2f93d486f 100644 --- a/li.strolch.rest/src/test/java/li/strolch/rest/inspector/test/AuthenticationTest.java +++ b/li.strolch.rest/src/test/java/li/strolch/rest/inspector/test/AuthenticationTest.java @@ -58,11 +58,11 @@ public class AuthenticationTest extends AbstractRestfulTest { LoginResult loginResult = result.readEntity(LoginResult.class); assertNotNull(loginResult); assertEquals("jill", loginResult.getUsername()); - assertEquals(64, loginResult.getSessionId().length()); + assertEquals(64, loginResult.getAuthToken().length()); assertNull(loginResult.getMsg()); // logout - result = target().path(ROOT_PATH + "/" + loginResult.getSessionId()).request(MediaType.APPLICATION_JSON) + result = target().path(ROOT_PATH + "/" + loginResult.getAuthToken()).request(MediaType.APPLICATION_JSON) .delete(); assertEquals(Status.OK.getStatusCode(), result.getStatus()); assertNotNull(loginResult); @@ -86,12 +86,12 @@ public class AuthenticationTest extends AbstractRestfulTest { LoginResult loginResult = result.readEntity(LoginResult.class); assertNotNull(loginResult); assertEquals("jill", loginResult.getUsername()); - assertEquals(64, loginResult.getSessionId().length()); + assertEquals(64, loginResult.getAuthToken().length()); assertEquals(Locale.ITALY.toString(), loginResult.getLocale()); assertNull(loginResult.getMsg()); // logout - result = target().path(ROOT_PATH + "/" + loginResult.getSessionId()).request(MediaType.APPLICATION_JSON) + result = target().path(ROOT_PATH + "/" + loginResult.getAuthToken()).request(MediaType.APPLICATION_JSON) .delete(); assertEquals(Status.OK.getStatusCode(), result.getStatus()); assertNotNull(loginResult); @@ -128,7 +128,7 @@ public class AuthenticationTest extends AbstractRestfulTest { LoginResult loginResult = result.readEntity(LoginResult.class); assertNotNull(loginResult); assertEquals("jill", loginResult.getUsername()); - assertEquals(64, loginResult.getSessionId().length()); + assertEquals(64, loginResult.getAuthToken().length()); assertNull(loginResult.getMsg()); // logout