Skip to content
This repository has been archived by the owner on Jan 21, 2024. It is now read-only.

Commit

Permalink
43 securedby with uses (#44)
Browse files Browse the repository at this point in the history
* #43 added testcase for securedby_with_uses (test will FAIL)

TODO implementation needs to be changed to generate constructor
with user/password.

* #43 forgot to add "securedBy:"  (test will still FAIL)

TODO implementation needs to be changed to generate constructor
with user/password.

* #43 find SecurityScheme referenced by SecuredBy as well (e.g. via uses:)

TODO implementation needs to be changed to generate constructor
with user/password.
  • Loading branch information
ca-stefan-cordes authored and machaval committed Jul 16, 2019
1 parent 06e2eb2 commit 7b3082a
Show file tree
Hide file tree
Showing 17 changed files with 682 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,12 @@ public static List<Pair<String, SecurityScheme>> getSupportedSecuritySchemes(Api
supportedSecuritySchemes.add(new ImmutablePair<>(schemeMap.getType(), schemeMap));
}
}
List<SecurityScheme> securedBy = raml.getSecuredBy();
for (SecurityScheme securedBySecurityScheme : securedBy) {
if (SUPPORTED_SECURITY_SCHEMES.contains(securedBySecurityScheme.getType())) {
supportedSecuritySchemes.add(new ImmutablePair<>(securedBySecurityScheme.getType(), securedBySecurityScheme));
}
}
return supportedSecuritySchemes;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ public static Iterable<Object[]> folders() {
{"oauth_override"},
{"recursive_type"},
{"simple"},
{"securedby_with_uses"},
{"sub_resource_on_same_line"},
{"same_path_multiple_times"},
{"type_decl"},
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#%RAML 1.0
version: api
title: BuyosExperienceLayer
baseUri: http://localhost:24045/api

uses:
candaCommons: canda-commons/1.0.8/canda-commons.raml

securedBy: [candaCommons.basicAuth]

# Workaround as https://github.com/mulesoft-labs/raml-java-client-generator
# does not detect securitySchemes placed in the "uses" section.
#securitySchemes:
# clientid:
# description: Client ID Policy
# type: Basic Authentication

#securedBy: [clientid]

/users/{id}:
get:
responses:
200:
body:
application/json:
example: |
{ "userId": "foo" }
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#%RAML 1.0 Library

securitySchemes:
basicAuth:
displayName: Basic Authentication
description: This API supports Basic Authentication. The client has to provide an "Authorization" header with valid credentials.
type: Basic Authentication
describedBy:
headers:
Authorization:
description: Used to send valid credentials.
type: string
responses:
401:
description: Credentials are missing or could not be validated by the server.
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@

package securedby_with_uses.api;

import javax.ws.rs.client.ClientBuilder;
import org.glassfish.jersey.client.authentication.HttpAuthenticationFeature;
import securedby_with_uses.resource.users.Users;

public class BuyosExperienceLayerClient {

private static java.lang.String username;
private static java.lang.String password;
private java.lang.String _baseUrl;
public final Users users;

public BuyosExperienceLayerClient(java.lang.String baseUrl, java.lang.String username, java.lang.String password) {
this.username = username;
this.password = password;
_baseUrl = baseUrl;
users = new Users(getBaseUri(), getClient());
}

public BuyosExperienceLayerClient(java.lang.String username, java.lang.String password) {
this("http://localhost:24045/api", username, password);
}

protected javax.ws.rs.client.Client getClient() {
final javax.ws.rs.client.Client _client = ClientBuilder.newClient();
_client.register(HttpAuthenticationFeature.basic(username, password));
return _client;
}

protected java.lang.String getBaseUri() {
return _baseUrl;
}

public static BuyosExperienceLayerClient create(java.lang.String baseUrl, java.lang.String username, java.lang.String password) {
return new BuyosExperienceLayerClient(baseUrl, username, password);
}

public static BuyosExperienceLayerClient create(java.lang.String username, java.lang.String password) {
return new BuyosExperienceLayerClient(username, password);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@

package securedby_with_uses.exceptions;

import javax.ws.rs.core.MultivaluedMap;
import javax.ws.rs.core.Response;

public class BuyosExperienceLayerException
extends RuntimeException
{

private int statusCode;
private String reason;
private MultivaluedMap<String, String> headers;
private Response response;

public BuyosExperienceLayerException(int statusCode, String reason, MultivaluedMap<String, String> headers, Response response) {
super(reason);
this.statusCode = statusCode;
this.reason = reason;
this.headers = headers;
this.response = response;
}

public BuyosExperienceLayerException(int statusCode, String reason) {
this(statusCode, reason, null, null);
}

public int getStatusCode() {
return this.statusCode;
}

public String getReason() {
return this.reason;
}

public MultivaluedMap<String, String> getHeaders() {
return this.headers;
}

public Response getResponse() {
return this.response;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@

package securedby_with_uses.resource.users;

import javax.ws.rs.client.Client;
import securedby_with_uses.resource.users.id.Id;

public class Users {

private String _baseUrl;
private Client _client;

public Users() {
_baseUrl = null;
_client = null;
}

public Users(String baseUrl, Client _client) {
_baseUrl = (baseUrl +"/users");
this._client = _client;
}

protected Client getClient() {
return this._client;
}

private String getBaseUri() {
return _baseUrl;
}

public Id id(String id) {
return new Id(getBaseUri(), getClient(), id);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@

package securedby_with_uses.resource.users.id;

import java.net.URLEncoder;
import javax.ws.rs.client.Client;
import javax.ws.rs.client.WebTarget;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.Response.Status.Family;
import securedby_with_uses.exceptions.BuyosExperienceLayerException;

public class Id {

private String _baseUrl;
private Client _client;

public Id() {
_baseUrl = null;
_client = null;
}

public Id(String baseUrl, Client _client, String uriParam) {
_baseUrl = (baseUrl +("/"+ URLEncoder.encode(uriParam)));
this._client = _client;
}

protected Client getClient() {
return this._client;
}

private String getBaseUri() {
return _baseUrl;
}

public securedby_with_uses.resource.users.id.model.IdGETResponse get() {
WebTarget target = this._client.target(getBaseUri());
final javax.ws.rs.client.Invocation.Builder invocationBuilder = target.request(MediaType.APPLICATION_JSON_TYPE);
Response response = invocationBuilder.get();
if (response.getStatusInfo().getFamily()!= Family.SUCCESSFUL) {
Response.StatusType statusInfo = response.getStatusInfo();
throw new BuyosExperienceLayerException(statusInfo.getStatusCode(), statusInfo.getReasonPhrase(), response.getStringHeaders(), response);
}
return response.readEntity(securedby_with_uses.resource.users.id.model.IdGETResponse.class);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@

package securedby_with_uses.resource.users.id.model;

import java.util.HashMap;
import java.util.Map;
import com.fasterxml.jackson.annotation.JsonAnyGetter;
import com.fasterxml.jackson.annotation.JsonAnySetter;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonPropertyOrder;

@JsonInclude(JsonInclude.Include.NON_NULL)
@JsonPropertyOrder({
"userId"
})
public class IdGETResponse {

@JsonProperty("userId")
private String userId;
@JsonIgnore
private Map<String, Object> additionalProperties = new HashMap<String, Object>();

/**
* No args constructor for use in serialization
*
*/
public IdGETResponse() {
}

/**
*
* @param userId
*/
public IdGETResponse(String userId) {
super();
this.userId = userId;
}

@JsonProperty("userId")
public String getUserId() {
return userId;
}

@JsonProperty("userId")
public void setUserId(String userId) {
this.userId = userId;
}

public IdGETResponse withUserId(String userId) {
this.userId = userId;
return this;
}

@JsonAnyGetter
public Map<String, Object> getAdditionalProperties() {
return this.additionalProperties;
}

@JsonAnySetter
public void setAdditionalProperty(String name, Object value) {
this.additionalProperties.put(name, value);
}

public IdGETResponse withAdditionalProperty(String name, Object value) {
this.additionalProperties.put(name, value);
return this;
}

@Override
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append(IdGETResponse.class.getName()).append('@').append(Integer.toHexString(System.identityHashCode(this))).append('[');
sb.append("userId");
sb.append('=');
sb.append(((this.userId == null)?"<null>":this.userId));
sb.append(',');
sb.append("additionalProperties");
sb.append('=');
sb.append(((this.additionalProperties == null)?"<null>":this.additionalProperties));
sb.append(',');
if (sb.charAt((sb.length()- 1)) == ',') {
sb.setCharAt((sb.length()- 1), ']');
} else {
sb.append(']');
}
return sb.toString();
}

@Override
public int hashCode() {
int result = 1;
result = ((result* 31)+((this.userId == null)? 0 :this.userId.hashCode()));
result = ((result* 31)+((this.additionalProperties == null)? 0 :this.additionalProperties.hashCode()));
return result;
}

@Override
public boolean equals(Object other) {
if (other == this) {
return true;
}
if ((other instanceof IdGETResponse) == false) {
return false;
}
IdGETResponse rhs = ((IdGETResponse) other);
return (((this.userId == rhs.userId)||((this.userId!= null)&&this.userId.equals(rhs.userId)))&&((this.additionalProperties == rhs.additionalProperties)||((this.additionalProperties!= null)&&this.additionalProperties.equals(rhs.additionalProperties))));
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#%RAML 1.0
version: api
title: BuyosExperienceLayer
baseUri: http://localhost:24045/api

uses:
candaCommons: canda-commons/1.0.8/canda-commons.raml

securedBy: [candaCommons.basicAuth]

# Workaround as https://github.com/mulesoft-labs/raml-java-client-generator
# does not detect securitySchemes placed in the "uses" section.
#securitySchemes:
# clientid:
# description: Client ID Policy
# type: Basic Authentication

#securedBy: [clientid]

/users/{id}:
get:
responses:
200:
body:
application/json:
example: |
{ "userId": "foo" }
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#%RAML 1.0 Library

securitySchemes:
basicAuth:
displayName: Basic Authentication
description: This API supports Basic Authentication. The client has to provide an "Authorization" header with valid credentials.
type: Basic Authentication
describedBy:
headers:
Authorization:
description: Used to send valid credentials.
type: string
responses:
401:
description: Credentials are missing or could not be validated by the server.
Loading

0 comments on commit 7b3082a

Please sign in to comment.