Commit 9264aa87 authored by Gradl, Tobias's avatar Gradl, Tobias
Browse files

374: Reflect user role in schema editor

Task-Url: https://home.tgradl.de/mantisbt/view.php?id=374
parent 61d35974
......@@ -7,6 +7,7 @@ public class AuthPojo {
private int userId;
private int level;
private String displayName;
private String language;
private List<String> roles;
public boolean isAuth() { return auth; }
......@@ -21,6 +22,9 @@ public class AuthPojo {
public String getDisplayName() { return displayName; }
public void setDisplayName(String displayName) { this.displayName = displayName; }
public String getLanguage() { return language; }
public void setLanguage(String language) { this.language = language; }
public List<String> getRoles() { return roles; }
public void setRoles(List<String> roles) { this.roles = roles; }
}
package de.dariah.aai.javasp.web.controller;
package de.dariah.aai.javasp.web.helper;
import java.util.ArrayList;
import javax.servlet.http.HttpServletRequest;
......@@ -8,18 +8,11 @@ import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.core.userdetails.User;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.web.bind.annotation.ModelAttribute;
import de.dariah.aai.javasp.base.SimpleUserDetails;
import de.dariah.samlsp.model.pojo.AuthPojo;
import eu.dariah.de.minfba.core.web.controller.BaseTranslationController;
public abstract class BaseSecurityController extends BaseTranslationController {
public BaseSecurityController(String mainNavId) {
super(mainNavId);
}
public class AuthInfoHelper {
@ModelAttribute("_auth")
public AuthPojo getAuth(HttpServletRequest request) {
return this.getCurrentUserDetails(request);
}
......@@ -33,7 +26,7 @@ public abstract class BaseSecurityController extends BaseTranslationController {
}
}
protected AuthPojo getCurrentUserDetails(HttpServletRequest request) {
public AuthPojo getCurrentUserDetails(HttpServletRequest request) {
Authentication auth = SecurityContextHolder.getContext().getAuthentication();
if (auth!=null && auth.isAuthenticated()==true) {
if (auth.getDetails()!=null && auth.getDetails() instanceof UserDetails) {
......
......@@ -2,40 +2,32 @@ package de.dariah.aai.javasp.web.view;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.util.StringUtils;
import org.springframework.web.servlet.LocaleResolver;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;
import org.springframework.web.servlet.support.RequestContextUtils;
import de.dariah.aai.javasp.base.SimpleUserDetails;
import de.dariah.aai.javasp.web.helper.AuthInfoHelper;
import de.dariah.samlsp.model.pojo.AuthPojo;
public class AuthInfoHandlerInterceptor extends HandlerInterceptorAdapter {
private AuthInfoHelper authInfoHelper;
public AuthInfoHelper getAuthInfoHelper() { return authInfoHelper; }
public void setAuthInfoHelper(AuthInfoHelper authInfoHelper) { this.authInfoHelper = authInfoHelper; }
@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
HttpSession session = request.getSession();
Authentication auth = SecurityContextHolder.getContext().getAuthentication();
UserDetails user = null;
if (auth != null && auth.getDetails() instanceof UserDetails) {
user = (UserDetails) auth.getDetails();
session.setAttribute("__auth", true);
if (user instanceof SimpleUserDetails) {
setUserLocale(request, response, ((SimpleUserDetails)user).getLanguage());
session.setAttribute("__authLevel", ((SimpleUserDetails)user).getMaxAuthorityLevel());
}
} else {
session.setAttribute("__auth", false);
session.setAttribute("__authLevel", 0);
public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception {
if (modelAndView==null) {
return;
}
AuthPojo auth = authInfoHelper.getAuth(request);
if (auth!=null && auth.isAuth()) {
modelAndView.addObject("_auth", auth);
setUserLocale(request, response, auth.getLanguage());
}
return true;
}
private void setUserLocale(final HttpServletRequest request, final HttpServletResponse response, String localeString) {
......@@ -47,5 +39,4 @@ public class AuthInfoHandlerInterceptor extends HandlerInterceptorAdapter {
localeResolver.setLocale(request, response, StringUtils.parseLocaleString(localeString));
}
}
}
}
\ No newline at end of file
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment