|
|
@ -23,17 +23,17 @@ import org.apache.commons.collections.iterators.IteratorEnumeration;
|
|
|
|
import org.apache.commons.logging.Log;
|
|
|
|
import org.apache.commons.logging.Log;
|
|
|
|
import org.apache.commons.logging.LogFactory;
|
|
|
|
import org.apache.commons.logging.LogFactory;
|
|
|
|
import org.wso2.carbon.dynamic.client.registration.DynamicClientRegistrationException;
|
|
|
|
import org.wso2.carbon.dynamic.client.registration.DynamicClientRegistrationException;
|
|
|
|
import org.wso2.carbon.dynamic.client.registration.DynamicClientRegistrationService;
|
|
|
|
|
|
|
|
import org.wso2.carbon.dynamic.client.registration.OAuthApplicationInfo;
|
|
|
|
import org.wso2.carbon.dynamic.client.registration.OAuthApplicationInfo;
|
|
|
|
import org.wso2.carbon.dynamic.client.registration.profile.RegistrationProfile;
|
|
|
|
import org.wso2.carbon.dynamic.client.registration.profile.RegistrationProfile;
|
|
|
|
import org.wso2.carbon.dynamic.client.web.app.registration.dto.OAuthAppDetails;
|
|
|
|
|
|
|
|
import org.wso2.carbon.dynamic.client.web.app.registration.dto.JaggeryOAuthConfigurationSettings;
|
|
|
|
import org.wso2.carbon.dynamic.client.web.app.registration.dto.JaggeryOAuthConfigurationSettings;
|
|
|
|
import org.wso2.carbon.dynamic.client.web.app.registration.internal.DynamicClientWebAppRegistrationDataHolder;
|
|
|
|
import org.wso2.carbon.dynamic.client.web.app.registration.dto.OAuthAppDetails;
|
|
|
|
import org.wso2.carbon.dynamic.client.web.app.registration.util.DynamicClientWebAppRegistrationConstants;
|
|
|
|
import org.wso2.carbon.dynamic.client.web.app.registration.util.DynamicClientWebAppRegistrationConstants;
|
|
|
|
import org.wso2.carbon.dynamic.client.web.app.registration.util.DynamicClientWebAppRegistrationUtil;
|
|
|
|
import org.wso2.carbon.dynamic.client.web.app.registration.util.DynamicClientWebAppRegistrationUtil;
|
|
|
|
|
|
|
|
|
|
|
|
import javax.servlet.ServletContext;
|
|
|
|
import javax.servlet.ServletContext;
|
|
|
|
import java.util.*;
|
|
|
|
import java.util.Enumeration;
|
|
|
|
|
|
|
|
import java.util.HashMap;
|
|
|
|
|
|
|
|
import java.util.Map;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* This class contains the logic to handle the OAuth application creation process.
|
|
|
|
* This class contains the logic to handle the OAuth application creation process.
|
|
|
@ -77,13 +77,13 @@ public class DynamicClientWebAppRegistrationManager {
|
|
|
|
return oAuthAppDetails;
|
|
|
|
return oAuthAppDetails;
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
DynamicClientWebAppRegistrationUtil.unregisterOAuthApplication(registrationProfile.getOwner(),
|
|
|
|
DynamicClientWebAppRegistrationUtil.unregisterOAuthApplication(registrationProfile.getOwner(),
|
|
|
|
oAuthApplicationInfo.getClientName(),
|
|
|
|
oAuthApplicationInfo.getClientName(),
|
|
|
|
oAuthApplicationInfo.getClientId());
|
|
|
|
oAuthApplicationInfo.getClientId());
|
|
|
|
log.warn("Error occurred while persisting the OAuth application data in registry.");
|
|
|
|
log.warn("Error occurred while persisting the OAuth application data in registry.");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} catch (DynamicClientRegistrationException e) {
|
|
|
|
} catch (DynamicClientRegistrationException e) {
|
|
|
|
log.error("Error occurred while registering the OAuth application : " +
|
|
|
|
log.error("Error occurred while registering the OAuth application : " +
|
|
|
|
registrationProfile.getClientName(), e);
|
|
|
|
registrationProfile.getClientName(), e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
return null;
|
|
|
@ -94,7 +94,7 @@ public class DynamicClientWebAppRegistrationManager {
|
|
|
|
return DynamicClientWebAppRegistrationUtil.getOAuthApplicationData(clientName);
|
|
|
|
return DynamicClientWebAppRegistrationUtil.getOAuthApplicationData(clientName);
|
|
|
|
} catch (DynamicClientRegistrationException e) {
|
|
|
|
} catch (DynamicClientRegistrationException e) {
|
|
|
|
log.error("Error occurred while fetching the OAuth application data for web app : " +
|
|
|
|
log.error("Error occurred while fetching the OAuth application data for web app : " +
|
|
|
|
clientName, e);
|
|
|
|
clientName, e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -102,7 +102,7 @@ public class DynamicClientWebAppRegistrationManager {
|
|
|
|
public boolean isRegisteredOAuthApplication(String clientName) {
|
|
|
|
public boolean isRegisteredOAuthApplication(String clientName) {
|
|
|
|
OAuthAppDetails oAuthAppDetails = this.getOAuthApplicationData(clientName);
|
|
|
|
OAuthAppDetails oAuthAppDetails = this.getOAuthApplicationData(clientName);
|
|
|
|
if (oAuthAppDetails != null && (oAuthAppDetails.getClientKey() != null && oAuthAppDetails.getClientSecret() !=
|
|
|
|
if (oAuthAppDetails != null && (oAuthAppDetails.getClientKey() != null && oAuthAppDetails.getClientSecret() !=
|
|
|
|
null)) {
|
|
|
|
null)) {
|
|
|
|
return true;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
return false;
|
|
|
@ -110,7 +110,7 @@ public class DynamicClientWebAppRegistrationManager {
|
|
|
|
|
|
|
|
|
|
|
|
public void saveServletContextToCache(StandardContext context) {
|
|
|
|
public void saveServletContextToCache(StandardContext context) {
|
|
|
|
DynamicClientWebAppRegistrationManager.webAppContexts.put(context.getBaseName(),
|
|
|
|
DynamicClientWebAppRegistrationManager.webAppContexts.put(context.getBaseName(),
|
|
|
|
context.getServletContext());
|
|
|
|
context.getServletContext());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void initiateDynamicClientRegistration() {
|
|
|
|
public void initiateDynamicClientRegistration() {
|
|
|
@ -129,7 +129,7 @@ public class DynamicClientWebAppRegistrationManager {
|
|
|
|
oAuthAppDetails = new OAuthAppDetails();
|
|
|
|
oAuthAppDetails = new OAuthAppDetails();
|
|
|
|
webAppName = (String) enumeration.nextElement();
|
|
|
|
webAppName = (String) enumeration.nextElement();
|
|
|
|
serviceProviderName = DynamicClientWebAppRegistrationUtil.replaceInvalidChars(DynamicClientWebAppRegistrationUtil.getUserName())
|
|
|
|
serviceProviderName = DynamicClientWebAppRegistrationUtil.replaceInvalidChars(DynamicClientWebAppRegistrationUtil.getUserName())
|
|
|
|
+ "_" + webAppName;
|
|
|
|
+ "_" + webAppName;
|
|
|
|
servletContext = DynamicClientWebAppRegistrationManager.webAppContexts.get(webAppName);
|
|
|
|
servletContext = DynamicClientWebAppRegistrationManager.webAppContexts.get(webAppName);
|
|
|
|
requiredDynamicClientRegistration = servletContext.getInitParameter(
|
|
|
|
requiredDynamicClientRegistration = servletContext.getInitParameter(
|
|
|
|
DynamicClientWebAppRegistrationConstants.DYNAMIC_CLIENT_REQUIRED_FLAG);
|
|
|
|
DynamicClientWebAppRegistrationConstants.DYNAMIC_CLIENT_REQUIRED_FLAG);
|
|
|
@ -140,7 +140,7 @@ public class DynamicClientWebAppRegistrationManager {
|
|
|
|
if (!dynamicClientWebAppRegistrationManager.isRegisteredOAuthApplication(serviceProviderName)) {
|
|
|
|
if (!dynamicClientWebAppRegistrationManager.isRegisteredOAuthApplication(serviceProviderName)) {
|
|
|
|
//Construct the RegistrationProfile
|
|
|
|
//Construct the RegistrationProfile
|
|
|
|
registrationProfile = DynamicClientWebAppRegistrationUtil.
|
|
|
|
registrationProfile = DynamicClientWebAppRegistrationUtil.
|
|
|
|
constructRegistrationProfile(servletContext, webAppName);
|
|
|
|
constructRegistrationProfile(servletContext, webAppName);
|
|
|
|
//Register the OAuth application
|
|
|
|
//Register the OAuth application
|
|
|
|
oAuthAppDetails =
|
|
|
|
oAuthAppDetails =
|
|
|
|
dynamicClientWebAppRegistrationManager.registerOAuthApplication(registrationProfile);
|
|
|
|
dynamicClientWebAppRegistrationManager.registerOAuthApplication(registrationProfile);
|
|
|
@ -155,21 +155,24 @@ public class DynamicClientWebAppRegistrationManager {
|
|
|
|
if (jaggeryOAuthConfigurationSettings.isRequireDynamicClientRegistration()) {
|
|
|
|
if (jaggeryOAuthConfigurationSettings.isRequireDynamicClientRegistration()) {
|
|
|
|
if (!dynamicClientWebAppRegistrationManager.isRegisteredOAuthApplication(serviceProviderName)) {
|
|
|
|
if (!dynamicClientWebAppRegistrationManager.isRegisteredOAuthApplication(serviceProviderName)) {
|
|
|
|
registrationProfile = DynamicClientWebAppRegistrationUtil.
|
|
|
|
registrationProfile = DynamicClientWebAppRegistrationUtil.
|
|
|
|
constructRegistrationProfile(jaggeryOAuthConfigurationSettings,
|
|
|
|
constructRegistrationProfile(jaggeryOAuthConfigurationSettings,
|
|
|
|
webAppName);
|
|
|
|
webAppName);
|
|
|
|
oAuthAppDetails = dynamicClientWebAppRegistrationManager.
|
|
|
|
oAuthAppDetails = dynamicClientWebAppRegistrationManager.
|
|
|
|
registerOAuthApplication(registrationProfile);
|
|
|
|
registerOAuthApplication(registrationProfile);
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
oAuthAppDetails = dynamicClientWebAppRegistrationManager.getOAuthApplicationData(webAppName);
|
|
|
|
oAuthAppDetails = dynamicClientWebAppRegistrationManager.getOAuthApplicationData(webAppName);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
//Add client credentials to the web-context
|
|
|
|
//Add client credentials to the web-context
|
|
|
|
if ((oAuthAppDetails != null && oAuthAppDetails.getClientKey() != null) && !oAuthAppDetails.getClientKey().isEmpty()) {
|
|
|
|
if ((oAuthAppDetails != null && oAuthAppDetails.getClientKey() != null) &&
|
|
|
|
|
|
|
|
!oAuthAppDetails.getClientKey().isEmpty()) {
|
|
|
|
DynamicClientWebAppRegistrationUtil.addClientCredentialsToWebContext(oAuthAppDetails,
|
|
|
|
DynamicClientWebAppRegistrationUtil.addClientCredentialsToWebContext(oAuthAppDetails,
|
|
|
|
servletContext);
|
|
|
|
servletContext);
|
|
|
|
log.info("Added OAuth application credentials to webapp context of webapp : " +
|
|
|
|
if (log.isDebugEnabled()) {
|
|
|
|
webAppName);
|
|
|
|
log.debug("Added OAuth application credentials to webapp context of webapp : " +
|
|
|
|
|
|
|
|
webAppName);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|