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) {