Spring Security, authentication-provider - SQL state [99999]; error code [17059]

1,786 views
Skip to first unread message

juan zapata

unread,
Sep 16, 2011, 12:10:32 PM9/16/11
to Spring User Group Peru
Buenos días, estoy intentando aplicar spring security 3 en un proyecto
java ya avanzado con las tecnologías de hibernate, Spring mvc y
Oracle; bueno sucede que he logrado implementar spring security pero
trabajando con una bd embebida utilizando en el siguiente data source:

<jdbc:embedded-database id="dataSourceE">
<jdbc:script location="classpath:schema.sql"/>
<jdbc:script location="classpath:test-data.sql"/>
</jdbc:embedded-database>

y en el authentication-manager

<sec:authentication-provider>
<sec:password-encoder hash="sha" />
<sec:jdbc-user-service data-source-ref="dataSourceE"
users-by-username-query="select username, password, 'true' enabled
from usuario
where username = ?"
authorities-by-username-query="select u.username, r.nombre from
usuario u
inner join usuario_rol ur on u.id_usuario = ur.id_usuario
inner join rol r on r.id_rol=ur.id_rol where u.username=?"/>

</sec:authentication-provider>

y funciona normal, pero cuando le cambio el dataSource por el de
oracle

<bean id="dataSource"
class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName"
value="oracle.jdbc.driver.OracleDriver" />
<property name="url" value="jdbc:oracle:thin:@<miIp>:orcl" />
<property name="username" value="username" />
<property name="password" value="password" />
</bean>

la cual contiene las mismas tablas que el script usado en el
dataSource anterior, me bota el siguiente error "SQL state [99999];
error code [17059]" en el cual quisiera me ayuden de ser posible,
detallo el log completo a continuacion.

INFO: 2011-09-16 10:16:25,730 DEBUG
[org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter]
- Authentication request failed:
org.springframework.security.authentication.AuthenticationServiceException:
PreparedStatementCallback; uncategorized SQLException for SQL [select
username, password, 'true' enabled from usr_administrador where
username = ?]; SQL state [99999]; error code [17059]; Fallo al
convertir a representación interna; nested exception is
java.sql.SQLException: Fallo al convertir a representación interna

INFO: 2011-09-16 10:16:25,730 DEBUG
[org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter]
- Updated SecurityContextHolder to contain null Authentication

INFO: 2011-09-16 10:16:25,730 DEBUG
[org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter]
- Delegating to authentication failure
handlerorg.springframework.security.web.authentication.SimpleUrlAuthenticationFailureHandler@1846a80

INFO: 2011-09-16 10:16:25,730 DEBUG
[org.springframework.security.web.authentication.SimpleUrlAuthenticationFailureHandler]
- Redirecting to /redbackoffice/bologinerror.htm

INFO: 2011-09-16 10:16:25,730 DEBUG
[org.springframework.security.web.DefaultRedirectStrategy] -
Redirecting to '/redbackoffice/bologinerror.htm'

INFO: 2011-09-16 10:16:25,730 DEBUG
[org.springframework.security.web.context.HttpSessionSecurityContextRepository]
- SecurityContext is empty or anonymous - context will not be stored
in HttpSession.

INFO: 2011-09-16 10:16:25,730 DEBUG
[org.springframework.security.web.context.SecurityContextPersistenceFilter]
- SecurityContextHolder now cleared, as request processing completed

INFO: 2011-09-16 10:16:25,730 DEBUG
[org.springframework.security.web.FilterChainProxy] - Converted URL to
lowercase, from: '/redbackoffice/bologinerror.htm'; to: '/
redbackoffice/bologinerror.htm'

INFO: 2011-09-16 10:16:25,730 DEBUG
[org.springframework.security.web.FilterChainProxy] - Candidate is: '/
redbackoffice/bologinerror.htm'; pattern is /redbackoffice/
bologin.htm; matched=false

INFO: 2011-09-16 10:16:25,730 DEBUG
[org.springframework.security.web.FilterChainProxy] - Converted URL to
lowercase, from: '/redbackoffice/bologinerror.htm'; to: '/
redbackoffice/bologinerror.htm'

INFO: 2011-09-16 10:16:25,730 DEBUG
[org.springframework.security.web.FilterChainProxy] - Candidate is: '/
redbackoffice/bologinerror.htm'; pattern is /redbackoffice/
boprincipal.htm; matched=false

INFO: 2011-09-16 10:16:25,730 DEBUG
[org.springframework.security.web.FilterChainProxy] - Converted URL to
lowercase, from: '/redbackoffice/bologinerror.htm'; to: '/
redbackoffice/bologinerror.htm'

