Skip to content

Commit

Permalink
assign base url prefix to value of 'patient' context parameter, copie…
Browse files Browse the repository at this point in the history
…d from authorization subject
  • Loading branch information
timcoffman committed Sep 25, 2024
1 parent 6ea470a commit cb2b9e3
Show file tree
Hide file tree
Showing 12 changed files with 330 additions and 96 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@ private OAuth2AuthenticatedPrincipal oauth2PrincipalFromAuthentication(Authentic

private IIdType authorizedUserIdFromAuthentication(Authentication authentication) {
OAuth2AuthenticatedPrincipal oauth2Principal = oauth2PrincipalFromAuthentication(authentication);
return authorizedUserIdFromOAuth2Principal( oauth2Principal );
}

private IIdType authorizedUserIdFromOAuth2Principal( OAuth2AuthenticatedPrincipal oauth2Principal ) {
if ( null == oauth2Principal )
return null ;

Expand All @@ -76,20 +80,35 @@ private LaunchContext launchContextFromAuthentication(Authentication authenticat
if (null == contextPatient)
return null;

IIdType contextPatientId = idFromContextParameter( "Patient", contextPatient.toString());

IIdType contextPatientId = idFromContextParameter( contextPatient.toString() ).withResourceType( "Patient" ) ;
IIdType fullyQualifiedContextPatientId = fullyQualifiedContextPatientId( contextPatientId, oauth2Principal );

return new LaunchContext() {

@Override
public IIdType getPatient() {
return contextPatientId;
return fullyQualifiedContextPatientId;
}

};
}

private IIdType fullyQualifiedContextPatientId( IIdType contextPatientId, OAuth2AuthenticatedPrincipal oauth2Principal ) {
if ( contextPatientId.hasBaseUrl() )
return contextPatientId ;

IIdType authorizedUserId = authorizedUserIdFromOAuth2Principal( oauth2Principal );
if ( null == authorizedUserId )
throw new AuthenticationException(Msg.code(644) + "Launch Context Patient \"" + contextPatientId + "\" is missing required base url, but no authorized user id is available to provide one");
if ( !authorizedUserId.hasBaseUrl() )
throw new AuthenticationException(Msg.code(644) + "Launch Context Patient \"" + contextPatientId + "\" is missing required base url, but authorized user id \"" + authorizedUserId + "\" does not provide one");

return contextPatientId.withServerBase( authorizedUserId.getBaseUrl(), contextPatientId.getResourceType() ) ;
}

protected abstract IIdType idFromSubject( String subject ) ;

protected abstract IIdType idFromContextParameter( String resourceType, String contextParameterValue ) ;
protected abstract IIdType idFromContextParameter( String contextParameterValue ) ;

}
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ private void linkNonLocalCompartment( IIdType nonLocalCompartment, PatientCompar
requireClaimedLocalCompartment( linkingContext ),
requireClaimedNonLocalCompartment( nonLocalCompartment, linkingContext )
);
linkingContext.basisCompartmentIsAlreadyLinked() ;
linkingContext.nonLocalCompartmentIsAlreadyLinked( nonLocalCompartment ) ;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ protected IIdType idFromSubject(String subject) {
}

@Override
protected IIdType idFromContextParameter( String resourceType, String contextParameterValue ) {
return new IdType(contextParameterValue.toString()).withResourceType(resourceType);
protected IIdType idFromContextParameter( String contextParameterValue ) {
return new IdType(contextParameterValue.toString());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ protected IIdType idFromSubject(String subject) {
}

@Override
protected IIdType idFromContextParameter( String resourceType, String contextParameterValue ) {
return new IdType(contextParameterValue.toString()).withResourceType(resourceType);
protected IIdType idFromContextParameter( String contextParameterValue ) {
return new IdType(contextParameterValue.toString());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ protected IIdType idFromSubject(String subject) {
}

@Override
protected IIdType idFromContextParameter( String resourceType, String contextParameterValue ) {
return new IdType(contextParameterValue.toString()).withResourceType(resourceType);
protected IIdType idFromContextParameter( String contextParameterValue ) {
return new IdType(contextParameterValue.toString());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ protected IIdType idFromSubject(String subject) {
}

@Override
protected IIdType idFromContextParameter( String resourceType, String contextParameterValue ) {
return new IdType(contextParameterValue.toString()).withResourceType(resourceType);
protected IIdType idFromContextParameter( String contextParameterValue ) {
return new IdType(contextParameterValue.toString());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ protected IIdType idFromSubject(String subject) {
}

@Override
protected IIdType idFromContextParameter( String resourceType, String contextParameterValue ) {
return new IdType(contextParameterValue.toString()).withResourceType(resourceType);
protected IIdType idFromContextParameter( String contextParameterValue ) {
return new IdType(contextParameterValue.toString());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,32 @@ void canShareForeignPartitionOtherThanForAuthorizedPatient() {
assertThat( linkages, hasSize(1) ) ;
}

@Test
void canShareMultipleForeignPartitions() {

/* store local patient */
localPartition.operations().patient().create() ;

/* store foreign partition 1 */
foreignPartition1.operations().patient().create() ;

List<Runnable> resourceTasks1 = partitionResourceCreationTasks( foreignPartition1.operations() ) ;
resourceTasks1.forEach( Runnable::run ) ;

foreignPartition1.assertClaimed() ;
List<Linkage> linkages1 = foreignPartition1.linkages().assertPresent() ;
assertThat( linkages1, hasSize(1) ) ;

/* store foreign partition 2 */
foreignPartition2.operations().patient().create() ;

List<Runnable> resourceTasks2 = partitionResourceCreationTasks( foreignPartition2.operations() ) ;
resourceTasks2.forEach( Runnable::run ) ;
foreignPartition2.assertClaimed() ;
List<Linkage> linkages2 = foreignPartition2.linkages().assertPresent() ;
assertThat( linkages2, hasSize(1) ) ;
}

private List<Runnable> partitionResourceCreationTasks(SdsPartitionOperations ops) {
List<Runnable> resourceTasks = new ArrayList<>() ;
for ( int i = 0 ; i < 10 ; ++i ) {
Expand Down
Loading

0 comments on commit cb2b9e3

Please sign in to comment.