Java 使用Oracle JDBC10进行Spring身份验证

Java 使用Oracle JDBC10进行Spring身份验证,java,spring,oracle,authentication,Java,Spring,Oracle,Authentication,我正在学习一门Spring课程,老师以Spring安全性为例(使用Spring mvc登录页面)。。。他使用的是mysql,我也在尝试使用它,但是Oracle数据库19c,DBC10,但我遗漏了一些东西 我有相同的表(用户和密码),其中包含相同的数据,但当我尝试登录时,身份验证失败,比如用户名或密码错误 属性文件 # #JDBC connection properties # jdbc.driver=oracle.jdbc.driver.OracleDriver jdbc.url=jdbc:or

我正在学习一门Spring课程,老师以Spring安全性为例(使用Spring mvc登录页面)。。。他使用的是mysql,我也在尝试使用它,但是Oracle数据库19c,DBC10,但我遗漏了一些东西

我有相同的表(用户和密码),其中包含相同的数据,但当我尝试登录时,身份验证失败,比如用户名或密码错误

属性文件

#
#JDBC connection properties
#
jdbc.driver=oracle.jdbc.driver.OracleDriver
jdbc.url=jdbc:oracle:thin:@192.168.240.11:1521:orcl
jdbc.user=jcataldo
jdbc.password=Pola1095


App config.java

ort org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;
import org.springframework.core.env.Environment;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.web.servlet.ViewResolver;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.view.InternalResourceViewResolver;

import com.mchange.v2.c3p0.ComboPooledDataSource;

@Configuration
@EnableWebMvc
@ComponentScan(basePackages="com.luv2code.springsecurity.demo")
@PropertySource("classpath:persistence-oracle.properties")
public class DemoAppConfig { 
    
    // define a bean for ViewResolver ==> Indica que es lo que debería mostrar, en este caso todo los
    // .jsp ubicados en /WEB-INF/view
    
    @Autowired
    private Environment env; //hold data read from properties file
    
    // set up a logger for diagnostics
    private Logger logger = Logger.getLogger(getClass().getName());
    
    // define a bean for ViewResolver
    @Bean
    public ViewResolver viewResolver() {
        
        InternalResourceViewResolver viewResolver = new InternalResourceViewResolver();
        
        viewResolver.setPrefix("/WEB-INF/view/");
        viewResolver.setSuffix(".jsp");
        
        return viewResolver;
    }
    
    // define a bean for our security datasource
    @Bean
    public DataSource securityDataSource() {
        
        // create a connection pool
        ComboPooledDataSource securityDataSource
            = new ComboPooledDataSource();
        
        // set the jdbc driver class
        try {
            securityDataSource.setDriverClass(env.getProperty("jdbc.driver"));
        } catch (PropertyVetoException exc) {
        
            throw new RuntimeException(exc);
        }
        
        // log the connection props
        // check if we are really reading data from properties file     
        logger.info(">>>>> jdbc.url=" + env.getProperty("jdbc.url"));
        logger.info(">>>>> jdbc.user=" + env.getProperty("jdbc.user"));
        
        // set database connection props
        securityDataSource.setJdbcUrl(env.getProperty("jdbc.url"));
        securityDataSource.setUser(env.getProperty("jdbc.user"));
        securityDataSource.setPassword(env.getProperty("jdbc.password"));
        
        // set connection pool props
        securityDataSource.setInitialPoolSize(
                getIntProperty("connection.pool.initialPoolSize"));
        
        securityDataSource.setMinPoolSize(
                getIntProperty("connection.pool.minPoolSize"));
        
        securityDataSource.setMaxPoolSize(
                getIntProperty("connection.pool.maxPoolSize"));
        
        securityDataSource.setMaxIdleTime(
                getIntProperty("connection.pool.maxIdleTime"));
        
        return securityDataSource;
    }
    private int getIntProperty(String propName) {
        
        String propVal = env.getProperty(propName);
        
        // convert to int
        int intPropVal = Integer.parseInt(propVal);
        
        return intPropVal;
    }
    
}

我没有连接错误,但它就像用户和密码表中的数据与我在mvc登录页面中的输入不匹配一样

希望有人能帮助我


提前感谢,如果我弄错了什么,很抱歉,我是新来的。

嗯,我把表的数据库弄乱了,没有遵循正确的模式,这是:

CREATE TABLE USERS (
USERNAME NVARCHAR2(128) PRIMARY KEY,
PASSWORD NVARCHAR2(128) NOT NULL,
ENABLED CHAR(1) CHECK (ENABLED IN ('Y','N') ) NOT NULL);

CREATE TABLE AUTHORITIES (
USERNAME NVARCHAR2(128) NOT NULL,
AUTHORITY NVARCHAR2(128) NOT NULL);

ALTER TABLE AUTHORITIES ADD CONSTRAINT AUTHORITIES_UNIQUE UNIQUE (USERNAME, AUTHORITY);

ALTER TABLE AUTHORITIES ADD CONSTRAINT AUTHORITIES_FK1 FOREIGN KEY (USERNAME) REFERENCES USERS (USERNAME) ENABLE;