Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sprint-1-Fixes #12

Merged
merged 26 commits into from
Apr 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
bbd0066
[SLS-5] Added checksum generation for jar file, extraction for all av…
Apr 3, 2023
d94aeef
[SLS-5] configured artifact sharing between subproject in order to al…
Apr 3, 2023
46be394
[SLS-5] Upgraded rep-build config to determine fixed java version
Apr 3, 2023
0d06fc2
[SLS-5] Introduced gradle plugin to apply reproducible builds and .bu…
Apr 4, 2023
4b06709
[SLS-5] Introducing verification-metadata.xml and build.gradle and .g…
Apr 4, 2023
4ee3905
[SLS-9] Generated openAPI REST Client for retrieving assertion
svariant Apr 5, 2023
dcba982
[SLS-9] Implemented AssertionClient with getAssertion method
svariant Apr 5, 2023
c388924
[SLS-9] Unit test for AssertionSimpleClient
svariant Apr 5, 2023
17575ca
[SLS-9] Added javadoc
svariant Apr 5, 2023
0b51613
[core_sprint_1_fix] Removed lombok rc version
Apr 5, 2023
5e89684
[core_sprint_1_fix] Applied spotless formatting
Apr 5, 2023
51012ae
[core_sprint_1_fix] Updated docs. Applied spotless formatting
Apr 5, 2023
b53c4e3
Merge branch 'core-sprint-1' into SLS-5
alessio-cialini Apr 5, 2023
f212855
Merge pull request #6 from pagopa/SLS-5
alessio-cialini Apr 5, 2023
fbe2e9c
[core_sprint_1_fix] Removed lombok rc version
Apr 5, 2023
e605a83
[core_sprint_1_fix] Applied spotless formatting
Apr 5, 2023
875c286
[core_sprint_1_fix] Updated docs. Applied spotless formatting
Apr 5, 2023
6613b4e
[core_sprint_1_fix] Updated verification-metadata.xml after merge. Up…
Apr 5, 2023
a215ce0
Merge remote-tracking branch 'origin/core-spring-1-fix' into core-spr…
Apr 5, 2023
0021c0a
[core_sprint_1_fix] Updated verification-metadata.xml to skip sources…
Apr 5, 2023
44bc5ce
[SLS-9] Implemented MockServer for AssertionSimpleClient testing
svariant Apr 5, 2023
7900cc6
Merge branch 'core-spring-1-fix' into SLS-9
alessio-cialini Apr 5, 2023
98169c7
Merge pull request #13 from pagopa/SLS-9
alessio-cialini Apr 5, 2023
4370651
[core_sprint_1_fix] Updated verification-metadata.xml, Applied spotle…
Apr 5, 2023
36265b1
update verification-metadata.xml
gquadrati Apr 5, 2023
7595659
[core_sprint_1_fix] Updated gradle wrapper
Apr 5, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,5 @@
# Ignore IntelliJ
.idea

# Ignore Gradle
gradle

# Ignore Gradle build output directory
build
53 changes: 52 additions & 1 deletion assertion-rest-client-native/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
plugins {
// Apply the java-library plugin for API and implementation separation.
id 'java-library'
id("io.freefair.lombok") version "8.0.0-rc4"
id("io.freefair.lombok") version "8.0.0"
/*id("org.openapi.generator") version "6.5.0"*/
}

group 'it.pagopa.commons'
Expand All @@ -20,13 +21,63 @@ repositories {
mavenCentral()
}

configurations {
implementation {
attributes {
attribute(LibraryElements.LIBRARY_ELEMENTS_ATTRIBUTE, objects.named(LibraryElements, 'instrumented-core-jar'))
}
}
}

abstract class InstrumentedJarsRule implements AttributeCompatibilityRule<LibraryElements> {

@Override
void execute(CompatibilityCheckDetails<LibraryElements> details) {
if (details.consumerValue.name == 'instrumented-core-jar' && details.producerValue.name == 'jar') {
details.compatible()
}
}
}

