Skip to content

Commit

Permalink
Added an extendable ApplicationBuilder and created OIdCApplicationBui…
Browse files Browse the repository at this point in the history
…lder. (#360)

* Created builder for OpenIdConnectApplication.

* Created builder for OpenIdConnectApplication.

* Fixing pmd/findbug failures.

* Created builder for OpenIdConnectApplication.

* Created builder for OpenIdConnectApplication.

* Fixing pmd/findbug failures.

* Fixing license check failures (that were missed).

* Update ApplicationBuilder.java

* Update OIdCApplicationBuilder.java

* Update DefaultApplicationBuilder.java

* Update DefaultOIdCApplicationBuilder.java

* Update DefaultApplicationBuilderTest.groovy

* Update DefaultOIdcApplicationBuilderTest.groovy

* Update OIdCApplicationIT.groovy

Co-authored-by: Jeyadev Asokan <jeyadev_asokan@baxter.com>
Co-authored-by: Arvind Krishnakumar <61501885+arvindkrishnakumar-okta@users.noreply.github.com>
  • Loading branch information
3 people authored Jun 30, 2020
1 parent 83edb78 commit bd43772
Show file tree
Hide file tree
Showing 7 changed files with 814 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
* 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.application;

import com.okta.commons.lang.Classes;
import com.okta.sdk.client.Client;

public interface ApplicationBuilder<T extends ApplicationBuilder> {
static ApplicationBuilder<ApplicationBuilder> instance() {
return Classes.newInstance("com.okta.sdk.impl.resource.DefaultApplicationBuilder");
}

T setName(String name);

T setLabel(String label);

T setErrorRedirectUrl(String errorRedirectUrl);

T setLoginRedirectUrl(String loginRedirectUrl);

T setSelfService(Boolean selfService);

T setSignOnMode(ApplicationSignOnMode signOnMode);

T setIOS(Boolean iOS);

T setWeb(Boolean web);

Application buildAndCreate(Client client);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/*
* 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.application;

import com.okta.commons.lang.Classes;

import java.util.List;

public interface OIdCApplicationBuilder extends ApplicationBuilder<OIdCApplicationBuilder> {

static OIdCApplicationBuilder instance() {
return Classes.newInstance("com.okta.sdk.impl.resource.DefaultOIdCApplicationBuilder");
}

OIdCApplicationBuilder setApplicationType(OpenIdConnectApplicationType applicationType);

OIdCApplicationBuilder setClientUri(String clientUri);

OIdCApplicationBuilder setConsentMethod(OpenIdConnectApplicationConsentMethod consentMethod);

OIdCApplicationBuilder setGrantTypes(List<OAuthGrantType> grantTypes);

OIdCApplicationBuilder addGrantTypes(OAuthGrantType grantType);

OIdCApplicationBuilder setLogoUri(String logoUri);

OIdCApplicationBuilder setPolicyUri(String policyUri);

OIdCApplicationBuilder setRedirectUris(List<String> redirectUris);

OIdCApplicationBuilder addRedirectUris(String redirectUri);

OIdCApplicationBuilder setResponseTypes(List<OAuthResponseType> responseTypes);

OIdCApplicationBuilder addResponseTypes(OAuthResponseType responseType);

OIdCApplicationBuilder setTosUri(String tosUri);

OIdCApplicationBuilder setClientId(String clientId);

OIdCApplicationBuilder setClientSecret(String clientSecret);

OIdCApplicationBuilder setAutoKeyRotation(Boolean autoKeyRotation);

OIdCApplicationBuilder setTokenEndpointAuthMethod(OAuthEndpointAuthenticationMethod tokenEndpointAuthMethod);


}
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
/*
* 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;

import com.okta.commons.lang.Strings;
import com.okta.sdk.client.Client;
import com.okta.sdk.resource.application.*;

import java.util.Objects;

public class DefaultApplicationBuilder<T extends ApplicationBuilder> implements ApplicationBuilder<T> {

protected String name;
protected String label;
protected String errorRedirectUrl;
protected String loginRedirectUrl;
protected Boolean selfService;
protected ApplicationSignOnMode signOnMode;
protected Boolean iOS;
protected Boolean web;


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

@Override
public T setLabel(String label) {
this.label = label;
return self();
}

@Override
public T setErrorRedirectUrl(String errorRedirectUrl) {
this.errorRedirectUrl = errorRedirectUrl;
return self();
}

@Override
public T setLoginRedirectUrl(String loginRedirectUrl) {
this.loginRedirectUrl = loginRedirectUrl;
return self();
}

@Override
public T setSelfService(Boolean selfService) {
this.selfService = selfService;
return self();
}

@Override
public T setSignOnMode(ApplicationSignOnMode signOnMode) {
this.signOnMode = signOnMode;
return self();
}

@Override
public T setIOS(Boolean iOS) {
this.iOS = iOS;
return self();
}

@Override
public T setWeb(Boolean web) {
this.web = web;
return self();
}

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

@Override
public Application buildAndCreate(Client client) { return client.createApplication(build(client)); }

private Application build(Client client){

Application application = client.instantiate(Application.class);

if (Strings.hasText(name))
((AbstractResource)application).setProperty("name", name, true);

if (Strings.hasText(label)) application.setLabel(label);

if (Objects.nonNull(signOnMode)) application.setSignOnMode(signOnMode);

// Accessibility
application.setAccessibility(client.instantiate(ApplicationAccessibility.class));
ApplicationAccessibility applicationAccessibility = application.getAccessibility();

if (Strings.hasText(loginRedirectUrl))
applicationAccessibility.setLoginRedirectUrl(loginRedirectUrl);

if (Strings.hasText(errorRedirectUrl))
applicationAccessibility.setErrorRedirectUrl(errorRedirectUrl);

if (Objects.nonNull(selfService))
applicationAccessibility.setSelfService(selfService);

// Visibility
application.setVisibility(client.instantiate(ApplicationVisibility.class));
ApplicationVisibility applicationVisibility = application.getVisibility();
ApplicationVisibilityHide applicationVisibilityHide = client.instantiate(ApplicationVisibilityHide.class);

if(Objects.nonNull(iOS))
applicationVisibility.setHide(applicationVisibilityHide
.setIOS(iOS));

if(Objects.nonNull(web))
applicationVisibility.setHide(applicationVisibilityHide
.setWeb(web));

return application;
}

}
Loading

0 comments on commit bd43772

Please sign in to comment.