Java Code Examples for org.springframework.jdbc.datasource.DriverManagerDataSource#setDriverClassName()

The following examples show how to use org.springframework.jdbc.datasource.DriverManagerDataSource#setDriverClassName() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MyDataSource.java    From luckwheel with Apache License 2.0 6 votes vote down vote up
@Bean
public JdbcTemplate mydataSource(){
    // JDBC模板依赖于连接池来获得数据的连接,所以必须先要构造连接池
    DriverManagerDataSource dataSource = new DriverManagerDataSource();
    dataSource.setDriverClassName("com.mysql.jdbc.Driver");
    dataSource.setUrl(url);
    dataSource.setUsername(name);
    dataSource.setPassword(pass);

    // 创建JDBC模板
    JdbcTemplate jdbcTemplate = new JdbcTemplate();
    // 这里也可以使用构造方法
    jdbcTemplate.setDataSource(dataSource);

    return jdbcTemplate;
}
 
Example 2
Source File: MysqlAccountManagementService.java    From wecube-platform with Apache License 2.0 5 votes vote down vote up
public DriverManagerDataSource newMysqlDatasource(String host, String port, String username, String password, String database) {
    DriverManagerDataSource dataSource = new DriverManagerDataSource();
    dataSource.setDriverClassName("com.mysql.cj.jdbc.Driver");
    if(Strings.isNullOrEmpty(database)) {
        dataSource.setUrl("jdbc:mysql://" + host + ":" + port + "?characterEncoding=utf8&serverTimezone=UTC");
    }else {
        dataSource.setUrl("jdbc:mysql://" + host + ":" + port +"/"+ database +"?characterEncoding=utf8&serverTimezone=UTC");
    }
    dataSource.setUsername(username);
    dataSource.setPassword(password);
    return dataSource;
}
 
Example 3
Source File: DataSourceConfig1.java    From Spring with Apache License 2.0 5 votes vote down vote up
@Bean
public DataSource dataSource(@Value("#{dbProps.driverClassName}") String driverClassName,
		@Value("#{dbProps.url}") String url,
		@Value("#{dbProps.username}") String username,
		@Value("#{dbProps.password}") String password) {
	DriverManagerDataSource ds = new DriverManagerDataSource();
	ds.setDriverClassName(driverClassName);
	ds.setUrl(url);
	ds.setUsername(username);
	ds.setPassword(password);
	return ds;
}
 
Example 4
Source File: HibernateConfiguration.java    From butterfly with Apache License 2.0 5 votes vote down vote up
@Bean
public DriverManagerDataSource dataSource() {
    final DriverManagerDataSource source = new DriverManagerDataSource();
    source.setDriverClassName(this.driverClassName);
    source.setUsername(this.username);
    source.setPassword(this.password);
    source.setUrl(this.connectionUrl.replace('\\', '/'));

    return source;
}
 
Example 5
Source File: RepositoryConfig.java    From Spring with Apache License 2.0 5 votes vote down vote up
@Bean
public DriverManagerDataSource getDataSource() {
	final DriverManagerDataSource  ds = new DriverManagerDataSource();
	ds.setDriverClassName(driverClassName);
	ds.setUrl(url);
	ds.setUsername(username);
	ds.setPassword(password);
	return ds;
}
 
Example 6
Source File: TestDataConfig.java    From Spring with Apache License 2.0 5 votes vote down vote up
@Bean
public DataSource dataSource() {
	final DriverManagerDataSource ds = new DriverManagerDataSource();
	ds.setDriverClassName(driverClassName);
	ds.setUrl(url);
	ds.setUsername(username);
	ds.setPassword(password);
	return ds;
}
 
Example 7
Source File: PluginInstanceService.java    From wecube-platform with Apache License 2.0 4 votes vote down vote up
private void performUpgradeMysqlDatabaseData(PluginMysqlInstance mysqlInstance, PluginPackage pluginPackage,
        String latestVersion) throws IOException {
    String tmpFolderName = new SimpleDateFormat("yyyyMMddHHmmssSSS").format(new Date());
    String baseTmpDir = SystemUtils.getTempFolderPath() + tmpFolderName + "/";
    String initSqlPath = baseTmpDir + pluginProperties.getInitDbSql();

    String s3KeyName = pluginPackage.getName() + File.separator + pluginPackage.getVersion() + File.separator
            + pluginProperties.getInitDbSql();
    logger.info("Download init.sql from S3: {}", s3KeyName);

    s3Client.downFile(pluginProperties.getPluginPackageBucketName(), s3KeyName, initSqlPath);

    ResourceServer dbServer = resourceItemRepository.findById(mysqlInstance.getResourceItemId()).get()
            .getResourceServer();
    DriverManagerDataSource dataSource = new DriverManagerDataSource(
            "jdbc:mysql://" + dbServer.getHost() + ":" + dbServer.getPort() + "/" + mysqlInstance.getSchemaName()
                    + "?characterEncoding=utf8&serverTimezone=UTC",
            mysqlInstance.getUsername(), EncryptionUtils.decryptWithAes(mysqlInstance.getPassword(),
                    resourceProperties.getPasswordEncryptionSeed(), mysqlInstance.getSchemaName()));
    dataSource.setDriverClassName("com.mysql.cj.jdbc.Driver");

    File initSqlFile = new File(initSqlPath);

    File upgradeSqlFile = parseUpgradeMysqlDataFile(baseTmpDir, initSqlFile, pluginPackage, latestVersion);
    List<Resource> scripts = newArrayList(new FileSystemResource(upgradeSqlFile));
    ResourceDatabasePopulator populator = new ResourceDatabasePopulator();
    populator.setContinueOnError(false);
    populator.setIgnoreFailedDrops(false);
    populator.setSeparator(";");
    populator.setCommentPrefix("#");
    populator.setSqlScriptEncoding("utf-8");
    for(Resource script : scripts) {
    	populator.addScript(script);
    }
    try {
    	logger.info("start to execute sql script file:{}, host:{},port:{},schema:{}", 
    			upgradeSqlFile.getAbsolutePath(),
    			dbServer.getHost(),
    			dbServer.getPort(),
    			mysqlInstance.getSchemaName());
        populator.execute(dataSource);
    } catch (Exception e) {
        String errorMessage = String.format("Failed to execute [{}] for schema[%s]",
        		upgradeSqlFile.getName(), mysqlInstance.getSchemaName());
        logger.error(errorMessage);
        throw new WecubeCoreException(errorMessage, e);
    }
    logger.info(String.format("Upgrade database[%s] finished...", mysqlInstance.getSchemaName()));
}
 
Example 8
Source File: CustomerHandlerAuthentication.java    From CAS with Apache License 2.0 4 votes vote down vote up
@Override
protected AuthenticationHandlerExecutionResult doAuthentication(Credential credential) throws GeneralSecurityException, PreventedException {

    CustomCredential customCredential = (CustomCredential) credential;

    String username = customCredential.getUsername();
    String password = customCredential.getPassword();
    String email = customCredential.getEmail();
    String telephone = customCredential.getTelephone();
    String capcha = customCredential.getCapcha();

    ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
    String right = attributes.getRequest().getSession().getAttribute("captcha_code").toString();


    if (!capcha.equalsIgnoreCase(right)) {
        throw new CheckCodeErrorException();
    }

    // 添加邮箱和电话的判断逻辑


    System.out.println("username : " + username);
    System.out.println("password : " + password);
    System.out.println("email : " + email);
    System.out.println("telephone : " + telephone);
    System.out.println("capcha : " + capcha);
    System.out.println("right : " + right);


    // JDBC模板依赖于连接池来获得数据的连接,所以必须先要构造连接池
    DriverManagerDataSource dataSource = new DriverManagerDataSource();
    dataSource.setDriverClassName("com.mysql.jdbc.Driver");
    dataSource.setUrl("jdbc:mysql://localhost:3306/cas");
    dataSource.setUsername("root");
    dataSource.setPassword("123");

    // 创建JDBC模板
    JdbcTemplate jdbcTemplate = new JdbcTemplate();
    jdbcTemplate.setDataSource(dataSource);

    String sql = "SELECT * FROM user WHERE username = ?";

    User info = (User) jdbcTemplate.queryForObject(sql, new Object[]{username}, new BeanPropertyRowMapper(User.class));

    System.out.println("database username : " + info.getUsername());
    System.out.println("database password : " + info.getPassword());


    if (info == null) {
        throw new AccountException("Sorry, username not found!");
    }

    if (!info.getPassword().equals(password)) {
        throw new FailedLoginException("Sorry, password not correct!");
    } else {

        final List<MessageDescriptor> list = new ArrayList<>();
        // 可自定义返回给客户端的多个属性信息
        HashMap<String, Object> returnInfo = new HashMap<>();
        returnInfo.put("expired", info.getDisabled());
        returnInfo.put("email", info.getEmail());
        returnInfo.put("username", info.getUsername());
        returnInfo.put("password", info.getPassword());
        returnInfo.put("disabled", info.getDisabled());

        return createHandlerResult(customCredential,
                this.principalFactory.createPrincipal(username, returnInfo), list);
    }


}
 
Example 9
Source File: CustomerHandlerAuthentication.java    From CAS with Apache License 2.0 4 votes vote down vote up
@Override
protected AuthenticationHandlerExecutionResult doAuthentication(Credential credential) throws GeneralSecurityException, PreventedException {

    CustomCredential customCredential = (CustomCredential) credential;

    String username = customCredential.getUsername();
    String password = customCredential.getPassword();
    String email = customCredential.getEmail();
    String telephone = customCredential.getTelephone();
    String capcha = customCredential.getCapcha();

    ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
    String right = attributes.getRequest().getSession().getAttribute("captcha_code").toString();


    if (!capcha.equalsIgnoreCase(right)) {
        throw new CheckCodeErrorException();
    }

    // 添加邮箱和电话的判断逻辑


    System.out.println("username : " + username);
    System.out.println("password : " + password);
    System.out.println("email : " + email);
    System.out.println("telephone : " + telephone);
    System.out.println("capcha : " + capcha);
    System.out.println("right : " + right);


    // JDBC模板依赖于连接池来获得数据的连接,所以必须先要构造连接池
    DriverManagerDataSource dataSource = new DriverManagerDataSource();
    dataSource.setDriverClassName("com.mysql.jdbc.Driver");
    dataSource.setUrl("jdbc:mysql://localhost:3306/cas");
    dataSource.setUsername("root");
    dataSource.setPassword("123");

    // 创建JDBC模板
    JdbcTemplate jdbcTemplate = new JdbcTemplate();
    jdbcTemplate.setDataSource(dataSource);

    String sql = "SELECT * FROM user WHERE username = ?";

    User info = (User) jdbcTemplate.queryForObject(sql, new Object[]{username}, new BeanPropertyRowMapper(User.class));

    System.out.println("database username : " + info.getUsername());
    System.out.println("database password : " + info.getPassword());


    if (info == null) {
        throw new AccountException("Sorry, username not found!");
    }

    if (!info.getPassword().equals(password)) {
        throw new FailedLoginException("Sorry, password not correct!");
    } else {

        final List<MessageDescriptor> list = new ArrayList<>();
        // 可自定义返回给客户端的多个属性信息
        HashMap<String, Object> returnInfo = new HashMap<>();
        returnInfo.put("expired", info.getDisabled());
        returnInfo.put("email", info.getEmail());
        returnInfo.put("username", info.getUsername());
        returnInfo.put("password", info.getPassword());
        returnInfo.put("disabled", info.getDisabled());

        return createHandlerResult(customCredential,
                this.principalFactory.createPrincipal(username, returnInfo), list);
    }


}
 
Example 10
Source File: CustomerHandlerAuthentication.java    From CAS with Apache License 2.0 4 votes vote down vote up
@Override
protected AuthenticationHandlerExecutionResult doAuthentication(Credential credential) throws GeneralSecurityException, PreventedException {

    CustomCredential customCredential = (CustomCredential) credential;

    String username = customCredential.getUsername();
    String password = customCredential.getPassword();
    String email = customCredential.getEmail();
    String telephone = customCredential.getTelephone();
    String capcha = customCredential.getCapcha();

    ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
    String right = attributes.getRequest().getSession().getAttribute("captcha_code").toString();


    if(!capcha.equalsIgnoreCase(right)){
        throw new CheckCodeErrorException();
    }

    // 添加邮箱和电话的判断逻辑


    System.out.println("username : " + username);
    System.out.println("password : " + password);
    System.out.println("email : " + email);
    System.out.println("telephone : " + telephone);
    System.out.println("capcha : " + capcha);
    System.out.println("right : " + right);


    // JDBC模板依赖于连接池来获得数据的连接,所以必须先要构造连接池
    DriverManagerDataSource dataSource = new DriverManagerDataSource();
    dataSource.setDriverClassName("com.mysql.jdbc.Driver");
    dataSource.setUrl("jdbc:mysql://localhost:3306/cas");
    dataSource.setUsername("root");
    dataSource.setPassword("123");

    // 创建JDBC模板
    JdbcTemplate jdbcTemplate = new JdbcTemplate();
    jdbcTemplate.setDataSource(dataSource);

    String sql = "SELECT * FROM user WHERE username = ?";

    User info = (User) jdbcTemplate.queryForObject(sql, new Object[]{username}, new BeanPropertyRowMapper(User.class));

    System.out.println("database username : "+ info.getUsername());
    System.out.println("database password : "+ info.getPassword());


    if (info == null) {
        throw new AccountException("Sorry, username not found!");
    }

    if (!info.getPassword().equals(password)) {
        throw new FailedLoginException("Sorry, password not correct!");
    } else {

        final List<MessageDescriptor> list = new ArrayList<>();

        return createHandlerResult(customCredential,
                this.principalFactory.createPrincipal(username, Collections.emptyMap()), list);
    }


}
 
Example 11
Source File: CustomUsernamePasswordAuthentication.java    From CAS with Apache License 2.0 2 votes vote down vote up
@Override
protected AuthenticationHandlerExecutionResult authenticateUsernamePasswordInternal(UsernamePasswordCredential usernamePasswordCredential, String s) throws GeneralSecurityException, PreventedException {

    String username = usernamePasswordCredential.getUsername();

    String password = usernamePasswordCredential.getPassword();

    System.out.println("username : " + username);
    System.out.println("password : " + password);


    // JDBC模板依赖于连接池来获得数据的连接,所以必须先要构造连接池
    DriverManagerDataSource dataSource = new DriverManagerDataSource();
    dataSource.setDriverClassName("com.mysql.jdbc.Driver");
    dataSource.setUrl("jdbc:mysql://localhost:3306/cas");
    dataSource.setUsername("root");
    dataSource.setPassword("123");

    // 创建JDBC模板
    JdbcTemplate jdbcTemplate = new JdbcTemplate();
    jdbcTemplate.setDataSource(dataSource);

    String sql = "SELECT * FROM user WHERE username = ?";

    User info = (User) jdbcTemplate.queryForObject(sql, new Object[]{username}, new BeanPropertyRowMapper(User.class));

    System.out.println("database username : "+ info.getUsername());
    System.out.println("database password : "+ info.getPassword());



    if (info == null) {
        throw new AccountException("Sorry, username not found!");
    }

    if (!info.getPassword().equals(password)) {
        throw new FailedLoginException("Sorry, password not correct!");
    } else {

        // 可自定义返回给客户端的多个属性信息
        HashMap<String, Object> returnInfo = new HashMap<>();
        returnInfo.put("expired", info.getDisabled());

        final List<MessageDescriptor> list = new ArrayList<>();

        return createHandlerResult(usernamePasswordCredential,
                this.principalFactory.createPrincipal(username, returnInfo), list);
    }
}
 
Example 12
Source File: CustomUsernamePasswordAuthentication.java    From CAS with Apache License 2.0 2 votes vote down vote up
@Override
protected AuthenticationHandlerExecutionResult authenticateUsernamePasswordInternal(UsernamePasswordCredential usernamePasswordCredential, String s) throws GeneralSecurityException, PreventedException {

    String username = usernamePasswordCredential.getUsername();

    String password = usernamePasswordCredential.getPassword();

    System.out.println("username : " + username);
    System.out.println("password : " + password);


    // JDBC模板依赖于连接池来获得数据的连接,所以必须先要构造连接池
    DriverManagerDataSource dataSource = new DriverManagerDataSource();
    dataSource.setDriverClassName("com.mysql.jdbc.Driver");
    dataSource.setUrl("jdbc:mysql://localhost:3306/cas");
    dataSource.setUsername("root");
    dataSource.setPassword("123");

    // 创建JDBC模板
    JdbcTemplate jdbcTemplate = new JdbcTemplate();
    jdbcTemplate.setDataSource(dataSource);

    String sql = "SELECT * FROM user WHERE username = ?";

    User info = (User) jdbcTemplate.queryForObject(sql, new Object[]{username}, new BeanPropertyRowMapper(User.class));

    System.out.println("database username : "+ info.getUsername());
    System.out.println("database password : "+ info.getPassword());



    if (info == null) {
        throw new AccountException("Sorry, username not found!");
    }

    if (!info.getPassword().equals(password)) {
        throw new FailedLoginException("Sorry, password not correct!");
    } else {

        // 可自定义返回给客户端的多个属性信息
        HashMap<String, Object> returnInfo = new HashMap<>();
        returnInfo.put("expired", info.getDisabled());

        final List<MessageDescriptor> list = new ArrayList<>();

        return createHandlerResult(usernamePasswordCredential,
                this.principalFactory.createPrincipal(username, returnInfo), list);
    }
}
 
Example 13
Source File: CustomUsernamePasswordAuthentication.java    From CAS with Apache License 2.0 2 votes vote down vote up
@Override
protected AuthenticationHandlerExecutionResult authenticateUsernamePasswordInternal(UsernamePasswordCredential usernamePasswordCredential, String s) throws GeneralSecurityException, PreventedException {

    String username = usernamePasswordCredential.getUsername();

    String password = usernamePasswordCredential.getPassword();

    System.out.println("username : " + username);
    System.out.println("password : " + password);


    // JDBC模板依赖于连接池来获得数据的连接,所以必须先要构造连接池
    DriverManagerDataSource dataSource = new DriverManagerDataSource();
    dataSource.setDriverClassName("com.mysql.jdbc.Driver");
    dataSource.setUrl("jdbc:mysql://localhost:3306/cas");
    dataSource.setUsername("root");
    dataSource.setPassword("123");

    // 创建JDBC模板
    JdbcTemplate jdbcTemplate = new JdbcTemplate();
    jdbcTemplate.setDataSource(dataSource);

    String sql = "SELECT * FROM user WHERE username = ?";

    User info = (User) jdbcTemplate.queryForObject(sql, new Object[]{username}, new BeanPropertyRowMapper(User.class));

    System.out.println("database username : "+ info.getUsername());
    System.out.println("database password : "+ info.getPassword());



    if (info == null) {
        throw new AccountException("Sorry, username not found!");
    }

    if (!info.getPassword().equals(password)) {
        throw new FailedLoginException("Sorry, password not correct!");
    } else {

        // 可自定义返回给客户端的多个属性信息
        HashMap<String, Object> returnInfo = new HashMap<>();
        returnInfo.put("expired", info.getDisabled());

        final List<MessageDescriptor> list = new ArrayList<>();

        return createHandlerResult(usernamePasswordCredential,
                this.principalFactory.createPrincipal(username, returnInfo), list);
    }
}
 
Example 14
Source File: CustomerHandlerAuthentication.java    From CAS with Apache License 2.0 2 votes vote down vote up
@Override
protected AuthenticationHandlerExecutionResult doAuthentication(Credential credential) throws GeneralSecurityException, PreventedException {

    UsernamePasswordCredential usernamePasswordCredentia = (UsernamePasswordCredential) credential;

    String username = usernamePasswordCredentia.getUsername();
    String password = usernamePasswordCredentia.getPassword();

    System.out.println("username : " + username);
    System.out.println("password : " + password);


    // JDBC模板依赖于连接池来获得数据的连接,所以必须先要构造连接池
    DriverManagerDataSource dataSource = new DriverManagerDataSource();
    dataSource.setDriverClassName("com.mysql.jdbc.Driver");
    dataSource.setUrl("jdbc:mysql://localhost:3306/cas");
    dataSource.setUsername("root");
    dataSource.setPassword("123");

    // 创建JDBC模板
    JdbcTemplate jdbcTemplate = new JdbcTemplate();
    jdbcTemplate.setDataSource(dataSource);

    String sql = "SELECT * FROM user WHERE username = ?";

    User info = (User) jdbcTemplate.queryForObject(sql, new Object[]{username}, new BeanPropertyRowMapper(User.class));

    System.out.println("database username : "+ info.getUsername());
    System.out.println("database password : "+ info.getPassword());


    if (info == null) {
        throw new AccountException("Sorry, username not found!");
    }

    if (!info.getPassword().equals(password)) {
        throw new FailedLoginException("Sorry, password not correct!");
    } else {

        final List<MessageDescriptor> list = new ArrayList<>();

        return createHandlerResult(usernamePasswordCredentia,
                this.principalFactory.createPrincipal(username, Collections.emptyMap()), list);
    }


}
 
Example 15
Source File: CustomUsernamePasswordAuthentication.java    From CAS with Apache License 2.0 2 votes vote down vote up
@Override
protected AuthenticationHandlerExecutionResult authenticateUsernamePasswordInternal(UsernamePasswordCredential usernamePasswordCredential, String s) throws GeneralSecurityException, PreventedException {

    String username = usernamePasswordCredential.getUsername();

    String password = usernamePasswordCredential.getPassword();

    System.out.println("username : " + username);
    System.out.println("password : " + password);


    // JDBC模板依赖于连接池来获得数据的连接,所以必须先要构造连接池
    DriverManagerDataSource dataSource = new DriverManagerDataSource();
    dataSource.setDriverClassName("com.mysql.jdbc.Driver");
    dataSource.setUrl("jdbc:mysql://localhost:3306/cas");
    dataSource.setUsername("root");
    dataSource.setPassword("123");

    // 创建JDBC模板
    JdbcTemplate jdbcTemplate = new JdbcTemplate();
    jdbcTemplate.setDataSource(dataSource);

    String sql = "SELECT * FROM user WHERE username = ?";

    User info = (User) jdbcTemplate.queryForObject(sql, new Object[]{username}, new BeanPropertyRowMapper(User.class));

    System.out.println("database username : "+ info.getUsername());
    System.out.println("database password : "+ info.getPassword());



    if (info == null) {
        throw new AccountException("Sorry, username not found!");
    }

    if (!info.getPassword().equals(password)) {
        throw new FailedLoginException("Sorry, password not correct!");
    } else {

        // 可自定义返回给客户端的多个属性信息
        HashMap<String, Object> returnInfo = new HashMap<>();
        returnInfo.put("expired", info.getDisabled());

        final List<MessageDescriptor> list = new ArrayList<>();

        return createHandlerResult(usernamePasswordCredential,
                this.principalFactory.createPrincipal(username, returnInfo), list);
    }
}
 
Example 16
Source File: CustomUsernamePasswordAuthentication.java    From CAS with Apache License 2.0 2 votes vote down vote up
@Override
protected AuthenticationHandlerExecutionResult authenticateUsernamePasswordInternal(UsernamePasswordCredential usernamePasswordCredential, String s) throws GeneralSecurityException, PreventedException {

    String username = usernamePasswordCredential.getUsername();

    String password = usernamePasswordCredential.getPassword();

    System.out.println("username : " + username);
    System.out.println("password : " + password);


    // JDBC模板依赖于连接池来获得数据的连接,所以必须先要构造连接池
    DriverManagerDataSource dataSource = new DriverManagerDataSource();
    dataSource.setDriverClassName("com.mysql.jdbc.Driver");
    dataSource.setUrl("jdbc:mysql://localhost:3306/cas");
    dataSource.setUsername("root");
    dataSource.setPassword("123");

    // 创建JDBC模板
    JdbcTemplate jdbcTemplate = new JdbcTemplate();
    jdbcTemplate.setDataSource(dataSource);

    String sql = "SELECT * FROM user WHERE username = ?";

    User info = (User) jdbcTemplate.queryForObject(sql, new Object[]{username}, new BeanPropertyRowMapper(User.class));

    System.out.println("database username : "+ info.getUsername());
    System.out.println("database password : "+ info.getPassword());



    if (info == null) {
        throw new AccountException("Sorry, username not found!");
    }

    if (!info.getPassword().equals(password)) {
        throw new FailedLoginException("Sorry, password not correct!");
    } else {

        // 可自定义返回给客户端的多个属性信息
        HashMap<String, Object> returnInfo = new HashMap<>();
        returnInfo.put("expired", info.getDisabled());

        final List<MessageDescriptor> list = new ArrayList<>();

        return createHandlerResult(usernamePasswordCredential,
                this.principalFactory.createPrincipal(username, returnInfo), list);
    }
}
 
