Skip to content
Snippets Groups Projects
Commit a52c9ee4 authored by Tor-Einar Skog's avatar Tor-Einar Skog
Browse files

First working version of login from VIPSWeb

parent 9bca8337
No related branches found
No related tags found
No related merge requests found
...@@ -55,6 +55,7 @@ import no.nibio.vips.util.ServletUtil; ...@@ -55,6 +55,7 @@ import no.nibio.vips.util.ServletUtil;
* @author Tor-Einar Skog <tor-einar.skog@nibio.no> * @author Tor-Einar Skog <tor-einar.skog@nibio.no>
*/ */
public class LoginController extends HttpServlet { public class LoginController extends HttpServlet {
//private static final String CLOSE_AND_RELOAD_PARENT = "close_and_reload_parent";
/** /**
* Processes requests for both HTTP * Processes requests for both HTTP
...@@ -110,7 +111,14 @@ public class LoginController extends HttpServlet { ...@@ -110,7 +111,14 @@ public class LoginController extends HttpServlet {
{ {
request.getSession().setAttribute("user", user); request.getSession().setAttribute("user", user);
this.handleRememberUser(request, response, user); this.handleRememberUser(request, response, user);
response.sendRedirect(new StringBuilder("http://").append(ServletUtil.getServerName(request)).append(nextPage).toString()); if(nextPage.indexOf("http") == 0)
{
response.sendRedirect(nextPage);
}
else
{
response.sendRedirect(new StringBuilder("http://").append(ServletUtil.getServerName(request)).append(nextPage).toString());
}
} }
else else
{ {
...@@ -171,7 +179,14 @@ public class LoginController extends HttpServlet { ...@@ -171,7 +179,14 @@ public class LoginController extends HttpServlet {
{ {
request.getSession().setAttribute("user", user); request.getSession().setAttribute("user", user);
this.handleRememberUser(request, response, user); this.handleRememberUser(request, response, user);
response.sendRedirect(new StringBuilder("http://").append(ServletUtil.getServerName(request)).append(nextPage).toString()); if(nextPage.indexOf("http") == 0)
{
response.sendRedirect(nextPage);
}
else
{
response.sendRedirect(new StringBuilder("http://").append(ServletUtil.getServerName(request)).append(nextPage).toString());
}
} }
else else
{ {
...@@ -223,6 +238,7 @@ public class LoginController extends HttpServlet { ...@@ -223,6 +238,7 @@ public class LoginController extends HttpServlet {
// No login attempt. Show form // No login attempt. Show form
else else
{ {
request.setAttribute("checkRemember", request.getParameter("nextPage").indexOf("http") == 0);
request.setAttribute("messageKey", request.getParameter("messageKey")); request.setAttribute("messageKey", request.getParameter("messageKey"));
request.setAttribute("errorMessageKey", request.getParameter("errorMessageKey")); request.setAttribute("errorMessageKey", request.getParameter("errorMessageKey"));
request.getRequestDispatcher("/login.ftl").forward(request, response); request.getRequestDispatcher("/login.ftl").forward(request, response);
......
...@@ -571,7 +571,9 @@ public class UserBean { ...@@ -571,7 +571,9 @@ public class UserBean {
} }
q = em.createNamedQuery("VipsLogicUser.findByUserId", VipsLogicUser.class); q = em.createNamedQuery("VipsLogicUser.findByUserId", VipsLogicUser.class);
q.setParameter("userId", uUuid.getUserUuidPK().getUserId()); q.setParameter("userId", uUuid.getUserUuidPK().getUserId());
return (VipsLogicUser) q.getSingleResult(); VipsLogicUser user = (VipsLogicUser) q.getSingleResult();
user.setUserUuid(uuid);
return user;
} }
catch(NoResultException ex) catch(NoResultException ex)
{ {
......
...@@ -42,6 +42,7 @@ import javax.validation.constraints.Size; ...@@ -42,6 +42,7 @@ import javax.validation.constraints.Size;
import javax.xml.bind.annotation.XmlRootElement; import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient; import javax.xml.bind.annotation.XmlTransient;
import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonIgnore;
import java.util.UUID;
/** /**
* @copyright 2013 <a href="http://www.nibio.no/">NIBIO</a> * @copyright 2013 <a href="http://www.nibio.no/">NIBIO</a>
...@@ -81,6 +82,8 @@ public class VipsLogicUser implements Serializable { ...@@ -81,6 +82,8 @@ public class VipsLogicUser implements Serializable {
private String emailVerificationCode; private String emailVerificationCode;
private Set<VipsLogicRole> vipsLogicRoles; private Set<VipsLogicRole> vipsLogicRoles;
private Integer vipsCoreUserId; private Integer vipsCoreUserId;
private UUID userUuid;
public VipsLogicUser() { public VipsLogicUser() {
} }
...@@ -352,4 +355,19 @@ public class VipsLogicUser implements Serializable { ...@@ -352,4 +355,19 @@ public class VipsLogicUser implements Serializable {
} }
return null; return null;
} }
/**
* @return the userUuid
*/
@Transient
public UUID getUserUuid() {
return userUuid;
}
/**
* @param userUuid the userUuid to set
*/
public void setUserUuid(UUID userUuid) {
this.userUuid = userUuid;
}
} }
...@@ -32,6 +32,7 @@ import java.util.List; ...@@ -32,6 +32,7 @@ import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.UUID; import java.util.UUID;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import javax.ws.rs.DELETE;
import javax.ws.rs.FormParam; import javax.ws.rs.FormParam;
import javax.ws.rs.GET; import javax.ws.rs.GET;
import javax.ws.rs.POST; import javax.ws.rs.POST;
...@@ -523,15 +524,39 @@ public class LogicService { ...@@ -523,15 +524,39 @@ public class LogicService {
@Produces("application/json;charset=UTF-8") @Produces("application/json;charset=UTF-8")
public Response getVipsLogicUserByUUID(@PathParam("userUUID") String userUUID) public Response getVipsLogicUserByUUID(@PathParam("userUUID") String userUUID)
{ {
UUID uUUID = UUID.fromString(userUUID); try
VipsLogicUser user = SessionControllerGetter.getUserBean().findVipsLogicUser(uUUID); {
if(user != null) UUID uUUID = UUID.fromString(userUUID);
VipsLogicUser user = SessionControllerGetter.getUserBean().findVipsLogicUser(uUUID);
if(user != null)
{
return Response.ok().entity(user).build();
}
else
{
return Response.status(Response.Status.NOT_FOUND).build();
}
}
catch(IllegalArgumentException ex)
{
return Response.serverError().entity(ex.getMessage()).build();
}
}
@DELETE
@Path("user/uuid/{userUUID}")
@Produces("application/json;charset=UTF-8")
public Response deleteVipsLogicUserUUID(@PathParam("userUUID") String userUUID)
{
try
{ {
return Response.ok().entity(user).build(); UUID uUUID = UUID.fromString(userUUID);
SessionControllerGetter.getUserBean().deleteUserUuid(uUUID);
return Response.ok().build();
} }
else catch(IllegalArgumentException ex)
{ {
return Response.status(Response.Status.NOT_FOUND).build(); return Response.serverError().entity(ex.getMessage()).build();
} }
} }
......
...@@ -79,6 +79,7 @@ ...@@ -79,6 +79,7 @@
<url-pattern>/logout</url-pattern> <url-pattern>/logout</url-pattern>
<url-pattern>/loginsubmit</url-pattern> <url-pattern>/loginsubmit</url-pattern>
<url-pattern>/oauth2callback</url-pattern> <url-pattern>/oauth2callback</url-pattern>
<url-pattern>/closeAndReloadParentAfterLogin</url-pattern>
</servlet-mapping> </servlet-mapping>
<servlet-mapping> <servlet-mapping>
<servlet-name>UserControllerServlet</servlet-name> <servlet-name>UserControllerServlet</servlet-name>
......
<#--
Copyright (c) 2014 NIBIO <http://www.nibio.no/>.
This file is part of VIPSLogic.
VIPSLogic is free software: you can redistribute it and/or modify
it under the terms of the NIBIO Open Source License as published by
NIBIO, either version 1 of the License, or (at your option) any
later version.
VIPSLogic is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
NIBIO Open Source License for more details.
You should have received a copy of the NIBIO Open Source License
along with VIPSLogic. If not, see <http://www.nibio.no/licenses/>.
-->
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript">
function closeAndReloadParent()
{
window.opener.postMessage("PleaseReload","*");
window.close();
}
</script>
</head>
<body onload="if(window.opener != undefined){closeAndReloadParent();}">
</body>
</html>
...@@ -42,7 +42,7 @@ ...@@ -42,7 +42,7 @@
<input type="text" class="form-control" placeholder="${i18nBundle.username}" name="username" size="15" autofocus/> <input type="text" class="form-control" placeholder="${i18nBundle.username}" name="username" size="15" autofocus/>
<input type="password" class="form-control" placeholder="${i18nBundle.password}" name="password" size="15"/> <input type="password" class="form-control" placeholder="${i18nBundle.password}" name="password" size="15"/>
<button class="btn btn-lg btn-primary btn-block" type="submit">${i18nBundle.login}</button> <button class="btn btn-lg btn-primary btn-block" type="submit">${i18nBundle.login}</button>
<input type="checkbox" name="rememberUser"/> ${i18nBundle.rememberLogin}<br/> <input type="checkbox" name="rememberUser"<#if checkRemember?has_content && checkRemember> checked="checked"</#if>/> ${i18nBundle.rememberLogin}<br/>
<a href="/user?action=registerNewUserForm&userAuthenticationTypeId=1">${i18nBundle.registerNewUser}</a><br/> <a href="/user?action=registerNewUserForm&userAuthenticationTypeId=1">${i18nBundle.registerNewUser}</a><br/>
<a href="/user?action=resetPasswordRequestForm">${i18nBundle.forgottenPassword}</a> <a href="/user?action=resetPasswordRequestForm">${i18nBundle.forgottenPassword}</a>
</form> </form>
...@@ -50,8 +50,8 @@ ...@@ -50,8 +50,8 @@
<input type="hidden" name="userAuthenticationTypeId" value="3"/> <input type="hidden" name="userAuthenticationTypeId" value="3"/>
<input type="hidden" name="nextPage" value="${nextPage!"/"}"/> <input type="hidden" name="nextPage" value="${nextPage!"/"}"/>
<h2 class="form-signin-heading">${i18nBundle.or}</h2> <h2 class="form-signin-heading">${i18nBundle.or}</h2>
<input type="image"src="/images/btn_sign_in_with_google.png" alt="${i18nBundle.signInWith} Google"/><br/> <input type="image" src="/images/btn_sign_in_with_google.png" alt="${i18nBundle.signInWith} Google"/><br/>
<input type="checkbox" name="rememberUser"/> ${i18nBundle.rememberLogin} <input type="checkbox" name="rememberUser"<#if checkRemember?has_content && checkRemember> checked="checked"</#if>/> ${i18nBundle.rememberLogin}
</form> </form>
</div> </div>
</#macro> </#macro>
......
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<!-- Copyright 2010 Nicholas C. Zakas. All rights reserved. BSD Licensed. -->
<html>
<body>
<script type="text/javascript">
function getCookie(cname){
var name = cname + "=";
var ca = document.cookie.split(';');
for(var i=0; i<ca.length; i++) {
var c = ca[i];
while (c.charAt(0)==' ') c = c.substring(1);
if (c.indexOf(name) == 0) return c.substring(name.length,c.length);
}
return "";
}
(function(){
//allowed domains
var whitelist = ["localhost","vipsweb","nibio.no"];
function verifyOrigin(origin){
var domain = origin.replace(/^https?:\/\/|:\d{1,4}$/g, "").toLowerCase(),
i = 0,
len = whitelist.length;
while(i < len){
if (whitelist[i] === domain){
return true;
}
i++;
}
return false;
}
function handleRequest(event){
if (verifyOrigin(event.origin)){
var data = JSON.parse(event.data);
if(data.type === "localStorage")
{
var value = localStorage.getItem(data.key);
event.source.postMessage(JSON.stringify({id: data.id, type:data.type, key:data.key, value: value}), event.origin);
}
else if(data.type === "cookie")
{
var value = getCookie(data.name);
event.source.postMessage(JSON.stringify({id: data.id, type:data.type, name:data.name, value: value}), event.origin);
}
}
}
if(window.addEventListener){
window.addEventListener("message", handleRequest, false);
} else if (window.attachEvent){
window.attachEvent("onmessage", handleRequest);
}
})();
</script>
</body>
</html>
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment