1 package org
.argeo
.slc
.web
.mvc
.management
;
3 import java
.io
.IOException
;
5 import javax
.servlet
.ServletException
;
6 import javax
.servlet
.http
.HttpServletRequest
;
7 import javax
.servlet
.http
.HttpServletResponse
;
9 import org
.springframework
.security
.Authentication
;
10 import org
.springframework
.security
.GrantedAuthority
;
11 import org
.springframework
.security
.context
.SecurityContextHolder
;
12 import org
.springframework
.web
.HttpRequestHandler
;
14 import com
.springsource
.json
.writer
.JSONWriter
;
15 import com
.springsource
.json
.writer
.JSONWriterImpl
;
17 public class GetCredentials
implements HttpRequestHandler
{
19 public void handleRequest(HttpServletRequest request
,
20 HttpServletResponse response
) throws ServletException
, IOException
{
21 response
.setContentType("application/json");
23 Authentication authentication
= SecurityContextHolder
.getContext()
26 JSONWriter jsonWriter
= new JSONWriterImpl(response
.getWriter())
27 .object().key("user").value(authentication
.getName());
28 jsonWriter
.key("roles").array();
29 for (GrantedAuthority ga
: authentication
.getAuthorities()) {
30 jsonWriter
.value(ga
.getAuthority());
32 jsonWriter
.endArray();
33 jsonWriter
.endObject();