package net.davidvoid.thor.lightning.util;

import net.davidvoid.thor.lightning.exception.BadRequestException;

/**
 * Created by david on 4/27/16.
 */
public class HttpRequestAssertion {
    public static void assertNotNull(Object obj, String msg) {
        if (obj == null) throw new BadRequestException(msg);
    }

    public static void assertNotNull(Object obj) {
        assertNotNull(obj, "");
    }

    public static void assertNotEmpty(String str, String msg) {
        if (str.isEmpty()) throw new BadRequestException(msg);
    }

    public static void assertNotEmpty(String str) {
        assertNotEmpty(str, "");
    }

    public static void assertStringNotEmpty(Object str, String msg) {
        if (str == null || !(str instanceof String) || ((String) str).isEmpty()) {
            throw new BadRequestException(msg);
        }
    }

    public static void assertStringNotEmpty(Object str) {
        assertStringNotEmpty(str, "");
    }

    public static void isTrue(boolean predicate, String msg) {
        if (!predicate) throw new BadRequestException(msg);
    }

    public static void isTrue(boolean predicate) {
        isTrue(predicate, "");
    }
}

@@ -37,16 +37,159 @@
 .util;%0A%0A
+import org.springframework.security.core.context.SecurityContextHolder;%0A%0Aimport net.davidvoid.thor.lightning.exception.AuthorizationException;%0A
 import n
@@ -1310,11 +1310,365 @@
 );%0A    %7D
+%0A%0A    public static void assertCurrentUserAs(String username, String msg) %7B%0A        if (!SecurityContextHolder.getContext().getAuthentication().getName()%0A                .equals(username))%0A            throw new AuthorizationException();%0A    %7D%0A%0A    public static void assertCurrentUserAs(String username) %7B%0A        assertCurrentUserAs(username, %22%22);%0A    %7D
 %0A%7D%0A

add assertion for current user