dependencies {
attributesSchema {
attribute(LibraryElements.LIBRARY_ELEMENTS_ATTRIBUTE) {
compatibilityRules.add(InstrumentedJarsRule)
}
}
implementation project(path: ':core')

implementation 'javax.annotation:javax.annotation-api:1.3.2'
implementation 'com.fasterxml.jackson.dataformat:jackson-dataformat-xml:2.14.2'
implementation 'org.openapitools:jackson-databind-nullable:0.2.6'
implementation 'com.fasterxml.jackson.datatype:jackson-datatype-jsr310:2.14.2'
implementation 'com.google.code.findbugs:jsr305:3.0.2'

implementation 'org.mock-server:mockserver-client-java:5.15.0'
implementation 'javax.inject:javax.inject:1'
implementation 'junit:junit:4.13.2'
// Use JUnit Jupiter for testing.
testImplementation 'org.junit.jupiter:junit-jupiter:5.9.2'
testImplementation 'org.assertj:assertj-core:3.24.2'
//Mockserver for testing api
testImplementation 'org.mock-server:mockserver-netty:5.15.0'
}

tasks.named('test') {
// Use JUnit Platform for unit tests.
useJUnitPlatform()
}
/*
compileJava.dependsOn tasks.openApiGenerate

openApiGenerate {
generatorName = "java"
inputSpec = "$projectDir/openapi/openapi-spec.yml"
outputDir = "$projectDir/generated"
configOptions = [
dataLibrary: "java8",
library: "native",
useRuntimeException: "true",
sourceFolder: "build/generated/sources/"
]
}*/
166 changes: 166 additions & 0 deletions assertion-rest-client-native/openapi/openapi-spec.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,166 @@
openapi: "3.0.1"
info:
title: Assertion Client
version: $npm_package_version
x-logo:
url: https://io.italia.it/assets/img/io-logo-blue.svg
description: |-
Client used to get the assertion from the identity provider
servers:
- url: http://localhost:3000
security:
- ApiKeyAuth: []
paths:
/assertions/{assertion_ref}:
get:
operationId: getAssertion
summary: Get Assertion related to a given assertion ref
parameters:
- name: assertion_ref
required: true
in: path
schema:
$ref: '#/components/schemas/AssertionRef'
- name: x-pagopa-lollipop-auth
required: true
in: header
schema:
$ref: '#/components/schemas/LollipopAuthBearer'
responses:
'200':
description: The assertion related to a valid assertion_ref
content:
application/json:
schema:
$ref: '#/components/schemas/LCUserInfo'
'400':
description: Bad Request
content:
application/json:
schema:
$ref: '#/components/schemas/ProblemJson'
'401':
description: Unauthorized
'403':
description: Forbidden
'404':
description: Not Found
content:
application/json:
schema:
$ref: '#/components/schemas/ProblemJson'
'410':
description: Assertion gone
'500':
description: Internal Server Error
content:
application/json:
schema:
$ref: '#/components/schemas/ProblemJson'
components:
securitySchemes:
ApiKeyAuth:
type: apiKey
in: header
name: Ocp-Apim-Subscription-Key
schemas:
ProblemJson:
type: object
properties:
type:
type: string
format: uri
description: |-
An absolute URI that identifies the problem type. When dereferenced,
it SHOULD provide human-readable documentation for the problem type
(e.g., using HTML).
default: about:blank
example: https://example.com/problem/constraint-violation
title:
type: string
description: >-
A short, summary of the problem type. Written in english and
readable

for engineers (usually not suited for non technical stakeholders and

not localized); example: Service Unavailable
status:
type: integer
format: int32
description: >-
The HTTP status code generated by the origin server for this
occurrence

of the problem.
minimum: 100
maximum: 600
exclusiveMaximum: true
example: 200
detail:
type: string
description: |-
A human readable explanation specific to this occurrence of the
problem.
example: There was an error processing the request
instance:
type: string
format: uri
description: >-
An absolute URI that identifies the specific occurrence of the
problem.

