Example usage for javax.servlet.http HttpServletRequestWrapper getUserPrincipal

List of usage examples for javax.servlet.http HttpServletRequestWrapper getUserPrincipal

Introduction

In this page you can find the example usage for javax.servlet.http HttpServletRequestWrapper getUserPrincipal.

Prototype

@Override
public java.security.Principal getUserPrincipal() 

Source Link

Document

The default behavior of this method is to return getUserPrincipal() on the wrapped request object.

Usage

From source file:de.zib.gndms.kit.monitor.GroovyMoniServlet.java

@SuppressWarnings({ "NonSerializableObjectBoundToHttpSession" })
@Nullable/*w ww  . ja  v a2s  .c om*/
GroovyMonitor createMonitor(@NotNull HttpServletRequestWrapper request, @NotNull HttpSession session,
        @NotNull String token, @NotNull String args, @NotNull HttpServletResponse response) throws IOException {
    GroovyMonitor monitor;
    final Principal principal = request.getUserPrincipal();

    synchronized (session) {
        monitor = (GroovyMonitor) session.getAttribute(token);
        if (monitor == null) {
            GroovyMonitor.RunMode mode = parseMode(request, moniServer.getDefaultMode());
            if (mode == GroovyMonitor.RunMode.CLOSE)
                throw badRequest("Cant close unavailable token");
            final PrintWriter outWriter = response.getWriter();
            monitor = new GroovyMonitor(moniServer, principal, token, mode, args, outWriter);
            session.setAttribute(token, monitor);
        } else {
            GroovyMonitor.RunMode mode = parseMode(request, moniServer.getDefaultMode());
            if (GroovyMonitor.RunMode.CLOSE.equals(mode)) {
                // monitor.destroyMonitor(session) will be calle by doGet finalizer
                monitor.setRunMode(mode);
                return null;
            } else
                throw badRequest("Token already open");
        }
    }

    return monitor;
}