INFO: 2011-09-16 10:16:25,730 DEBUG
[org.springframework.security.web.FilterChainProxy] - Candidate is: '/
redbackoffice/bologinerror.htm'; pattern is /redbackoffice/
boinicio.htm; matched=false

INFO: 2011-09-16 10:16:25,730 DEBUG
[org.springframework.security.web.FilterChainProxy] - Converted URL to
lowercase, from: '/redbackoffice/bologinerror.htm'; to: '/
redbackoffice/bologinerror.htm'

INFO: 2011-09-16 10:16:25,730 DEBUG
[org.springframework.security.web.FilterChainProxy] - Candidate is: '/
redbackoffice/bologinerror.htm'; pattern is /**; matched=true

INFO: 2011-09-16 10:16:25,730 DEBUG
[org.springframework.security.web.FilterChainProxy] - /redbackoffice/
bologinerror.htm at position 1 of 10 in additional filter chain;
firing Filter: 'SecurityContextPersistenceFilter'

INFO: 2011-09-16 10:16:25,730 DEBUG
[org.springframework.security.web.context.HttpSessionSecurityContextRepository]
- HttpSession returned null object for SPRING_SECURITY_CONTEXT

INFO: 2011-09-16 10:16:25,730 DEBUG
[org.springframework.security.web.context.HttpSessionSecurityContextRepository]
- No SecurityContext was available from the HttpSession:
org.apache.catalina.session.StandardSessionFacade@d0dd67. A new one
will be created.

INFO: 2011-09-16 10:16:25,746 DEBUG
[org.springframework.security.web.FilterChainProxy] - /redbackoffice/
bologinerror.htm at position 2 of 10 in additional filter chain;
firing Filter: 'LogoutFilter'

INFO: 2011-09-16 10:16:25,746 DEBUG
[org.springframework.security.web.FilterChainProxy] - /redbackoffice/
bologinerror.htm at position 3 of 10 in additional filter chain;
firing Filter: 'UsernamePasswordAuthenticationFilter'

INFO: 2011-09-16 10:16:25,746 DEBUG
[org.springframework.security.web.FilterChainProxy] - /redbackoffice/
bologinerror.htm at position 4 of 10 in additional filter chain;
firing Filter: 'BasicAuthenticationFilter'

INFO: 2011-09-16 10:16:25,746 DEBUG
[org.springframework.security.web.FilterChainProxy] - /redbackoffice/
bologinerror.htm at position 5 of 10 in additional filter chain;
firing Filter: 'RequestCacheAwareFilter'

INFO: 2011-09-16 10:16:25,746 DEBUG
[org.springframework.security.web.FilterChainProxy] - /redbackoffice/
bologinerror.htm at position 6 of 10 in additional filter chain;
firing Filter: 'SecurityContextHolderAwareRequestFilter'

INFO: 2011-09-16 10:16:25,746 DEBUG
[org.springframework.security.web.FilterChainProxy] - /redbackoffice/
bologinerror.htm at position 7 of 10 in additional filter chain;
firing Filter: 'AnonymousAuthenticationFilter'

INFO: 2011-09-16 10:16:25,746 DEBUG
[org.springframework.security.web.authentication.AnonymousAuthenticationFilter]
- Populated SecurityContextHolder with anonymous token:
'org.springframework.security.authentication.AnonymousAuthenticationToken@6fab4e5e:
Principal: anonymousUser; Credentials: [PROTECTED]; Authenticated:
true; Details:
org.springframework.security.web.authentication.WebAuthenticationDetails@fffe3f86:
RemoteIpAddress: 127.0.0.1; SessionId: 2a3a2de12599b9b570d412eac14d;
Granted Authorities: ROLE_ANONYMOUS'

INFO: 2011-09-16 10:16:25,746 DEBUG
[org.springframework.security.web.FilterChainProxy] - /redbackoffice/
bologinerror.htm at position 8 of 10 in additional filter chain;
firing Filter: 'SessionManagementFilter'

INFO: 2011-09-16 10:16:25,746 DEBUG
[org.springframework.security.web.FilterChainProxy] - /redbackoffice/
bologinerror.htm at position 9 of 10 in additional filter chain;
firing Filter: 'ExceptionTranslationFilter'

INFO: 2011-09-16 10:16:25,746 DEBUG
[org.springframework.security.web.FilterChainProxy] - /redbackoffice/
bologinerror.htm at position 10 of 10 in additional filter chain;
firing Filter: 'FilterSecurityInterceptor'

INFO: 2011-09-16 10:16:25,746 DEBUG
[org.springframework.security.web.access.intercept.DefaultFilterInvocationSecurityMetadataSource]
- Converted URL to lowercase, from: '/redbackoffice/bologinerror.htm';
to: '/redbackoffice/bologinerror.htm'

INFO: 2011-09-16 10:16:25,746 DEBUG
[org.springframework.security.web.access.intercept.DefaultFilterInvocationSecurityMetadataSource]
- Candidate is: '/redbackoffice/bologinerror.htm'; pattern is /
redbackoffice/boacerca.htm; matched=false

INFO: 2011-09-16 10:16:25,746 DEBUG
[org.springframework.security.web.access.intercept.DefaultFilterInvocationSecurityMetadataSource]
- Candidate is: '/redbackoffice/bologinerror.htm'; pattern is /
redbackoffice/detalleusuarioaverificar.htm; matched=false

INFO: 2011-09-16 10:16:25,746 DEBUG
[org.springframework.security.web.access.intercept.FilterSecurityInterceptor]
- Public object - authentication not attempted

INFO: 2011-09-16 10:16:25,761 DEBUG
[org.springframework.security.web.FilterChainProxy] - /redbackoffice/
bologinerror.htm reached end of additional filter chain; proceeding
with original chain

juan zapata

unread,
Sep 16, 2011, 12:11:34 PM9/16/11
to Spring User Group Peru

jamdi...@gmail.com

unread,
Sep 16, 2011, 12:16:22 PM9/16/11
to spring-user...@googlegroups.com
Has corrido ese sql en un cliente oracle?? Esta bien la sentencia?

Joe.
Enviado desde mi BlackBerry de Claro.
--
Has recibido este mensaje porque estás suscrito al grupo "Spring User Group Peru" de Grupos de Google.
Para publicar una entrada en este grupo, envía un correo electrónico a spring-user...@googlegroups.com.
Para anular tu suscripción a este grupo, envía un correo electrónico a spring-user-group...@googlegroups.com
Para tener acceso a más opciones, visita el grupo en http://groups.google.com/group/spring-user-group-peru?hl=es.

juan zapata

unread,
Sep 16, 2011, 12:23:33 PM9/16/11
to Spring User Group Peru
si, fue lo primero q hice.
> [org.springframework.security.web.authentication.SimpleUrlAuthenticationFai lureHandler]
> ...
>
> leer más »

Susan Inga

unread,
Sep 16, 2011, 12:28:31 PM9/16/11
to spring-user...@googlegroups.com
Creo que también puede ir por el lado que ORACLE no maneja booleanos, como si lo hace MySQL (y quizás tu BD embebida).

Te lo comento por el error que te marca

PreparedStatementCallback; uncategorized SQLException for SQL [select
username, password, 'true' enabled from usr_administrador where
username = ?]; SQL state [99999]; error code [17059]; Fallo al
convertir a representación interna; nested exception is
java.sql.SQLException: Fallo al convertir a representación interna


Está fallando al convertir un tipo de dato. Puede ser porque antes manejabas valores booleanos en tu bd y ORACLE ya no los soporta, pero Security sigue esperándolos en el enabled.

En hibernate resolví ese mismo problema usando la propiedad hibernate.query.substitutions en el sessionFactory algo como
hibernate.query.substitutions = true 1, false 0. Donde 1 y 0 eran la representaciones en la BD. 

Susan 

Gustavo Guanilo Alvino

unread,
Sep 16, 2011, 1:21:58 PM9/16/11
to spring-user...@googlegroups.com
Oracle si soporta booleanos parece que esta mal esta sentencia "select username, password, 'true' enabled"
donde el enabled es de tipo char mas no un booleano

--
Has recibido este mensaje porque estás suscrito al grupo "Spring User Group Peru" de Grupos de Google.
Para publicar una entrada en este grupo, envía un correo electrónico a spring-user...@googlegroups.com.
Para anular tu suscripción a este grupo, envía un correo electrónico a spring-user-group...@googlegroups.com
Para tener acceso a más opciones, visita el grupo en http://groups.google.com/group/spring-user-group-peru?hl=es.



--
Saludos

Juan Gustavo Guanilo Albino
Software Developer



Susan Inga

unread,
Sep 16, 2011, 1:38:58 PM9/16/11
to spring-user...@googlegroups.com
Sobre lo dicho.

El UserDetails de Spring Security espera un boolean en el campo enabled. Lo cual no está siendo bien asignado pues están asignándolo con otro tipo de dato.

Interesante lo que mencionas Gustavo, cuando vi el tema la solución propuesta por hibernate fue el substitutions en el caso de Oracle. Si tuvieras a mano un ejemplo del mapeo directo con Oracle sobre booleans seria excelente para poder actualizar mi solución y mejorarla ;)

Saludos,

Susan


2011/9/16 Gustavo Guanilo Alvino <ggua...@gmail.com>

Gustavo Guanilo Alvino

