Skip to content
Snippets Groups Projects
Unverified Commit 33c67b3a authored by jasongwq's avatar jasongwq Committed by GitHub
Browse files

OIDC support groups (#2679)

parent 63da35d2
No related branches found
No related tags found
Loading
......@@ -18,10 +18,11 @@ package org.codelibs.fess.app.web.base.login;
import static org.codelibs.core.stream.StreamUtil.split;
import static org.codelibs.core.stream.StreamUtil.stream;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import java.util.*;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.codelibs.core.lang.StringUtil;
import org.codelibs.fess.entity.FessUser;
import org.codelibs.fess.helper.SystemHelper;
......@@ -46,8 +47,16 @@ public class OpenIdConnectCredential implements LoginCredential, FessCredential
return (String) attributes.get("email");
}
public String[] getUserGroups() {
String[] userGroups = (String[]) attributes.get("groups");
if (userGroups == null) {
userGroups = getDefaultGroupsAsArray();
}
return (userGroups);
}
public OpenIdUser getUser() {
return new OpenIdUser(getUserId(), getDefaultGroupsAsArray(), getDefaultRolesAsArray());
return new OpenIdUser(getUserId(), getUserGroups(), getDefaultRolesAsArray());
}
protected static String[] getDefaultGroupsAsArray() {
......
......@@ -16,9 +16,7 @@
package org.codelibs.fess.sso.oic;
import java.io.IOException;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.*;
import javax.annotation.PostConstruct;
import javax.servlet.http.HttpServletRequest;
......@@ -198,6 +196,15 @@ public class OpenIdConnectAuthenticator implements SsoAuthenticator {
case "exp":
attributes.put("exp", jsonParser.getText());
break;
case "groups":
List<String> list = new ArrayList<String>();
while (jsonParser.nextToken() != JsonToken.END_ARRAY) {
final String group = jsonParser.getText();
list.add(group);
logger.debug(group);
}
attributes.put("groups", list.toArray(new String[list.size()]));
break;
}
}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment