Commit ec9b9456 authored by Matija Obreza's avatar Matija Obreza
Browse files

Asserts

parent b5577a02
......@@ -66,7 +66,7 @@ public class SecurityContextUtil {
* @param clazz the clazz
* @return the t
*/
static final <T> T updateBean(Class<T> clazz) {
private static final <T> T updateBean(Class<T> clazz) {
ApplicationContext context = CurrentApplicationContext.getContext();
if (context != null) {
try {
......@@ -146,6 +146,8 @@ public class SecurityContextUtil {
* @return true, if successful
*/
public static boolean hasRole(String role) {
assert role != null;
final Authentication auth = SecurityContextHolder.getContext().getAuthentication();
if (auth != null) {
for (GrantedAuthority authority : auth.getAuthorities()) {
......@@ -165,6 +167,9 @@ public class SecurityContextUtil {
* @return true, if successful
*/
public static boolean hasPermission(Object targetDomainObject, Object permission) {
assert targetDomainObject != null;
assert permission != null;
if (permissionEvaluator == null) {
LOG.info("permissionEvaluator not available. Checking context again");
if (! updatePermissionEvaluator()) {
......@@ -189,6 +194,9 @@ public class SecurityContextUtil {
* @return true, if successful
*/
public static boolean anyoneHasPermission(Object targetDomainObject, Object permission) {
assert targetDomainObject != null;
assert permission != null;
if (permissionEvaluator == null) {
LOG.info("permissionEvaluator not available. Checking context again");
if (! updatePermissionEvaluator()) {
......
......@@ -90,6 +90,10 @@ public class CurrentPermissionsWriter extends VirtualBeanPropertyWriter {
*/
@Override
protected Object value(Object bean, JsonGenerator gen, SerializerProvider prov) throws Exception {
if (bean == null) {
return null;
}
Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
if (authentication == null) {
return NO_PERMISSIONS;
......
Markdown is supported
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