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(); + } + +}