Example usage for org.springframework.security.authentication AbstractAuthenticationToken getAuthorities

List of usage examples for org.springframework.security.authentication AbstractAuthenticationToken getAuthorities

Introduction

In this page you can find the example usage for org.springframework.security.authentication AbstractAuthenticationToken getAuthorities.

Prototype

public Collection<GrantedAuthority> getAuthorities() 

Source Link

Usage

From source file:$.LoginController.java

@RequestMapping(value = "/mainmenu.do")
    public ExtjsStore getMenu(HttpServletRequest request, Device device, Locale locale) {
        String[] roles = null;/*from   ww  w  .  j  a v a 2s  .  c  o  m*/
        if (request.getUserPrincipal() instanceof AbstractAuthenticationToken) {
            AbstractAuthenticationToken user = (AbstractAuthenticationToken) request.getUserPrincipal();
            roles = new String[user.getAuthorities().size()];
            GrantedAuthority[] ga = user.getAuthorities().toArray(new GrantedAuthority[0]);
            for (int i = 0; i < user.getAuthorities().size(); i++) {
                roles[i] = ga[i].getAuthority();
            }
        }
        ExtjsStore result = new ExtjsStore();
        com.katsu.springframework.web.servlet.menu.Device deviceAux;
        if (device.isMobile())
            deviceAux = com.katsu.springframework.web.servlet.menu.Device.MOBILE;
        else if (device.isNormal())
            deviceAux = com.katsu.springframework.web.servlet.menu.Device.DESKTOP;
        else
            deviceAux = com.katsu.springframework.web.servlet.menu.Device.TABLET;
        result.setData(this.menuService.getMenus(request.getContextPath(), deviceAux, locale, roles));
        return result;
    }