It may or may not yield further information if dereferenced.
AssertionType:
type: string
enum:
- SAML
- OIDC
AssertionRefSha256:
type: string
pattern: ^(sha256-[A-Za-z0-9-_=]{1,44})$
AssertionRefSha384:
type: string
pattern: ^(sha384-[A-Za-z0-9-_=]{1,66})$
AssertionRefSha512:
type: string
pattern: ^(sha512-[A-Za-z0-9-_=]{1,88})$
AssertionRef:
oneOf:
- $ref: '#/components/schemas/AssertionRefSha256'
- $ref: '#/components/schemas/AssertionRefSha384'
- $ref: '#/components/schemas/AssertionRefSha512'
LollipopAuthBearer:
type: string
pattern: ^Bearer [a-zA-Z0-9-_].+
description: A lollipop's JWT auth custom header as `Bearer <JWT Token>`
example: >-
Bearer
eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c
SamlUserInfo:
type: object
properties:
response_xml:
type: string
description: A string representation of a signed SPID/CIE response
minLength: 1
required:
- response_xml
OidcSignedJwt:
type: string
description: A JWT representation of a signed SPID/CIE OIDC Idp
minLength: 1
OidcUserInfo:
type: object
properties:
id_token:
$ref: '#/components/schemas/OidcSignedJwt'
claims_token:
$ref: '#/components/schemas/OidcSignedJwt'
required:
- id_token
- claims_token
LCUserInfo:
oneOf:
- $ref: '#/components/schemas/SamlUserInfo'
- $ref: '#/components/schemas/OidcUserInfo'
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/* (C)2023 */
package it.pagopa.tech.lollipop.consumer.assertion.client.simple;

import it.pagopa.tech.lollipop.consumer.assertion.client.AssertionClient;
import it.pagopa.tech.lollipop.consumer.assertion.client.simple.internal.ApiClient;
import it.pagopa.tech.lollipop.consumer.assertion.client.simple.internal.ApiException;
import it.pagopa.tech.lollipop.consumer.assertion.client.simple.internal.api.DefaultApi;
import it.pagopa.tech.lollipop.consumer.assertion.client.simple.internal.model.AssertionRef;
import it.pagopa.tech.lollipop.consumer.assertion.client.simple.internal.model.LCUserInfo;
import it.pagopa.tech.lollipop.consumer.assertion.client.simple.internal.model.SamlUserInfo;
import it.pagopa.tech.lollipop.consumer.exception.LollipopAssertionNotFoundException;
import it.pagopa.tech.lollipop.consumer.model.SamlAssertion;
import javax.inject.Inject;

/** Implementation of the @AssertionClient using generated openAPI REST Client */
public class AssertionSimpleClient implements AssertionClient {

ApiClient apiClient;
DefaultApi defaultApi;

@Inject
public AssertionSimpleClient(ApiClient client) {
this.apiClient = client;
this.defaultApi = new DefaultApi(client);
}

/**
* Retrieve assertion from IdentityProvider using REST Client The retrieved assertion can be of
* two types: SAML or OIDC Only SAML assertions are supported at this moment
*
* @param jwt Auth token for header param x-pagopa-lollipop-auth
* @param assertionRef Assertion unique identification
* @return the retrieved assertion or null if the assertion is not supported (not SAML)
* @throws LollipopAssertionNotFoundException if some error occurred in the request
*/
@Override
public SamlAssertion getAssertion(String jwt, String assertionRef)
throws LollipopAssertionNotFoundException {
AssertionRef ref = new AssertionRef(assertionRef);

if (jwt.isEmpty() || assertionRef.isEmpty()) {
throw new IllegalArgumentException("Jwt or Assertion Ref missing");
}

LCUserInfo responseAssertion;

try {
responseAssertion = this.defaultApi.getAssertion(ref, jwt);
} catch (ApiException e) {
throw new LollipopAssertionNotFoundException(
"Error retrieving assertion: " + e.getMessage(), e);
}

if (responseAssertion.getActualInstance().getClass().equals(SamlUserInfo.class)) {
SamlAssertion response = new SamlAssertion();
SamlUserInfo data = (SamlUserInfo) responseAssertion.getActualInstance();
String assertionData = data.getResponseXml();
response.setAssertionRef(assertionRef);
response.setAssertionData(assertionData);
return response;
}

return null;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/* (C)2023 */
package it.pagopa.tech.lollipop.consumer.assertion.client.simple;

import it.pagopa.tech.lollipop.consumer.assertion.client.AssertionClient;
import it.pagopa.tech.lollipop.consumer.assertion.client.AssertionClientProvider;
import it.pagopa.tech.lollipop.consumer.assertion.client.simple.internal.ApiClient;

/** Provider class for retrieving an instance of {@link AssertionSimpleClient} */
public class AssertionSimpleClientProvider implements AssertionClientProvider {

/**
* Provide an instance of {@link AssertionSimpleClient}
*
* @return {@link AssertionSimpleClient}
*/
@Override
public AssertionClient provideClient() {
return new AssertionSimpleClient(new ApiClient());
}
}
Loading