Skip to content

Commit

Permalink
OKTA-289663: Add IdP Integration Tests (#409)
Browse files Browse the repository at this point in the history
  • Loading branch information
arvindkrishnakumar-okta authored Jun 29, 2020
1 parent d59723e commit 8175213
Show file tree
Hide file tree
Showing 10 changed files with 1,185 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* Copyright 2020-Present Okta, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.okta.sdk.resource.identity.provider;

import com.okta.sdk.client.Client;
import com.okta.sdk.resource.policy.PolicySubjectMatchType;

import java.util.List;

public interface IdentityProviderBuilder<T extends IdentityProviderBuilder> {

T setName(String name);

T setClientId(String clientId);

T setClientSecret(String clientSecret);

T setScopes(List<String> scopes);

T setMaxClockSkew(Integer maxClockSkew);

T setUserName(String userName);

T setMatchType(PolicySubjectMatchType policySubjectMatchType);

T setIsProfileMaster(Boolean isProfileMaster);

T isProfileMaster(Boolean isProfileMaster);

IdentityProvider buildAndCreate(Client client);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* Copyright 2020-Present Okta, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.okta.sdk.resource.identity.provider;

import com.okta.commons.lang.Classes;

public class IdentityProviderBuilders {

public static OIDCIdentityProviderBuilder oidc() {
return Classes.newInstance("com.okta.sdk.impl.resource.identity.provider.DefaultOIDCIdentityProviderBuilder");
}

public static IdentityProviderBuilder google() {
return Classes.newInstance("com.okta.sdk.impl.resource.identity.provider.DefaultGoogleIdentityProviderBuilder");
}

public static IdentityProviderBuilder facebook() {
return Classes.newInstance("com.okta.sdk.impl.resource.identity.provider.DefaultFacebookIdentityProviderBuilder");
}

public static IdentityProviderBuilder microsoft() {
return Classes.newInstance("com.okta.sdk.impl.resource.identity.provider.DefaultMicrosoftIdentityProviderBuilder");
}

public static IdentityProviderBuilder linkedin() {
return Classes.newInstance("com.okta.sdk.impl.resource.identity.provider.DefaultLinkedInIdentityProviderBuilder");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/*
* Copyright 2020-Present Okta, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.okta.sdk.resource.identity.provider;

import com.okta.sdk.resource.policy.PolicySubjectMatchType;

public interface OIDCIdentityProviderBuilder extends IdentityProviderBuilder<OIDCIdentityProviderBuilder> {

OIDCIdentityProviderBuilder setIssuerMode(IdentityProvider.IssuerModeEnum issuerMode);

OIDCIdentityProviderBuilder setRequestSignatureAlgorithm(String requestSignatureAlgorithm);

OIDCIdentityProviderBuilder setRequestSignatureScope(ProtocolAlgorithmTypeSignature.ScopeEnum requestSignatureScope);

OIDCIdentityProviderBuilder setResponseSignatureAlgorithm(String responseSignatureAlgorithm);

OIDCIdentityProviderBuilder setResponseSignatureScope(ProtocolAlgorithmTypeSignature.ScopeEnum responseSignatureScope);

OIDCIdentityProviderBuilder setAcsEndpointBinding(ProtocolEndpoint.BindingEnum acsEndpointBinding);

OIDCIdentityProviderBuilder setAcsEndpointType(ProtocolEndpoint.TypeEnum acsEndpointType);

OIDCIdentityProviderBuilder setAuthorizationEndpointBinding(ProtocolEndpoint.BindingEnum authorizationEndpointBinding);

OIDCIdentityProviderBuilder setAuthorizationEndpointUrl(String authorizationEndpointUrl);

OIDCIdentityProviderBuilder setTokenEndpointBinding(ProtocolEndpoint.BindingEnum tokenEndpointBinding);

OIDCIdentityProviderBuilder setTokenEndpointUrl(String tokenEndpointUrl);

OIDCIdentityProviderBuilder setUserInfoEndpointBinding(ProtocolEndpoint.BindingEnum userInfoEndpointBinding);

OIDCIdentityProviderBuilder setUserInfoEndpointUrl(String userInfoEndpointUrl);

OIDCIdentityProviderBuilder setJwksEndpointBinding(ProtocolEndpoint.BindingEnum jwksEndpointBinding);

OIDCIdentityProviderBuilder setJwksEndpointUrl(String jwksEndpointUrl);

OIDCIdentityProviderBuilder setIssuerUrl(String issuerUrl);

OIDCIdentityProviderBuilder setUserName(String userName);

OIDCIdentityProviderBuilder setMatchType(PolicySubjectMatchType matchType);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
/*
* Copyright 2020-Present Okta, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.okta.sdk.impl.resource.identity.provider;

import com.okta.sdk.client.Client;
import com.okta.sdk.resource.identity.provider.IdentityProvider;
import com.okta.sdk.resource.identity.provider.IdentityProviderCredentials;
import com.okta.sdk.resource.identity.provider.IdentityProviderCredentialsClient;
import com.okta.sdk.resource.identity.provider.Protocol;
import com.okta.sdk.resource.identity.provider.Provisioning;
import com.okta.sdk.resource.identity.provider.ProvisioningConditions;
import com.okta.sdk.resource.identity.provider.ProvisioningDeprovisionedCondition;
import com.okta.sdk.resource.identity.provider.ProvisioningGroups;
import com.okta.sdk.resource.identity.provider.ProvisioningSuspendedCondition;
import com.okta.sdk.resource.policy.IdentityProviderPolicy;
import com.okta.sdk.resource.policy.PolicyAccountLink;
import com.okta.sdk.resource.policy.PolicySubject;
import com.okta.sdk.resource.policy.PolicyUserNameTemplate;

public class DefaultFacebookIdentityProviderBuilder extends DefaultIdentityProviderBuilder {

@Override
public IdentityProvider buildAndCreate(Client client) {

IdentityProvider createdIdp = client.createIdentityProvider(client.instantiate(IdentityProvider.class)
.setType(IdentityProvider.TypeEnum.FACEBOOK)
.setName(name)
.setProtocol(client.instantiate(Protocol.class)
.setType(Protocol.TypeEnum.OAUTH2)
.setScopes(scopes)
.setCredentials(client.instantiate(IdentityProviderCredentials.class)
.setClient(client.instantiate(IdentityProviderCredentialsClient.class)
.setClientId(clientId)
.setClientSecret(clientSecret))))
.setPolicy(client.instantiate(IdentityProviderPolicy.class)
.setProvisioning(client.instantiate(Provisioning.class)
.setAction(Provisioning.ActionEnum.AUTO)
.setProfileMaster(isProfileMaster)
.setGroups(client.instantiate(ProvisioningGroups.class)
.setAction(ProvisioningGroups.ActionEnum.NONE))
.setConditions(client.instantiate(ProvisioningConditions.class)
.setDeprovisioned(client.instantiate(ProvisioningDeprovisionedCondition.class)
.setAction(ProvisioningDeprovisionedCondition.ActionEnum.NONE))
.setSuspended(client.instantiate(ProvisioningSuspendedCondition.class)
.setAction(ProvisioningSuspendedCondition.ActionEnum.NONE))))
.setAccountLink(client.instantiate(PolicyAccountLink.class)
.setFilter(null)
.setAction(PolicyAccountLink.ActionEnum.AUTO))
.setSubject(client.instantiate(PolicySubject.class)
.setUserNameTemplate(client.instantiate(PolicyUserNameTemplate.class)
.setTemplate(userName))
.setMatchType(matchType))
.setMaxClockSkew(maxClockSkew)));

return createdIdp;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
/*
* Copyright 2020-Present Okta, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.okta.sdk.impl.resource.identity.provider;

import com.okta.sdk.client.Client;
import com.okta.sdk.resource.identity.provider.IdentityProvider;
import com.okta.sdk.resource.identity.provider.IdentityProviderCredentials;
import com.okta.sdk.resource.identity.provider.IdentityProviderCredentialsClient;
import com.okta.sdk.resource.identity.provider.Protocol;
import com.okta.sdk.resource.identity.provider.Provisioning;
import com.okta.sdk.resource.identity.provider.ProvisioningConditions;
import com.okta.sdk.resource.identity.provider.ProvisioningDeprovisionedCondition;
import com.okta.sdk.resource.identity.provider.ProvisioningGroups;
import com.okta.sdk.resource.identity.provider.ProvisioningSuspendedCondition;
import com.okta.sdk.resource.policy.IdentityProviderPolicy;
import com.okta.sdk.resource.policy.PolicyAccountLink;
import com.okta.sdk.resource.policy.PolicySubject;
import com.okta.sdk.resource.policy.PolicyUserNameTemplate;

public class DefaultGoogleIdentityProviderBuilder extends DefaultIdentityProviderBuilder {

@Override
public IdentityProvider buildAndCreate(Client client) {

return client.createIdentityProvider(client.instantiate(IdentityProvider.class)
.setType(IdentityProvider.TypeEnum.GOOGLE)
.setName(name)
.setProtocol(client.instantiate(Protocol.class)
.setType(Protocol.TypeEnum.OIDC)
.setScopes(scopes)
.setCredentials(client.instantiate(IdentityProviderCredentials.class)
.setClient(client.instantiate(IdentityProviderCredentialsClient.class)
.setClientId(clientId)
.setClientSecret(clientSecret))))
.setPolicy(client.instantiate(IdentityProviderPolicy.class)
.setProvisioning(client.instantiate(Provisioning.class)
.setAction(Provisioning.ActionEnum.AUTO)
.setProfileMaster(isProfileMaster)
.setGroups(client.instantiate(ProvisioningGroups.class)
.setAction(ProvisioningGroups.ActionEnum.NONE))
.setConditions(client.instantiate(ProvisioningConditions.class)
.setDeprovisioned(client.instantiate(ProvisioningDeprovisionedCondition.class)
.setAction(ProvisioningDeprovisionedCondition.ActionEnum.NONE))
.setSuspended(client.instantiate(ProvisioningSuspendedCondition.class)
.setAction(ProvisioningSuspendedCondition.ActionEnum.NONE))))
.setAccountLink(client.instantiate(PolicyAccountLink.class)
.setFilter(null)
.setAction(PolicyAccountLink.ActionEnum.AUTO))
.setSubject(client.instantiate(PolicySubject.class)
.setUserNameTemplate(client.instantiate(PolicyUserNameTemplate.class)
.setTemplate(userName))
.setMatchType(matchType))
.setMaxClockSkew(maxClockSkew)));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
/*
* Copyright 2020-Present Okta, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.okta.sdk.impl.resource.identity.provider;

import com.okta.sdk.client.Client;
import com.okta.sdk.resource.identity.provider.IdentityProvider;
import com.okta.sdk.resource.identity.provider.IdentityProviderBuilder;
import com.okta.sdk.resource.policy.PolicySubjectMatchType;

import java.util.List;

@SuppressWarnings("rawtypes")
public class DefaultIdentityProviderBuilder<T extends IdentityProviderBuilder> implements IdentityProviderBuilder<T> {

protected String name;
protected String clientId;
protected String clientSecret;
protected List<String> scopes;
protected Integer maxClockSkew;
protected String userName;
protected PolicySubjectMatchType matchType;
protected Boolean isProfileMaster;

@Override
public T setName(String name) {
this.name = name;
return self();
}

@Override
public T setClientId(String clientId) {
this.clientId = clientId;
return self();
}

@Override
public T setClientSecret(String clientSecret) {
this.clientSecret = clientSecret;
return self();
}

@Override
public T setScopes(List<String> scopes) {
this.scopes = scopes;
return self();
}

@Override
public T setMaxClockSkew(Integer maxClockSkew) {
this.maxClockSkew = maxClockSkew;
return self();
}

@Override
public T setUserName(String userName) {
this.userName = userName;
return self();
}

@Override
public T setMatchType(PolicySubjectMatchType matchType) {
this.matchType = matchType;
return self();
}

@Override
public T setIsProfileMaster(Boolean isProfileMaster) {
this.isProfileMaster = isProfileMaster;
return self();
}

@Override
public T isProfileMaster(Boolean isProfileMaster) {
return setIsProfileMaster(isProfileMaster);
}

@Override
public IdentityProvider buildAndCreate(Client client) {
return client.createIdentityProvider(client.instantiate(IdentityProvider.class));
}

@SuppressWarnings("unchecked")
protected T self() {
return (T) this;
}
}
Loading

0 comments on commit 8175213

Please sign in to comment.