This is the codeAbility Sharing Platform! Learn more about the codeAbility Sharing Platform.

Skip to content
Snippets Groups Projects
Commit 4750e22d authored by Michael Breu's avatar Michael Breu :speech_balloon:
Browse files

Fix Admin access

parent 3ae08dec
2 merge requests!188Merging Peer Reviewing et. al to Master,!164211 peer reviewing functionality
package at.ac.uibk.gitsearch.security;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.authority.SimpleGrantedAuthority;
/**
* Constants for Spring Security authorities.
*/
......@@ -10,7 +13,37 @@ public final class AuthoritiesConstants {
public static final String USER = "ROLE_USER";
public static final String ANONYMOUS = "ROLE_ANONYMOUS";
/** just a convenience enum to access authorities in all their variants */
public enum AuthoritiesConstantEnum {
ADMIN(AuthoritiesConstants.ADMIN), USER(AuthoritiesConstants.USER), ANONYMOUS(AuthoritiesConstants.ANONYMOUS);
private String name;
private GrantedAuthority grantedAuthority;
AuthoritiesConstantEnum(String name) {
this.name = name;
grantedAuthority = new SimpleGrantedAuthority(name);
}
/**
* @return the name
*/
public String getName() {
return name;
}
/**
* @return the grantedAuthority
*/
public GrantedAuthority getGrantedAuthority() {
return grantedAuthority;
}
}
public static final GrantedAuthority ADMIN_AUTHORITY = new SimpleGrantedAuthority(ADMIN);
private AuthoritiesConstants() {
}
}
......@@ -16,6 +16,7 @@ import org.springframework.transaction.annotation.Transactional;
import at.ac.uibk.gitsearch.domain.UserWatchList;
import at.ac.uibk.gitsearch.repository.UserWatchListRepository;
import at.ac.uibk.gitsearch.security.AuthoritiesConstants.AuthoritiesConstantEnum;
import at.ac.uibk.gitsearch.security.jwt.TokenProvider;
import at.ac.uibk.gitsearch.service.dto.UserWatchListDTO;
import at.ac.uibk.gitsearch.service.mapper.UserWatchListMapper;
......@@ -54,6 +55,9 @@ public class UserWatchListService {
log.warn("Cannot find a principal for watchlist {} for exercise {}", watchlistId, description);
throw new IllegalAccessError("Cannot find a principal");
}
if(currentPrincipal.get().getAuthorities().contains(AuthoritiesConstantEnum.ADMIN.getGrantedAuthority())) {
return; // ADMIN is always allowed
}
final Optional<UserWatchListDTO> watchListO = findOne(watchlistId);
if(watchListO.isEmpty()) {
log.warn("Cannot find watchlist for : {} for exercise {}", watchlistId, description);
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment