119 lines
4.3 KiB
Java
119 lines
4.3 KiB
Java
package com.nubisware.oidc.lr62;
|
|
|
|
import java.util.Collections;
|
|
import java.util.HashMap;
|
|
import java.util.Map;
|
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
|
import com.liferay.portal.kernel.exception.SystemException;
|
|
import com.liferay.portal.kernel.log.Log;
|
|
import com.liferay.portal.kernel.log.LogFactoryUtil;
|
|
import com.liferay.portal.kernel.util.PrefsPropsUtil;
|
|
import com.liferay.portal.security.auth.CompanyThreadLocal;
|
|
import com.liferay.portal.util.PortalUtil;
|
|
import com.nubisware.oidc.rest.OpenIdConnectConfiguration;
|
|
|
|
public class LiferayOpenIdConnectConfiguration implements OpenIdConnectConfiguration {
|
|
|
|
protected static final Log log = LogFactoryUtil.getLog(LiferayOpenIdConnectConfiguration.class);
|
|
|
|
public static Map<Long, LiferayOpenIdConnectConfiguration> companyId2Configuration = Collections
|
|
.synchronizedMap(new HashMap<Long, LiferayOpenIdConnectConfiguration>());
|
|
|
|
private Long companyId;
|
|
private String authorizationUrl;
|
|
private String tokenUrl;
|
|
private String logoutUrl;
|
|
private String issuerUrl;
|
|
private String clientId;
|
|
private String scope;
|
|
private boolean logoutOnPortalLogout;
|
|
private boolean createUnexistingUser;
|
|
|
|
public static synchronized LiferayOpenIdConnectConfiguration getConfiguration(Long companyId) {
|
|
log.trace("Getting config from companyId");
|
|
if (!companyId2Configuration.containsKey(companyId)) {
|
|
companyId2Configuration.put(companyId, new LiferayOpenIdConnectConfiguration(companyId));
|
|
}
|
|
return companyId2Configuration.get(companyId);
|
|
}
|
|
|
|
public static synchronized LiferayOpenIdConnectConfiguration getConfiguration(HttpServletRequest request) {
|
|
log.trace("Getting config from request");
|
|
return LiferayOpenIdConnectConfiguration.getConfiguration(PortalUtil.getCompanyId(request));
|
|
}
|
|
|
|
public static synchronized LiferayOpenIdConnectConfiguration getConfiguration() {
|
|
log.trace("Getting config from thread local");
|
|
return LiferayOpenIdConnectConfiguration.getConfiguration(CompanyThreadLocal.getCompanyId());
|
|
}
|
|
|
|
private LiferayOpenIdConnectConfiguration(Long companyId) {
|
|
log.info("Creating config from companyId: " + companyId);
|
|
this.companyId = companyId;
|
|
try {
|
|
this.authorizationUrl = PrefsPropsUtil.getString(companyId, "d4science.oidc-authorization");
|
|
this.tokenUrl = PrefsPropsUtil.getString(companyId, "d4science.oidc-token");
|
|
this.logoutUrl = PrefsPropsUtil.getString(companyId, "d4science.oidc-logout");
|
|
this.issuerUrl = PrefsPropsUtil.getString(companyId, "d4science.oidc-issuer");
|
|
this.clientId = PrefsPropsUtil.getString(companyId, "d4science.oidc-client-id");
|
|
this.scope = PrefsPropsUtil.getString(companyId, "d4science.oidc-scope");
|
|
this.logoutOnPortalLogout = PrefsPropsUtil.getBoolean(companyId, "d4science.oidc-logout-on-portal-logout");
|
|
this.createUnexistingUser = PrefsPropsUtil.getBoolean(companyId, "d4science.oidc-create-unexisting-user");
|
|
} catch (SystemException e) {
|
|
throw new RuntimeException(e);
|
|
}
|
|
log.info("authorizationUrl=" + getAuthorizationUrl());
|
|
log.info("tokenUrl=" + getTokenUrl());
|
|
log.info("logoutUrl=" + getLogoutUrl());
|
|
log.info("issuerUrl=" + getIssuerUrl());
|
|
log.info("clientId=" + getClientId());
|
|
log.info("scope=" + getScope());
|
|
log.info("logoutOnPortalLogout=" + logoutOnPortalLogout());
|
|
log.info("createUnexistingUser=" + createUnexistingUser());
|
|
}
|
|
|
|
public Long getCompanyId() {
|
|
return companyId;
|
|
}
|
|
|
|
@Override
|
|
public String getAuthorizationUrl() {
|
|
return this.authorizationUrl;
|
|
}
|
|
|
|
@Override
|
|
public String getTokenUrl() {
|
|
return this.tokenUrl;
|
|
}
|
|
|
|
@Override
|
|
public String getLogoutUrl() {
|
|
return this.logoutUrl;
|
|
}
|
|
|
|
@Override
|
|
public String getIssuerUrl() {
|
|
return this.issuerUrl;
|
|
}
|
|
|
|
@Override
|
|
public String getClientId() {
|
|
return this.clientId;
|
|
}
|
|
|
|
@Override
|
|
public String getScope() {
|
|
return this.scope;
|
|
}
|
|
|
|
public boolean logoutOnPortalLogout() {
|
|
return this.logoutOnPortalLogout;
|
|
}
|
|
|
|
public boolean createUnexistingUser() {
|
|
return this.createUnexistingUser;
|
|
}
|
|
}
|