br.com.jreader.util.security.Session.java Source code

Java tutorial

Introduction

Here is the source code for br.com.jreader.util.security.Session.java

Source

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package br.com.jreader.util.security;

import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContext;
import org.springframework.security.core.context.SecurityContextHolder;

/**
 *
 * @author jonat
 */
public class Session {

    private Authentication authentication;

    public static String getUserSession() {
        SecurityContext context = SecurityContextHolder.getContext();
        if (context instanceof SecurityContext) {
            Authentication authentication = context.getAuthentication();
            if (authentication instanceof Authentication) {
                return authentication.getName();
            }
        }
        return null;
    }

}