Java tutorial
/* * 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 es.us.isa.ideas.app.social; import org.springframework.security.core.Authentication; import org.springframework.security.core.context.SecurityContextHolder; /** * * @author japarejo */ public class CustomUserIdSource { public String getUserId() { Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); if (authentication == null) { throw new IllegalStateException("Unable to get a ConnectionRepository: no user signed in"); } return authentication.getName(); } }