繁体   English   中英

使用jdbc-provider在Mule中配置Spring Security

[英]Configure Spring Security in Mule using jdbc-provider

我有以下Mule App,我正在尝试使用数据库来提供用户(jdbc-provider)的Spring Security保护它。

我在Mule App的类路径中正确配置了mysql数据库和mysql jdbc驱动程序,但是当我尝试登录时出现以下错误:

无法获得JDBC连接。 嵌套异常为java.sql.SQLException:找不到适用于jdbc:mysql:// localhost:3306 / test的驱动程序(org.springframework.jdbc.CannotGetJdbcConnectionException)org.springframework.jdbc.datasource.DataSourceUtils:80(空)

Mule App(基于Mule ESB 3.6.1):

<?xml version="1.0" encoding="UTF-8"?>

<mule xmlns:http="http://www.mulesoft.org/schema/mule/http" xmlns="http://www.mulesoft.org/schema/mule/core" xmlns:doc="http://www.mulesoft.org/schema/mule/documentation"
     xmlns:spring="http://www.springframework.org/schema/beans" version="EE-3.6.1"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:mule-ss="http://www.mulesoft.org/schema/mule/spring-security"
    xmlns:ss="http://www.springframework.org/schema/security"
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-current.xsd
http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd
http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd
http://www.mulesoft.org/schema/mule/ee/tracking http://www.mulesoft.org/schema/mule/ee/tracking/current/mule-tracking-ee.xsd
http://www.mulesoft.org/schema/mule/spring-security http://www.mulesoft.org/schema/mule/spring-security/3.1/mule-spring-security.xsd
http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-3.0.xsd
http://www.mulesoft.org/schema/mule/tls http://www.mulesoft.org/schema/mule/tls/current/mule-tls.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.mulesoft.org/schema/mule/https http://www.mulesoft.org/schema/mule/https/current/mule-https.xsd">
    <spring:beans>
        <spring:bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
            <spring:property name="driverClassName" value="com.mysql.jdbc.Driver"/>
            <spring:property name="url" value="jdbc:mysql://localhost:3306/test"/>
            <spring:property name="username" value="root"/>
            <spring:property name="password" value="sonar"/>
        </spring:bean>

  <ss:authentication-manager  alias="authenticationManager">
      <ss:authentication-provider>
        <ss:jdbc-user-service data-source-ref="dataSource"
          users-by-username-query=
            "select username,password, enabled from users where username=?"
          authorities-by-username-query=
            "select username, role from user_roles where username =?  " />
      </ss:authentication-provider>
    </ss:authentication-manager>
  </spring:beans>

  <mule-ss:security-manager>
      <mule-ss:delegate-security-provider name="jdbc-provider" delegate-ref="authenticationManager" />
  </mule-ss:security-manager>

  <http:listener-config name="HTTP_Listener_Configuration" host="localhost" port="8081" doc:name="HTTP Listener Configuration" />

  <flow name="SpringExample">
    <http:listener config-ref="HTTP_Listener_Configuration" path="/" doc:name="HTTP"/>
      <logger level="INFO" message="## received" doc:name="Logger"/>
      <http:basic-security-filter realm="mule-realm" securityProviders="jdbc-provider"/>      
    <logger level="INFO" message="## passed security" doc:name="Logger"/>
  </flow>
</mule>

堆栈跟踪:

INFO  2015-03-27 21:31:04,255 [[spring-security-maven].HTTP_Listener_Configuration.worker.01] org.mule.api.processor.LoggerMessageProcessor: ## received
ERROR 2015-03-27 21:31:04,299 [[spring-security-maven].HTTP_Listener_Configuration.worker.01] org.mule.exception.DefaultMessagingExceptionStrategy: 
********************************************************************************
Message               : Authentication Attempt Failed. Message payload is of type: NullPayload
Code                  : MULE_ERROR--2
--------------------------------------------------------------------------------
Exception stack is:
1. No suitable driver found for jdbc:mysql://localhost:3306/test (java.sql.SQLException)
  java.sql.DriverManager:596 (null)
2. Could not get JDBC Connection; nested exception is java.sql.SQLException: No suitable driver found for jdbc:mysql://localhost:3306/test (org.springframework.jdbc.CannotGetJdbcConnectionException)
  org.springframework.jdbc.datasource.DataSourceUtils:80 (null)
3. Could not get JDBC Connection; nested exception is java.sql.SQLException: No suitable driver found for jdbc:mysql://localhost:3306/test (org.springframework.security.authentication.AuthenticationServiceException)
  org.springframework.security.authentication.dao.DaoAuthenticationProvider:85 (null)
4. Authentication Attempt Failed. Message payload is of type: NullPayload (org.mule.api.security.UnauthorisedException)
  org.mule.security.MuleSecurityManager:91 (http://www.mulesoft.org/docs/site/current3/apidocs/org/mule/api/security/UnauthorisedException.html)
--------------------------------------------------------------------------------
Root Exception stack trace:
java.sql.SQLException: No suitable driver found for jdbc:mysql://localhost:3306/test
    at java.sql.DriverManager.getConnection(DriverManager.java:596)
    at java.sql.DriverManager.getConnection(DriverManager.java:187)
    at org.springframework.jdbc.datasource.DriverManagerDataSource.getConnectionFromDriverManager(DriverManagerDataSource.java:173)
    + 3 more (set debug level logging or '-Dmule.verbose.exceptions=true' for everything)
********************************************************************************

这是a子的问题。 将罐子添加到

<MULE_PATH>/mule-standalone-3.x.0/lib/mule

<MULE_STUDIO_PATH>/AnypointStudio/plugins/org.mule.tooling.server.3.x.xxxx/mule/lib/mule

默认情况下,mole不为各个数据库连接提供jdbc驱动程序。 我们需要将jar显式添加到项目开发的类路径中。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM