Package com.dream.util

Source Code of com.dream.util.SecurityUtil

package com.dream.util;

import com.dream.domain.user.User;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContext;
import org.springframework.security.core.context.SecurityContextHolder;

/**
* Created by IntelliJ IDEA.
* User: Gang Zhong
* Date: 13-3-15
* Time: 下午7:58
*/
public class SecurityUtil {

    public static String currentUserGuid() {
        User user = currentUser();
        if (user == null) {
            return null;
        }
        return user.guid();
    }

    public static User currentUser() {
        SecurityContext context = SecurityContextHolder.getContext();
        if (context == null) {
            return null;
        }
        Authentication authentication = context.getAuthentication();
        if (authentication == null) {
            return null;
        }

        return (User) authentication.getPrincipal();
    }
}
TOP

Related Classes of com.dream.util.SecurityUtil

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.