Opravena chyba při inicializaci prázdné databáze. Vypnuto lazy loadování

rolí u uživatele- getter pro role naganeruje k rolím práva a záznam pak
nejde uložit. Do budoucna se musí vyřešit jinak.
multitenant
Josef Rokos 10 years ago
parent a32451167d
commit a04b5719f8

@ -38,7 +38,7 @@ public class User extends Member implements UserDetails, DataModel {
private String email; private String email;
@Column(name="NOTIFY") @Column(name="NOTIFY")
private boolean 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")}) @JoinTable(name="USER_ROLE", joinColumns={@JoinColumn(name="USER_ID")}, inverseJoinColumns={@JoinColumn(name="ROLE_ID")})
private List<Role> authorities; private List<Role> authorities;

@ -36,7 +36,7 @@ public class AbstractOwnedService<T extends OwnedDataModel> extends AbstractServ
@Transactional @Transactional
protected User getLoggedInUser() { protected User getLoggedInUser() {
if (sessionData.getCurrentUser() != null) { if (!this.isFakeLogin() && sessionData.getCurrentUser() != null) {
return sessionData.getCurrentUser(); return sessionData.getCurrentUser();
} }
@ -49,4 +49,13 @@ public class AbstractOwnedService<T extends OwnedDataModel> extends AbstractServ
} }
} }
private boolean isFakeLogin() {
User user = (User)SecurityContextHolder.getContext().getAuthentication().getPrincipal();
if (user != null && user.getLastName() != null && user.getLastName().equals("fakeLogin")) {
return true;
}
return false;
}
} }

@ -19,7 +19,7 @@ import info.bukova.isspst.Constants;
import info.bukova.isspst.data.Role; import info.bukova.isspst.data.Role;
import info.bukova.isspst.data.User; import info.bukova.isspst.data.User;
import info.bukova.isspst.services.AbstractService; import info.bukova.isspst.services.AbstractService;
import info.bukova.isspst.services.LazyLoader; //import info.bukova.isspst.services.LazyLoader;
public class UserServiceImpl extends AbstractService<User> implements UserService { public class UserServiceImpl extends AbstractService<User> implements UserService {
@ -104,6 +104,7 @@ public class UserServiceImpl extends AbstractService<User> implements UserServic
tmpRole.setAuthority(Constants.ROLE_ADMIN); tmpRole.setAuthority(Constants.ROLE_ADMIN);
tmpAdmin.setUsername(Constants.DEF_ADMIN); tmpAdmin.setUsername(Constants.DEF_ADMIN);
tmpAdmin.addAuthority(tmpRole); tmpAdmin.addAuthority(tmpRole);
tmpAdmin.setLastName("fakeLogin");
SecurityContextHolder.getContext().setAuthentication(new UsernamePasswordAuthenticationToken(tmpAdmin, null, tmpAdmin.getAuthorities())); SecurityContextHolder.getContext().setAuthentication(new UsernamePasswordAuthenticationToken(tmpAdmin, null, tmpAdmin.getAuthorities()));
} }
@ -136,7 +137,7 @@ public class UserServiceImpl extends AbstractService<User> implements UserServic
@Override @Override
@Transactional @Transactional
@LazyLoader({"grid", "form"}) // @LazyLoader({"grid", "form"})
public void loadAuthorities(User user) { public void loadAuthorities(User user) {
try { try {
if (user.getAuthorities() == null) { if (user.getAuthorities() == null) {

Loading…
Cancel
Save