All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.springframework.flex.security3.AuthenticationResultUtils Maven / Gradle / Ivy

Go to download

Spring BlazeDS Integration is a top-level Spring project, and a component of the complete Spring Web stack. This project's purpose is to make it easier to build Spring-powered Rich Internet Applications using Adobe Flex as the front-end client. It aims to achieve this purpose by providing first-class support for using the open source Adobe BlazeDS project and its powerful remoting and messaging facilities in combination with the familiar Spring programming model.

There is a newer version: 1.5.2.RELEASE
Show newest version

package org.springframework.flex.security3;

import java.util.HashMap;
import java.util.Map;

import org.springframework.security.core.Authentication;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.context.SecurityContextHolder;

/**
 * Helper that ensures consistent handling of a Spring Security {@link Authentication}, providing translation to a structure that will be
 * useful to a Flex client in determining the credentials of an authenticated user.
 * 
 * 

* When this helper is used to convert the {@link Authentication} into a BlazeDS message, the body of the returned * message will contain the following properties as obtained from the {@link Authentication} object: *

    *
  • name - the "name" property from the authentication
  • *
  • authorities - an array of String representations of the authentication's authorities (i.e. obtained through * {@link GrantedAuthority#getAuthority})
  • *
* * @author Jeremy Grelle */ public abstract class AuthenticationResultUtils { /** * Checks for an {@link Authentication} object in the current {@link SecurityContext} and if one is found, constructs and returns * a map that will result in an object of the expected format when returned to the Flex client. * @return a map of the {@link Authentication} properties to be serialized over AMF, or null if no Authentication is found */ public static Map getAuthenticationResult() { Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); if (authentication == null) { return null; } Map authenticationResult = new HashMap(); authenticationResult.put("name", authentication.getName()); String[] authorities = new String[authentication.getAuthorities().size()]; int i=0; for (GrantedAuthority granted : authentication.getAuthorities()) { authorities[i++] = granted.getAuthority(); } authenticationResult.put("authorities", authorities); return authenticationResult; } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy