Skip to content

Commit

Permalink
Add UAA Client Mixed Actions Functionality
Browse files Browse the repository at this point in the history
This commit adds support for the Mixed Actions functionality of UAA Client.

[#125572641][ci skip]
  • Loading branch information
twoseat committed Oct 19, 2016
1 parent 1bc49c8 commit af5249b
Show file tree
Hide file tree
Showing 27 changed files with 796 additions and 44 deletions.
Expand Up @@ -42,6 +42,8 @@
import org.cloudfoundry.uaa.clients.ListClientsResponse;
import org.cloudfoundry.uaa.clients.ListMetadatasRequest;
import org.cloudfoundry.uaa.clients.ListMetadatasResponse;
import org.cloudfoundry.uaa.clients.MixedActionsRequest;
import org.cloudfoundry.uaa.clients.MixedActionsResponse;
import org.cloudfoundry.uaa.clients.UpdateClientRequest;
import org.cloudfoundry.uaa.clients.UpdateClientResponse;
import org.cloudfoundry.uaa.clients.UpdateMetadataRequest;
Expand All @@ -64,6 +66,11 @@ public ReactorClients(ConnectionContext connectionContext, Mono<String> root, To
super(connectionContext, root, tokenProvider);
}

@Override
public Mono<BatchChangeSecretResponse> batchChangeSecret(BatchChangeSecretRequest request) {
return post(request, BatchChangeSecretResponse.class, builder -> builder.pathSegment("oauth", "clients", "tx", "secret"));
}

@Override
public Mono<BatchCreateClientsResponse> batchCreate(BatchCreateClientsRequest request) {
return post(request, BatchCreateClientsResponse.class, builder -> builder.pathSegment("oauth", "clients", "tx"));
Expand All @@ -79,11 +86,6 @@ public Mono<BatchUpdateClientsResponse> batchUpdate(BatchUpdateClientsRequest re
return put(request, BatchUpdateClientsResponse.class, builder -> builder.pathSegment("oauth", "clients", "tx"));
}

@Override
public Mono<BatchChangeSecretResponse> batchChangeSecret(BatchChangeSecretRequest request) {
return post(request, BatchChangeSecretResponse.class, builder -> builder.pathSegment("oauth", "clients", "tx", "secret"));
}

@Override
public Mono<ChangeSecretResponse> changeSecret(ChangeSecretRequest request) {
return put(request, ChangeSecretResponse.class, builder -> builder.pathSegment("oauth", "clients", request.getClientId(), "secret"));
Expand Down Expand Up @@ -119,6 +121,11 @@ public Mono<ListMetadatasResponse> listMetadatas(ListMetadatasRequest request) {
return get(request, ListMetadatasResponse.class, builder -> builder.pathSegment("oauth", "clients", "meta"));
}

@Override
public Mono<MixedActionsResponse> mixedActions(MixedActionsRequest request) {
return post(request, MixedActionsResponse.class, builder -> builder.pathSegment("oauth", "clients", "tx", "modify"));
}

@Override
public Mono<UpdateClientResponse> update(UpdateClientRequest request) {
return put(request, UpdateClientResponse.class, builder -> builder.pathSegment("oauth", "clients", request.getClientId()));
Expand Down
Expand Up @@ -21,6 +21,7 @@
import org.cloudfoundry.reactor.TestResponse;
import org.cloudfoundry.reactor.uaa.AbstractUaaApiTest;
import org.cloudfoundry.uaa.SortOrder;
import org.cloudfoundry.uaa.clients.ActionClient;
import org.cloudfoundry.uaa.clients.BatchChangeSecretRequest;
import org.cloudfoundry.uaa.clients.BatchChangeSecretResponse;
import org.cloudfoundry.uaa.clients.BatchCreateClientsRequest;
Expand All @@ -34,8 +35,10 @@
import org.cloudfoundry.uaa.clients.ChangeSecretResponse;
import org.cloudfoundry.uaa.clients.Client;
import org.cloudfoundry.uaa.clients.CreateClient;
import org.cloudfoundry.uaa.clients.CreateClientAction;
import org.cloudfoundry.uaa.clients.CreateClientRequest;
import org.cloudfoundry.uaa.clients.CreateClientResponse;
import org.cloudfoundry.uaa.clients.DeleteClientAction;
import org.cloudfoundry.uaa.clients.DeleteClientRequest;
import org.cloudfoundry.uaa.clients.DeleteClientResponse;
import org.cloudfoundry.uaa.clients.GetClientRequest;
Expand All @@ -47,11 +50,14 @@
import org.cloudfoundry.uaa.clients.ListMetadatasRequest;
import org.cloudfoundry.uaa.clients.ListMetadatasResponse;
import org.cloudfoundry.uaa.clients.Metadata;
import org.cloudfoundry.uaa.clients.MixedActionsRequest;
import org.cloudfoundry.uaa.clients.MixedActionsResponse;
import org.cloudfoundry.uaa.clients.UpdateClient;
import org.cloudfoundry.uaa.clients.UpdateClientRequest;
import org.cloudfoundry.uaa.clients.UpdateClientResponse;
import org.cloudfoundry.uaa.clients.UpdateMetadataRequest;
import org.cloudfoundry.uaa.clients.UpdateMetadataResponse;
import org.cloudfoundry.uaa.clients.UpdateSecretAction;
import reactor.core.publisher.Mono;
import reactor.test.subscriber.ScriptedSubscriber;

Expand Down Expand Up @@ -534,6 +540,7 @@ protected DeleteClientRequest validRequest() {
.clientId("test-client-id")
.build();
}

}

public static final class Deserialize extends AbstractUaaApiTest<ListClientsRequest, ListClientsResponse> {
Expand Down Expand Up @@ -809,6 +816,105 @@ protected ListMetadatasRequest validRequest() {
}
}

public static final class MixedActions extends AbstractUaaApiTest<MixedActionsRequest, MixedActionsResponse> {

private final ReactorClients clients = new ReactorClients(CONNECTION_CONTEXT, this.root, TOKEN_PROVIDER);

@Override
protected ScriptedSubscriber<MixedActionsResponse> expectations() {
return ScriptedSubscriber.<MixedActionsResponse>create()
.expectValue(MixedActionsResponse.builder()
.client(ActionClient.builder()
.action("secret")
.approvalsDeleted(false)
.clientId("Zkgt1Y")
.build())
.client(ActionClient.builder()
.accessTokenValidity(2700L)
.action("delete")
.allowedProvider("uaa", "ldap", "my-saml-provider")
.approvalsDeleted(true)
.authority("clients.read", "new.authority", "clients.write")
.authorizedGrantType(CLIENT_CREDENTIALS)
.autoApprove("true")
.clientId("Xm43aH")
.lastModified(1474923482302L)
.name("My Client Name")
.redirectUriPattern("http*://ant.path.wildcard/**/passback/*", "http://test1.com")
.refreshTokenValidity(7000L)
.resourceId("none")
.scope("clients.read", "clients.write")
.tokenSalt("WjlWvu")
.build())
.client(ActionClient.builder()
.accessTokenValidity(2700L)
.action("add")
.allowedProvider("uaa", "ldap", "my-saml-provider")
.authority("clients.read", "clients.write")
.authorizedGrantType(CLIENT_CREDENTIALS)
.autoApprove("true")
.clientId("tlA1z5")
.lastModified(1474923482727L)
.name("My Client Name")
.redirectUriPattern("http*://ant.path.wildcard/**/passback/*", "http://test1.com")
.refreshTokenValidity(7000L)
.resourceId("none")
.scope("clients.read", "clients.write")
.tokenSalt("UpzrHR")
.build())
.build())
.expectComplete();
}

@Override
protected InteractionContext interactionContext() {
return InteractionContext.builder()
.request(TestRequest.builder()
.method(POST).path("/oauth/clients/tx/modify")
.payload("fixtures/uaa/clients/POST_tx_modify_request.json")
.build())
.response(TestResponse.builder()
.status(OK)
.payload("fixtures/uaa/clients/POST_tx_modify_response.json")
.build())
.build();
}

@Override
protected Mono<MixedActionsResponse> invoke(MixedActionsRequest request) {
return this.clients.mixedActions(request);
}

@Override
protected MixedActionsRequest validRequest() {
return MixedActionsRequest.builder()
.action(UpdateSecretAction.builder()
.clientId("Zkgt1Y")
.secret("new_secret")
.build())
.action(DeleteClientAction.builder()
.clientId("Xm43aH")
.build())
.action(CreateClientAction.builder()
.accessTokenValidity(2700L)
.allowedProvider("uaa", "ldap", "my-saml-provider")
.authority("clients.read", "clients.write")
.authorizedGrantType(CLIENT_CREDENTIALS)
.autoApprove("true")
.clientId("tlA1z5")
.clientSecret("secret")
.name("My Client Name")
.redirectUriPattern("http://test1.com", "http*://ant.path.wildcard/**/passback/*")
.refreshTokenValidity(7000L)
.resourceId()
.scope("clients.read", "clients.write")
.tokenSalt("UpzrHR")
.build())
.build();
}

}

public static final class Update extends AbstractUaaApiTest<UpdateClientRequest, UpdateClientResponse> {

private final ReactorClients clients = new ReactorClients(CONNECTION_CONTEXT, this.root, TOKEN_PROVIDER);
Expand Down
@@ -0,0 +1,42 @@
[
{
"action": "secret",
"client_secret": "new_secret",
"client_id": "Zkgt1Y"
},
{
"action": "delete",
"client_id": "Xm43aH"
},
{
"scope": [
"clients.read",
"clients.write"
],
"client_id": "tlA1z5",
"client_secret": "secret",
"resource_ids": [],
"authorized_grant_types": [
"client_credentials"
],
"access_token_validity": 2700,
"refresh_token_validity": 7000,
"action": "add",
"authorities": [
"clients.read",
"clients.write"
],
"token_salt": "UpzrHR",
"autoapprove": [ "true" ],
"allowedproviders": [
"uaa",
"ldap",
"my-saml-provider"
],
"name": "My Client Name",
"redirect_uri": [
"http://test1.com",
"http*://ant.path.wildcard/**/passback/*"
]
}
]
@@ -0,0 +1,83 @@
[
{
"scope": [],
"client_id": "Zkgt1Y",
"resource_ids": [],
"authorized_grant_types": [],
"action": "secret",
"authorities": [],
"approvals_deleted": false
},
{
"scope": [
"clients.read",
"clients.write"
],
"client_id": "Xm43aH",
"resource_ids": [
"none"
],
"authorized_grant_types": [
"client_credentials"
],
"redirect_uri": [
"http*://ant.path.wildcard/**/passback/*",
"http://test1.com"
],
"autoapprove": [
"true"
],
"access_token_validity": 2700,
"refresh_token_validity": 7000,
"action": "delete",
"authorities": [
"clients.read",
"new.authority",
"clients.write"
],
"token_salt": "WjlWvu",
"allowedproviders": [
"uaa",
"ldap",
"my-saml-provider"
],
"name": "My Client Name",
"lastModified": 1474923482302,
"approvals_deleted": true
},
{
"scope": [
"clients.read",
"clients.write"
],
"client_id": "tlA1z5",
"resource_ids": [
"none"
],
"authorized_grant_types": [
"client_credentials"
],
"redirect_uri": [
"http*://ant.path.wildcard/**/passback/*",
"http://test1.com"
],
"autoapprove": [
"true"
],
"access_token_validity": 2700,
"refresh_token_validity": 7000,
"action": "add",
"authorities": [
"clients.read",
"clients.write"
],
"token_salt": "UpzrHR",
"allowedproviders": [
"uaa",
"ldap",
"my-saml-provider"
],
"name": "My Client Name",
"lastModified": 1474923482727
}
]
Expand Up @@ -35,6 +35,13 @@ void checkAuthorizedGrantTypes() {
}
}

/**
* The access token validity
*/
@JsonProperty("access_token_validity")
@Nullable
abstract Long getAccessTokenValidity();

/**
* A list of origin keys (alias) for identity providers the client is limited to. Null implies any identity provider is allowed.
*/
Expand Down Expand Up @@ -104,6 +111,13 @@ void checkAuthorizedGrantTypes() {
@Nullable
abstract List<String> getRedirectUriPatterns();

/**
* The refresh token validity
*/
@JsonProperty("refresh_token_validity")
@Nullable
abstract Long getRefreshTokenValidity();

/**
* Resources the client is allowed access to
*/
Expand Down
@@ -0,0 +1,24 @@
/*
* Copyright 2013-2016 the original author or authors.
*
* 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 org.cloudfoundry.uaa.clients;

/*
* An interface that indicates the type of a UAA mixed action
*/
public interface Action {

}

0 comments on commit af5249b

Please sign in to comment.