簡體   English   中英

我如何使用我的 persistence.xml 和 datasource-jdbc.xml 進行 jdbc 身份驗證?

[英]How can i jdbc authentication with my persistence.xml and datasource-jdbc.xml?

我使用:Maven、spring 安全 5.1.4、DB Oracle 12 和 Weblogic 服務器 12。

我想使用我的 persistence.xml 和 datasource-1-jdbc.xml 文件執行 jdbc 身份驗證,我該如何繼續?

預先感謝您的幫助

我的 WebSecurityConfig class:

@EnableWebSecurity
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {

    @Autowired
    PasswordEncoder passwordEncoder;    

    @Autowired
    private DataSource dataSource;

    @PersistenceContext(unitName = "projetSSPFDB_war_1.0-SNAPSHOTPU")
    private EntityManager em;   

    @Autowired
    public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
        auth
            .jdbcAuthentication().dataSource(dataSource);

    }

    @Bean
    public PasswordEncoder passwordEncoder() {
        return new BCryptPasswordEncoder();
    }
}

我的堅持。xml:

<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.1" xmlns="http://xmlns.jcp.org/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd">
  <persistence-unit name="projetSSPFDB_war_1.0-SNAPSHOTPU" transaction-type="JTA">
    <jta-data-source>DSprojet</jta-data-source>
    <exclude-unlisted-classes>false</exclude-unlisted-classes>
    <properties/>
  </persistence-unit>
</persistence>

我的數據源文件位於“..\middleware\user_projects\domains\developerSRV\servers\AdminServer\upload\DSprojet\app\datasource-1-jdbc.xml”,

我的 datasource-1-jdbc.xml 是:

<?xml version="1.0" encoding="UTF-8"?>
<jdbc-data-source xmlns="http://xmlns.oracle.com/weblogic/jdbc-data-source">
  <name>DSprojet</name>
  <jdbc-driver-params>
    <url>jdbc:oracle:thin:@myurl</url>
    <driver-name>oracle.jdbc.OracleDriver</driver-name>
    <properties>
      <property>
        <name>user</name>
        <value>myusername</value>
      </property>
      <property>
        <name>password</name>
        <value>mypassword</value>
      </property>
    </properties>
  </jdbc-driver-params>
  <jdbc-data-source-params>
    <jndi-name>DSprojet</jndi-name>
  </jdbc-data-source-params>
</jdbc-data-source>

我的身份驗證臨時解決方案是:

@Bean
public DataSource getDataSource() {
    dataSource.setDriverClassName("oracle.jdbc.OracleDriver");
    dataSource.setUrl("jdbc:oracle:thin:@myURL");
    dataSource.setUsername("myUSERNAME");
    dataSource.setPassword("myPASSWORD");

    return dataSource;
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM