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

Commit

Permalink
feat(dcr): Support multiple initial access token providers
Browse files Browse the repository at this point in the history
  • Loading branch information
brasseld authored and aelamrani committed May 13, 2019
1 parent 249f774 commit 8180a78
Show file tree
Hide file tree
Showing 14 changed files with 414 additions and 195 deletions.
Expand Up @@ -17,6 +17,7 @@

import com.fasterxml.jackson.annotation.JsonProperty;

import javax.validation.constraints.NotNull;
import java.util.Date;
import java.util.List;
import java.util.Objects;
Expand All @@ -36,6 +37,9 @@ public class ClientRegistrationProviderEntity {
@JsonProperty("discovery_endpoint")
private String discoveryEndpoint;

@JsonProperty("initial_access_token_type")
private InitialAccessTokenType initialAccessTokenType;

@JsonProperty("client_id")
private String clientId;

Expand All @@ -50,6 +54,9 @@ public class ClientRegistrationProviderEntity {
@JsonProperty("updated_at")
private Date updatedAt;

@JsonProperty("initial_access_token")
private String initialAccessToken;

public String getId() {
return id;
}
Expand Down Expand Up @@ -82,6 +89,14 @@ public void setDiscoveryEndpoint(String discoveryEndpoint) {
this.discoveryEndpoint = discoveryEndpoint;
}

public InitialAccessTokenType getInitialAccessTokenType() {
return initialAccessTokenType;
}

public void setInitialAccessTokenType(InitialAccessTokenType initialAccessTokenType) {
this.initialAccessTokenType = initialAccessTokenType;
}

public String getClientId() {
return clientId;
}
Expand All @@ -106,6 +121,14 @@ public void setScopes(List<String> scopes) {
this.scopes = scopes;
}

public String getInitialAccessToken() {
return initialAccessToken;
}

public void setInitialAccessToken(String initialAccessToken) {
this.initialAccessToken = initialAccessToken;
}

public Date getCreatedAt() {
return createdAt;
}
Expand Down
@@ -0,0 +1,21 @@
/**
* Copyright (C) 2015 The Gravitee team (http://gravitee.io)
*
* 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 io.gravitee.management.model.configuration.application.registration;

public enum InitialAccessTokenType {
INITIAL_ACCESS_TOKEN,
CLIENT_CREDENTIALS
}
Expand Up @@ -39,15 +39,20 @@ public class NewClientRegistrationProviderEntity {
private String discoveryEndpoint;

@NotNull
@JsonProperty("initial_access_token_type")
private InitialAccessTokenType initialAccessTokenType;

@JsonProperty("client_id")
private String clientId;

@NotNull
@JsonProperty("client_secret")
private String clientSecret;

private List<String> scopes;

@JsonProperty("initial_access_token")
private String initialAccessToken;

public String getName() {
return name;
}
Expand All @@ -72,6 +77,14 @@ public void setDiscoveryEndpoint(String discoveryEndpoint) {
this.discoveryEndpoint = discoveryEndpoint;
}

public InitialAccessTokenType getInitialAccessTokenType() {
return initialAccessTokenType;
}

public void setInitialAccessTokenType(InitialAccessTokenType initialAccessTokenType) {
this.initialAccessTokenType = initialAccessTokenType;
}

public String getClientId() {
return clientId;
}
Expand All @@ -96,6 +109,14 @@ public void setScopes(List<String> scopes) {
this.scopes = scopes;
}

public String getInitialAccessToken() {
return initialAccessToken;
}

public void setInitialAccessToken(String initialAccessToken) {
this.initialAccessToken = initialAccessToken;
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
Expand Down
Expand Up @@ -36,15 +36,20 @@ public class UpdateClientRegistrationProviderEntity {
private String discoveryEndpoint;

@NotNull
@JsonProperty("initial_access_token_type")
private InitialAccessTokenType initialAccessTokenType;

@JsonProperty("client_id")
private String clientId;

@NotNull
@JsonProperty("client_secret")
private String clientSecret;

private List<String> scopes;

@JsonProperty("initial_access_token")
private String initialAccessToken;

public String getName() {
return name;
}
Expand All @@ -69,6 +74,14 @@ public void setDiscoveryEndpoint(String discoveryEndpoint) {
this.discoveryEndpoint = discoveryEndpoint;
}

public InitialAccessTokenType getInitialAccessTokenType() {
return initialAccessTokenType;
}

public void setInitialAccessTokenType(InitialAccessTokenType initialAccessTokenType) {
this.initialAccessTokenType = initialAccessTokenType;
}

public String getClientId() {
return clientId;
}
Expand All @@ -93,6 +106,14 @@ public void setScopes(List<String> scopes) {
this.scopes = scopes;
}

public String getInitialAccessToken() {
return initialAccessToken;
}

public void setInitialAccessToken(String initialAccessToken) {
this.initialAccessToken = initialAccessToken;
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
Expand Down
Expand Up @@ -17,6 +17,7 @@

import io.gravitee.common.http.MediaType;
import io.gravitee.management.model.configuration.application.registration.ClientRegistrationProviderEntity;
import io.gravitee.management.model.configuration.application.registration.InitialAccessTokenType;
import io.gravitee.management.model.configuration.application.registration.NewClientRegistrationProviderEntity;
import io.gravitee.management.model.permissions.RolePermission;
import io.gravitee.management.model.permissions.RolePermissionAction;
Expand Down Expand Up @@ -83,8 +84,18 @@ public List<ClientRegistrationProviderListItem> listClientRegistrationProviders(
@ApiResponse(code = 201, message = "Client registration provider provider successfully created",
response = ClientRegistrationProviderEntity.class),
@ApiResponse(code = 500, message = "Internal server error")})
public Response createIdentityProvider(
public Response createClientRegistrationProvider(
@ApiParam(name = "identity-provider", required = true) @Valid @NotNull NewClientRegistrationProviderEntity newClientRegistrationProviderEntity) {
if (newClientRegistrationProviderEntity.getInitialAccessTokenType() == InitialAccessTokenType.CLIENT_CREDENTIALS) {
if (newClientRegistrationProviderEntity.getClientId() == null || newClientRegistrationProviderEntity.getClientSecret() == null) {
throw new IllegalArgumentException("Client credentials are missing");
}
} else {
if (newClientRegistrationProviderEntity.getInitialAccessToken() == null) {
throw new IllegalArgumentException("Access token is missing");
}
}

ClientRegistrationProviderEntity newClientRegistrationProvider = clientRegistrationService.create(newClientRegistrationProviderEntity);

if (newClientRegistrationProvider != null) {
Expand Down

0 comments on commit 8180a78

Please sign in to comment.