Skip to content

Commit

Permalink
Fixed problem with retrieving the configuration: Instance first and t…
Browse files Browse the repository at this point in the history
…hen System if it doesn't exist
  • Loading branch information
kgolebiowski committed Jan 10, 2025
1 parent 86379e4 commit 38b36f7
Show file tree
Hide file tree
Showing 4 changed files with 350 additions and 379 deletions.
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
/**
* Copyright (c) 2000-present Liferay, Inc. All rights reserved.
*
* <p>
* This library is free software; you can redistribute it and/or modify it under
* the terms of the GNU Lesser General Public License as published by the Free
* Software Foundation; either version 2.1 of the License, or (at your option)
* any later version.
*
* <p>
* This library is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
Expand All @@ -29,63 +29,66 @@
*
* @author Michael C. Han
*/
@ExtendedObjectClassDefinition(category = "sso")
@ExtendedObjectClassDefinition(
scope = ExtendedObjectClassDefinition.Scope.COMPANY,
category = "sso"
)
@Meta.OCD(
id = "com.liferay.portal.security.sso.cas.configuration.CASConfiguration",
localization = "content/Language", name = "cas-configuration-name"
id = "com.liferay.portal.security.sso.cas.configuration.CASConfiguration",
localization = "content/Language", name = "cas-configuration-name"
)
public interface CASConfiguration {

@Meta.AD(
deflt = "false", description = "enabled-help[cas]", name = "enabled",
required = false
)
public boolean enabled();
@Meta.AD(
deflt = "false", description = "enabled-help[cas]", name = "enabled",
required = false
)
public boolean enabled();

@Meta.AD(
deflt = "false",
description = "a-user-may-be-authenticated-by-cas-and-not-yet-exist-in-the-portal",
name = "import-from-ldap", required = false
)
public boolean importFromLDAP();
@Meta.AD(
deflt = "false",
description = "a-user-may-be-authenticated-by-cas-and-not-yet-exist-in-the-portal",
name = "import-from-ldap", required = false
)
public boolean importFromLDAP();

@Meta.AD(
deflt = "https://localhost:8443/cas-web/login", name = "login-url",
required = false
)
public String loginURL();
@Meta.AD(
deflt = "https://localhost:8443/cas-web/login", name = "login-url",
required = false
)
public String loginURL();

@Meta.AD(
deflt = "false", description = "logout-on-session-expiration-help",
name = "logout-on-session-expiration", required = false
)
public boolean logoutOnSessionExpiration();
@Meta.AD(
deflt = "false", description = "logout-on-session-expiration-help",
name = "logout-on-session-expiration", required = false
)
public boolean logoutOnSessionExpiration();

@Meta.AD(
deflt = "https://localhost:8443/cas-web/logout", name = "logout-url",
required = false
)
public String logoutURL();
@Meta.AD(
deflt = "https://localhost:8443/cas-web/logout", name = "logout-url",
required = false
)
public String logoutURL();

@Meta.AD(
deflt = "http://localhost:8080", description = "server-name-help",
name = "server-name", required = false
)
public String serverName();
@Meta.AD(
deflt = "http://localhost:8080", description = "server-name-help",
name = "server-name", required = false
)
public String serverName();

@Meta.AD(
deflt = "https://localhost:8443/cas-web", name = "server-url",
required = false
)
public String serverURL();
@Meta.AD(
deflt = "https://localhost:8443/cas-web", name = "server-url",
required = false
)
public String serverURL();

@Meta.AD(name = "service-url", required = false)
public String serviceURL();
@Meta.AD(name = "service-url", required = false)
public String serviceURL();

@Meta.AD(
deflt = "http://localhost:8080", name = "no-such-user-redirect-url",
required = false
)
public String noSuchUserRedirectURL();
@Meta.AD(
deflt = "http://localhost:8080", name = "no-such-user-redirect-url",
required = false
)
public String noSuchUserRedirectURL();

}
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
/**
* Copyright (c) 2000-present Liferay, Inc. All rights reserved.
*
* <p>
* This library is free software; you can redistribute it and/or modify it under
* the terms of the GNU Lesser General Public License as published by the Free
* Software Foundation; either version 2.1 of the License, or (at your option)
* any later version.
*
* <p>
* This library is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
Expand All @@ -19,10 +19,7 @@
import com.liferay.portal.kernel.log.LogFactoryUtil;
import com.liferay.portal.kernel.module.configuration.ConfigurationException;
import com.liferay.portal.kernel.security.sso.SSO;
import com.liferay.portal.kernel.settings.CompanyServiceSettingsLocator;
import com.liferay.portal.security.sso.cas.configuration.CASConfiguration;
import com.liferay.portal.security.sso.cas.constants.CASConstants;

import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.Reference;

Expand All @@ -33,74 +30,71 @@
* @author Michael C. Han
*/
@Component(
configurationPid = "com.liferay.portal.security.sso.cas.configuration.CASConfiguration",
immediate = true, service = SSO.class
configurationPid = "com.liferay.portal.security.sso.cas.configuration.CASConfiguration",
immediate = true, service = SSO.class
)
public class SSOImpl implements SSO {

@Override
public String getSessionExpirationRedirectUrl(long companyId) {
CASConfiguration casConfiguration = _getCASConfiguration(companyId);
@Override
public String getSessionExpirationRedirectUrl(long companyId) {
CASConfiguration casConfiguration = _getCASConfiguration(companyId);

if (casConfiguration.logoutOnSessionExpiration()) {
return casConfiguration.logoutURL();
}
if (casConfiguration.logoutOnSessionExpiration()) {
return casConfiguration.logoutURL();
}

return null;
}
return null;
}

@Override
public String getSignInURL(long companyId, String defaultSigninURL) {
return defaultSigninURL;
}
@Override
public String getSignInURL(long companyId, String defaultSigninURL) {
return defaultSigninURL;
}

@Override
public boolean isLoginRedirectRequired(long companyId) {
return _isCASAuthEnabled(companyId);
}
@Override
public boolean isLoginRedirectRequired(long companyId) {
return _isCASAuthEnabled(companyId);
}

@Override
public boolean isRedirectRequired(long companyId) {
return _isCASAuthEnabled(companyId);
}
@Override
public boolean isRedirectRequired(long companyId) {
return _isCASAuthEnabled(companyId);
}

@Override
public boolean isSessionRedirectOnExpire(long companyId) {
CASConfiguration casConfiguration = _getCASConfiguration(companyId);
@Override
public boolean isSessionRedirectOnExpire(long companyId) {
CASConfiguration casConfiguration = _getCASConfiguration(companyId);

return casConfiguration.logoutOnSessionExpiration();
}
return casConfiguration.logoutOnSessionExpiration();
}

@Reference(unbind = "-")
protected void setConfigurationProvider(
ConfigurationProvider configurationProvider) {
@Reference(unbind = "-")
protected void setConfigurationProvider(
ConfigurationProvider configurationProvider) {

_configurationProvider = configurationProvider;
}
_configurationProvider = configurationProvider;
}

private CASConfiguration _getCASConfiguration(long companyId) {
try {
return _configurationProvider.getConfiguration(
CASConfiguration.class,
new CompanyServiceSettingsLocator(
companyId, CASConstants.SERVICE_NAME));
}
catch (ConfigurationException configurationException) {
_log.error(
"Unable to get CAS configuration", configurationException);
}
private CASConfiguration _getCASConfiguration(long companyId) {
try {
return _configurationProvider.getCompanyConfiguration(
CASConfiguration.class, companyId);
} catch (ConfigurationException configurationException) {
_log.error(
"Unable to get CAS configuration", configurationException);
}

return null;
}
return null;
}

private boolean _isCASAuthEnabled(long companyId) {
CASConfiguration casConfiguration = _getCASConfiguration(companyId);
private boolean _isCASAuthEnabled(long companyId) {
CASConfiguration casConfiguration = _getCASConfiguration(companyId);

return casConfiguration.enabled();
}
return casConfiguration.enabled();
}

private static final Log _log = LogFactoryUtil.getLog(SSOImpl.class);
private static final Log _log = LogFactoryUtil.getLog(SSOImpl.class);

private ConfigurationProvider _configurationProvider;
private ConfigurationProvider _configurationProvider;

}
Loading

0 comments on commit 38b36f7

Please sign in to comment.