网站开发开题报告引言,xampp 搭建wordpress,张家港专业做网站,湖北建设招标网 官方网站在上一篇文章中#xff0c;我们基于Spring Security发出请求的默认表架构实现了安全性。 考虑到用户和角色#xff0c;应用程序开发人员使用适合其需求的架构。 Spring使我们能够指定所需的查询#xff0c;以便检索用户名#xff0c;密码和角色等信息。 我们的自定义表将… 在上一篇文章中我们基于Spring Security发出请求的默认表架构实现了安全性。 考虑到用户和角色应用程序开发人员使用适合其需求的架构。 Spring使我们能够指定所需的查询以便检索用户名密码和角色等信息。 我们的自定义表将与第一个示例的表完全不同。 drop table if exists Custom_Users;
create table Custom_Users(id bigint auto_increment, username varchar(255), password varchar(255));
insert into Custom_Users(username,password) values(TestUser,TestPass);drop table if exists Custom_Roles;
create table Custom_Roles(username varchar(255),authority varchar(255), UNIQUE(username,authority));
insert into Custom_Roles(username,authority) values(TestUser,superadmin); 为了在Spring Security中使用这些表我们必须传递Spring Security将使用的查询以检索所需的安全信息。 为此我们将创建一个安全配置该安全配置将设置所需的查询。 package com.gkatzioura.spring.security.config;import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Profile;
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;import javax.sql.DataSource;/*** Created by gkatzioura on 9/20/16.*/
EnableWebSecurity
Profile(customquery)
public class CustomQuerySecurityConfig extends WebSecurityConfigurerAdapter {Autowiredprivate DataSource dataSource;Autowiredpublic void configAuthentication(AuthenticationManagerBuilder auth) throws Exception {auth.jdbcAuthentication().dataSource(dataSource).usersByUsernameQuery(SELECT username,password,1 FROM Custom_Users where username?).authoritiesByUsernameQuery(SELECT username,authority FROM Custom_Roles where username?);}Overrideprotected void configure(HttpSecurity http) throws Exception {http.authorizeRequests().antMatchers(/public).permitAll().anyRequest().authenticated().and().formLogin().permitAll().and().logout().permitAll();}} 我们使用弹簧轮廓。 我们的spring配置文件将是“ customquery”因此CustomQuerySecurityConfig将绑定到“ customquery”配置文件。 为了运行出于方便起见我们必须在build.gradle文件中更改默认配置文件。 group com.gkatzioura
version 1.0-SNAPSHOTbuildscript {repositories {mavenCentral()}dependencies {classpath(org.springframework.boot:spring-boot-gradle-plugin:1.4.0.RELEASE)}
}apply plugin: java
apply plugin: idea
apply plugin: spring-bootsourceCompatibility 1.8repositories {mavenCentral()
}dependencies {compile(org.springframework.boot:spring-boot-starter-web)compile(org.thymeleaf:thymeleaf-spring4)compile(org.springframework.boot:spring-boot-starter-security)compile(org.springframework:spring-jdbc)compile(com.h2database:h2:1.4.192)compile(org.slf4j:slf4j-api:1.6.6)compile(ch.qos.logback:logback-core:1.1.7)compile(ch.qos.logback:logback-classic:1.1.7)testCompile junit:junit:4.11
}bootRun {systemProperty spring.profiles.active, customquery
} 运行应用程序问题 gradle bootRun 您可以在github上找到源代码 翻译自: https://www.javacodegeeks.com/2016/09/spring-boot-spring-security-jdbc-part-2.html