Example usage for org.springframework.security.core.context SecurityContextHolder getContextHolderStrategy

List of usage examples for org.springframework.security.core.context SecurityContextHolder getContextHolderStrategy

Introduction

In this page you can find the example usage for org.springframework.security.core.context SecurityContextHolder getContextHolderStrategy.

Prototype

public static SecurityContextHolderStrategy getContextHolderStrategy() 

Source Link

Document

Allows retrieval of the context strategy.

Usage

From source file:net.cristcost.study.services.ServiceTestUtil.java

private static void dumpSecurityInformation(PrintWriter writer, AuthenticationManager authenticationManager) {
    writer.println("### General Security Information ###");

    writer.println("Security Strategy is " + SecurityContextHolder.getContextHolderStrategy().toString());

    writer.println("Current Thread is " + Thread.currentThread().getName() + " ("
            + Thread.currentThread().getId() + ")");

    writer.println();//  ww w  .  j  av  a2s.c  o m

    if (authenticationManager != null) {
        writer.println("I've been injected with the AuthenticationManager");
    } else {
        writer.println("I've not been injected with the AuthenticationManager");
    }
    writer.println();

    Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
    if (authentication != null) {
        writer.println("There is an Authentication of type: " + authentication.getClass().getName());
        writer.println("Principal is of type: " + authentication.getPrincipal().getClass().getName()
                + " and is value is: " + authentication.getPrincipal().toString());
        for (GrantedAuthority ga : authentication.getAuthorities()) {
            writer.println(" - you have " + ga.getAuthority() + " authority");
        }

    } else {
        writer.println("There is no Authentication!");
    }
    writer.println();
}