Skip to content

Commit

Permalink
allow asset and idprovider on draft #10004
Browse files Browse the repository at this point in the history
  • Loading branch information
anatol-sialitski authored and rymsha committed Jan 31, 2023
1 parent 29d5d45 commit 25772dc
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,11 @@ protected PortalRequest createPortalRequest( final WebRequest webRequest, final

if ( ContentConstants.BRANCH_DRAFT.equals( portalRequest.getBranch() ) )
{
final String endpointPath = portalRequest.getEndpointPath();
if ( endpointPath != null && ( endpointPath.startsWith( "/_/asset/" ) || endpointPath.startsWith( "/_/idprovider/" ) ) )
{
return portalRequest;
}
final AuthenticationInfo authInfo = ContextAccessor.current().getAuthInfo();
if ( !authInfo.hasRole( RoleKeys.ADMIN ) && authInfo.getPrincipals().stream().noneMatch( draftBranchAllowedFor::contains ) )
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,14 +79,36 @@ public void testCreateRequestForAnonymousDraft()
result = ContextBuilder.create()
.authInfo( AuthenticationInfo.create()
.principals( RoleKeys.ADMIN_LOGIN )
.user( User.create().
key( PrincipalKey.ofUser( IdProviderKey.from( "enonic" ), "user1" ) ).
login( "user1" ).
build() )
.user( User.create()
.key( PrincipalKey.ofUser( IdProviderKey.from( "enonic" ), "user1" ) )
.login( "user1" )
.build() )
.build() )
.build()
.callWith( () -> handler.createPortalRequest( request, response ) );

assertNotNull( result );
}

@Test
public void testCreatePortalRequestForAssetAndIdproviderEndpoints()
{
this.request.setRawPath( "/site/myrepo/draft/mycontent/_/asset/demo/css/main.css" );
this.request.setEndpointPath( "/_/asset/demo/css/main.css" );

assertNotNull( createRequestWithAuthenticatedUser() );

this.request.setRawPath( "/site/default/draft/_/idprovider/system/login" );
this.request.setEndpointPath( "/_/idprovider/system/login" );

assertNotNull( createRequestWithAuthenticatedUser() );
}

private PortalRequest createRequestWithAuthenticatedUser()
{
return ContextBuilder.create()
.authInfo( AuthenticationInfo.copyOf( AuthenticationInfo.unAuthenticated() ).principals( PrincipalKey.ofAnonymous() ).build() )
.build()
.callWith( () -> handler.createPortalRequest( request, response ) );
}
}

0 comments on commit 25772dc

Please sign in to comment.