Screenname is the OIDC user's username (if provided) for new users

This commit is contained in:
Mauro Mugnaini 2020-07-01 19:35:20 +02:00
parent 9727f330c6
commit 446286b77a
1 changed files with 7 additions and 6 deletions

View File

@ -10,9 +10,6 @@ import javax.servlet.http.HttpServletResponse;
import org.gcube.oidc.URLEncodedContextMapper;
import org.gcube.oidc.rest.JWTToken;
import org.gcube.portal.oidc.lr62.JWTTokenUtil;
import org.gcube.portal.oidc.lr62.LiferayOpenIdConnectConfiguration;
import org.gcube.portal.oidc.lr62.UserSitesToGroupsAndRolesMapper;
import com.liferay.portal.kernel.exception.PortalException;
import com.liferay.portal.kernel.exception.SystemException;
@ -76,6 +73,7 @@ public class OpenIdConnectAutoLogin extends BaseAutoLogin {
String given = token.getGiven();
String family = token.getFamily();
String subject = token.getSub();
String username = token.getUserName();
User user = null;
try {
boolean updateUser = false;
@ -89,7 +87,7 @@ public class OpenIdConnectAutoLogin extends BaseAutoLogin {
log.debug("No Liferay user found with openid=" + subject + " and email address=" + email);
if (configuration.createUnexistingUser()) {
log.info("A new user will be created");
user = addUser(companyId, groupId, portalURL, email, given, family, subject);
user = addUser(companyId, groupId, portalURL, email, given, family, subject, username);
} else {
log.info("User will not be created according to configuration");
return null;
@ -124,15 +122,18 @@ public class OpenIdConnectAutoLogin extends BaseAutoLogin {
}
public static User addUser(long companyId, long groupId, String portalURL, String emailAddress, String firstName,
String lastName, String openid) throws SystemException, PortalException {
String lastName, String openid, String username) throws SystemException, PortalException {
Locale locale = LocaleUtil.getMostRelevantLocale();
long creatorUserId = 0;
boolean autoPassword = false;
String password1 = PwdGenerator.getPassword();
String password2 = password1;
boolean autoScreenName = true;
boolean autoScreenName = username == null;
String screenName = StringPool.BLANK;
if (!autoScreenName) {
screenName = username;
}
long facebookId = 0;
String openId = openid;
String middleName = StringPool.BLANK;