I have a method which extract the loggedin user details from springsecuritycontext object.
I have read that only utility methods(which does certain calculation) should be static .
Here is my method , it doesn't seems to be a utility method but I don't find any reason why I shouldn't make it static as I am using it in multiple beans
public static int getSignedUpUser()
{
final SecurityContext ctx = SecurityContextHolder.getContext();
if(ctx != null)
{
final Authentication auth = ctx.getAuthentication();
if(auth != null)
{
final Object principal = auth.getPrincipal();
if(principal instanceof AUser)
{
final AUser au = (AUser)principal;
return au.getId();
}
}
}
return 0;
}
}
Aucun commentaire:
Enregistrer un commentaire