-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
26 changed files
with
202 additions
and
133 deletions.
There are no files selected for viewing
This file contains 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
45 changes: 45 additions & 0 deletions
45
src/main/java/org/rutebanken/tiamat/auth/AuthorizationService.java
This file contains 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,45 @@ | ||
package org.rutebanken.tiamat.auth; | ||
|
||
import org.rutebanken.helper.organisation.RoleAssignment; | ||
import org.rutebanken.tiamat.model.EntityStructure; | ||
import org.springframework.security.access.AccessDeniedException; | ||
|
||
import java.util.Collection; | ||
import java.util.Set; | ||
|
||
/** | ||
* Authorize operations for the current user. | ||
*/ | ||
public interface AuthorizationService { | ||
|
||
/** | ||
* Does the current user have edit right on all the given entities? | ||
*/ | ||
boolean canEditEntities(Collection<? extends EntityStructure> entities); | ||
|
||
/** | ||
* Verify that the current user has edit right on all the given entities. | ||
* @throws AccessDeniedException if not. | ||
*/ | ||
void verifyCanEditEntities(Collection<? extends EntityStructure> entities); | ||
|
||
/** | ||
* Verify that the current user has delete right on all the given entities. | ||
* @throws AccessDeniedException if not. | ||
*/ | ||
void verifyCanDeleteEntities(Collection<? extends EntityStructure> entities); | ||
|
||
/** | ||
* Return the subset of the roles that the current user holds that apply to this entity. | ||
* */ | ||
<T extends EntityStructure> Set<String> getRelevantRolesForEntity(T entity); | ||
|
||
/** | ||
* Does the role assignment give edit right on the given entity? | ||
* (for unit tests only) | ||
*/ | ||
<T extends EntityStructure> boolean canEditEntity(RoleAssignment roleAssignment, T entity); | ||
|
||
|
||
|
||
} |
47 changes: 47 additions & 0 deletions
47
src/main/java/org/rutebanken/tiamat/auth/DefaultAuthorizationService.java
This file contains 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 @@ | ||
package org.rutebanken.tiamat.auth; | ||
|
||
import org.rutebanken.helper.organisation.DataScopedAuthorizationService; | ||
import org.rutebanken.helper.organisation.RoleAssignment; | ||
import org.rutebanken.tiamat.model.EntityStructure; | ||
|
||
import java.util.Collection; | ||
import java.util.Set; | ||
|
||
import static org.rutebanken.helper.organisation.AuthorizationConstants.ROLE_DELETE_STOPS; | ||
import static org.rutebanken.helper.organisation.AuthorizationConstants.ROLE_EDIT_STOPS; | ||
|
||
public class DefaultAuthorizationService implements AuthorizationService { | ||
private final DataScopedAuthorizationService dataScopedAuthorizationService; | ||
|
||
public DefaultAuthorizationService(DataScopedAuthorizationService dataScopedAuthorizationService) { | ||
this.dataScopedAuthorizationService = dataScopedAuthorizationService; | ||
} | ||
|
||
@Override | ||
public boolean canEditEntities(Collection<? extends EntityStructure> entities) { | ||
return dataScopedAuthorizationService.isAuthorized(ROLE_EDIT_STOPS, entities); | ||
} | ||
|
||
@Override | ||
public <T extends EntityStructure> boolean canEditEntity(RoleAssignment roleAssignment, T entity) { | ||
return dataScopedAuthorizationService.authorized(roleAssignment, entity, ROLE_EDIT_STOPS); | ||
} | ||
|
||
@Override | ||
public void verifyCanEditEntities(Collection<? extends EntityStructure> entities) { | ||
dataScopedAuthorizationService.assertAuthorized(ROLE_EDIT_STOPS, entities); | ||
} | ||
|
||
@Override | ||
public void verifyCanDeleteEntities(Collection<? extends EntityStructure> entities) { | ||
dataScopedAuthorizationService.assertAuthorized(ROLE_DELETE_STOPS, entities); | ||
|
||
} | ||
|
||
@Override | ||
public <T extends EntityStructure> Set<String> getRelevantRolesForEntity(T entity) { | ||
return dataScopedAuthorizationService.getRelevantRolesForEntity(entity); | ||
} | ||
|
||
|
||
} |
This file contains 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 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 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 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 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 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 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.