-
-
Notifications
You must be signed in to change notification settings - Fork 499
Public permalink to private md #9059
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
Draft
cmangeat
wants to merge
42
commits into
geonetwork:main
Choose a base branch
from
sebr72:public_permalink_to_private_md
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
42 commits
Select commit
Hold shift + click to select a range
5bb0f79
Anonymous user can read an MD given appropriate security context perm…
cmangeat 0a450d0
Fix typo
cmangeat 11a7239
migrate from uuid to id, keep it simple stupid (avoid try/catch and d…
cmangeat 4fb8dc6
introduce AnonymousAccessLink in domain and grantViewAuthorityFilter …
cmangeat fd648df
nominal test
cmangeat 37db114
spring security filter granting view md according to registred hash a…
cmangeat afd6cd4
need for uuid in GrantedWiewMdSecurity to patch EsFilterBuilder
cmangeat 6d090ba
rename tests
cmangeat 20e26bf
es http proxy take ViewMdGrantedAuthority into account
cmangeat 5e4fff8
create anonymousAccessLink
cmangeat 18117a3
list anonymousAccessLink
cmangeat af88e90
delete anonymousAccessLink
cmangeat 7116cc1
swagger for api
cmangeat 3fea366
prefer hasAuthority on as hasRole
cmangeat 08d2050
wip override HttpSessionSecurityContextRepository trust resolver so t…
cmangeat 5b72ea7
refactor
cmangeat 229cce9
randomize hash
cmangeat c536924
rename test method
cmangeat 2f285a3
delete anonymous link using its md uuid
cmangeat eb66068
add converter / 'encryptor' for hash
cmangeat fc57473
introduce service and dto
cmangeat aa29686
add headers
cmangeat 5f7ed7a
service nominal test
cmangeat 401f821
always hide hash but when create
cmangeat 7c21444
by now, api return dto, not entity
cmangeat 9e6a2e9
test for delete with service
cmangeat 9d6f521
does a link exist service
cmangeat 030adb4
refactor test
cmangeat 7ca608e
does a link exist api
cmangeat f86a5f0
refactor test
cmangeat 7c8f587
do not include null field (hash) when json serialize
cmangeat e8ed951
delete and create now take a md uuid as path param, no body to provid…
cmangeat 7b3b5cb
refactor test
cmangeat a231d19
service to return links bound with md info
cmangeat adc1fce
fix test
cmangeat 9040494
avoid bad url forging when contact logo from existing org
cmangeat 55a7bd3
at this point, two links cannot give access to the same md
cmangeat 2e4079b
trigger link deletion when md published
cmangeat 18c2ab2
make anonymous session not anonymous for httpSessionSecurityContextRe…
cmangeat 1704440
create anonymous access link does not operate for published md
cmangeat 0d26eeb
encrypt hash in db
cmangeat 2f4a5ab
missing headers
cmangeat File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
core/src/main/java/org/fao/geonet/kernel/security/ViewMdGrantedAuthority.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/* | ||
* Copyright (C) 2001-2025 Food and Agriculture Organization of the | ||
* United Nations (FAO-UN), United Nations World Food Programme (WFP) | ||
* and United Nations Environment Programme (UNEP) | ||
* | ||
* This program is free software; you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation; either version 2 of the License, or (at | ||
* your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, but | ||
* WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
* General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program; if not, write to the Free Software | ||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA | ||
* | ||
* Contact: Jeroen Ticheler - FAO - Viale delle Terme di Caracalla 2, | ||
* Rome - Italy. email: [email protected] | ||
*/ | ||
|
||
package org.fao.geonet.kernel.security; | ||
|
||
import org.fao.geonet.domain.AnonymousAccessLink; | ||
import org.springframework.security.core.GrantedAuthority; | ||
|
||
public final class ViewMdGrantedAuthority implements GrantedAuthority { | ||
private static final long serialVersionUID = -5004823258126237689L; | ||
|
||
private AnonymousAccessLink anonymousAccessLink; | ||
|
||
public AnonymousAccessLink getAnonymousAccessLink() { | ||
return anonymousAccessLink; | ||
} | ||
|
||
public ViewMdGrantedAuthority setAnonymousAccessLink(AnonymousAccessLink anonymousAccessLink) { | ||
this.anonymousAccessLink = anonymousAccessLink; | ||
return this; | ||
} | ||
|
||
@Override | ||
public String getAuthority() { | ||
return anonymousAccessLink.getMetadataUuid(); | ||
} | ||
} |
43 changes: 43 additions & 0 deletions
43
core/src/main/java/org/fao/geonet/security/AuthenticatedUserFilter.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/* | ||
* Copyright (C) 2001-2025 Food and Agriculture Organization of the | ||
* United Nations (FAO-UN), United Nations World Food Programme (WFP) | ||
* and United Nations Environment Programme (UNEP) | ||
* | ||
* This program is free software; you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation; either version 2 of the License, or (at | ||
* your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, but | ||
* WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
* General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program; if not, write to the Free Software | ||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA | ||
* | ||
* Contact: Jeroen Ticheler - FAO - Viale delle Terme di Caracalla 2, | ||
* Rome - Italy. email: [email protected] | ||
*/ | ||
|
||
package org.fao.geonet.security; | ||
|
||
import org.springframework.security.core.context.SecurityContextHolder; | ||
import org.springframework.web.filter.GenericFilterBean; | ||
|
||
import javax.servlet.FilterChain; | ||
import javax.servlet.ServletException; | ||
import javax.servlet.ServletRequest; | ||
import javax.servlet.ServletResponse; | ||
import java.io.IOException; | ||
|
||
public class AuthenticatedUserFilter extends GenericFilterBean { | ||
|
||
@Override | ||
public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException { | ||
if (SecurityContextHolder.getContext().getAuthentication() != null) { | ||
filterChain.doFilter(servletRequest, servletResponse); | ||
} | ||
} | ||
} |
20 changes: 0 additions & 20 deletions
20
core/src/main/java/org/fao/geonet/security/AuthenticathedUserFilter.java
This file was deleted.
Oops, something went wrong.
102 changes: 102 additions & 0 deletions
102
core/src/main/java/org/fao/geonet/security/GrantViewMdAuthorityFilter.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
/* | ||
* Copyright (C) 2001-2025 Food and Agriculture Organization of the | ||
* United Nations (FAO-UN), United Nations World Food Programme (WFP) | ||
* and United Nations Environment Programme (UNEP) | ||
* | ||
* This program is free software; you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation; either version 2 of the License, or (at | ||
* your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, but | ||
* WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
* General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program; if not, write to the Free Software | ||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA | ||
* | ||
* Contact: Jeroen Ticheler - FAO - Viale delle Terme di Caracalla 2, | ||
* Rome - Italy. email: [email protected] | ||
*/ | ||
|
||
package org.fao.geonet.security; | ||
cmangeat marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
import org.fao.geonet.domain.AnonymousAccessLink; | ||
import org.fao.geonet.kernel.security.ViewMdGrantedAuthority; | ||
import org.fao.geonet.repository.AnonymousAccessLinkRepository; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.security.authentication.AnonymousAuthenticationToken; | ||
import org.springframework.security.authentication.AuthenticationTrustResolver; | ||
import org.springframework.security.authentication.AuthenticationTrustResolverImpl; | ||
import org.springframework.security.core.Authentication; | ||
import org.springframework.security.core.GrantedAuthority; | ||
import org.springframework.security.core.context.SecurityContextHolder; | ||
import org.springframework.security.web.context.HttpSessionSecurityContextRepository; | ||
import org.springframework.web.filter.GenericFilterBean; | ||
|
||
import javax.servlet.FilterChain; | ||
import javax.servlet.ServletException; | ||
import javax.servlet.ServletRequest; | ||
import javax.servlet.ServletResponse; | ||
import java.io.IOException; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
public class GrantViewMdAuthorityFilter extends GenericFilterBean { | ||
|
||
@Autowired | ||
AnonymousAccessLinkRepository anonymousAccessLinkRepository; | ||
|
||
private HttpSessionSecurityContextRepository repo; | ||
|
||
public GrantViewMdAuthorityFilter(HttpSessionSecurityContextRepository httpSessionSecurityContextRepository) { | ||
httpSessionSecurityContextRepository.setTrustResolver(new AuthenticationTrustResolver() { | ||
AuthenticationTrustResolver delegate = new AuthenticationTrustResolverImpl(); | ||
|
||
@Override | ||
public boolean isAnonymous(Authentication authentication) { | ||
if (authentication.getAuthorities().stream().anyMatch(ViewMdGrantedAuthority.class::isInstance)) { | ||
return false; | ||
} | ||
return delegate.isAnonymous(authentication); | ||
} | ||
|
||
@Override | ||
public boolean isRememberMe(Authentication authentication) { | ||
return delegate.isRememberMe(authentication); | ||
} | ||
}); | ||
} | ||
|
||
@Override | ||
public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException { | ||
Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); | ||
boolean isAnonymous = authentication instanceof AnonymousAuthenticationToken; | ||
if (!isAnonymous) { | ||
filterChain.doFilter(servletRequest, servletResponse); | ||
return; | ||
} | ||
String hash = servletRequest.getParameter("hash"); | ||
AnonymousAccessLink authority = anonymousAccessLinkRepository.findOneByHash(hash); | ||
if (authority == null) { | ||
filterChain.doFilter(servletRequest, servletResponse); | ||
return; | ||
} | ||
boolean alreadyGranted = authentication.getAuthorities().stream() // | ||
.filter(ViewMdGrantedAuthority.class::isInstance) // | ||
.map(ViewMdGrantedAuthority.class::cast) // | ||
.map(ViewMdGrantedAuthority::getAnonymousAccessLink) // | ||
.anyMatch(authority::equals); | ||
if (alreadyGranted){ | ||
filterChain.doFilter(servletRequest, servletResponse); | ||
return; | ||
} | ||
List<GrantedAuthority> authorities = new ArrayList<>(authentication.getAuthorities()); | ||
authorities.add(new ViewMdGrantedAuthority().setAnonymousAccessLink(authority)); | ||
AnonymousAuthenticationToken token = new AnonymousAuthenticationToken(authentication.getName(), authentication.getPrincipal(), authorities); | ||
SecurityContextHolder.getContext().setAuthentication(token); | ||
filterChain.doFilter(servletRequest, servletResponse); | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.