Skip to content

Commit

Permalink
Merge pull request #335 from esuomi/fix_authorization_for_graphql_fet…
Browse files Browse the repository at this point in the history
…chers

replace old style role checks with delegation to userContextService
  • Loading branch information
testower authored Jun 6, 2024
2 parents 44610e2 + 1e1ecbe commit ed7b9aa
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@

package no.entur.uttu.graphql.fetchers;

import static no.entur.uttu.graphql.GraphQLNames.*;
import static org.rutebanken.helper.organisation.AuthorizationConstants.ROLE_ROUTE_DATA_ADMIN;
import static no.entur.uttu.graphql.GraphQLNames.FIELD_INPUT;
import static no.entur.uttu.graphql.GraphQLNames.FIELD_XMLNS;
import static no.entur.uttu.graphql.GraphQLNames.FIELD_XMLNS_URL;

import graphql.schema.DataFetcher;
import graphql.schema.DataFetchingEnvironment;
import no.entur.uttu.graphql.ArgumentWrapper;
import no.entur.uttu.model.Codespace;
import no.entur.uttu.repository.CodespaceRepository;
import no.entur.uttu.util.Preconditions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.stereotype.Component;
Expand All @@ -37,7 +37,7 @@ public class CodespaceUpdater implements DataFetcher<Codespace> {
private CodespaceRepository repository;

@Override
@PreAuthorize("hasRole('" + ROLE_ROUTE_DATA_ADMIN + "')")
@PreAuthorize("@userContextService.isAdmin()")
public Codespace get(DataFetchingEnvironment env) {
ArgumentWrapper input = new ArgumentWrapper(env.getArgument(FIELD_INPUT));
String codespaceXmlns = input.get(FIELD_XMLNS);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,8 @@

import static no.entur.uttu.graphql.GraphQLNames.FIELD_CODE;
import static no.entur.uttu.graphql.GraphQLNames.FIELD_CODE_SPACE_XMLNS;
import static no.entur.uttu.graphql.GraphQLNames.FIELD_ID;
import static no.entur.uttu.graphql.GraphQLNames.FIELD_INPUT;
import static no.entur.uttu.graphql.GraphQLNames.FIELD_NAME;
import static org.rutebanken.helper.organisation.AuthorizationConstants.ROLE_ROUTE_DATA_ADMIN;

import graphql.schema.DataFetcher;
import graphql.schema.DataFetchingEnvironment;
Expand All @@ -46,7 +44,7 @@ public class ProviderUpdater implements DataFetcher<Provider> {
private CodespaceRepository codespaceRepository;

@Override
@PreAuthorize("hasRole('" + ROLE_ROUTE_DATA_ADMIN + "')")
@PreAuthorize("@userContextService.isAdmin()")
public Provider get(DataFetchingEnvironment env) {
ArgumentWrapper input = new ArgumentWrapper(env.getArgument(FIELD_INPUT));
String code = input.get(FIELD_CODE);
Expand Down

0 comments on commit ed7b9aa

Please sign in to comment.