From b1063b2e3ded1395f0d712046379fc71649ba5e9 Mon Sep 17 00:00:00 2001 From: "pavel.stastny" Date: Thu, 9 Jul 2020 12:23:41 +0200 Subject: [PATCH] Debug http headers option --- .../InternalAuthenticatedUsersImpl.java | 21 ++++++-- .../rest/api/guice/ApiServletModule.java | 4 ++ .../rest/api/k5/client/debug/HTTPHeaders.java | 48 +++++++++++++++++++ 3 files changed, 69 insertions(+), 4 deletions(-) create mode 100644 rest/src/main/java/cz/incad/kramerius/rest/api/k5/client/debug/HTTPHeaders.java diff --git a/authfilters/src/main/java/cz/incad/kramerius/auth/thirdparty/shibb/internal/InternalAuthenticatedUsersImpl.java b/authfilters/src/main/java/cz/incad/kramerius/auth/thirdparty/shibb/internal/InternalAuthenticatedUsersImpl.java index e441796871..233cb18ea0 100644 --- a/authfilters/src/main/java/cz/incad/kramerius/auth/thirdparty/shibb/internal/InternalAuthenticatedUsersImpl.java +++ b/authfilters/src/main/java/cz/incad/kramerius/auth/thirdparty/shibb/internal/InternalAuthenticatedUsersImpl.java @@ -1,8 +1,12 @@ package cz.incad.kramerius.auth.thirdparty.shibb.internal; import java.sql.SQLException; +import java.util.ArrayList; +import java.util.Arrays; import java.util.List; +import java.util.stream.Collectors; +import cz.incad.kramerius.security.Role; import org.apache.commons.configuration.ConfigurationException; import org.json.JSONException; @@ -36,10 +40,19 @@ protected String updateExistingUser(String userName, ShibbolethUserWrapper w) th UserUtils.associateGroups(u, this.usersManager); UserUtils.associateCommonGroup(u, this.usersManager); String password = GeneratePasswordUtils.generatePswd(); - List roles = w.getRoles(); - this.usersManager.saveUserPassword(u, password); - if (roles.size() > 0) { - this.usersManager.changeRoles(u, roles); + + User userByLoginName = this.usersManager.findUserByLoginName(userName); + Role[] groups = userByLoginName.getGroups(); + + List fromDb = Arrays.stream(groups).map(Role::getName).collect(Collectors.toList()); + List fromSettings = new ArrayList<>(w.getRoles()); + + int max = Math.min(fromDb.size(), fromSettings.size()); + for(int i=0;i requestProvider; + + @GET + @Path("headers") + @Produces({ MediaType.TEXT_PLAIN + ";charset=utf-8" }) + public String headers() throws IOException { + Properties properties = new Properties(); + HttpServletRequest httpServletRequest = requestProvider.get(); + Enumeration headerNames = httpServletRequest.getHeaderNames(); + while (headerNames.hasMoreElements()) { + Object o = headerNames.nextElement(); + String val = httpServletRequest.getHeader(o.toString()); + properties.put(o, val); + } + StringWriter writer = new StringWriter(); + properties.store(writer,"HTTP Request headers"); + return writer.toString(); + } + +}