|
|
|
@ -41,7 +41,9 @@ import org.wso2.carbon.identity.sso.saml.dto.SAMLSSOServiceProviderDTO;
|
|
|
|
|
import org.wso2.carbon.registry.core.Registry;
|
|
|
|
|
import org.wso2.carbon.utils.multitenancy.MultitenantUtils;
|
|
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
import java.util.Arrays;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Implementation of DynamicClientRegistrationService.
|
|
|
|
@ -60,9 +62,12 @@ public class DynamicClientRegistrationServiceImpl implements DynamicClientRegist
|
|
|
|
|
private static final int STEP_ORDER = 1;
|
|
|
|
|
private static final String OAUTH_VERSION = "OAuth-2.0";
|
|
|
|
|
|
|
|
|
|
private static final String APPLICATION_TYPE_WEBAPP = "webapp";
|
|
|
|
|
private static final String APPLICATION_TYPE_DEVICE = "device";
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public OAuthApplicationInfo registerOAuthApplication(RegistrationProfile profile) throws
|
|
|
|
|
DynamicClientRegistrationException {
|
|
|
|
|
public OAuthApplicationInfo registerOAuthApplication(
|
|
|
|
|
RegistrationProfile profile) throws DynamicClientRegistrationException {
|
|
|
|
|
OAuthApplicationInfo oAuthApplicationInfo = new OAuthApplicationInfo();
|
|
|
|
|
String applicationName = profile.getClientName();
|
|
|
|
|
|
|
|
|
@ -78,9 +83,7 @@ public class DynamicClientRegistrationServiceImpl implements DynamicClientRegist
|
|
|
|
|
OAuthApplicationInfo info;
|
|
|
|
|
try {
|
|
|
|
|
info = this.createOAuthApplication(profile);
|
|
|
|
|
} catch (DynamicClientRegistrationException e) {
|
|
|
|
|
throw new DynamicClientRegistrationException("Can not create OAuth application : " + applicationName, e);
|
|
|
|
|
} catch (IdentityException e) {
|
|
|
|
|
} catch (DynamicClientRegistrationException | IdentityException e) {
|
|
|
|
|
throw new DynamicClientRegistrationException("Can not create OAuth application : " + applicationName, e);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -199,8 +202,7 @@ public class DynamicClientRegistrationServiceImpl implements DynamicClientRegist
|
|
|
|
|
// Set the OAuthApp in InboundAuthenticationConfig
|
|
|
|
|
InboundAuthenticationConfig inboundAuthenticationConfig =
|
|
|
|
|
new InboundAuthenticationConfig();
|
|
|
|
|
InboundAuthenticationRequestConfig[] inboundAuthenticationRequestConfigs = new
|
|
|
|
|
InboundAuthenticationRequestConfig[2];
|
|
|
|
|
List<InboundAuthenticationRequestConfig> inboundAuthenticationRequestConfigs = new ArrayList<>();
|
|
|
|
|
|
|
|
|
|
InboundAuthenticationRequestConfig inboundAuthenticationRequestConfig = new
|
|
|
|
|
InboundAuthenticationRequestConfig();
|
|
|
|
@ -211,19 +213,22 @@ public class DynamicClientRegistrationServiceImpl implements DynamicClientRegist
|
|
|
|
|
Property property = new Property();
|
|
|
|
|
property.setName(OAUTH_CONSUMER_SECRET);
|
|
|
|
|
property.setValue(oauthConsumerSecret);
|
|
|
|
|
Property[] properties = { property };
|
|
|
|
|
Property[] properties = {property};
|
|
|
|
|
inboundAuthenticationRequestConfig.setProperties(properties);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (APPLICATION_TYPE_WEBAPP.equals(profile.getApplicationType())) {
|
|
|
|
|
SAMLSSOServiceProviderDTO samlssoServiceProviderDTO = new SAMLSSOServiceProviderDTO();
|
|
|
|
|
samlssoServiceProviderDTO.setIssuer(MDM);
|
|
|
|
|
samlssoServiceProviderDTO.setIssuer(applicationName);
|
|
|
|
|
|
|
|
|
|
SAMLSSOConfigAdmin configAdmin = new SAMLSSOConfigAdmin(getConfigSystemRegistry());
|
|
|
|
|
configAdmin.addRelyingPartyServiceProvider(samlssoServiceProviderDTO);
|
|
|
|
|
|
|
|
|
|
InboundAuthenticationRequestConfig samlAuthenticationRequest = new InboundAuthenticationRequestConfig();
|
|
|
|
|
samlAuthenticationRequest.setInboundAuthKey(MDM);
|
|
|
|
|
samlAuthenticationRequest.setInboundAuthKey(applicationName);
|
|
|
|
|
samlAuthenticationRequest.setInboundAuthType(SAML_SSO);
|
|
|
|
|
inboundAuthenticationRequestConfigs.add(samlAuthenticationRequest);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
LocalAuthenticatorConfig localAuth = new LocalAuthenticatorConfig();
|
|
|
|
|
localAuth.setName(BASIC_AUTHENTICATOR);
|
|
|
|
@ -235,18 +240,18 @@ public class DynamicClientRegistrationServiceImpl implements DynamicClientRegist
|
|
|
|
|
authStep.setSubjectStep(true);
|
|
|
|
|
authStep.setAttributeStep(true);
|
|
|
|
|
|
|
|
|
|
authStep.setLocalAuthenticatorConfigs(new LocalAuthenticatorConfig[] { localAuth });
|
|
|
|
|
authStep.setLocalAuthenticatorConfigs(new LocalAuthenticatorConfig[]{localAuth});
|
|
|
|
|
|
|
|
|
|
LocalAndOutboundAuthenticationConfig localOutboundAuthConfig = new LocalAndOutboundAuthenticationConfig();
|
|
|
|
|
localOutboundAuthConfig.setAuthenticationType(LOCAL);
|
|
|
|
|
localOutboundAuthConfig.setAuthenticationSteps(new AuthenticationStep[] { authStep });
|
|
|
|
|
localOutboundAuthConfig.setAuthenticationSteps(new AuthenticationStep[]{authStep});
|
|
|
|
|
createdServiceProvider.setLocalAndOutBoundAuthenticationConfig(localOutboundAuthConfig);
|
|
|
|
|
|
|
|
|
|
inboundAuthenticationRequestConfigs[0] = inboundAuthenticationRequestConfig;
|
|
|
|
|
inboundAuthenticationRequestConfigs[1] = samlAuthenticationRequest;
|
|
|
|
|
inboundAuthenticationRequestConfigs.add(inboundAuthenticationRequestConfig);
|
|
|
|
|
inboundAuthenticationConfig
|
|
|
|
|
.setInboundAuthenticationRequestConfigs(inboundAuthenticationRequestConfigs);
|
|
|
|
|
.setInboundAuthenticationRequestConfigs(inboundAuthenticationRequestConfigs.toArray(
|
|
|
|
|
new InboundAuthenticationRequestConfig[inboundAuthenticationRequestConfigs.size()]));
|
|
|
|
|
createdServiceProvider.setInboundAuthenticationConfig(inboundAuthenticationConfig);
|
|
|
|
|
createdServiceProvider.setLocalAndOutBoundAuthenticationConfig(localOutboundAuthConfig);
|
|
|
|
|
|
|
|
|
|
// Update the Service Provider app to add OAuthApp as an Inbound Authentication Config
|
|
|
|
|
appMgtService.updateApplication(createdServiceProvider, tenantDomain, userName);
|
|
|
|
@ -360,7 +365,7 @@ public class DynamicClientRegistrationServiceImpl implements DynamicClientRegist
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private String replaceInvalidChars(String username) {
|
|
|
|
|
return username.replaceAll("@","_AT_");
|
|
|
|
|
return username.replaceAll("@", "_AT_");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|