Skip to content

Commit

Permalink
Use manage for policies endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
oharsta committed Mar 25, 2024
1 parent a55015e commit 3a95858
Show file tree
Hide file tree
Showing 9 changed files with 22 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -133,10 +133,9 @@ export default function AuthorizationPolicyOverview({app, type, onPolicyChange})
</div>
{isAllowedToMaintainPolicies && (
<div>
{I18n.t('policies.overview.numberOfRevisions')}:{' '}
<Link
to={`/apps/${app.id}/${type}/settings/authorization_policies/${policy.id}/revisions`}>
{policy.numberOfRevisions}
{I18n.t('policies.overview.numberOfRevisions')}
</Link>
</div>
)}
Expand Down
2 changes: 1 addition & 1 deletion dashboard-server/src/main/java/dashboard/Application.java
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public JiraClient jiraClient(ObjectMapper objectMapper,

@Bean
public PdpService pdpService(ObjectMapper objectMapper,
@Value("${dashboard.feature.pdp}") PolicyDataSource policyDataSource,
@Value("${dashboard.feature.pdpSource}") PolicyDataSource policyDataSource,
@Value("${pdp.server}") String pdpBaseUrl,
@Value("${pdp.username}") String pdpUsername,
@Value("${pdp.password}") String pdpPassword,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,13 +113,13 @@ public ResponseEntity<RestResponse<Policy>> newPolicy() {

@PreAuthorize("hasAnyRole('DASHBOARD_ADMIN','DASHBOARD_VIEWER','DASHBOARD_SUPER_USER')")
@RequestMapping(path = "/{id}", method = GET)
public RestResponse<Policy> policy(@PathVariable("id") Long id) {
public RestResponse<Policy> policy(@PathVariable("id") Object id) {
return createRestResponse(pdpService.policy(id));
}

@PreAuthorize("hasAnyRole('DASHBOARD_ADMIN','DASHBOARD_VIEWER','DASHBOARD_SUPER_USER')")
@RequestMapping(path = "/{id}", method = DELETE)
public void delete(@PathVariable("id") Long id) {
public void delete(@PathVariable("id") Object id) {
CoinUser currentUser = SpringSecurity.getCurrentUser();
if (currentUser.getCurrentLoaLevel() < 2 && dashboardStepupEnabled) {
String msg = String.format("Consent endpoint requires LOA level 2 or higher, currentUser %s", currentUser);
Expand All @@ -131,7 +131,7 @@ public void delete(@PathVariable("id") Long id) {

@PreAuthorize("hasAnyRole('DASHBOARD_ADMIN','DASHBOARD_VIEWER','DASHBOARD_SUPER_USER')")
@RequestMapping(path = "/{id}/revisions", method = GET)
public RestResponse<List<Policy>> revisions(@PathVariable("id") Long id) {
public RestResponse<List<Policy>> revisions(@PathVariable("id") Object id) {
return createRestResponse(pdpService.revisions(id));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
@JsonIgnoreProperties(ignoreUnknown = true)
public class Policy {

private Long id;
private Object id;

private String name;
private String description;
Expand Down
6 changes: 3 additions & 3 deletions dashboard-server/src/main/java/dashboard/pdp/PdpService.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,17 @@ public interface PdpService {

List<Policy> policies();

Policy policy(Long id);
Policy policy(Object id);

Policy create(Policy policy);

Policy update(Policy policy);

List<Attribute> allowedAttributes();

ResponseEntity<String> delete(Long id);
ResponseEntity<String> delete(Object id);

List<Policy> revisions(Long id);
List<Policy> revisions(Object id);

boolean isAvailable();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,8 @@ public List<Policy> policies() {
}).getBody());
}

public Policy policy(Long id) {
@Override
public Policy policy(Object id) {
RequestEntity<?> request = buildGetRequest("/protected/policies/" + id);

return executeWithExceptionLogging(() -> pdpRestTemplate
Expand All @@ -90,7 +91,7 @@ public Policy create(Policy policy) {
RequestEntity<?> request = buildPostRequest("/protected/policies", policy);
try {
try {
String json = new ObjectMapper().writerWithDefaultPrettyPrinter().writeValueAsString(policy);
String json = this.objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(policy);
LOG.info("creation of policy {}", json);
} catch (IOException e) {
LOG.error("Unexpected error from PdP", e);
Expand Down Expand Up @@ -123,13 +124,13 @@ public Policy update(Policy policy) {
}

@Override
public ResponseEntity<String> delete(Long id) {
public ResponseEntity<String> delete(Object id) {
RequestEntity<?> request = buildDeleteRequest("/protected/policies/" + id);
return executeWithExceptionLogging(() -> pdpRestTemplate.exchange(request, String.class));
}

@Override
public List<Policy> revisions(Long id) {
public List<Policy> revisions(Object id) {
RequestEntity<?> request = buildGetRequest("/protected/revisions/" + id);

return executeWithExceptionLogging(() -> {
Expand Down
12 changes: 6 additions & 6 deletions dashboard-server/src/main/java/dashboard/pdp/PdpServiceMock.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import java.util.List;
import java.util.Locale;
import java.util.Optional;
import java.util.UUID;

import static java.util.Optional.ofNullable;
import static java.util.stream.Collectors.toList;
Expand All @@ -26,7 +27,7 @@ public class PdpServiceMock implements PdpService {
new Attribute("urn:mace:dir:attribute-def:eduPersonAffiliation", "Edu person affiliation"),
new Attribute("urn:mace:dir:attribute-def:eduPersonScopedAffiliation", "Edu person scoped affiliation"));

private final ListMultimap<Long, Policy> policies = Multimaps.synchronizedListMultimap(ArrayListMultimap.create());
private final ListMultimap<Object, Policy> policies = Multimaps.synchronizedListMultimap(ArrayListMultimap.create());

@Autowired
private Services services;
Expand All @@ -37,7 +38,7 @@ public List<Policy> policies() {
}

@Override
public Policy policy(Long id) {
public Policy policy(Object id) {
return ofNullable(policies.get(id)).map(Iterables::getLast).orElseThrow(RuntimeException::new);
}

Expand Down Expand Up @@ -67,13 +68,13 @@ public List<Attribute> allowedAttributes() {
}

@Override
public ResponseEntity<String> delete(Long id) {
public ResponseEntity<String> delete(Object id) {
policies.removeAll(id);
return null;
}

@Override
public List<Policy> revisions(Long id) {
public List<Policy> revisions(Object id) {
return Optional.ofNullable(policies.get(id)).orElseThrow(RuntimeException::new);
}

Expand All @@ -84,8 +85,7 @@ public boolean isAvailable() {

@SneakyThrows
private Policy savePolicy(Policy policy) {
Long id = policies.keySet().stream().max(Long::compare).map(l -> l + 1).orElse(1L);
policy.setId(id);
policy.setId(UUID.randomUUID().toString());
policy.setUserDisplayName(SpringSecurity.getCurrentUser().getDisplayName());
policy.setCreated(String.valueOf(System.currentTimeMillis()));
policy.setActionsAllowed(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
public class MockShibbolethFilter extends GenericFilterBean {

public static final String idp = "http://mock-idp";//,"https://idp.surfnet.nl";//"https://localhost.surf.id"; //"https://idp.surf.nl"
public String role = "super";//"";
public String role = "admin";//"";

@Override
public void doFilter(ServletRequest servletRequest, ServletResponse response, FilterChain chain) throws IOException,
Expand Down
2 changes: 1 addition & 1 deletion dashboard-server/src/main/resources/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ dashboard.feature.manage=false
dashboard.feature.jira=false
dashboard.feature.consent=true
# Choices are 'MOCK', 'PDP' and 'MANAGE'
dashboard.feature.pdp=MOCK
dashboard.feature.pdpSource=MOCK
dashboard.feature.statistics=false
dashboard.feature.mail=false
dashboard.feature.oidc=true
Expand Down

0 comments on commit 3a95858

Please sign in to comment.