Example 17
Source File: CustomUsernamePasswordAuthentication.java    From CAS with Apache License 2.0 2 votes vote down vote up
@Override
protected AuthenticationHandlerExecutionResult authenticateUsernamePasswordInternal(UsernamePasswordCredential usernamePasswordCredential, String s) throws GeneralSecurityException, PreventedException {

    String username = usernamePasswordCredential.getUsername();

    String password = usernamePasswordCredential.getPassword();

    System.out.println("username : " + username);
    System.out.println("password : " + password);


    // JDBC模板依赖于连接池来获得数据的连接,所以必须先要构造连接池
    DriverManagerDataSource dataSource = new DriverManagerDataSource();
    dataSource.setDriverClassName("com.mysql.jdbc.Driver");
    dataSource.setUrl("jdbc:mysql://localhost:3306/cas");
    dataSource.setUsername("root");
    dataSource.setPassword("123");

    // 创建JDBC模板
    JdbcTemplate jdbcTemplate = new JdbcTemplate();
    jdbcTemplate.setDataSource(dataSource);

    String sql = "SELECT * FROM user WHERE username = ?";

    User info = (User) jdbcTemplate.queryForObject(sql, new Object[]{username}, new BeanPropertyRowMapper(User.class));

    System.out.println("database username : "+ info.getUsername());
    System.out.println("database password : "+ info.getPassword());



    if (info == null) {
        throw new AccountException("Sorry, username not found!");
    }

    if (!info.getPassword().equals(password)) {
        throw new FailedLoginException("Sorry, password not correct!");
    } else {

        // 可自定义返回给客户端的多个属性信息
        HashMap<String, Object> returnInfo = new HashMap<>();
        returnInfo.put("expired", info.getDisabled());

        final List<MessageDescriptor> list = new ArrayList<>();

        return createHandlerResult(usernamePasswordCredential,
                this.principalFactory.createPrincipal(username, returnInfo), list);
    }
}
 
Example 18
Source File: CustomUsernamePasswordAuthentication.java    From CAS with Apache License 2.0 2 votes vote down vote up
@Override
protected AuthenticationHandlerExecutionResult authenticateUsernamePasswordInternal(UsernamePasswordCredential usernamePasswordCredential, String s) throws GeneralSecurityException, PreventedException {

    String username = usernamePasswordCredential.getUsername();

    String password = usernamePasswordCredential.getPassword();

    System.out.println("username : " + username);
    System.out.println("password : " + password);


    // JDBC模板依赖于连接池来获得数据的连接,所以必须先要构造连接池
    DriverManagerDataSource dataSource = new DriverManagerDataSource();
    dataSource.setDriverClassName("com.mysql.jdbc.Driver");
    dataSource.setUrl("jdbc:mysql://localhost:3306/cas");
    dataSource.setUsername("root");
    dataSource.setPassword("123");

    // 创建JDBC模板
    JdbcTemplate jdbcTemplate = new JdbcTemplate();
    jdbcTemplate.setDataSource(dataSource);

    String sql = "SELECT * FROM user WHERE username = ?";

    User info = (User) jdbcTemplate.queryForObject(sql, new Object[]{username}, new BeanPropertyRowMapper(User.class));

    System.out.println("database username : "+ info.getUsername());
    System.out.println("database password : "+ info.getPassword());



    if (info == null) {
        throw new AccountException("Sorry, username not found!");
    }

    if (!info.getPassword().equals(password)) {
        throw new FailedLoginException("Sorry, password not correct!");
    } else {

        // 可自定义返回给客户端的多个属性信息
        HashMap<String, Object> returnInfo = new HashMap<>();
        returnInfo.put("expired", info.getDisabled());

        final List<MessageDescriptor> list = new ArrayList<>();

        return createHandlerResult(usernamePasswordCredential,
                this.principalFactory.createPrincipal(username, returnInfo), list);
    }
}
 
