MARMOTTA-534: revisited functionality
Project: http://git-wip-us.apache.org/repos/asf/marmotta/repo Commit: http://git-wip-us.apache.org/repos/asf/marmotta/commit/6272b263 Tree: http://git-wip-us.apache.org/repos/asf/marmotta/tree/6272b263 Diff: http://git-wip-us.apache.org/repos/asf/marmotta/diff/6272b263 Branch: refs/heads/develop Commit: 6272b263f655a4b9c7e408afcdeabf85abb7204c Parents: fd300f2 Author: Sergio Fernández <[email protected]> Authored: Wed May 10 11:37:04 2017 +0200 Committer: Sergio Fernández <[email protected]> Committed: Wed May 10 11:37:04 2017 +0200 ---------------------------------------------------------------------- .../user/webservices/UserWebService.java | 37 +++++++++++++++++--- .../main/resources/web/admin/widgets/user.js | 30 ++++------------ 2 files changed, 40 insertions(+), 27 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/marmotta/blob/6272b263/platform/marmotta-user/src/main/java/org/apache/marmotta/platform/user/webservices/UserWebService.java ---------------------------------------------------------------------- diff --git a/platform/marmotta-user/src/main/java/org/apache/marmotta/platform/user/webservices/UserWebService.java b/platform/marmotta-user/src/main/java/org/apache/marmotta/platform/user/webservices/UserWebService.java index 63d4c22..3703cbd 100644 --- a/platform/marmotta-user/src/main/java/org/apache/marmotta/platform/user/webservices/UserWebService.java +++ b/platform/marmotta-user/src/main/java/org/apache/marmotta/platform/user/webservices/UserWebService.java @@ -31,6 +31,7 @@ import org.openrdf.model.URI; import org.openrdf.model.Value; import org.openrdf.repository.RepositoryConnection; import org.openrdf.repository.RepositoryException; +import org.slf4j.Logger; import javax.annotation.PostConstruct; import javax.inject.Inject; @@ -60,18 +61,21 @@ public class UserWebService { private static final Pattern PROFILE_URI_PATTERN = Pattern.compile("^<([^>]+)>$"); @Inject + private Logger log; + + @Inject private ConfigurationService configurationService; @Inject - private UserService userService; + private UserService userService; @Inject - private AccountService accountService; + private AccountService accountService; @Inject - private SesameService sesameService; + private SesameService sesameService; - private List<String> acceptedFoafProperties; + private List<String> acceptedFoafProperties; @PostConstruct public void initialize() { @@ -233,6 +237,7 @@ public class UserWebService { * @HTTP 400 if no valid resource uri could be built with the login * @HTTP 500 on other exceptions */ + //TODO: MARMOTTA-663 //@GET //@Path("/{login:[^#?]+}") public Response getUser(@PathParam("login") String login, @HeaderParam("Accept") String types) { @@ -295,6 +300,30 @@ public class UserWebService { } /** + * Throws a {@link AccessDeniedException} if currently no user is logged in + * (aka: current user is anonymous). + * + * @param ref the referer to redirect to + * @param logout set to true to log out (does currently nothing) + * @return a redirect to the referer url + * @throws AccessDeniedException if currently no user is logged in. + * @HTTP 303 if the user is already logged in (or <code>logout == true</code>) + */ + @GET + @Path("/logout") + public Response logout(@HeaderParam(REFERER) String ref) { + log.debug("Current user before logout was: {}", userService.getCurrentUser().getLocalName()); + userService.setCurrentUser(userService.getAnonymousUser()); + userService.clearCurrentUser(); + log.debug("Current user after logout is now: {}", userService.getCurrentUser().getLocalName()); + + if (ref == null || "".equals(ref)) { + ref = configurationService.getServerUri() + configurationService.getStringConfiguration("kiwi.pages.startup"); + } + return Response.seeOther(java.net.URI.create(ref)).build(); + } + + /** * Wrapped AccountInformation for serialisation. * * @author Jakob Frank <[email protected]> http://git-wip-us.apache.org/repos/asf/marmotta/blob/6272b263/platform/marmotta-user/src/main/resources/web/admin/widgets/user.js ---------------------------------------------------------------------- diff --git a/platform/marmotta-user/src/main/resources/web/admin/widgets/user.js b/platform/marmotta-user/src/main/resources/web/admin/widgets/user.js index 9748908..ef055f6 100644 --- a/platform/marmotta-user/src/main/resources/web/admin/widgets/user.js +++ b/platform/marmotta-user/src/main/resources/web/admin/widgets/user.js @@ -25,7 +25,7 @@ var LoginLogout = { - draw : function(basic_url,container) { + draw : function(basic_url, container) { function getUser(url) { var xmlHttp = new XMLHttpRequest(); @@ -35,34 +35,18 @@ var LoginLogout = { } var user = eval('('+getUser(basic_url+"user/me")+')'); - function call(url) { - console.log("calling '" + url + "'..."); - var xhr = new XMLHttpRequest(); - xhr.open("GET", url, false, "anonymous", ""); - xhr.send(""); - document.location.reload(true); - } - console.log("current login: " + user.login); + var link = document.createElement("a"); if(user.login=="anonymous") { - var login_link = document.createElement("a"); - login_link.innerHTML = "login"; - login_link.onclick = function() { - call(basic_url+"user/login"); - }; - document.getElementById(container).appendChild(login_link); + link.innerHTML = "login"; + link.setAttribute("href", basic_url+"user/login"); } else { - //logout button - var logout_link = document.createElement("a"); - logout_link.innerHTML = "change user"; - logout_link.onclick = function() { - call(basic_url+"user/login?logout=true"); - }; - + link.innerHTML = "logout"; + link.setAttribute("href", basic_url+"user/logout"); document.getElementById(container).innerHTML = "<span><a href='"+basic_url+"user/me.html'>"+user.login+"</a></span> | "; - document.getElementById(container).appendChild(logout_link); } + document.getElementById(container).appendChild(link); }
