Optimalizace načítání dat z databáze. Joinované kolekce lze označit jako
lazy. Do servisní vrstvy se pak implementuje transakční metoda s anotací LazyLoader, která donačte kolekci.multitenant
parent
5b69b04264
commit
a32451167d
@ -0,0 +1,59 @@
|
|||||||
|
package info.bukova.isspst;
|
||||||
|
|
||||||
|
import info.bukova.isspst.data.Role;
|
||||||
|
import info.bukova.isspst.data.User;
|
||||||
|
import info.bukova.isspst.data.Workgroup;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
public class SessionData implements Serializable {
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
private static final long serialVersionUID = -764426911263559758L;
|
||||||
|
|
||||||
|
private List<Workgroup> userCentres;
|
||||||
|
private List<Workgroup> userWorkgroups;
|
||||||
|
private User currentUser;
|
||||||
|
private Map<Integer, List<Role>> workgroupRoles;
|
||||||
|
|
||||||
|
public SessionData() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<Workgroup> getUserCentres() {
|
||||||
|
return userCentres;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setUserCentres(List<Workgroup> userCentres) {
|
||||||
|
this.userCentres = userCentres;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<Workgroup> getUserWorkgroups() {
|
||||||
|
return userWorkgroups;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setUserWorkgroups(List<Workgroup> userWorkgroups) {
|
||||||
|
this.userWorkgroups = userWorkgroups;
|
||||||
|
}
|
||||||
|
|
||||||
|
public User getCurrentUser() {
|
||||||
|
return currentUser;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCurrentUser(User currentUser) {
|
||||||
|
this.currentUser = currentUser;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Map<Integer, List<Role>> getWorkgroupRoles() {
|
||||||
|
return workgroupRoles;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setWorkgroupRoles(Map<Integer, List<Role>> workgroupRoles) {
|
||||||
|
this.workgroupRoles = workgroupRoles;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,59 @@
|
|||||||
|
package info.bukova.isspst.security;
|
||||||
|
|
||||||
|
import info.bukova.isspst.SessionData;
|
||||||
|
import info.bukova.isspst.data.Role;
|
||||||
|
import info.bukova.isspst.data.User;
|
||||||
|
import info.bukova.isspst.data.Workgroup;
|
||||||
|
import info.bukova.isspst.services.users.UserService;
|
||||||
|
import info.bukova.isspst.services.workgroups.WorkgroupService;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import javax.servlet.ServletException;
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.security.core.Authentication;
|
||||||
|
import org.springframework.security.web.authentication.AuthenticationSuccessHandler;
|
||||||
|
|
||||||
|
public class LoginSuccessHandler implements AuthenticationSuccessHandler {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private SessionData sessionData;
|
||||||
|
@Autowired
|
||||||
|
private WorkgroupService workgroupService;
|
||||||
|
@Autowired
|
||||||
|
private UserService userService;
|
||||||
|
|
||||||
|
private static final Logger logger = LoggerFactory.getLogger(LoginSuccessHandler.class);
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onAuthenticationSuccess(HttpServletRequest request,
|
||||||
|
HttpServletResponse response, Authentication auth) throws IOException,
|
||||||
|
ServletException {
|
||||||
|
|
||||||
|
User u = (User) userService.loadUserByUsername(((User)auth.getPrincipal()).getUsername());
|
||||||
|
|
||||||
|
logger.info("User " + u.getUsername() + " logged in");
|
||||||
|
|
||||||
|
sessionData.setUserCentres(workgroupService.getUserCentres((User) auth.getPrincipal()));
|
||||||
|
sessionData.setUserWorkgroups(workgroupService.getUserWorkgroups((User) auth.getPrincipal()));
|
||||||
|
workgroupService.loadParents(u);
|
||||||
|
sessionData.setCurrentUser(u);
|
||||||
|
|
||||||
|
Map<Integer, List<Role>> wgRoles = new HashMap<Integer, List<Role>>();
|
||||||
|
for (Workgroup w : u.getParents()) {
|
||||||
|
wgRoles.put(w.getId(), workgroupService.getUserWorkgroupRoles(w, u));
|
||||||
|
}
|
||||||
|
sessionData.setWorkgroupRoles(wgRoles);
|
||||||
|
|
||||||
|
response.sendRedirect("app/");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,12 @@
|
|||||||
|
package info.bukova.isspst.services;
|
||||||
|
|
||||||
|
|
||||||
|
public class LazyLoadException extends RuntimeException {
|
||||||
|
|
||||||
|
private static final long serialVersionUID = -2251676786418660140L;
|
||||||
|
|
||||||
|
public LazyLoadException(Throwable cause) {
|
||||||
|
super(cause);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,12 @@
|
|||||||
|
package info.bukova.isspst.services;
|
||||||
|
|
||||||
|
import java.lang.annotation.ElementType;
|
||||||
|
import java.lang.annotation.Retention;
|
||||||
|
import java.lang.annotation.RetentionPolicy;
|
||||||
|
import java.lang.annotation.Target;
|
||||||
|
|
||||||
|
@Retention(RetentionPolicy.RUNTIME)
|
||||||
|
@Target(ElementType.METHOD)
|
||||||
|
public @interface LazyLoader {
|
||||||
|
String[] value() default "";
|
||||||
|
}
|
Loading…
Reference in New Issue