package com.qryord.mp.common;

import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.subject.Subject;
import org.apache.tomcat.websocket.AuthenticationException;

@Slf4j
public class BaseApiController {

    @SneakyThrows
    protected UserContext getUserContext() {
        Subject subject = SecurityUtils.getSubject();
        if (subject != null
                && subject.getPrincipal() != null
                && subject.getPrincipal() instanceof UserContext) {
            return (UserContext)subject.getPrincipal();
        } else {
            log.error("UNLOGIN");
            throw new AuthenticationException("UNLOGIN");
        }
    }

}