Example 19
Source File: CustomUsernamePasswordAuthentication.java    From CAS with Apache License 2.0 2 votes vote down vote up
@Override
protected AuthenticationHandlerExecutionResult authenticateUsernamePasswordInternal(UsernamePasswordCredential usernamePasswordCredential, String s) throws GeneralSecurityException, PreventedException {

    String username = usernamePasswordCredential.getUsername();

    String password = usernamePasswordCredential.getPassword();

    System.out.println("username : " + username);
    System.out.println("password : " + password);


    // JDBC模板依赖于连接池来获得数据的连接,所以必须先要构造连接池
    DriverManagerDataSource dataSource = new DriverManagerDataSource();
    dataSource.setDriverClassName("com.mysql.jdbc.Driver");
    dataSource.setUrl("jdbc:mysql://localhost:3306/cas");
    dataSource.setUsername("root");
    dataSource.setPassword("123");

    // 创建JDBC模板
    JdbcTemplate jdbcTemplate = new JdbcTemplate();
    jdbcTemplate.setDataSource(dataSource);

    String sql = "SELECT * FROM user WHERE username = ?";

    User info = (User) jdbcTemplate.queryForObject(sql, new Object[]{username}, new BeanPropertyRowMapper(User.class));

    System.out.println("database username : "+ info.getUsername());
    System.out.println("database password : "+ info.getPassword());



    if (info == null) {
        throw new AccountException("Sorry, username not found!");
    }

    if (!info.getPassword().equals(password)) {
        throw new FailedLoginException("Sorry, password not correct!");
    } else {

        // 可自定义返回给客户端的多个属性信息
        HashMap<String, Object> returnInfo = new HashMap<>();
        returnInfo.put("expired", info.getDisabled());

        final List<MessageDescriptor> list = new ArrayList<>();

        return createHandlerResult(usernamePasswordCredential,
                this.principalFactory.createPrincipal(username, returnInfo), list);
    }
}
 
Example 20
Source File: CustomUsernamePasswordAuthentication.java    From CAS with Apache License 2.0 2 votes vote down vote up
@Override
protected AuthenticationHandlerExecutionResult authenticateUsernamePasswordInternal(UsernamePasswordCredential usernamePasswordCredential, String s) throws GeneralSecurityException, PreventedException {

    String username = usernamePasswordCredential.getUsername();

    String password = usernamePasswordCredential.getPassword();

    System.out.println("username : " + username);
    System.out.println("password : " + password);


    // JDBC模板依赖于连接池来获得数据的连接,所以必须先要构造连接池
    DriverManagerDataSource dataSource = new DriverManagerDataSource();
    dataSource.setDriverClassName("com.mysql.jdbc.Driver");
    dataSource.setUrl("jdbc:mysql://localhost:3306/cas");
    dataSource.setUsername("root");
    dataSource.setPassword("123");

    // 创建JDBC模板
    JdbcTemplate jdbcTemplate = new JdbcTemplate();
    jdbcTemplate.setDataSource(dataSource);

    String sql = "SELECT * FROM user WHERE username = ?";

    User info = (User) jdbcTemplate.queryForObject(sql, new Object[]{username}, new BeanPropertyRowMapper(User.class));

    System.out.println("database username : "+ info.getUsername());
    System.out.println("database password : "+ info.getPassword());



    if (info == null) {
        throw new AccountException("Sorry, username not found!");
    }

    if (!info.getPassword().equals(password)) {
        throw new FailedLoginException("Sorry, password not correct!");
    } else {

        // 可自定义返回给客户端的多个属性信息
        HashMap<String, Object> returnInfo = new HashMap<>();
        returnInfo.put("expired", info.getDisabled());

        final List<MessageDescriptor> list = new ArrayList<>();

        return createHandlerResult(usernamePasswordCredential,
                this.principalFactory.createPrincipal(username, returnInfo), list);
    }
}