unread,
Sep 16, 2011, 3:10:12 PM9/16/11
to spring-user...@googlegroups.com
Hola tienes razón con respecto a los booleans en version 11g ya forma parte de los datatypes en las otras versiones no,con respecto a lo otro una solución inmediata seria la sgte... la estructura de la tabla asumo que es la siguiente

CREATE TABLE USERS (
    USERNAME    VARCHAR(10)    NOT NULL,
    PASSWORD    VARCHAR(32)    NOT NULL,
    ENABLED     SMALLINT,
    PRIMARY KEY (USERNAME)
)
para poder hacer el "select username,password, 1 as enabled from users....."
espero poderte ayudado

juan zapata

unread,
Sep 16, 2011, 3:22:13 PM9/16/11
to Spring User Group Peru
tienes razón le estaba asignando mal el valor a la columna enabled, lo
resolví asignándole el valor 1.
quedando la consulta de la siguiente manera:

users-by-username-query="select username, password, 1 enabled from
usr_administrador
where username = ?"

muchas gracias a todos por apoyarme.

On 16 sep, 14:10, Gustavo Guanilo Alvino <gguan...@gmail.com> wrote:
> Hola tienes razón con respecto a los booleans en version 11g ya forma parte
> de los datatypes en las otras versiones no,con respecto a lo otro
> una solución inmediata seria la sgte... la estructura de la tabla asumo que
> es la siguiente
>
> CREATE TABLE USERS (
>
>     USERNAME    VARCHAR(10)    NOT NULL,
>     PASSWORD    VARCHAR(32)    NOT NULL,
>     ENABLED     SMALLINT,
>     PRIMARY KEY (USERNAME)
> )
>
> para poder hacer el "select username,password, 1 as enabled from users....."
>
> espero poderte ayudado
>
> El 16 de septiembre de 2011 12:38, Susan Inga <ic.su...@gmail.com> escribió:
>
>
>
>
>
>
>
>
>
> > Sobre lo dicho.
>
> > El UserDetails de Spring Security espera un boolean en el campo enabled. Lo
> > cual no está siendo bien asignado pues están asignándolo con otro tipo de
> > dato.
>
> > Interesante lo que mencionas Gustavo, cuando vi el tema la solución
> > propuesta por hibernate fue el substitutions en el caso de Oracle. Si
> > tuvieras a mano un ejemplo del mapeo directo con Oracle sobre booleans seria
> > excelente para poder actualizar mi solución y mejorarla ;)
>
> > Saludos,
>
> > Susan
>
> > 2011/9/16 Gustavo Guanilo Alvino <gguan...@gmail.com>
>
> >> Oracle si soporta booleanos parece que esta mal esta sentencia "select
> >> username, password, 'true' enabled"
> >> donde el enabled es de tipo char mas no un booleano
>
> >> El 16 de septiembre de 2011 11:28, Susan Inga <ic.su...@gmail.com>escribió:
>
> >>> Creo que también puede ir por el lado que ORACLE no maneja booleanos,
> >>> como si lo hace MySQL (y quizás tu BD embebida).
>
> >>> Te lo comento por el error que te marca
>
> >>> PreparedStatementCallback; uncategorized SQLException for SQL [select
> >>> username, password, 'true' enabled from usr_administrador where
> >>> username = ?]; SQL state [99999]; error code [17059]; Fallo al
> >>> convertir a representación interna; nested exception is
> >>> *java.sql.SQLException: Fallo al convertir a representación interna*
>
> >>> Está fallando al convertir un tipo de dato. Puede ser porque antes
> >>> manejabas valores booleanos en tu bd y ORACLE ya no los soporta, pero
> >>> Security sigue esperándolos en el enabled.
>
> >>>  En hibernate resolví ese mismo problema usando la
> >>> propiedad hibernate.query.substitutions en el sessionFactory algo como
> >>> hibernate.query.substitutions = true 1, false 0. Donde 1 y 0 eran la
> >>> representaciones en la BD.
>
> >>> Susan
>
> >>> --
> >>> Has recibido este mensaje porque estás suscrito al grupo "Spring User
> >>> Group Peru" de Grupos de Google.
> >>> Para publicar una entrada en este grupo, envía un correo electrónico a
> >>> spring-user...@googlegroups.com.
> >>> Para anular tu suscripción a este grupo, envía un correo electrónico a
> >>> spring-user-group...@googlegroups.com
> >>> Para tener acceso a más opciones, visita el grupo en
> >>>http://groups.google.com/group/spring-user-group-peru?hl=es.
>
> >> --
> >> Saludos
>
> >> Juan Gustavo Guanilo Albino
> >> Software Developer
>
Reply all
Reply to author
Forward
0 new messages