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

Restrict findByUUID endpoint permissions and hide username on dashboard #792

Merged
merged 1 commit into from
Jun 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,11 @@
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.BindingResult;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import it.infn.mw.iam.api.common.ListResponseDTO;
import it.infn.mw.iam.api.common.form.PaginatedRequestWithFilterForm;
Expand Down Expand Up @@ -120,7 +124,6 @@ public ListResponseDTO<ScimUser> findNotInGroup(@PathVariable String groupUuid,
}

@GetMapping(value = FIND_BY_UUID_RESOURCE, produces = ScimConstants.SCIM_CONTENT_TYPE)
@PreAuthorize("#iam.hasScope('iam:admin.read') or #iam.hasDashboardRole('ROLE_ADMIN') or hasRole('USER')")
public ListResponseDTO<ScimUser> findByUuid(@PathVariable String accountUuid) {
return service.findAccountByUuid(accountUuid);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,12 +133,8 @@
});
}

function getClientStatusMessage(){
FindService.findAccountByUuid(self.clientVal.status_changed_by).then(function(res){
self.clientStatusMessage = "Suspended by " + res.userName + " on " + getFormatedDate(self.clientVal.status_changed_on);
}).catch(function (res) {
console.debug("Error retrieving user account!", res);
});
function getClientStatusMessage() {
self.clientStatusMessage = "Suspended by a VO admin on " + getFormatedDate(self.clientVal.status_changed_on);
}

function getFormatedDate(dateToFormat){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,12 +120,8 @@
});
}

function getClientStatusMessage(client){
FindService.findAccountByUuid(client.status_changed_by).then(function(res){
self.clientStatusMessage = "Suspended by " + res.userName + " on " + getFormatedDate(client.status_changed_on);
}).catch(function (res) {
console.debug("Error retrieving user account!", res);
});
function getClientStatusMessage(client) {
self.clientStatusMessage = "Suspended by a VO admin on " + getFormatedDate(client.status_changed_on);
}

function getFormatedDate(dateToFormat){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,11 +121,7 @@
}

function getClientStatusMessage(client){
FindService.findAccountByUuid(client.status_changed_by).then(function(res){
self.clientStatusMessage = "Suspended by " + res.userName + " on " + getFormatedDate(client.status_changed_on);
}).catch(function (res) {
console.debug("Error retrieving user account!", res);
});
self.clientStatusMessage = "Suspended by a VO admin on " + getFormatedDate(client.status_changed_on);
}

function getFormatedDate(dateToFormat){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,6 @@ public void findNotInGroupWorks() throws Exception {
}

@Test
@WithMockUser(username = "test", roles = "USER")
public void findByUUIDWorks() throws Exception {

IamAccount testAccount = accountRepo.findByUuid(TEST_USER_UUID)
Expand All @@ -308,10 +307,27 @@ public void findByUUIDWorks() throws Exception {

@Test
@WithMockUser(username = "test", roles = "USER")
public void totalResultDoesNotExistForUnknownUUID() throws Exception {
public void findByUUIDForbiddenForUsers() throws Exception {

IamAccount testAccount = accountRepo.findByUuid(TEST_USER_UUID)
.orElseThrow(assertionError(EXPECTED_ACCOUNT_NOT_FOUND));

mvc.perform(get(FIND_BY_UUID_RESOURCE, testAccount.getUuid()))
.andExpect(FORBIDDEN);
}

@Test
public void emptyResultForUnknownUUIDIfAdmin() throws Exception {
mvc.perform(get(FIND_BY_UUID_RESOURCE, "unknown_uuid"))
.andExpect(OK)
.andExpect(jsonPath("$.totalResults").doesNotExist())
.andExpect(jsonPath("$.Resources", emptyIterable()));
}

@Test
@WithMockUser(username = "test", roles = "USER")
public void forbiddenForUnknownUUIDIfUser() throws Exception {
mvc.perform(get(FIND_BY_UUID_RESOURCE, "unknown_uuid"))
.andExpect(FORBIDDEN);
}
}
Loading