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

Asserts

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