Skip to content
This repository has been archived by the owner on Oct 5, 2021. It is now read-only.

Commit

Permalink
Merge pull request #767 from thanujalk/master
Browse files Browse the repository at this point in the history
Using IdentityUtil  to get the server URL
  • Loading branch information
hasinthaindrajee committed Aug 7, 2015
2 parents 66a9898 + d806f7a commit 5b6523d
Show file tree
Hide file tree
Showing 9 changed files with 34 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import org.apache.axis2.engine.AxisConfiguration;
import org.apache.commons.codec.binary.Hex;
import org.apache.commons.io.Charsets;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.xerces.impl.Constants;
Expand Down Expand Up @@ -273,7 +274,7 @@ public static String getIdentityConfigDirPath() {
return CarbonUtils.getCarbonConfigDirPath() + File.separator + "identity";
}

public static String getServerURL() throws IdentityRuntimeException {
public static String getServerURL(String endpoint) throws IdentityRuntimeException {
String hostName = ServerConfiguration.getInstance().getFirstProperty(IdentityCoreConstants.HOST_NAME);

try {
Expand Down Expand Up @@ -306,6 +307,13 @@ public static String getServerURL() throws IdentityRuntimeException {
}
}

if(StringUtils.isNotBlank(endpoint)) {
if(!endpoint.startsWith("/")) {
serverUrl += "/";
}
serverUrl += endpoint;
}

return serverUrl;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ public IdentityProvider getResidentIdP(String tenantDomain)
tenantContext = MultitenantConstants.TENANT_AWARE_URL_PREFIX + "/" + tenantDomain + "/";
}

String serverUrl = IdentityUtil.getServerURL() + "/";
String serverUrl = IdentityUtil.getServerURL("") + "/";

String openIdUrl = null;
String samlSSOUrl = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -600,47 +600,47 @@ public static class OAuthURL {
public static String getOAuth1RequestTokenUrl() {
String oauth1RequestTokenUrl = OAuthServerConfiguration.getInstance().getOAuth1RequestTokenUrl();
if(StringUtils.isBlank(oauth1RequestTokenUrl)){
oauth1RequestTokenUrl = IdentityUtil.getServerURL() + "/oauth/request-token";
oauth1RequestTokenUrl = IdentityUtil.getServerURL("oauth/request-token");
}
return oauth1RequestTokenUrl;
}

public static String getOAuth1AuthorizeUrl() {
String oauth1AuthorizeUrl = OAuthServerConfiguration.getInstance().getOAuth1AuthorizeUrl();
if(StringUtils.isBlank(oauth1AuthorizeUrl)){
oauth1AuthorizeUrl = IdentityUtil.getServerURL() + "/oauth/authorize-url";
oauth1AuthorizeUrl = IdentityUtil.getServerURL("oauth/authorize-url");
}
return oauth1AuthorizeUrl;
}

public static String getOAuth1AccessTokenUrl() {
String oauth1AccessTokenUrl = OAuthServerConfiguration.getInstance().getOAuth1AccessTokenUrl();
if(StringUtils.isBlank(oauth1AccessTokenUrl)){
oauth1AccessTokenUrl = IdentityUtil.getServerURL() + "/oauth/access-token";
oauth1AccessTokenUrl = IdentityUtil.getServerURL("oauth/access-token");
}
return oauth1AccessTokenUrl;
}

public static String getOAuth2AuthzEPUrl() {
String oauth2AuthzEPUrl = OAuthServerConfiguration.getInstance().getOAuth2AuthzEPUrl();
if(StringUtils.isBlank(oauth2AuthzEPUrl)){
oauth2AuthzEPUrl = IdentityUtil.getServerURL() + "/oauth2/authorize";
oauth2AuthzEPUrl = IdentityUtil.getServerURL("oauth2/authorize");
}
return oauth2AuthzEPUrl;
}

public static String getOAuth2TokenEPUrl() {
String oauth2TokenEPUrl = OAuthServerConfiguration.getInstance().getOAuth2TokenEPUrl();
if(StringUtils.isBlank(oauth2TokenEPUrl)){
oauth2TokenEPUrl = IdentityUtil.getServerURL() + "/oauth2/token";
oauth2TokenEPUrl = IdentityUtil.getServerURL("oauth2/token");
}
return oauth2TokenEPUrl;
}

public static String getOAuth2UserInfoEPUrl() {
String oauth2UserInfoEPUrl = OAuthServerConfiguration.getInstance().getOauth2UserInfoEPUrl();
if(StringUtils.isBlank(oauth2UserInfoEPUrl)){
oauth2UserInfoEPUrl = IdentityUtil.getServerURL() + "/oauth2/userinfo";
oauth2UserInfoEPUrl = IdentityUtil.getServerURL("oauth2/userinfo");
}
return oauth2UserInfoEPUrl;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ public static String getOpenIDServerURL() {
String openIDServerURL = IdentityUtil.getProperty(IdentityConstants.ServerConfig.OPENID_SERVER_URL);
// If configuration are not defined, build URL from server configurations.
if (StringUtils.isBlank(openIDServerURL)) {
openIDServerURL = IdentityUtil.getServerURL() + "/" + OpenIDServerConstants.OPENID_SERVER;
openIDServerURL = IdentityUtil.getServerURL(OpenIDServerConstants.OPENID_SERVER);
}
return openIDServerURL;
}
Expand All @@ -226,7 +226,7 @@ public static String getOpenIDUserPattern() {
String openIDUserPattern = IdentityUtil.getProperty(IdentityConstants.ServerConfig.OPENID_USER_PATTERN);
// If configuration are not defined, build URL from server configurations.
if (StringUtils.isBlank(openIDUserPattern)) {
openIDUserPattern = IdentityUtil.getServerURL() + "/" + OpenIDServerConstants.OPENID;
openIDUserPattern = IdentityUtil.getServerURL(OpenIDServerConstants.OPENID);
}
return openIDUserPattern;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ public class SAMLSSOConstants {
public static final String CLAIM_DIALECT_URL = "http://wso2.org/claims";
public static final String SAML_ENDPOINT = "samlsso/carbon/";
public static final String DEFAULT_LOGOUT_LOCATION = "authenticationendpoint/samlsso_logout.do";
public static final String SAMLSSO_URL = "/samlsso";

private SAMLSSOConstants() {
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import org.wso2.carbon.identity.authenticator.saml2.sso.common.Util;
import org.wso2.carbon.identity.base.IdentityConstants;
import org.wso2.carbon.identity.core.util.IdentityUtil;
import org.wso2.carbon.identity.sso.saml.SAMLSSOConstants;
import org.wso2.carbon.identity.sso.saml.SSOServiceProviderConfigManager;
import org.wso2.carbon.identity.sso.saml.admin.FileBasedConfigManager;
import org.wso2.carbon.identity.sso.saml.servlet.SAMLSSOProviderServlet;
Expand Down Expand Up @@ -60,7 +61,6 @@
*/
public class IdentitySAMLSSOServiceComponent {

public static final String SAMLSSO_URL = "/samlsso";
private static Log log = LogFactory.getLog(IdentitySAMLSSOServiceComponent.class);
private static int defaultSingleLogoutRetryCount = 5;

Expand All @@ -77,9 +77,10 @@ protected void activate(ComponentContext ctxt) {
HttpService httpService = SAMLSSOUtil.getHttpService();

// Register SAML SSO servlet
Servlet samlSSOServlet = new ContextPathServletAdaptor(new SAMLSSOProviderServlet(), SAMLSSO_URL);
Servlet samlSSOServlet = new ContextPathServletAdaptor(new SAMLSSOProviderServlet(),
SAMLSSOConstants.SAMLSSO_URL);
try {
httpService.registerServlet(SAMLSSO_URL, samlSSOServlet, null, null);
httpService.registerServlet(SAMLSSOConstants.SAMLSSO_URL, samlSSOServlet, null, null);
} catch (Exception e) {
String errMsg = "Error when registering SAML SSO Servlet via the HttpService.";
log.error(errMsg, e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,9 @@ public SAMLSSOReqValidationResponseDTO process(LogoutRequest logoutRequest, Stri

// Validate 'Destination'
String idpUrl = IdentityUtil.getProperty(IdentityConstants.ServerConfig.SSO_IDP_URL);
if(StringUtils.isBlank(idpUrl)) {
idpUrl = IdentityUtil.getServerURL(SAMLSSOConstants.SAMLSSO_URL);
}

if (logoutRequest.getDestination() == null ||
!idpUrl.equals(logoutRequest.getDestination())) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,9 @@ public SAMLSSORespDTO process(SAMLSSOAuthnReqDTO authnReqDTO, String sessionId,

// Validate 'Destination'
String idpUrl = IdentityUtil.getProperty(IdentityConstants.ServerConfig.SSO_IDP_URL);
if(StringUtils.isBlank(idpUrl)) {
idpUrl = IdentityUtil.getServerURL(SAMLSSOConstants.SAMLSSO_URL);
}

if (authnReqDTO.getDestination() == null
|| !idpUrl.equals(authnReqDTO.getDestination())) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package org.wso2.carbon.identity.tools.saml.validator.processors;

import org.apache.commons.lang.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.opensaml.common.SAMLVersion;
Expand All @@ -28,6 +29,7 @@
import org.wso2.carbon.identity.base.IdentityException;
import org.wso2.carbon.identity.core.model.SAMLSSOServiceProviderDO;
import org.wso2.carbon.identity.core.util.IdentityUtil;
import org.wso2.carbon.identity.sso.saml.SAMLSSOConstants;
import org.wso2.carbon.identity.sso.saml.util.SAMLSSOUtil;
import org.wso2.carbon.identity.tools.saml.validator.dto.ValidatedItemDTO;
import org.wso2.carbon.identity.tools.saml.validator.util.SAMLValidatorConstants;
Expand Down Expand Up @@ -175,6 +177,9 @@ public void validate(List<ValidatedItemDTO> validatedItems) throws IdentityExcep

// Validate Destination
String idPUrl = IdentityUtil.getProperty(IdentityConstants.ServerConfig.SSO_IDP_URL);
if(StringUtils.isBlank(idPUrl)) {
idPUrl = IdentityUtil.getServerURL(SAMLSSOConstants.SAMLSSO_URL);
}

if (authnRequest.getDestination() != null &&
idPUrl.equals(authnRequest.getDestination())) {
Expand Down

0 comments on commit 5b6523d

Please sign in to comment.