<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>JotaDeveloper &#187; spring security</title>
	<atom:link href="http://blog.jotadeveloper.com/tag/spring-security/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.jotadeveloper.com</link>
	<description>Programacion y algo más</description>
	<lastBuildDate>Wed, 20 Jan 2010 09:28:05 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Spring Security 2, la configuración a la medida con DAO Hibernate IV</title>
		<link>http://blog.jotadeveloper.com/2009/06/23/spring-security-2-la-configuracion-a-la-medida-con-dao-hibernate-iv/</link>
		<comments>http://blog.jotadeveloper.com/2009/06/23/spring-security-2-la-configuracion-a-la-medida-con-dao-hibernate-iv/#comments</comments>
		<pubDate>Tue, 23 Jun 2009 16:08:12 +0000</pubDate>
		<dc:creator>Jota</dc:creator>
				<category><![CDATA[Articulos]]></category>
		<category><![CDATA[Programación]]></category>
		<category><![CDATA[filtros]]></category>
		<category><![CDATA[Hibernate]]></category>
		<category><![CDATA[spring]]></category>
		<category><![CDATA[spring security]]></category>

		<guid isPermaLink="false">http://blog.jotadeveloper.com/?p=2143</guid>
		<description><![CDATA[Más filtros de los que explicamos en el artículo anterior se puede usar en Spring Security, donde vimos los filtros esenciales para la configuración de nuestra capa de seguridad.
AnonymousProcessingFilter
Este filtro es muy util, nos permite darle acceso a un usuarios anónimos a secciones del sistema, digamos que la pagina de registro debe ser de acceso [...]]]></description>
			<content:encoded><![CDATA[<p>Más filtros de los que explicamos en el <a href="http://blog.jotadeveloper.com/wp-content/plugins/feed-statistics.php?url=aHR0cDovL2Jsb2cuam90YWRldmVsb3Blci5jb20vMjAwOS8wNS8yNS9zcHJpbmctc2VjdXJpdHktMi1sYS1jb25maWd1cmFjaW9uLWEtbGEtbWVkaWRhLWNvbi1kYW8taGliZXJuYXRlLWlpaS8=" target=\"_blank\">artículo anterior</a> se puede usar en Spring Security, donde vimos los filtros esenciales para la configuración de nuestra capa de seguridad.</p>
<h2>AnonymousProcessingFilter</h2>
<p>Este filtro es muy util, nos permite darle acceso a un usuarios anónimos a secciones del sistema, digamos que la pagina de registro debe ser de acceso anónimo, en el <strong>FilterChainProxy</strong>  agregamos otra linea donde colocamos el recurso y le asignamos el filtro, ese recurso sera accesible siempre y cuando en el <strong>FilterSecurityInterceptor </strong> también podemos hacer uso del Rol que indicamos que seran Roles para identificar al usuario anónimo.</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;bean</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;anonymousProcessingFilter&quot;</span></span>
<span style="color: #009900;">		<span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;org.springframework.security.providers.anonymous.AnonymousProcessingFilter&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;key&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
			<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;value<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>MU7kyU0he1MvXEDZ9Mdj7MVvkXOXJ8uRgtg/Xb/3eJyW0HZa3csBoyvinGEC4vmi<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/value<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/property<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;userAttribute&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
			<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;value<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>anonymousUser,ENCUESTAME_ANONYMOUS
			<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/value<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/property<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/bean<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<h2> ExceptionTranslationFilter </h2>
<p>Maneja cualquier <strong>AccessDeniedException </strong>y <strong>AuthenticationException </strong> arrojados dentro de la cadena de filtro. Este filtro es necesario, ya que proporciona el puente entre las excepciones de Java y las respuestas HTTP.  Sólo se ocupan de mantener la interfaz de usuario. Este filtro no hace ninguna garantía real de la ejecución. Para utilizar este filtro, es necesario especificar las siguientes propiedades:</p>
<ul>
<li><strong>authenticationEntryPoint </strong>indica que el controlador debe comenzar el proceso de autenticación si un AuthenticationException se detecta. Tenga en cuenta que esto también puede cambiar el actual protocolo de http a https para un inicio de sesión SSL.</li>
<li><strong>portResolver</strong> (opcional) Se utiliza para determinar el &#8220;verdadero&#8221; puerto por la que fue recibida la petición.</li>
<ul>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;bean</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;exceptionTranslationFilter&quot;</span></span>
<span style="color: #009900;">		<span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;org.springframework.security.ui.ExceptionTranslationFilter&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;authenticationEntryPoint&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
			<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;ref</span> <span style="color: #000066;">local</span>=<span style="color: #ff0000;">&quot;authenticationEntryPoint&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/property<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/bean<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<h2> BasicProcessingFilterEntryPoint</h2>
<p>Este filtro es responsable de la tramitación de cualquier solicitud que tiene un encabezado de petición HTTP Authorization con un sistema de autenticación Basica y una codificación username:password simbólico. Por ejemplo, para autenticar el usuario &#8220;Aladdin&#8221;, con contraseña &#8220;ábrete Sésamo&#8221; el siguiente encabezado se mostrara como el siguiente ejemplo, (<strong>Autorización: Básica QWxhZGRpbjpvcGVuIHNlc2FtZQ == </strong> ). Si la autorización es satisfactoria, el objeto<strong>Authentication </strong>se colocará en el <strong>SecurityContextHolder.</strong></p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;bean</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;authenticationEntryPoint&quot;</span> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;org.springframework.security.ui.basicauth.BasicProcessingFilterEntryPoint&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
  		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;realmName&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span><span style="color: #000000; font-weight: bold;">&lt;value<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>EmForge<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/value<span style="color: #000000; font-weight: bold;">&gt;</span></span><span style="color: #000000; font-weight: bold;">&lt;/property<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/bean<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<h2>LogoutFilter</h2>
<p>Se necesita una forma de cerrar sesión, el <strong>LogoutFilter</strong> es la solución perfecta, indicamos en el constructor del bean el lugar donde seremos dirigidos cuando cerremos la sesión, y una lista de beans o manejadores de Cerrar sesión, por defecto se debe usar el SecurityContextLogoutHandler, aunque puedes personalizar el tuyo propio.</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;bean</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;logoutFilter&quot;</span> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;org.springframework.security.ui.logout.LogoutFilter&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
	 <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;constructor-arg</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;/pages/index.me&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;constructor-arg<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
			<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;list<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
				<span style="color: #808080; font-style: italic;">&lt;!--  &lt;ref bean=&quot;rememberMeServices&quot;/&gt;  --&gt;</span>
				<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;bean</span></span>
<span style="color: #009900;">					<span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;org.springframework.security.ui.logout.SecurityContextLogoutHandler&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
			<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/list<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/constructor-arg<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<h2>AuthenticationProcessingFilterEntryPoint</h2>
<p>AuthenticationProcessingFilterEntryPoint, es el bean que nos redirecionará a la pantalla de la aplicación donde se inicia sesión, o a donde nosotros queramos por eso la propiedad <strong>loginFormUrl</strong>. En el caso en que los credenciales no sean correctos se utliza el objeto <strong>AccessDeniedHandlerImpl</strong>, y en su propiedad errorPage se le especifica a que camino se debe dirigir la aplicación en caso de error.</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;bean</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;formEntryPoint&quot;</span> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;org.springframework.security.ui.webapp.AuthenticationProcessingFilterEntryPoint&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
      	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;loginFormUrl&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;/login.faces&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
   	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/bean<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>Estos son los filtros más usados y que podemos aplicar a nuestra seguridad, junto con los explicados anteriormente son una <strong>magnifica opción</strong> para crear nuestra seguridad, y como ven, con muy poca programación. En el <strong>siguiente artícul</strong>o veremos la integración del <strong>OPENID</strong> en Spring Security.</p>
 <img src="http://blog.jotadeveloper.com/wp-content/plugins/feed-statistics.php?view=1&post_id=2143" width="1" height="1" style="display: none;" />]]></content:encoded>
			<wfw:commentRss>http://blog.jotadeveloper.com/2009/06/23/spring-security-2-la-configuracion-a-la-medida-con-dao-hibernate-iv/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Spring Security 2, la configuración a la medida con DAO Hibernate III</title>
		<link>http://blog.jotadeveloper.com/2009/05/25/spring-security-2-la-configuracion-a-la-medida-con-dao-hibernate-iii/</link>
		<comments>http://blog.jotadeveloper.com/2009/05/25/spring-security-2-la-configuracion-a-la-medida-con-dao-hibernate-iii/#comments</comments>
		<pubDate>Mon, 25 May 2009 15:32:11 +0000</pubDate>
		<dc:creator>Jota</dc:creator>
				<category><![CDATA[Articulos]]></category>
		<category><![CDATA[filtros]]></category>
		<category><![CDATA[Hibernate]]></category>
		<category><![CDATA[jsf]]></category>
		<category><![CDATA[Seguridad]]></category>
		<category><![CDATA[spring]]></category>
		<category><![CDATA[spring security]]></category>

		<guid isPermaLink="false">http://blog.jotadeveloper.com/?p=1723</guid>
		<description><![CDATA[El dia de hoy vamos a continuar con los Filtros, es la parte central de la seguridad de Spring, y por eso la hace tan flexible, porque esta completamente separada del modelo de Negocio, eso es lo que lo hace tan genial, pues si el dia de mañana se te ocurre cambiar toda la seguridad, [...]]]></description>
			<content:encoded><![CDATA[<p>El dia de hoy vamos a continuar con los Filtros, es la parte central de la <strong>seguridad de Spring</strong>, y por eso la hace tan flexible, porque esta completamente separada del modelo de Negocio, eso es lo que lo hace tan genial, pues si el dia de mañana se te ocurre cambiar toda la seguridad, tu sistema no sufrirá grandes cambios.</p>
<p><strong>Los filtros se encargan de la seguridad de la aplicación</strong>. Existen tres filtros fundamentales se <strong>encadenan</strong> juntos mediante un objeto llamado &#8220;filterChainProxy&#8221;, que crea e inicializa los tres filtros; como se ve en el siguiente diagrama.
</p>
<p><a href="http://blog.jotadeveloper.com/wp-content/plugins/feed-statistics.php?url=aHR0cDovL2Jsb2cuam90YWRldmVsb3Blci5jb20vd3AtY29udGVudC91cGxvYWRzLzIwMDkvMDUvZmlsdHJvc2FjZWdpLmpwZw=="><img class="size-full wp-image-1724 alignnone" title="filtrosacegi" src="http://blog.jotadeveloper.com/wp-content/uploads/2009/05/filtrosacegi.jpg" alt="filtrosacegi" width="592" height="324" /></a></p>
<ol>
<li> El filtro <strong>AuthenticationProcessingFilter</strong> maneja la petición o requerimiento (request) que chequea la autenticación -Authentication Request Check- (&#8220;el login de la aplicación&#8221;). Para ello usa el <strong>AuthenticationManager </strong>que vimos en el articulo anterior.</li>
<li> El filtro <strong>HttpSessionContextIntegrationFilter </strong>mantiene el objeto Authentication entre varios requests y se lo pasa al <strong>AuthenticationManager</strong> y al <strong>AccessDecisionManager </strong>cuando sea necesario.</li>
<li> El filtro <strong>ExceptonTranslationFilter</strong> verifica la existencia de autenticación , maneja las excepciones de seguridad y ejecuta la acción apropiada. El ExceptonTranslationFilter depende del filtro siguiente, <strong>FilterSecurityInterceptor.</strong></li>
<li> <strong>FilterSecurityInterceptor </strong>controla el acceso restricto a recursos determinados , y el chequeo de autorización.  Conoce <em>qué recursos son seguros y qué roles tienen acceso a ellos</em>.  FilterSecurityInterceptor usa el <strong>AuthenticationManager </strong>y el  <strong>AccessDecisionManager </strong>para hacer su trabajo.</li>
</ol>
<p>Cuando inicias, todo esto es una maraña de filtros sin sentido, pero vamos a profundizar un poco para que te quede más claro la funcion y configuración de cada uno de ellos.</p>
<h2>AuthenticationProcessingFilter</h2>
<p>El primer filtro donde pasa el RequestHTTP. Este filtro se especializa en manejar el request de autentificación, valida el usuario y la contraseña, más alla de esto solo debes conocer otros parametros imporantes.</p>
<ul>
<li> <strong>authenticationFailureUrl: </strong> En el caso de fallo, algún lugar debe de ir cuando no se logea el usuario.</li>
<li> <strong>defaultTargetUrl:</strong> Es el URL por defecto, generalmente es la raiz.</li>
<li> <strong>filterProcessesUrl:</strong> Es a quien le encarga la responsbilidad de verificar si el usuario se logea o no..</li>
</ul>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;bean</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;authenticationProcessingFilter&quot;</span></span>
<span style="color: #009900;">		<span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;org.springframework.security.ui.webapp.AuthenticationProcessingFilter&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;authenticationManager&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
			<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;ref</span> <span style="color: #000066;">bean</span>=<span style="color: #ff0000;">&quot;authenticationManager&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/property<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;authenticationFailureUrl&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
			<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;value<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>/login.me<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/value<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/property<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;defaultTargetUrl&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
			<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;value<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>/<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/value<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/property<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;filterProcessesUrl&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
			<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;value<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>/j_spring_security_check<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/value<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/property<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/bean<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<h2>HttpSessionContextIntegrationFilter</h2>
<p>El HttpSessionContextIntegrationFilter es fácil de configurar. Su única función, es propagar por el Contexto de Seguridad la autenticación a través de todas las solicitudes. No necesita propiedades ni nada en especial.</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;bean</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;httpSessionContextIntegrationFilter&quot;</span></span>
<span style="color: #009900;">		<span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;org.springframework.security.context.HttpSessionContextIntegrationFilter&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span></pre></div></div>

<h2>ExceptionTranslationFilter</h2>
<p>El filtro ExceptionTranslationFilter  intercepta cualquier error de autenticación o autorización, por ejemplo <strong>UsernameNotFoundException</strong> o <strong>DataAccessException</strong>.</p>
<p>Si la excepción fue causada por una excepción de autorización lanzada por el filtro FilterSecurityInterceptor (puede ser porque no tiene permisos para acceder a un Recurso Web, una imagen o un URL), el filtro lanzará un HTTP 403 al navegador, el cual mostrará una página de acceso no autorizado.</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;bean</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;formExceptionTranslationFilter&quot;</span></span>
<span style="color: #009900;">		<span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;org.springframework.security.ui.ExceptionTranslationFilter&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;authenticationEntryPoint&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
			<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;ref</span> <span style="color: #000066;">local</span>=<span style="color: #ff0000;">&quot;formEntryPoint&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/property<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/bean<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;bean</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;formEntryPoint&quot;</span></span>
<span style="color: #009900;">		<span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;org.springframework.security.ui.webapp.AuthenticationProcessingFilterEntryPoint&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;loginFormUrl&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;/login.me&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/bean<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<h2>FilterSecurityInterceptor</h2>
<p>El FilterSecurityInterceptor, es donde protegeremos todos nuestros recursos, donde decidimos que ROL entra a ciertos recursos, cuales pueden ser accedido por usuarios anónimos, todo esto se configura en el <strong>objectDefinitionSource</strong>. Necesitamos 2 referencias para configurar este Filtro, el <strong>authenticationManager</strong> y el bean <strong>accessDecisionManager</strong> que miraremos en el siguiente artículo.</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;bean</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;filterInvocationInterceptor&quot;</span></span>
<span style="color: #009900;">		<span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;org.springframework.security.intercept.web.FilterSecurityInterceptor&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;authenticationManager&quot;</span> <span style="color: #000066;">ref</span>=<span style="color: #ff0000;">&quot;authenticationManager&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;accessDecisionManager&quot;</span> <span style="color: #000066;">ref</span>=<span style="color: #ff0000;">&quot;voteAccessDecisionManager&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;objectDefinitionSource&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
			<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;value<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
				CONVERT_URL_TO_LOWERCASE_BEFORE_COMPARISON
				PATTERN_TYPE_APACHE_ANT
				/=ENCUESTAME_ANONYMOUS
				/pages/**=ENCUESTAME_USER
				/pages/admon/**=ENCUESTAME_ADMIN
				/user/**=ENCUESTAME_ANONYMOUS,ENCUESTAME_USER,ENCUESTAME_ADMIN				           
         <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/value<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/property<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/bean<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<h2>FilterChainProxy</h2>
<p>El filtro inicializador, su función principal es indicar o personalizar, que recursos ejecutaran los filtros deseados en <strong>filterInvocationDefinitionSource</strong>, por ejemplo, si tenemos un sevlet<strong> /uploadFile</strong> y solo nos interesa aplicar algunos filtros</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;bean</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;springSecurityFilterChain&quot;</span> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;org.springframework.security.util.FilterChainProxy&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;filterInvocationDefinitionSource&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
         <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;value<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
		   CONVERT_URL_TO_LOWERCASE_BEFORE_COMPARISON
		    PATTERN_TYPE_APACHE_ANT
               /**=httpSessionContextIntegrationFilter,logoutFilter,basicProcessingFilter,authenticationProcessingFilter....
              /uploadFile= basicProcessingFilter,OtroFiltroPersonalizado
         <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/value<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/property<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/bean<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>En el siguiente artículo, veremos una extensión de los diferentes filtros opcionales que podemos integrar en nuestra seguridad, <strong>¿preguntas?</strong></p>
 <img src="http://blog.jotadeveloper.com/wp-content/plugins/feed-statistics.php?view=1&post_id=1723" width="1" height="1" style="display: none;" />]]></content:encoded>
			<wfw:commentRss>http://blog.jotadeveloper.com/2009/05/25/spring-security-2-la-configuracion-a-la-medida-con-dao-hibernate-iii/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Spring Security 2, la configuración a la medida con DAO Hibernate II</title>
		<link>http://blog.jotadeveloper.com/2009/05/13/spring-security-2-la-configuracion-a-la-medida-con-dao-hibernate-ii/</link>
		<comments>http://blog.jotadeveloper.com/2009/05/13/spring-security-2-la-configuracion-a-la-medida-con-dao-hibernate-ii/#comments</comments>
		<pubDate>Wed, 13 May 2009 06:24:10 +0000</pubDate>
		<dc:creator>Jota</dc:creator>
				<category><![CDATA[Articulos]]></category>
		<category><![CDATA[filtros]]></category>
		<category><![CDATA[Hibernate]]></category>
		<category><![CDATA[jsf]]></category>
		<category><![CDATA[Seguridad]]></category>
		<category><![CDATA[spring]]></category>
		<category><![CDATA[spring security]]></category>

		<guid isPermaLink="false">http://blog.jotadeveloper.com/?p=1649</guid>
		<description><![CDATA[Siguiendo con el articulo anterior, voy a explicar los diferentes Filtros de Seguridad y las Configuraciones Personales que podemos aplicar en nuestra Seguridad. El siguiente gráfico explica el ciclo de vida de la autentificación en Spring.
En el post anterior, vimos el Bean del Formulario de logeo, donde se creo el objeto Authentication que se pasa [...]]]></description>
			<content:encoded><![CDATA[<p>Siguiendo con el articulo anterior, voy a explicar los diferentes <strong>Filtros de Seguridad y las Configuraciones Personales </strong>que podemos aplicar en nuestra Seguridad. El siguiente gráfico explica el ciclo de vida de la autentificación en Spring.</p>
<p>En el post anterior, vimos el Bean del Formulario de logeo, donde se creo el objeto <strong>Authentication </strong>que se pasa al <strong>AuthenticationManager</strong>.</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;">UsernamePasswordAuthenticationToken authReq <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> UsernamePasswordAuthenticationToken<span style="color: #009900;">&#40;</span>userName, password<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
.......
<span style="color: #006633;">Authentication</span> auth <span style="color: #339933;">=</span> getAuthenticationManager<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">authenticate</span><span style="color: #009900;">&#40;</span>authReq<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p><a href="http://blog.jotadeveloper.com/wp-content/plugins/feed-statistics.php?url=aHR0cDovL2Jsb2cuam90YWRldmVsb3Blci5jb20vd3AtY29udGVudC91cGxvYWRzLzIwMDkvMDUvc3ByaW5nX2V4Y2VwdGlvbl9maWx0ZXIuZ2lm"><img class="alignnone size-full wp-image-1650" title="spring_exception_filter" src="http://blog.jotadeveloper.com/wp-content/uploads/2009/05/spring_exception_filter.gif" alt="spring_exception_filter" width="637" height="400" /></a></p>
<h3>AuthenticationManager</h3>
<p>El bean AuthenticationManager es del tipo <strong>ProviderManager</strong>, lo que significa que actúa de proxy con AuthenticationProvider. En Spring, el <strong>AuthenticationProvider es el encargado de validar la combinación nombre de usuario/contraseña por medio del objeto Authentication  y retornar los roles asociados a dicho usuario.</strong> Esta clase tan sólo delega la autenticación en una lista de proveedores configurable, cada uno de los cuales implementa el interfaz AuthenticationProvider. Hay muchos tipos de AuthenticationProvider( JDBC, Hibernate,  LDAP, RememberMe, OpenID). Usted puede indicar cuales quiere usar son los proveedores de autentificación que desee usar, en nuestro caso, <strong>usaremos un DAO Hibernate personalizado</strong>.</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #339933;">&lt;</span>bean id<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;authenticationManager&quot;</span> <span style="color: #000000; font-weight: bold;">class</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;paquete.MiAuthenticationManager&quot;</span><span style="color: #339933;">&gt;</span>
	<span style="color: #339933;">&lt;</span>property name<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;providerString&quot;</span> value<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;userDaoProvider&quot;</span> <span style="color: #339933;">/&gt;</span>
<span style="color: #339933;">&lt;/</span>bean<span style="color: #339933;">&gt;</span></pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> MiAuthenticationManager <span style="color: #000000; font-weight: bold;">extends</span> ProviderManager <span style="color: #009900;">&#123;</span>
<span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #003399;">String</span> providerString<span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> setProviderString<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span> providerString<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">providerString</span> <span style="color: #339933;">=</span> providerString<span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
 <span style="color: #008000; font-style: italic; font-weight: bold;">/**
  * Agrega al Manejador de Proveedores un listado
  */</span> 
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> afterPropertiesSet<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">throws</span> <span style="color: #003399;">Exception</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>providerString <span style="color: #339933;">!=</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>			
			List<span style="color: #339933;">&lt;</span>authenticationprovider<span style="color: #339933;">&gt;</span> providers <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">LinkedList</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #003399;">String</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> names <span style="color: #339933;">=</span> providerString.<span style="color: #006633;">split</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;,&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>	
			<span style="color: #000000; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span> providerUnit <span style="color: #339933;">:</span> names<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
				AuthenticationProvider provider <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>AuthenticationProvider<span style="color: #009900;">&#41;</span> applicationContext
						.<span style="color: #006633;">getBean</span><span style="color: #009900;">&#40;</span>providerUnit.<span style="color: #006633;">trim</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>provider <span style="color: #339933;">==</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
					<span style="color: #000000; font-weight: bold;">throw</span> <span style="color: #000000; font-weight: bold;">new</span> EnMeExpcetion<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;AuthenticationProvider &quot;</span>
							<span style="color: #339933;">+</span> providerUnit <span style="color: #339933;">+</span> <span style="color: #0000ff;">&quot; don't exist&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				<span style="color: #009900;">&#125;</span>				
				providers.<span style="color: #006633;">add</span><span style="color: #009900;">&#40;</span>provider<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #009900;">&#125;</span>
			setProviders<span style="color: #009900;">&#40;</span>providers<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
		<span style="color: #000000; font-weight: bold;">super</span>.<span style="color: #006633;">afterPropertiesSet</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #339933;">&lt;/</span>authenticationprovider<span style="color: #339933;">&gt;</span></pre></div></div>

<h3>DaoAuthenticationProvider </h3>
<p>DaoAuthenticationProvider, es el comúnmente usado puesto que es el que permite acceder a la información almacenada en una base de datos. El proveedor DaoAuthenticationProvider merece una mención especial. Esta implementación delega a su vez en un objeto de tipo <strong>UserDetailsService</strong>, un interfaz que define un objeto de acceso a datos con un único método <strong>loadUserByUsername </strong>que permite obtener la información de un usuario a partir de su nombre de usuario.</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #339933;">&lt;</span>bean id<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;userDaoProvider&quot;</span>
		<span style="color: #000000; font-weight: bold;">class</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;org.springframework.security.providers.dao.DaoAuthenticationProvider&quot;</span><span style="color: #339933;">&gt;</span>
		<span style="color: #339933;">&lt;</span>property name<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;userDetailsService&quot;</span> ref<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;dbUserService&quot;</span> <span style="color: #339933;">/&gt;</span>		
	<span style="color: #339933;">&lt;/</span>bean<span style="color: #339933;">&gt;</span></pre></div></div>

<p>Si deseas agregarle encriptación a la contraseña del usuario, agregale una propiedad más al userDaoProvider, <a href="http://blog.jotadeveloper.com/wp-content/plugins/feed-statistics.php?url=aHR0cDovL2Jsb2cuam90YWRldmVsb3Blci5jb20vMjAwOC8xMS8yOS9lbmNyaXB0YWNpb24tamFweXN0LXNwcmluZy1zZWMtMi8=">este artículo que escribi tiempo atrás te ayudará a poner una mejor seguridad que el tipico MD5</a>. </p>
<h3>UserDetailsService, un Dao Personalizado</h3>
<p>Si no queremos que Spring acceda a la bases de datos directamente podemos configurar un Dao personalizado por medio de una Implementación UserDetailsService, , un interfaz que define un objeto de acceso a datos con un único método loadUserByUsername que permite obtener la información de un usuario a partir de su nombre de usuario.</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;">&nbsp;
<span style="color: #339933;">&lt;</span>bean id<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;dbUserService&quot;</span> <span style="color: #000000; font-weight: bold;">class</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;paquete.MiUserServiceImp&quot;</span><span style="color: #339933;">&gt;</span>
		<span style="color: #339933;">&lt;</span>property name<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;userDao&quot;</span> ref<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;userDao&quot;</span> <span style="color: #339933;">/&gt;</span>		
	<span style="color: #339933;">&lt;/</span>bean<span style="color: #339933;">&gt;</span></pre></div></div>

<p><!-- Un Dao Cualquiera para Hibernate --><br />
<bean id="userDao" class="paquete.dao.UserDaoImp"></p>
<property name="hibernateTemplate">
			<ref bean="hibernateTemplate" />
		</property>
</bean></p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> MiUserServiceImp <span style="color: #000000; font-weight: bold;">implements</span> UserDetailsService <span style="color: #009900;">&#123;</span>
         ......
        <span style="color: #000000; font-weight: bold;">public</span> UserDetails loadUserByUsername<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span> username<span style="color: #009900;">&#41;</span>
			<span style="color: #000000; font-weight: bold;">throws</span> UsernameNotFoundException, DataAccessException <span style="color: #009900;">&#123;</span>		
		SecUsers user <span style="color: #339933;">=</span> userDao.<span style="color: #006633;">getUser</span><span style="color: #009900;">&#40;</span>username<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>user <span style="color: #339933;">==</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			log.<span style="color: #006633;">info</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;no encontrado...&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #000000; font-weight: bold;">throw</span> <span style="color: #000000; font-weight: bold;">new</span> UsernameNotFoundException<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;username&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>		
		<span style="color: #000000; font-weight: bold;">return</span> convertToUserDetails<span style="color: #009900;">&#40;</span>user<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
         ......
&nbsp;
    <span style="color: #000000; font-weight: bold;">protected</span> UserDetails convertToUserDetails<span style="color: #009900;">&#40;</span>SecUsers user<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
         <span style="color: #666666; font-style: italic;">//lista de permisos, </span>
         List<span style="color: #339933;">&lt;</span>string<span style="color: #339933;">&gt;</span> listPermissions <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> ArrayList<span style="color: #339933;">&lt;/</span>string<span style="color: #339933;">&gt;&lt;</span>string<span style="color: #339933;">&gt;</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        ...........
        <span style="color: #006633;">GrantedAuthority</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> authorities <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> GrantedAuthority<span style="color: #009900;">&#91;</span>listPermissions
				.<span style="color: #006633;">size</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
		<span style="color: #000066; font-weight: bold;">int</span> i <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>
		<span style="color: #000000; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span> permission <span style="color: #339933;">:</span> listPermissions<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			authorities<span style="color: #009900;">&#91;</span>i<span style="color: #339933;">++</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> GrantedAuthorityImpl<span style="color: #009900;">&#40;</span>permission.<span style="color: #006633;">trim</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
&nbsp;
		User userDetails <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> User<span style="color: #009900;">&#40;</span>user.<span style="color: #006633;">getUsername</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>, user.<span style="color: #006633;">getPassword</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>,
				user.<span style="color: #006633;">isStatus</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> <span style="color: #000066; font-weight: bold;">null</span> <span style="color: #339933;">?</span> <span style="color: #000066; font-weight: bold;">false</span> <span style="color: #339933;">:</span> user.<span style="color: #006633;">isStatus</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>, <span style="color: #000066; font-weight: bold;">true</span>, 
				<span style="color: #000066; font-weight: bold;">true</span>, 
				<span style="color: #000066; font-weight: bold;">true</span>,
				authorities<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		log.<span style="color: #006633;">info</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;userDetails &quot;</span><span style="color: #339933;">+</span>userDetails<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000000; font-weight: bold;">return</span> userDetails<span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #339933;">&lt;/</span>string<span style="color: #339933;">&gt;</span></pre></div></div>

<p>Vamos a dejar la explicación de los Filtros, para una tercera parte, ya se hizo largo <img src='http://blog.jotadeveloper.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> .</p>
 <img src="http://blog.jotadeveloper.com/wp-content/plugins/feed-statistics.php?view=1&post_id=1649" width="1" height="1" style="display: none;" />]]></content:encoded>
			<wfw:commentRss>http://blog.jotadeveloper.com/2009/05/13/spring-security-2-la-configuracion-a-la-medida-con-dao-hibernate-ii/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Spring Security 2, la configuración a la medida con DAO Hibernate I</title>
		<link>http://blog.jotadeveloper.com/2009/05/11/spring-security-2-hibernate-dao-part/</link>
		<comments>http://blog.jotadeveloper.com/2009/05/11/spring-security-2-hibernate-dao-part/#comments</comments>
		<pubDate>Mon, 11 May 2009 15:38:48 +0000</pubDate>
		<dc:creator>Jota</dc:creator>
				<category><![CDATA[Articulos]]></category>
		<category><![CDATA[filtros]]></category>
		<category><![CDATA[Hibernate]]></category>
		<category><![CDATA[jsf]]></category>
		<category><![CDATA[Seguridad]]></category>
		<category><![CDATA[spring]]></category>
		<category><![CDATA[spring security]]></category>

		<guid isPermaLink="false">http://blog.jotadeveloper.com/?p=1617</guid>
		<description><![CDATA[Uno de los aspectos que toda aplicación debe considerar es la seguridad, entendiendo como tal la necesidad de saber que el usuario es quien dice ser (autenticación), y permitirle acceso sólo a aquellos recursos necesarios (autorización). En un princio el framework  se llamaba Acegi Security e inicio en el 2003, 5 años después en Abril [...]]]></description>
			<content:encoded><![CDATA[<p>Uno de los aspectos que toda aplicación debe considerar es la seguridad, entendiendo como tal la necesidad de saber que el usuario es quien dice ser (autenticación), y permitirle acceso sólo a aquellos recursos necesarios (autorización). En un princio el framework  se llamaba Acegi Security e inicio en el 2003, 5 años después en Abril del 2008 se incorporó al portafolio de Spring Framework como un súbmodulo. Spring trae por defecto ciertas caracteristicas que a la hora de querer integrarlas en nuestros sistemas avanzados no encajan a la perfección y por lo general se necesitan modificaciones a las clases principales.</p>
<p>Anteriormente hemos visto configuraciones mucho más sencillas :</p>
<ul>
<li> <a title=\"Permanent Link to Configuración Spring Security 2.0 con JDBC\" rel=\"bookmark\" href="http://blog.jotadeveloper.com/wp-content/plugins/feed-statistics.php?url=aHR0cDovL2Jsb2cuam90YWRldmVsb3Blci5jb20vMjAwOC8xMS8yMS9jb25maWd1cmFjaW9uLXNwcmluZy1zZWN1cml0eS0yMC1jb24tamRiYy8=">Configuración Spring Security 2.0 con JDBC</a></li>
<li> <a title=\"Permanent Link to Configuración Spring Security 2.04 para LDAP\" rel=\"bookmark\" href="http://blog.jotadeveloper.com/wp-content/plugins/feed-statistics.php?url=aHR0cDovL2Jsb2cuam90YWRldmVsb3Blci5jb20vMjAwOC8xMS8xNy9jb25maWd1cmFjaW9uLXNwcmluZy1zZWN1cml0eS0yMDQtcGFyYS1sZGFwLw==">Configuración Spring Security 2.04 para LDAP</a></li>
<li> <a title=\"Permanent Link to La Seguridad Perfecta con Spring y el dropDownMenu de RichFaces\" rel=\"bookmark\" href="http://blog.jotadeveloper.com/wp-content/plugins/feed-statistics.php?url=aHR0cDovL2Jsb2cuam90YWRldmVsb3Blci5jb20vMjAwOC8xMi8wNy9sYS1zZWd1cmlkYWQtcGVyZmVjdGEtY29uLXNwcmluZy15LWVsLWRyb3Bkb3dubWVudS1kZS1yaWNoZmFjZXMv">La Seguridad Perfecta con Spring y el dropDownMenu de RichFaces</a></li>
</ul>
<p>Creo que una de las configuraciones más complejas es fusionando con el framework Hibernate y esto nos permite no anclarnos a las tablas que ya Spring Security trae por defecto, asi poder personalizar nuestra seguridad de una mejor manera.</p>
<p><a href="http://blog.jotadeveloper.com/wp-content/plugins/feed-statistics.php?url=aHR0cDovL2Jsb2cuam90YWRldmVsb3Blci5jb20vd3AtY29udGVudC91cGxvYWRzLzIwMDkvMDUvdW1sLnBuZw=="><img class="size-full wp-image-1625 alignnone" title="uml" src="http://blog.jotadeveloper.com/wp-content/uploads/2009/05/uml.png" alt="uml" width="520" height="326" /></a></p>
<p>En nuestro caso vamos a trabajar con Spring Framework, y lo ideal es separar nuestra aplicación en 3 capas:</p>
<ul>
<li><strong>Capa de Presentación: </strong>En esta capa vamos a programar el formulario, el típico formulario con el nombre de usuario y la contraseña, podemos integrar OPEN ID, e incluso la funcionalidad de Recordar la Sessión por medio de un Cookie.</li>
<li><strong>Filtros de Seguridad: </strong>Aqui aplicaremos toda la configuración de Spring Security, aplicaremos todos los filtros y las clases que vamos a modificar algunas clases de Spring que se comuniquen con nuestros servicios en la capa de negocio.</li>
<li><strong>Servicios en la Capa de Negocio</strong>: En esta capa colocaremos nuestros Beans de Spring que a su vez acceden a otra capa en la cual no vamos a entrar en detalle, la de acceso a datos.</li>
</ul>
<p>Iniciemos con la capa de presentación y el formulario para logearse, en su forma más sencilla, aqui se pueden agregar validadores y mensajes de error, etc.</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;">	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;h</span> :inputText <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;j_username&quot;</span>  <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;#{loginForm.userName}&quot;</span> <span style="color: #000066;">size</span>=<span style="color: #ff0000;">&quot;40&quot;</span> <span style="color: #000066;">required</span>=<span style="color: #ff0000;">&quot;true&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;h</span> :inputSecret <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;j_password&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;#{loginForm.userPassword}&quot;</span> <span style="color: #000066;">size</span>=<span style="color: #ff0000;">&quot;40&quot;</span> <span style="color: #000066;">required</span>=<span style="color: #ff0000;">&quot;true&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;h</span> :commandButton <span style="color: #000066;">action</span>=<span style="color: #ff0000;">&quot;#{loginForm.login}&quot;</span>  <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;Iniciar Sesión&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span></pre></div></div>

<p>Ahora necesitamos nuestro Bean LoginForm, este puedes colocarlo como un ManageBean o un Bean de Spring, como mas te parezca, en mi caso use Spring.</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> LoginForm<span style="color: #009900;">&#123;</span>
&nbsp;
        <span style="color: #666666; font-style: italic;">//Bean Personalizado del Manejador de Autentificación</span>
	<span style="color: #000000; font-weight: bold;">private</span> AuthenticationManager authenticationManager<span style="color: #339933;">;</span>
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #003399;">String</span> userName<span style="color: #339933;">;</span>
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #003399;">String</span> userPassword<span style="color: #339933;">;</span>
	<span style="color: #000000; font-weight: bold;">private</span> Application app<span style="color: #339933;">;</span>
&nbsp;
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #003399;">String</span> getUserName<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">return</span> userName<span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> setUserName<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span> userName<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">userName</span> <span style="color: #339933;">=</span> userName<span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #003399;">String</span> getUserPassword<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">return</span> userPassword<span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> setUserPassword<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span> userPassword<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">userPassword</span> <span style="color: #339933;">=</span> userPassword<span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> AuthenticationManager getAuthenticationManager<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">return</span> authenticationManager<span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> setAuthenticationManager<span style="color: #009900;">&#40;</span>
			AuthenticationManager authenticationManager<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">authenticationManager</span> <span style="color: #339933;">=</span> authenticationManager<span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #008000; font-style: italic; font-weight: bold;">/**
	 * 
&nbsp;
	/**
	 * Ejecuta un envio a un url definido por la navegación JSF
	 * @param viewId
	 */</span>
	<span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #000066; font-weight: bold;">void</span> forward<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span> viewId<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    	ViewHandler viewHandler <span style="color: #339933;">=</span> getApplication<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">getViewHandler</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	    FacesContext facesCtx <span style="color: #339933;">=</span> getFacesContext<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	    UIViewRoot view <span style="color: #339933;">=</span> viewHandler.<span style="color: #006633;">createView</span><span style="color: #009900;">&#40;</span>facesCtx, viewId<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	    facesCtx.<span style="color: #006633;">setViewRoot</span><span style="color: #009900;">&#40;</span>view<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	    facesCtx.<span style="color: #006633;">renderResponse</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #008000; font-style: italic; font-weight: bold;">/**
	 * Obtiene el contexto de la Aplicación
	 * @return
	 */</span>
	<span style="color: #000000; font-weight: bold;">protected</span> Application getApplication<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>app <span style="color: #339933;">==</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			ApplicationFactory appFactory <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>ApplicationFactory<span style="color: #009900;">&#41;</span> FactoryFinder.<span style="color: #006633;">getFactory</span><span style="color: #009900;">&#40;</span>FactoryFinder.<span style="color: #006633;">APPLICATION_FACTORY</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	        app <span style="color: #339933;">=</span> appFactory.<span style="color: #006633;">getApplication</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span> 
		<span style="color: #000000; font-weight: bold;">return</span> app<span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #008000; font-style: italic; font-weight: bold;">/**
	 * Obtiene el Contexto de JSF
	 * @return
	 */</span>
	<span style="color: #000000; font-weight: bold;">protected</span> FacesContext getFacesContext<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">return</span> FacesContext.<span style="color: #006633;">getCurrentInstance</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #008000; font-style: italic; font-weight: bold;">/**
	 * Obtiene la Petición del HttpServletRequest
	 * @return
	 */</span>
	<span style="color: #000000; font-weight: bold;">protected</span> HttpServletRequest getRequest<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		ExternalContext context <span style="color: #339933;">=</span> 
			FacesContext.<span style="color: #006633;">getCurrentInstance</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">getExternalContext</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	    HttpServletRequest request <span style="color: #339933;">=</span> 
	    	<span style="color: #009900;">&#40;</span>HttpServletRequest<span style="color: #009900;">&#41;</span> context.<span style="color: #006633;">getRequest</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>	    
	    <span style="color: #000000; font-weight: bold;">return</span> request<span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #008000; font-style: italic; font-weight: bold;">/**
	 * Obtiene la Respuesta del HttpServletResponse	
	 * @return
	 */</span>
	<span style="color: #000000; font-weight: bold;">protected</span> HttpServletResponse getResponse<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		ExternalContext context <span style="color: #339933;">=</span> 
			FacesContext.<span style="color: #006633;">getCurrentInstance</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">getExternalContext</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		HttpServletResponse response <span style="color: #339933;">=</span> 
	    	<span style="color: #009900;">&#40;</span>HttpServletResponse<span style="color: #009900;">&#41;</span> context.<span style="color: #006633;">getResponse</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	    <span style="color: #000000; font-weight: bold;">return</span> response<span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #003399;">String</span> login<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		HttpServletRequest request <span style="color: #339933;">=</span> getRequest<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	    <span style="color: #000000; font-weight: bold;">try</span> <span style="color: #009900;">&#123;</span>
&nbsp;
&nbsp;
               <span style="color: #008000; font-style: italic; font-weight: bold;">/**
                 * Obtenemos del Formulario los Datos, por mayor seguridad podriamos agregar filtros contra XSS e Inyección HQL
                 * Creamos un token para Spring
                 */</span>
	    	<span style="color: #003399;">String</span> userName <span style="color: #339933;">=</span> getUserName<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	    	<span style="color: #003399;">String</span> password <span style="color: #339933;">=</span> getUserPassword<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	    	<span style="color: #008000; font-style: italic; font-weight: bold;">/**
                 * Creamos un token para Spring
                 */</span>
	    	UsernamePasswordAuthenticationToken authReq <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> UsernamePasswordAuthenticationToken<span style="color: #009900;">&#40;</span>userName, password<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
               <span style="color: #008000; font-style: italic; font-weight: bold;">/**
                 * Le agregamos al token el request de HttpServletRequest
                 */</span>
	    	authReq.<span style="color: #006633;">setDetails</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> WebAuthenticationDetails<span style="color: #009900;">&#40;</span>request<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>			    	
	    	HttpSession session <span style="color: #339933;">=</span> request.<span style="color: #006633;">getSession</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
&nbsp;
               <span style="color: #008000; font-style: italic; font-weight: bold;">/**
                 * Asignamos la sesión el atributo UserName
                 * Obtenemos el manager auth y le asignamos el token
                 */</span>
	    	session.<span style="color: #006633;">setAttribute</span><span style="color: #009900;">&#40;</span>AuthenticationProcessingFilter.<span style="color: #006633;">SPRING_SECURITY_LAST_USERNAME_KEY</span>, userName<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	    	Authentication auth <span style="color: #339933;">=</span> getAuthenticationManager<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">authenticate</span><span style="color: #009900;">&#40;</span>authReq<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>	    	
&nbsp;
                  <span style="color: #008000; font-style: italic; font-weight: bold;">/**
                 * Obtenemos el Contexto de Spring Security
                 * Le asignamos el Autentication Manager al Contexto de Seguridad
                 */</span>	
&nbsp;
	    	SecurityContext secCtx <span style="color: #339933;">=</span> SecurityContextHolder.<span style="color: #006633;">getContext</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>	    	
	    	secCtx.<span style="color: #006633;">setAuthentication</span><span style="color: #009900;">&#40;</span>auth<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	    	session.<span style="color: #006633;">setAttribute</span><span style="color: #009900;">&#40;</span>HttpSessionContextIntegrationFilter.<span style="color: #006633;">SPRING_SECURITY_CONTEXT_KEY</span>, secCtx<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>   			    	
&nbsp;
	    	<span style="color: #003399;">String</span> urlKey <span style="color: #339933;">=</span> AbstractProcessingFilter.<span style="color: #006633;">SPRING_SECURITY_SAVED_REQUEST_KEY</span><span style="color: #339933;">;</span>	   
	    	SavedRequest savedRequest <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>SavedRequest<span style="color: #009900;">&#41;</span>session.<span style="color: #006633;">getAttribute</span><span style="color: #009900;">&#40;</span>urlKey<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	    	session.<span style="color: #006633;">removeAttribute</span><span style="color: #009900;">&#40;</span>urlKey<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	    	<span style="color: #003399;">String</span> target <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;/index.jsf&quot;</span><span style="color: #339933;">;</span>
	    	<span style="color: #008000; font-style: italic; font-weight: bold;">/**
                  * Si perdiste la sesión en una página en particular, este parametro te ayudara a regresar a donde perdiste la sesión
                 */</span>
	    	<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>savedRequest <span style="color: #339933;">!=</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>	    		
		    	<span style="color: #003399;">String</span> targetUrl <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #339933;">;</span>
	    		targetUrl <span style="color: #339933;">=</span> savedRequest.<span style="color: #006633;">getFullRequestUrl</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>	    		
	    		FacesContext.<span style="color: #006633;">getCurrentInstance</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">getExternalContext</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">redirect</span><span style="color: #009900;">&#40;</span>targetUrl<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>	    		
	    		<span style="color: #000000; font-weight: bold;">return</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #339933;">;</span>	    		
	    	<span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">else</span> <span style="color: #009900;">&#123;</span>
	    		.................		  
	    	<span style="color: #009900;">&#125;</span>
	    	<span style="color: #008000; font-style: italic; font-weight: bold;">/**
                 * Si no existiera un SavedRequest, entonces te enviaria a la pagina de inicio
                  */</span>
	    	forward<span style="color: #009900;">&#40;</span>target<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	    <span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">catch</span> <span style="color: #009900;">&#40;</span>BadCredentialsException e<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	    	...............	    	
	    	<span style="color: #000000; font-weight: bold;">return</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #339933;">;</span>
	    <span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">catch</span> <span style="color: #009900;">&#40;</span><span style="color: #003399;">AuthenticationException</span> e<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	    	............
	    	<span style="color: #000000; font-weight: bold;">return</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #339933;">;</span>
	    <span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">catch</span> <span style="color: #009900;">&#40;</span><span style="color: #003399;">IOException</span> ioException<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	       ..............
	    <span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">return</span> <span style="color: #0000ff;">&quot;index&quot;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>	
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Y como lo vamos a integrar con Spring, la declaración del Bean en el contexto</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;">   <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;bean</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;loginForm&quot;</span> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;org.xxx.LoginForm&quot;</span> <span style="color: #000066;">scope</span>=<span style="color: #ff0000;">&quot;request&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;authenticationManager&quot;</span> <span style="color: #000066;">ref</span>=<span style="color: #ff0000;">&quot;authenticationManager&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/bean<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>En la <a href="http://blog.jotadeveloper.com/wp-content/plugins/feed-statistics.php?url=aHR0cDovL2Jsb2cuam90YWRldmVsb3Blci5jb20vMjAwOS8wNS8xMy9zcHJpbmctc2VjdXJpdHktMi1sYS1jb25maWd1cmFjaW9uLWEtbGEtbWVkaWRhLWNvbi1kYW8taGliZXJuYXRlLWlpLw==">parte II miraremos los Filtros de Seguridad.</a></p>
 <img src="http://blog.jotadeveloper.com/wp-content/plugins/feed-statistics.php?view=1&post_id=1617" width="1" height="1" style="display: none;" />]]></content:encoded>
			<wfw:commentRss>http://blog.jotadeveloper.com/2009/05/11/spring-security-2-hibernate-dao-part/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>La Seguridad Perfecta con Spring y el dropDownMenu de RichFaces</title>
		<link>http://blog.jotadeveloper.com/2008/12/07/la-seguridad-perfecta-con-spring-y-el-dropdownmenu-de-richfaces/</link>
		<comments>http://blog.jotadeveloper.com/2008/12/07/la-seguridad-perfecta-con-spring-y-el-dropdownmenu-de-richfaces/#comments</comments>
		<pubDate>Sun, 07 Dec 2008 13:04:17 +0000</pubDate>
		<dc:creator>Jota</dc:creator>
				<category><![CDATA[Articulos]]></category>
		<category><![CDATA[Ajax]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[jbug]]></category>
		<category><![CDATA[RichFaces]]></category>
		<category><![CDATA[spring]]></category>
		<category><![CDATA[spring security]]></category>

		<guid isPermaLink="false">http://blog.jotadeveloper.com/?p=1088</guid>
		<description><![CDATA[Bueno, sigo con la seguridad de Spring 2.0 o el conocido como el antiguo Acegi Security, ahora voy a proponer una alternativa para generar una seguridad con un componente de RichFaces, el dropDownMenu. ToolBar y menuItem.
Primero te recomiendo sigas la configuración de Spring con JDBC, o con LDAP, como tu lo desees, porque de todas [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://blog.jotadeveloper.com/wp-content/plugins/feed-statistics.php?url=aHR0cDovL2Jsb2cuam90YWRldmVsb3Blci5jb20vd3AtY29udGVudC91cGxvYWRzLzIwMDgvMTIvZHJvcGRvd25tZW51LmpwZw=="><img class="alignleft size-full wp-image-1089" style="margin: 6px;" title="dropdownmenu" src="http://blog.jotadeveloper.com/wp-content/uploads/2008/12/dropdownmenu.jpg" alt="" width="143" height="115" /></a>Bueno, sigo con la seguridad de Spring 2.0 o el conocido como el antiguo Acegi Security, ahora voy a proponer una alternativa para generar una seguridad con un componente de <strong>RichFaces, el dropDownMenu. ToolBar y menuItem</strong>.</p>
<p>Primero te recomiendo sigas <a href="http://blog.jotadeveloper.com/wp-content/plugins/feed-statistics.php?url=aHR0cDovL2Jsb2cuam90YWRldmVsb3Blci5jb20vMjAwOC8xMS8yMS9jb25maWd1cmFjaW9uLXNwcmluZy1zZWN1cml0eS0yMC1jb24tamRiYy8=">la configuración de Spring con JDBC</a>, o con <a href="http://blog.jotadeveloper.com/wp-content/plugins/feed-statistics.php?url=aHR0cDovL2Jsb2cuam90YWRldmVsb3Blci5jb20vMjAwOC8xMS8xNy9jb25maWd1cmFjaW9uLXNwcmluZy1zZWN1cml0eS0yMDQtcGFyYS1sZGFwLw==">LDAP</a>, como tu lo desees, porque de todas formas todos los Roles ( o Permisos) quedan almacenados en la misma variable de Spring. También <a href="http://blog.jotadeveloper.com/wp-content/plugins/feed-statistics.php?url=aHR0cDovL2Jsb2cuam90YWRldmVsb3Blci5jb20vMjAwOC8xMC8yMC9pbnRlZ3JhbmRvLWpzZi1mYWNlbGV0cy1zcHJpbmctc2VjdXJpdHktMjAv">si deseas integrarlo con Facelest, aqui tenes los pasos a seguir</a>.</p>
<p>Lo <strong>primero</strong> que hay que hacer, es construir el menú, para eso usamos un Tool Bar:</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;rich:toolBar<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;rich:dropDownMenu</span> <span style="color: #000000; font-weight: bold;">&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;f:facet</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;label&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;h:panelGroup<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;h:graphicImage</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;#{initParam['rootimages']}/images/icons/contexthelp.png&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;h:outputText</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;JotaDeveloper&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/h:panelGroup<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/f:facet<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;rich:menuItem</span> <span style="color: #000066;">submitMode</span>=<span style="color: #ff0000;">&quot;ajax&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;Articulos&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span><span style="color: #000000; font-weight: bold;">&lt;/rich:menuItem<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;rich:menuItem</span> <span style="color: #000066;">submitMode</span>=<span style="color: #ff0000;">&quot;ajax&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;Tutoriales&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span><span style="color: #000000; font-weight: bold;">&lt;/rich:menuItem<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;rich:menuItem</span> <span style="color: #000066;">submitMode</span>=<span style="color: #ff0000;">&quot;ajax&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;Ayuda&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span><span style="color: #000000; font-weight: bold;">&lt;/rich:menuItem<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/rich:dropDownMenu<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/rich:toolBar<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>El código es bien sencillo, no hace falta explicar mucho, solo que para poder colocar un dropDownMenu , es necesario el toolBar, y para el menuItem , debe estar dentro de un dropDownMenu.</p>
<p>Depues de esto, y <strong>espero que hayas leido los 3 articulos que sugerí anteriormente</strong>, vamos a crear un Bean, donde tendremos la logica de nuestra seguridad con el dropDownMenu.</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.util.ArrayList</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.util.Date</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.util.List</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.commons.logging.Log</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.commons.logging.LogFactory</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.springframework.security.Authentication</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.springframework.security.GrantedAuthority</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.springframework.security.context.SecurityContext</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.springframework.security.context.SecurityContextHolder</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.springframework.security.ui.WebAuthenticationDetails</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> JotaDeveloperMenuBean <span style="color: #009900;">&#123;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">// Un objeto Booleano por cada elemento del Menu</span>
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #003399;">Boolean</span> rootJotaDeveloper<span style="color: #339933;">;</span>
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #003399;">Boolean</span> rootTutoriales<span style="color: #339933;">;</span>
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #003399;">Boolean</span> rootArticulos<span style="color: #339933;">;</span>
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #003399;">Boolean</span> rootAyuda<span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">// Objetos Spring Security</span>
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #003399;">Object</span> seguridadAcegi<span style="color: #339933;">;</span>
	<span style="color: #666666; font-style: italic;">// El GrantedAuthority es un Array con todos los Roles que recupera de la BD</span>
	<span style="color: #000000; font-weight: bold;">private</span> GrantedAuthority<span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> listaAutoridades<span style="color: #339933;">;</span>
	<span style="color: #000000; font-weight: bold;">private</span> SecurityContext contexto<span style="color: #339933;">;</span>
	<span style="color: #000000; font-weight: bold;">private</span> Authentication autenticacion<span style="color: #339933;">;</span>
	<span style="color: #000000; font-weight: bold;">private</span> List<span style="color: #339933;">&lt;</span>String<span style="color: #339933;">&gt;</span> ListAutoridades <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> ArrayList<span style="color: #339933;">&lt;</span>String<span style="color: #339933;">&gt;</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #003399;">String</span> nombreUsuario<span style="color: #339933;">;</span>
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #003399;">Boolean</span> estaAutenticado<span style="color: #339933;">;</span>
	<span style="color: #000000; font-weight: bold;">private</span> WebAuthenticationDetails webAu<span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #008000; font-style: italic; font-weight: bold;">/**
	 * Constructor que accede a toda la información de Spring Security
	 */</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> JotaDeveloperMenuBean<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">seguridadAcegi</span> <span style="color: #339933;">=</span> SecurityContextHolder.<span style="color: #006633;">getContext</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
				.<span style="color: #006633;">getAuthentication</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">getPrincipal</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">contexto</span> <span style="color: #339933;">=</span> SecurityContextHolder.<span style="color: #006633;">getContext</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">autenticacion</span> <span style="color: #339933;">=</span> SecurityContextHolder.<span style="color: #006633;">getContext</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
				.<span style="color: #006633;">getAuthentication</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">listaAutoridades</span> <span style="color: #339933;">=</span> SecurityContextHolder.<span style="color: #006633;">getContext</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
				.<span style="color: #006633;">getAuthentication</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">getAuthorities</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		convertirArrayAuthoritiesToListAuthorities<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">nombreUsuario</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">autenticacion</span>.<span style="color: #006633;">getName</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">estaAutenticado</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">autenticacion</span>.<span style="color: #006633;">isAuthenticated</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #008000; font-style: italic; font-weight: bold;">/**
	 * Este metodo convierte el Array de Roles poco manejable en un List
	 */</span>
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000066; font-weight: bold;">void</span> convertirArrayAuthoritiesToListAuthorities<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000066; font-weight: bold;">int</span> it_cont<span style="color: #339933;">;</span>
		<span style="color: #000000; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span>it_cont <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span> it_cont <span style="color: #339933;">&lt;</span> listaAutoridades.<span style="color: #006633;">length</span><span style="color: #339933;">;</span> it_cont<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #003399;">String</span> ROL <span style="color: #339933;">=</span> listaAutoridades<span style="color: #009900;">&#91;</span>it_cont<span style="color: #009900;">&#93;</span>.<span style="color: #006633;">toString</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			ListAutoridades.<span style="color: #006633;">add</span><span style="color: #009900;">&#40;</span>ROL<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #008000; font-style: italic; font-weight: bold;">/**
	 * Comprueba si existe determinado Rol en la Lista de Autoridades del
	 * Usuario Logeado
	 * 
	 * @param cadena
	 *            ROL
	 * @return El resultado de la Busqueda
	 */</span>
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #003399;">Boolean</span> comprobarRol<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span> cadena<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #003399;">Integer</span> id <span style="color: #339933;">=</span> ListAutoridades.<span style="color: #006633;">indexOf</span><span style="color: #009900;">&#40;</span>cadena<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #666666; font-style: italic;">// Si el Id es -1, el valor no fue encontrado.</span>
		<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>id <span style="color: #339933;">!=</span> <span style="color: #339933;">-</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #000000; font-weight: bold;">return</span> <span style="color: #000066; font-weight: bold;">false</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">else</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #000000; font-weight: bold;">return</span> <span style="color: #000066; font-weight: bold;">true</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #008000; font-style: italic; font-weight: bold;">/**
	 * Los Getters que va leer cada elemento del Menu
	 */</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #003399;">Boolean</span> getRootJotaDeveloper<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">return</span> rootJotaDeveloper <span style="color: #339933;">=</span> comprobarRol<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;ROLE_ROOT_JOTADEVELOPER&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #003399;">Boolean</span> getRootTutoriales<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">return</span> rootTutoriales <span style="color: #339933;">=</span> comprobarRol<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;ROLE_ROOT_TUTORIALES&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #003399;">Boolean</span> getRootAyuda<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">return</span> rootArticulos <span style="color: #339933;">=</span> comprobarRol<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;ROLE_ROOT_AYUDA&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #003399;">Boolean</span> getRootArticulos<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">return</span> rootAyuda <span style="color: #339933;">=</span> comprobarRol<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;ROLE_ROOT_ARTICULOS&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Despues de esto y <strong>incluir el Bean el el ManageBean de faces-config.xml</strong>, solo agregamos a la propiedad disabled del MenuItem el get del Bean.</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;rich:toolBar<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;acegijsf:authorize</span> <span style="color: #000066;">ifAllGranted</span>=<span style="color: #ff0000;">&quot;ROLE_ROOT_JOTADEVELOPER&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;rich:dropDownMenu</span> <span style="color: #000000; font-weight: bold;">&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;f:facet</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;label&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;h:panelGroup<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;h:graphicImage</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;#{initParam['rootimages']}/images/icons/contexthelp.png&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;h:outputText</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;JotaDeveloper&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/h:panelGroup<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/f:facet<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;rich:menuItem</span> <span style="color: #000066;">submitMode</span>=<span style="color: #ff0000;">&quot;ajax&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;Articulos&quot;</span> <span style="color: #000066;">disabled</span>=<span style="color: #ff0000;">&quot;#{jotaDeveloperMenuBean.rootArticulos}&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span><span style="color: #000000; font-weight: bold;">&lt;/rich:menuItem<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;rich:menuItem</span> <span style="color: #000066;">submitMode</span>=<span style="color: #ff0000;">&quot;ajax&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;Tutoriales&quot;</span> <span style="color: #000066;">disabled</span>=<span style="color: #ff0000;">&quot;#{jotaDeveloperMenuBean.rootTutoriales}&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span><span style="color: #000000; font-weight: bold;">&lt;/rich:menuItem<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;rich:menuItem</span> <span style="color: #000066;">submitMode</span>=<span style="color: #ff0000;">&quot;ajax&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;Ayuda&quot;</span> <span style="color: #000066;">disabled</span>=<span style="color: #ff0000;">&quot;#{jotaDeveloperMenuBean.rootAyuda}&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span><span style="color: #000000; font-weight: bold;">&lt;/rich:menuItem<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/rich:dropDownMenu<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/acegijsf:authorize<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/rich:toolBar<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>El <strong>resultado </strong>de todo esto, es que cuando inices sesión, el GrantedAuthority que genera en la sesión del usuario Spring Security, lo convertimos en un List, luego cada elemente del menu que tu crees, va preguntarle al List si existe, si Existe, regresa <strong>True</strong>, sino, <strong>False</strong>, y apareceran los menus cuales el usuario no tenga permiso desactivados, ademas de eso, no podra acceder via URL, si has configurado correctamente el security.xml del Spring Security.</p>
 <img src="http://blog.jotadeveloper.com/wp-content/plugins/feed-statistics.php?view=1&post_id=1088" width="1" height="1" style="display: none;" />]]></content:encoded>
			<wfw:commentRss>http://blog.jotadeveloper.com/2008/12/07/la-seguridad-perfecta-con-spring-y-el-dropdownmenu-de-richfaces/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Encriptación de Contraseñas con Jasypt y Spring Security 2</title>
		<link>http://blog.jotadeveloper.com/2008/11/29/encriptacion-japyst-spring-sec-2/</link>
		<comments>http://blog.jotadeveloper.com/2008/11/29/encriptacion-japyst-spring-sec-2/#comments</comments>
		<pubDate>Sat, 29 Nov 2008 04:24:34 +0000</pubDate>
		<dc:creator>Jota</dc:creator>
				<category><![CDATA[Articulos]]></category>
		<category><![CDATA[encriptacion]]></category>
		<category><![CDATA[MD5]]></category>
		<category><![CDATA[Seguridad]]></category>
		<category><![CDATA[SHA-1]]></category>
		<category><![CDATA[spring]]></category>
		<category><![CDATA[spring security]]></category>

		<guid isPermaLink="false">http://blog.jotadeveloper.com/?p=1071</guid>
		<description><![CDATA[Continuando el artículo anterior, vamos hacer uso de una libreria muy poderosa de la familia Apache, se llama, Jasypt y la puedes encontrar aqui. Esta herramienta que se integra perfectamente con Spring Security 2.0 y con Hibernate, pero en este ejemplo, no la voy a integrar aun con Hibernate.
Puedes encriptar contraseñas con MD5, SHA-1 y personalizar tu [...]]]></description>
			<content:encoded><![CDATA[<p>Continuando el <a href="http://blog.jotadeveloper.com/wp-content/plugins/feed-statistics.php?url=aHR0cDovL2Jsb2cuam90YWRldmVsb3Blci5jb20vMjAwOC8xMS8yMS9jb25maWd1cmFjaW9uLXNwcmluZy1zZWN1cml0eS0yMC1jb24tamRiYy8=">artículo anterior</a>, vamos hacer uso de una libreria muy poderosa de la familia Apache, se llama, <strong>Jasypt </strong>y la puedes encontrar <a href="http://blog.jotadeveloper.com/wp-content/plugins/feed-statistics.php?url=aHR0cDovL3d3dy5qYXN5cHQub3JnLw==" target=\"_blank\">aqui</a>. Esta herramienta que se integra perfectamente con Spring Security 2.0 y con Hibernate, pero en este ejemplo, no la voy a integrar aun con Hibernate.</p>
<p>Puedes encriptar contraseñas con <strong>MD5, SHA-1</strong> y personalizar tu encriptación, solo voy a tocar los temas mas sencillos.</p>
<p>Para iniciar un ejemplo de código para cada una de estas dos formas de encriptar una contraseña, claro, puede encriptar lo que necesites, en mi caso, para hacerlo compatible con <strong>Spring</strong>, el password.</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;">&nbsp;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.jasypt.util.digest.Digester</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.jasypt.util.password.BasicPasswordEncryptor</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.jasypt.util.password.ConfigurablePasswordEncryptor</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.jasypt.util.password.StrongPasswordEncryptor</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">//Para una encriptacion sencilla en MD5</span>
BasicPasswordEncryptor passwordEncryptor <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> BasicPasswordEncryptor<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #003399;">String</span> encryptedPassword <span style="color: #339933;">=</span> passwordEncryptor.<span style="color: #006633;">encryptPassword</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;jotadeveloper&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">//Para una encriptacion mas fuerte en SHA-1</span>
StrongPasswordEncryptor passwordEncryptor2 <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> StrongPasswordEncryptor<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #003399;">String</span> encryptedPassword2 <span style="color: #339933;">=</span> passwordEncryptor2.<span style="color: #006633;">encryptPassword</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;jotadeveloper&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">//Para una encriptación Personalizada</span>
<span style="color: #666666; font-style: italic;">//SHA1</span>
ConfigurablePasswordEncryptor passwordEncryptor3 <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> ConfigurablePasswordEncryptor<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
passwordEncryptor3.<span style="color: #006633;">setAlgorithm</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;SHA-1&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
passwordEncryptor3.<span style="color: #006633;">setPlainDigest</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #003399;">String</span> encryptedPassword3 <span style="color: #339933;">=</span> passwordEncryptor3.<span style="color: #006633;">encryptPassword</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;jotadeveloper&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">//MD5</span>
ConfigurablePasswordEncryptor passwordEncryptor4 <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> ConfigurablePasswordEncryptor<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
passwordEncryptor4.<span style="color: #006633;">setAlgorithm</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;MD5&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
passwordEncryptor4.<span style="color: #006633;">setPlainDigest</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #003399;">String</span> encryptedPassword4 <span style="color: #339933;">=</span> passwordEncryptor4.<span style="color: #006633;">encryptPassword</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;jotadeveloper&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Una vez has creado tu clase con al encriptación deseada, es tan sencillo como usar las funciones de arriba y guardarlo donde quieras y como quieras.<br />
Ahora la configuración en tu security.xml de <strong>Spring Security 2.0</strong>
</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;">//En mi caso, seleccione StrongPasswordEncryptor porque voy a usar encriptacion SHA-1
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;beans:bean</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;jasyptPasswordEncryptor&quot;</span></span>
<span style="color: #009900;">		<span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;org.jasypt.util.password.StrongPasswordEncryptor&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
&nbsp;
//
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;beans:bean</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;passwordEncoder&quot;</span> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;org.jasypt.spring.security2.PasswordEncoder&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;beans:property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;passwordEncryptor&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
			<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;beans:ref</span> <span style="color: #000066;">bean</span>=<span style="color: #ff0000;">&quot;jasyptPasswordEncryptor&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/beans:property<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/beans:bean<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;authentication-provider</span> <span style="color: #000066;">user-service-ref</span>=<span style="color: #ff0000;">&quot;userService&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;password-encoder</span> <span style="color: #000066;">ref</span>=<span style="color: #ff0000;">&quot;passwordEncoder&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/password-encoder<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>El código anterior, lo agregas al mismo codigo del articulo anterior y listo. </p>
 <img src="http://blog.jotadeveloper.com/wp-content/plugins/feed-statistics.php?view=1&post_id=1071" width="1" height="1" style="display: none;" />]]></content:encoded>
			<wfw:commentRss>http://blog.jotadeveloper.com/2008/11/29/encriptacion-japyst-spring-sec-2/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Configuración Spring Security 2.0 con JDBC</title>
		<link>http://blog.jotadeveloper.com/2008/11/21/configuracion-spring-security-20-con-jdbc/</link>
		<comments>http://blog.jotadeveloper.com/2008/11/21/configuracion-spring-security-20-con-jdbc/#comments</comments>
		<pubDate>Fri, 21 Nov 2008 13:00:05 +0000</pubDate>
		<dc:creator>Jota</dc:creator>
				<category><![CDATA[Articulos]]></category>
		<category><![CDATA[acegi]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[jdbc]]></category>
		<category><![CDATA[spring]]></category>
		<category><![CDATA[spring security]]></category>

		<guid isPermaLink="false">http://blog.jotadeveloper.com/?p=1058</guid>
		<description><![CDATA[Esta configuración funciona perfectamente, con Spring Security 2.0 y JDBC, despues de varios dias probando configuraciones diferentes, puedo concluir dos cosas, que la versión de Spring  Security tiene un bug en su versión 2.0.8.
Yo usé mis propias tablas, pero para los nuevos, pueden usar las que trae por defecto programadas, las que estan aabajo [...]]]></description>
			<content:encoded><![CDATA[<p>Esta configuración funciona perfectamente, con Spring Security 2.0 y JDBC, despues de varios dias probando configuraciones diferentes, puedo concluir dos cosas, que la versión de Spring  Security tiene un bug en su versión 2.0.8.</p>
<p>Yo usé mis propias tablas, pero para los nuevos, pueden usar las que trae por defecto programadas, las que estan aabajo de este artículo, yo cree unas similares, pero en mi caso necesitaba otras moficiaciones, tablas con mas columnas para mi aplicación. El problema, es que si tu usar la nueva caracteristica de esta versión <strong>group-authorities-by-username-query</strong>  vas a tener un problema, pues aunque pongas tu propia configuración necesitas tener las tablas de <strong>groups,group_authorities y group_members</strong> en tu base de datos, aunque no estén siendo usadas, porque sinó, no te funcionará. Abajo les dejo la configuración que usé.</p>
<p><strong>En el web.xml</strong></p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;context-param<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;param-name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>contextConfigLocation<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/param-name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;param-value<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>/WEB-INF/applicationContext-security.xml<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/param-value<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/context-param<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;filter<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;filter-name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>springSecurityFilterChain<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/filter-name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;filter-class<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>org.springframework.web.filter.DelegatingFilterProxy<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/filter-class<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/filter<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;filter-mapping<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;filter-name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>springSecurityFilterChain<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/filter-name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;url-pattern<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>/*<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/url-pattern<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/filter-mapping<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;filter-mapping<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p><strong>applicationContext-security.xml</strong></p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;">&nbsp;
   <span style="color: #808080; font-style: italic;">&lt;!--  CONFIGURACION VALIDA PARA SPRING SECURITY 2.0 con JDBC </span>
<span style="color: #808080; font-style: italic;">          Author: www.jotadeveloper.com</span>
<span style="color: #808080; font-style: italic;">           http://blog.jotadeveloper.com/2008/11/21/configuracion-spring-security-20-con-jdbc/</span>
<span style="color: #808080; font-style: italic;"> --&gt;</span> 
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;?xml</span> <span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span> <span style="color: #000066;">encoding</span>=<span style="color: #ff0000;">&quot;UTF-8&quot;</span><span style="color: #000000; font-weight: bold;">?&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;beans:beans</span> <span style="color: #000066;">xmlns</span>=<span style="color: #ff0000;">&quot;http://www.springframework.org/schema/security&quot;</span></span>
<span style="color: #009900;">	<span style="color: #000066;">xmlns:beans</span>=<span style="color: #ff0000;">&quot;http://www.springframework.org/schema/beans&quot;</span> </span>
<span style="color: #009900;">	<span style="color: #000066;">xmlns:xsi</span>=<span style="color: #ff0000;">&quot;http://www.w3.org/2001/XMLSchema-instance&quot;</span></span>
<span style="color: #009900;">	<span style="color: #000066;">xsi:schemaLocation</span>=<span style="color: #ff0000;">&quot;http://www.springframework.org/schema/beans</span>
<span style="color: #009900;">						http://www.springframework.org/schema/beans/spring-beans-2.0.xsd</span>
<span style="color: #009900;">                        http://www.springframework.org/schema/security </span>
<span style="color: #009900;">                        http://www.springframework.org/schema/security/spring-security-2.0.1.xsd&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
&nbsp;
   <span style="color: #808080; font-style: italic;">&lt;!--  CONFIGURACION VALIDA PARA SPRING SECURITY 2.0 con JDBC   --&gt;</span> 
&nbsp;
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;http</span> <span style="color: #000066;">auto-config</span>=<span style="color: #ff0000;">&quot;true&quot;</span> <span style="color: #000066;">access-denied-page</span>=<span style="color: #ff0000;">&quot;/web/error.do&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
   	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;intercept-url</span> <span style="color: #000066;">pattern</span>=<span style="color: #ff0000;">&quot;/&quot;</span> <span style="color: #000066;">access</span>=<span style="color: #ff0000;">&quot;IS_AUTHENTICATED_ANONYMOUSLY&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;intercept-url</span> <span style="color: #000066;">pattern</span>=<span style="color: #ff0000;">&quot;/login.do&quot;</span> <span style="color: #000066;">access</span>=<span style="color: #ff0000;">&quot;IS_AUTHENTICATED_ANONYMOUSLY&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;intercept-url</span> <span style="color: #000066;">pattern</span>=<span style="color: #ff0000;">&quot;/j_spring_security_switch_user&quot;</span></span>
<span style="color: #009900;">			<span style="color: #000066;">access</span>=<span style="color: #ff0000;">&quot;ROLE_SUPERVISOR&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>		
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;intercept-url</span> <span style="color: #000066;">pattern</span>=<span style="color: #ff0000;">&quot;/web/css/**&quot;</span> <span style="color: #000066;">access</span>=<span style="color: #ff0000;">&quot;ROLE_WEBMASTER&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;intercept-url</span> <span style="color: #000066;">pattern</span>=<span style="color: #ff0000;">&quot;/templates/**&quot;</span> <span style="color: #000066;">access</span>=<span style="color: #ff0000;">&quot;ROLE_WEBMASTER&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;intercept-url</span> <span style="color: #000066;">pattern</span>=<span style="color: #ff0000;">&quot;/web/error/**&quot;</span> <span style="color: #000066;">access</span>=<span style="color: #ff0000;">&quot;ROLE_USER&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>	
&nbsp;
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;form-login</span> <span style="color: #000066;">login-page</span>=<span style="color: #ff0000;">&quot;/login.do&quot;</span> <span style="color: #000066;">default-target-url</span>=<span style="color: #ff0000;">'/web/index.do'</span></span>
<span style="color: #009900;">			<span style="color: #000066;">authentication-failure-url</span>=<span style="color: #ff0000;">&quot;/login.do?login_error=1&quot;</span>  <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;logout</span> <span style="color: #000066;">logout-success-url</span>=<span style="color: #ff0000;">&quot;/&quot;</span> <span style="color: #000066;">invalidate-session</span>=<span style="color: #ff0000;">&quot;true&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/http<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;authentication-provider</span> <span style="color: #000066;">user-service-ref</span>=<span style="color: #ff0000;">&quot;userService&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
&nbsp;
  <span style="color: #808080; font-style: italic;">&lt;!-- MYSQL --&gt;</span>
&nbsp;
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;beans:bean</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;securityDataSource&quot;</span> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;org.springframework.jdbc.datasource.DriverManagerDataSource&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;beans:property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;driverClassName&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;org.gjt.mm.mysql.Driver&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;beans:property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;url&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;jdbc:mysql://localhost/test&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;beans:property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;username&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;root&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;beans:property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;password&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/beans:bean<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>  
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;jdbc-user-service</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;userService&quot;</span> </span>
<span style="color: #009900;">	<span style="color: #000066;">data-source-ref</span>=<span style="color: #ff0000;">&quot;securityDataSource&quot;</span>	</span>
<span style="color: #009900;">	 <span style="color: #000066;">group-authorities-by-username-query</span>=<span style="color: #ff0000;">&quot;SELECT</span>
<span style="color: #009900;">                      g.nombre,</span>
<span style="color: #009900;">                      a.rol</span>
<span style="color: #009900;">                    FROM</span>
<span style="color: #009900;">                      dbo.bm_usuario u</span>
<span style="color: #009900;">                      INNER JOIN dbo.bm_grupo_usuario ug ON (u.id_usuario = ug.id_usuario)</span>
<span style="color: #009900;">                      INNER JOIN dbo.bm_grupo g ON (ug.id_grupo = g.id_grupo)</span>
<span style="color: #009900;">                      INNER JOIN dbo.bm_grupos_roles ON (g.id_grupo = dbo.bm_grupos_roles.id_grupo)</span>
<span style="color: #009900;">                      INNER JOIN dbo.bm_roles a ON (dbo.bm_grupos_roles.id_rol = a.id_rol)</span>
<span style="color: #009900;">                    WHERE</span>
<span style="color: #009900;">                      u.nombreUsuario = ? &quot;</span></span>
<span style="color: #009900;">		<span style="color: #000066;">users-by-username-query</span>=<span style="color: #ff0000;">&quot;SELECT </span>
<span style="color: #009900;">					  u.nombreUsuario AS Login,</span>
<span style="color: #009900;">					  u.password AS Password,</span>
<span style="color: #009900;">					  u.enabled AS Enabled</span>
<span style="color: #009900;">					FROM</span>
<span style="color: #009900;">					  dbo.bm_usuario u</span>
<span style="color: #009900;">					WHERE</span>
<span style="color: #009900;">					  u.nombreUsuario = ?&quot;</span></span>
<span style="color: #009900;">		<span style="color: #000066;">authorities-by-username-query</span>=<span style="color: #ff0000;">&quot;SELECT </span>
<span style="color: #009900;">					   u.nombreUsuario,</span>
<span style="color: #009900;">					    au.rol</span>
<span style="color: #009900;">					FROM</span>
<span style="color: #009900;">					  dbo.bm_usuario_roles ua</span>
<span style="color: #009900;">					  INNER JOIN dbo.bm_usuario u ON (ua.id_usuario = u.id_usuario)</span>
<span style="color: #009900;">					  INNER JOIN dbo.bm_roles au ON (ua.id_rol = au.id_rol)</span>
<span style="color: #009900;">					WHERE</span>
<span style="color: #009900;">					  u.nombreUsuario = ? &quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
&nbsp;
&nbsp;
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/beans:beans<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p><strong>Las tablas para que esto funcione. OJO, aviso que este SQL no es el mismo que yo usé en mi ejemplos, es similar pero para SQL Server, con algunas modfiicaciones a las tablas originales.</strong></p>

<div class="wp_syntax"><div class="code"><pre class="sql" style="font-family:monospace;"> <span style="color: #66cc66;">&lt;</span>!<span style="color: #808080; font-style: italic;">-- SQL --&gt;</span>
<span style="color: #993333; font-weight: bold;">CREATE</span> <span style="color: #993333; font-weight: bold;">TABLE</span> users<span style="color: #66cc66;">&#40;</span>
username varchar_ignorecase<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">50</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span> <span style="color: #993333; font-weight: bold;">PRIMARY</span> <span style="color: #993333; font-weight: bold;">KEY</span><span style="color: #66cc66;">,</span>
password varchar_ignorecase<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">50</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
enabled <span style="color: #993333; font-weight: bold;">BOOLEAN</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #66cc66;">&lt;</span>!<span style="color: #808080; font-style: italic;">--Tabla de Roles --&gt;</span>
<span style="color: #993333; font-weight: bold;">CREATE</span> <span style="color: #993333; font-weight: bold;">TABLE</span> authorities <span style="color: #66cc66;">&#40;</span>
username varchar_ignorecase<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">50</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
authority varchar_ignorecase<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">50</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
constraint fk_authorities_users <span style="color: #993333; font-weight: bold;">FOREIGN</span> <span style="color: #993333; font-weight: bold;">KEY</span><span style="color: #66cc66;">&#40;</span>username<span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">REFERENCES</span> users<span style="color: #66cc66;">&#40;</span>username<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #993333; font-weight: bold;">CREATE</span> <span style="color: #993333; font-weight: bold;">UNIQUE</span> <span style="color: #993333; font-weight: bold;">INDEX</span> ix_auth_username <span style="color: #993333; font-weight: bold;">ON</span> authorities <span style="color: #66cc66;">&#40;</span>username<span style="color: #66cc66;">,</span>authority<span style="color: #66cc66;">&#41;</span>;
&nbsp;
<span style="color: #993333; font-weight: bold;">CREATE</span> <span style="color: #993333; font-weight: bold;">TABLE</span> groups <span style="color: #66cc66;">&#40;</span>
id bigint generated <span style="color: #993333; font-weight: bold;">BY</span> <span style="color: #993333; font-weight: bold;">DEFAULT</span> <span style="color: #993333; font-weight: bold;">AS</span> identity<span style="color: #66cc66;">&#40;</span>start <span style="color: #993333; font-weight: bold;">WITH</span> <span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">PRIMARY</span> <span style="color: #993333; font-weight: bold;">KEY</span><span style="color: #66cc66;">,</span>
group_name varchar_ignorecase<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">50</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #66cc66;">&lt;</span>!<span style="color: #808080; font-style: italic;">--Tabla de Grupos Roles--&gt;</span>
<span style="color: #993333; font-weight: bold;">CREATE</span> <span style="color: #993333; font-weight: bold;">TABLE</span> group_authorities <span style="color: #66cc66;">&#40;</span>
group_id bigint <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
authority varchar<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">50</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
constraint fk_group_authorities_group <span style="color: #993333; font-weight: bold;">FOREIGN</span> <span style="color: #993333; font-weight: bold;">KEY</span><span style="color: #66cc66;">&#40;</span>group_id<span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">REFERENCES</span> groups<span style="color: #66cc66;">&#40;</span>id<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #66cc66;">&lt;</span>!<span style="color: #808080; font-style: italic;">--Tabla de Grupos Usuarios--&gt;</span>
<span style="color: #993333; font-weight: bold;">CREATE</span> <span style="color: #993333; font-weight: bold;">TABLE</span> group_members <span style="color: #66cc66;">&#40;</span>
id bigint generated <span style="color: #993333; font-weight: bold;">BY</span> <span style="color: #993333; font-weight: bold;">DEFAULT</span> <span style="color: #993333; font-weight: bold;">AS</span> identity<span style="color: #66cc66;">&#40;</span>start <span style="color: #993333; font-weight: bold;">WITH</span> <span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">PRIMARY</span> <span style="color: #993333; font-weight: bold;">KEY</span><span style="color: #66cc66;">,</span>
username varchar<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">50</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
group_id bigint <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
constraint fk_group_members_group <span style="color: #993333; font-weight: bold;">FOREIGN</span> <span style="color: #993333; font-weight: bold;">KEY</span><span style="color: #66cc66;">&#40;</span>group_id<span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">REFERENCES</span> groups<span style="color: #66cc66;">&#40;</span>id<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;</pre></div></div>

 <img src="http://blog.jotadeveloper.com/wp-content/plugins/feed-statistics.php?view=1&post_id=1058" width="1" height="1" style="display: none;" />]]></content:encoded>
			<wfw:commentRss>http://blog.jotadeveloper.com/2008/11/21/configuracion-spring-security-20-con-jdbc/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Configuración Spring Security 2.04 para LDAP</title>
		<link>http://blog.jotadeveloper.com/2008/11/17/configuracion-spring-security-204-para-ldap/</link>
		<comments>http://blog.jotadeveloper.com/2008/11/17/configuracion-spring-security-204-para-ldap/#comments</comments>
		<pubDate>Mon, 17 Nov 2008 05:51:53 +0000</pubDate>
		<dc:creator>Jota</dc:creator>
				<category><![CDATA[Programación]]></category>
		<category><![CDATA[acegi]]></category>
		<category><![CDATA[ldap]]></category>
		<category><![CDATA[spring]]></category>
		<category><![CDATA[spring security]]></category>

		<guid isPermaLink="false">http://blog.jotadeveloper.com/?p=1031</guid>
		<description><![CDATA[Por si te sirve de algo, me costo un monton, aun estoy detras de una configuración hibrida, medio LDAP medio Base de Datos, pero por ahora les dejo una configuración básica del LDAP con el Nuevo Acegi.

&#60;?xml version=&#34;1.0&#34; encoding=&#34;UTF-8&#34;?&#62;
&#60;beans xmlns=&#34;http://www.springframework.org/schema/beans&#34;
	xmlns:s=&#34;http://www.springframework.org/schema/security&#34; xmlns:xsi=&#34;http://www.w3.org/2001/XMLSchema-instance&#34;
	xsi:schemaLocation=&#34;
       http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
       [...]]]></description>
			<content:encoded><![CDATA[<p>Por si te sirve de algo, me costo un monton, aun estoy detras de una configuración hibrida, medio LDAP medio Base de Datos, pero por ahora les dejo una configuración básica del LDAP con el Nuevo Acegi.</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;?xml</span> <span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span> <span style="color: #000066;">encoding</span>=<span style="color: #ff0000;">&quot;UTF-8&quot;</span><span style="color: #000000; font-weight: bold;">?&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;beans</span> <span style="color: #000066;">xmlns</span>=<span style="color: #ff0000;">&quot;http://www.springframework.org/schema/beans&quot;</span></span>
<span style="color: #009900;">	<span style="color: #000066;">xmlns:s</span>=<span style="color: #ff0000;">&quot;http://www.springframework.org/schema/security&quot;</span> <span style="color: #000066;">xmlns:xsi</span>=<span style="color: #ff0000;">&quot;http://www.w3.org/2001/XMLSchema-instance&quot;</span></span>
<span style="color: #009900;">	<span style="color: #000066;">xsi:schemaLocation</span>=<span style="color: #ff0000;">&quot;</span>
<span style="color: #009900;">       http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd</span>
<span style="color: #009900;">       http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-2.0.1.xsd&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
&nbsp;
&nbsp;
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;s:http<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;s:intercept-url</span> <span style="color: #000066;">pattern</span>=<span style="color: #ff0000;">&quot;/&quot;</span> <span style="color: #000066;">access</span>=<span style="color: #ff0000;">&quot;IS_AUTHENTICATED_ANONYMOUSLY&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;s:intercept-url</span> <span style="color: #000066;">pattern</span>=<span style="color: #ff0000;">&quot;/j_spring_security_switch_user&quot;</span></span>
<span style="color: #009900;">			<span style="color: #000066;">access</span>=<span style="color: #ff0000;">&quot;ROLE_SUPERVISOR&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;s:intercept-url</span> <span style="color: #000066;">pattern</span>=<span style="color: #ff0000;">&quot;/web/**&quot;</span> <span style="color: #000066;">access</span>=<span style="color: #ff0000;">&quot;ROLE_USER&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;s:intercept-url</span> <span style="color: #000066;">pattern</span>=<span style="color: #ff0000;">&quot;/web/templates/**&quot;</span> <span style="color: #000066;">access</span>=<span style="color: #ff0000;">&quot;ROLE_ADMIN&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;s:intercept-url</span> <span style="color: #000066;">pattern</span>=<span style="color: #ff0000;">&quot;/&quot;</span></span>
<span style="color: #009900;">			<span style="color: #000066;">access</span>=<span style="color: #ff0000;">&quot;IS_AUTHENTICATED_ANONYMOUSLY&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;s:intercept-url</span> <span style="color: #000066;">pattern</span>=<span style="color: #ff0000;">&quot;/login.do&quot;</span></span>
<span style="color: #009900;">			<span style="color: #000066;">access</span>=<span style="color: #ff0000;">&quot;IS_AUTHENTICATED_ANONYMOUSLY&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;s:form-login</span> <span style="color: #000066;">login-page</span>=<span style="color: #ff0000;">&quot;/login.do&quot;</span> <span style="color: #000066;">default-target-url</span>=<span style="color: #ff0000;">'/web/index.do'</span></span>
<span style="color: #009900;">			<span style="color: #000066;">authentication-failure-url</span>=<span style="color: #ff0000;">&quot;/login.do?login_error=1&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
			 <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;s:logout</span></span>
<span style="color: #009900;">		<span style="color: #000066;">logout-success-url</span>=<span style="color: #ff0000;">&quot;/&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;s:http-basic</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;s:anonymous</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;s:logout</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/s:http<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;s:ldap-server</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;ldapServer&quot;</span> <span style="color: #000066;">url</span>=<span style="color: #ff0000;">&quot;ldap://localhost:389/ou=system&quot;</span></span>
<span style="color: #009900;">		<span style="color: #000066;">manager-dn</span>=<span style="color: #ff0000;">&quot;uid=admin,ou=system&quot;</span> <span style="color: #000066;">manager-password</span>=<span style="color: #ff0000;">&quot;test&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
&nbsp;
	<span style="color: #808080; font-style: italic;">&lt;!--  grop srch base was groups --&gt;</span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;s:ldap-authentication-provider</span></span>
<span style="color: #009900;">		<span style="color: #000066;">server-ref</span>=<span style="color: #ff0000;">&quot;ldapServer&quot;</span> <span style="color: #000066;">user-search-filter</span>=<span style="color: #ff0000;">&quot;sAMAccountName={0}&quot;</span></span>
<span style="color: #009900;">		<span style="color: #000066;">user-search-base</span>=<span style="color: #ff0000;">&quot;&quot;</span> <span style="color: #000066;">group-role-attribute</span>=<span style="color: #ff0000;">&quot;cn&quot;</span> <span style="color: #000066;">group-search-filter</span>=<span style="color: #ff0000;">&quot;memberOf={0}&quot;</span></span>
<span style="color: #009900;">		<span style="color: #000066;">group-search-base</span>=<span style="color: #ff0000;">&quot;ou=groups&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
&nbsp;
	<span style="color: #808080; font-style: italic;">&lt;!-- sAMAccountName java.naming.referrel follow --&gt;</span>
&nbsp;
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;bean</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;contextSource&quot;</span></span>
<span style="color: #009900;">		<span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;org.springframework.security.ldap.DefaultSpringSecurityContextSource&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;constructor-arg</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;ldap://localhost:389/ou=system&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;userDn&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;uid=admin,ou=system&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;password&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;test&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/bean<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;bean</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;ldapAuthenticationProvider&quot;</span></span>
<span style="color: #009900;">		<span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;org.springframework.security.providers.ldap.LdapAuthenticationProvider&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;constructor-arg<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
			<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;bean</span></span>
<span style="color: #009900;">				<span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;org.springframework.security.providers.ldap.authenticator.BindAuthenticator&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
				<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;constructor-arg</span> <span style="color: #000066;">ref</span>=<span style="color: #ff0000;">&quot;contextSource&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
				<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;userSearch&quot;</span> <span style="color: #000066;">ref</span>=<span style="color: #ff0000;">&quot;userSearch&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
			<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/bean<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/constructor-arg<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;constructor-arg<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
			<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;bean</span></span>
<span style="color: #009900;">				<span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;org.springframework.security.ldap.populator.DefaultLdapAuthoritiesPopulator&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
				<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;constructor-arg</span> <span style="color: #000066;">ref</span>=<span style="color: #ff0000;">&quot;contextSource&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
				<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;constructor-arg</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;cn=users,dc=development,dc=somecompany,dc=com&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
				<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;convertToUpperCase&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;true&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
				<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;defaultRole&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;Authenticated&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
				<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;rolePrefix&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
				<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;searchSubtree&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;true&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
				<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;groupSearchFilter&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;(memberUid={0})&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
				<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;groupRoleAttribute&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;cn&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
			<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/bean<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/constructor-arg<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/bean<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;bean</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;userSearch&quot;</span></span>
<span style="color: #009900;">		<span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;org.springframework.security.ldap.search.FilterBasedLdapUserSearch&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;constructor-arg</span> <span style="color: #000066;">index</span>=<span style="color: #ff0000;">&quot;0&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;ou=Users&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;constructor-arg</span> <span style="color: #000066;">index</span>=<span style="color: #ff0000;">&quot;1&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;(sAMAccountName={0})&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;constructor-arg</span> <span style="color: #000066;">index</span>=<span style="color: #ff0000;">&quot;2&quot;</span> <span style="color: #000066;">ref</span>=<span style="color: #ff0000;">&quot;contextSource&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;searchSubtree&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;true&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/bean<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
&nbsp;
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/beans<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

 <img src="http://blog.jotadeveloper.com/wp-content/plugins/feed-statistics.php?view=1&post_id=1031" width="1" height="1" style="display: none;" />]]></content:encoded>
			<wfw:commentRss>http://blog.jotadeveloper.com/2008/11/17/configuracion-spring-security-204-para-ldap/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
	</channel>
</rss>
