From a04b5719f890a44fd13d7335656c57d5f5a265e5 Mon Sep 17 00:00:00 2001 From: Josef Rokos Date: Fri, 25 Jul 2014 09:33:32 +0200 Subject: [PATCH] =?UTF-8?q?Opravena=20chyba=20p=C5=99i=20inicializaci=20pr?= =?UTF-8?q?=C3=A1zdn=C3=A9=20datab=C3=A1ze.=20Vypnuto=20lazy=20loadov?= =?UTF-8?q?=C3=A1n=C3=AD=20rol=C3=AD=20u=20u=C5=BEivatele-=20getter=20pro?= =?UTF-8?q?=20role=20naganeruje=20k=20rol=C3=ADm=20pr=C3=A1va=20a=20z?= =?UTF-8?q?=C3=A1znam=20pak=20nejde=20ulo=C5=BEit.=20Do=20budoucna=20se=20?= =?UTF-8?q?mus=C3=AD=20vy=C5=99e=C5=A1it=20jinak.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/info/bukova/isspst/data/User.java | 2 +- .../bukova/isspst/services/AbstractOwnedService.java | 11 ++++++++++- .../bukova/isspst/services/users/UserServiceImpl.java | 5 +++-- 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/src/main/java/info/bukova/isspst/data/User.java b/src/main/java/info/bukova/isspst/data/User.java index 40e3d03d..934c9bba 100644 --- a/src/main/java/info/bukova/isspst/data/User.java +++ b/src/main/java/info/bukova/isspst/data/User.java @@ -38,7 +38,7 @@ public class User extends Member implements UserDetails, DataModel { private String email; @Column(name="NOTIFY") private boolean notify; - @ManyToMany(fetch=FetchType.LAZY) + @ManyToMany(fetch=FetchType.EAGER) @JoinTable(name="USER_ROLE", joinColumns={@JoinColumn(name="USER_ID")}, inverseJoinColumns={@JoinColumn(name="ROLE_ID")}) private List authorities; diff --git a/src/main/java/info/bukova/isspst/services/AbstractOwnedService.java b/src/main/java/info/bukova/isspst/services/AbstractOwnedService.java index af7951ce..e1cbd3b0 100644 --- a/src/main/java/info/bukova/isspst/services/AbstractOwnedService.java +++ b/src/main/java/info/bukova/isspst/services/AbstractOwnedService.java @@ -36,7 +36,7 @@ public class AbstractOwnedService extends AbstractServ @Transactional protected User getLoggedInUser() { - if (sessionData.getCurrentUser() != null) { + if (!this.isFakeLogin() && sessionData.getCurrentUser() != null) { return sessionData.getCurrentUser(); } @@ -48,5 +48,14 @@ public class AbstractOwnedService extends AbstractServ return null; } } + + private boolean isFakeLogin() { + User user = (User)SecurityContextHolder.getContext().getAuthentication().getPrincipal(); + if (user != null && user.getLastName() != null && user.getLastName().equals("fakeLogin")) { + return true; + } + + return false; + } } diff --git a/src/main/java/info/bukova/isspst/services/users/UserServiceImpl.java b/src/main/java/info/bukova/isspst/services/users/UserServiceImpl.java index 4e3f713c..34c0dbe4 100644 --- a/src/main/java/info/bukova/isspst/services/users/UserServiceImpl.java +++ b/src/main/java/info/bukova/isspst/services/users/UserServiceImpl.java @@ -19,7 +19,7 @@ import info.bukova.isspst.Constants; import info.bukova.isspst.data.Role; import info.bukova.isspst.data.User; import info.bukova.isspst.services.AbstractService; -import info.bukova.isspst.services.LazyLoader; +//import info.bukova.isspst.services.LazyLoader; public class UserServiceImpl extends AbstractService implements UserService { @@ -104,6 +104,7 @@ public class UserServiceImpl extends AbstractService implements UserServic tmpRole.setAuthority(Constants.ROLE_ADMIN); tmpAdmin.setUsername(Constants.DEF_ADMIN); tmpAdmin.addAuthority(tmpRole); + tmpAdmin.setLastName("fakeLogin"); SecurityContextHolder.getContext().setAuthentication(new UsernamePasswordAuthenticationToken(tmpAdmin, null, tmpAdmin.getAuthorities())); } @@ -136,7 +137,7 @@ public class UserServiceImpl extends AbstractService implements UserServic @Override @Transactional - @LazyLoader({"grid", "form"}) +// @LazyLoader({"grid", "form"}) public void loadAuthorities(User user) { try { if (user.getAuthorities() == null) {