当前位置: 首页 > news >正文

网站菜单实现原理重庆新媒体运营公司有哪些

网站菜单实现原理,重庆新媒体运营公司有哪些,苏州网站模板建站,茶叶网站规划spring nosql在前面的文章中#xff0c;我们从一个SQL数据库提供用户和权威检索自定义查询设置弹簧安全配置。 如今#xff0c;许多现代应用程序都使用NoSQL数据库。 Spring安全性不是NoSQL数据库的现成解决方案。 在这种情况下#xff0c;我们需要通过实现自定义UserDeta… spring nosql 在前面的文章中我们从一个SQL数据库提供用户和权威检索自定义查询设置弹簧安全配置。 如今许多现代应用程序都使用NoSQL数据库。 Spring安全性不是NoSQL数据库的现成解决方案。 在这种情况下我们需要通过实现自定义UserDetailsS​​ervice提供解决方案。 在此示例中我们将使用MongoDB数据库。 我将使用docker映像但是通过从官方网站下载来建立mongodb数据库是一样容易的。 这些是开始使用docker和mongodb的一些命令如果不使用docker请忽略它们 #pull the mongo image docker pull mongo #create a mongo container docker run --name some-mongo -d mongo #get the docker container id docker ps #get the containers ip docker inspect --format {{ .NetworkSettings.IPAddress }} $CID #connection using the ip retrieved mongo $mongodb_container_ip 然后我们将编写一个简单的初始化脚本称为createuser.js。 该脚本将创建一个包含用户信息的文档例如用户名密码和授权。 use springsecurity db.users.insert({name:John,surname:doe,email:johndoe.com,password:cleartextpass,authorities:[user,admin]}) 我们将使用mongo cli执行它。 mongo 172.17.0.2:27017 createuser.js 为了在mongodb中使用spring security我们需要从users集合中检索用户信息。 第一步是将mongodb依赖项添加到我们的gradle文件中包括mongodb驱动程序。 请注意我们将使用名为“ customuserdetails”的配置文件。 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.mongodb:mongo-java-driver:1.3)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, customuserdetails } 然后我们将创建一个mongodb连接bean。 package com.gkatzioura.spring.security.config;import com.mongodb.Mongo; import com.mongodb.MongoClient; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Profile;/*** Created by gkatzioura on 9/27/16.*/ Configuration Profile(customuserdetails) public class MongoConfiguration {Beanpublic MongoClient createConnection() {//You should put your mongo ip herereturn new MongoClient(172.17.0.2:27017);} } 然后我们将创建一个自定义用户详细信息对象。 package com.gkatzioura.spring.security.model;import org.springframework.security.core.GrantedAuthority; import org.springframework.security.core.authority.AuthorityUtils; import org.springframework.security.core.userdetails.UserDetails;import java.util.Collection; import java.util.List;/*** Created by gkatzioura on 9/27/16.*/ public class MongoUserDetails implements UserDetails{private String username;private String password;private ListGrantedAuthority grantedAuthorities;public MongoUserDetails(String username,String password,String[] authorities) {this.username username;this.password password;this.grantedAuthorities AuthorityUtils.createAuthorityList(authorities);}Overridepublic Collection? extends GrantedAuthority getAuthorities() {return grantedAuthorities;}Overridepublic String getPassword() {return password;}Overridepublic String getUsername() {return username;}Overridepublic boolean isAccountNonExpired() {return true;}Overridepublic boolean isAccountNonLocked() {return true;}Overridepublic boolean isCredentialsNonExpired() {return true;}Overridepublic boolean isEnabled() {return true;} } 下一步我们将添加一个自定义UserDetailsS​​ervice以通过mongodb数据库检索用户详细信息。 package com.gkatzioura.spring.security.service;import com.gkatzioura.spring.security.model.MongoUserDetails; import com.mongodb.MongoClient; import com.mongodb.client.MongoCollection; import com.mongodb.client.MongoDatabase; import com.mongodb.client.model.Filters; import org.bson.Document; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.security.core.userdetails.UserDetails; import org.springframework.security.core.userdetails.UserDetailsService; import org.springframework.security.core.userdetails.UsernameNotFoundException; import org.springframework.stereotype.Service;import java.util.List;/*** Created by gkatzioura on 9/27/16.*/ public class CustomerUserDetailsService implements UserDetailsService {Autowiredprivate MongoClient mongoClient;Overridepublic UserDetails loadUserByUsername(String email) throws UsernameNotFoundException {MongoDatabase database mongoClient.getDatabase(springsecurity);MongoCollectionDocument collection database.getCollection(users);Document document collection.find(Filters.eq(email,email)).first();if(document!null) {String name document.getString(name);String surname document.getString(surname);String password document.getString(password);ListString authorities (ListString) document.get(authorities);MongoUserDetails mongoUserDetails new MongoUserDetails(email,password,authorities.toArray(new String[authorities.size()]));return mongoUserDetails;}return null;}} 最后一步是使用我们先前实现的自定义UserDetailsS​​ervice提供spring安全配置。 package com.gkatzioura.spring.security.config;import com.gkatzioura.spring.security.service.CustomerUserDetailsService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Bean; 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 org.springframework.security.core.userdetails.UserDetailsService;/*** Created by gkatzioura on 9/27/16.*/ EnableWebSecurity Profile(customuserdetails) public class CustomUserDetailsSecurityConfig extends WebSecurityConfigurerAdapter {Beanpublic UserDetailsService mongoUserDetails() {return new CustomerUserDetailsService();}Overrideprotected void configure(AuthenticationManagerBuilder auth) throws Exception {UserDetailsService userDetailsService mongoUserDetails();auth.userDetailsService(userDetailsService);}Overrideprotected void configure(HttpSecurity http) throws Exception {http.authorizeRequests().antMatchers(/public).permitAll().anyRequest().authenticated().and().formLogin().permitAll().and().logout().permitAll();}} 运行应用程序问题 gradle bootRun 您可以在github上找到源代码 翻译自: https://www.javacodegeeks.com/2016/09/spring-boot-spring-security-nosql.htmlspring nosql
http://www.sadfv.cn/news/87773/

相关文章:

  • pc网站转换成waphtml5移动网站开发流程
  • 设计师喜欢的购物网站电商开放平台
  • 网站流量查询 优帮云公司门户网站开发价格
  • 网站建设程序编制做编程的+网站有哪些内容
  • 广州智迅网络做网站百度站长平台官网死链提交
  • 做论坛网站好吗做网站用jsp还是html
  • 竞猜网站开发wordpress模板中国风
  • 新乡网站建设设计公司哪家好平面图怎么画
  • 取名字的网站 优帮云南京物流最新情况
  • 衡水专业制作网站羽毛球最新赛事
  • 网站建设项目实践报告书建设银行网站名怎么写
  • 即墨市网站建设科技守护者
  • 适合毕设做的简单网站在线制作图片加图片
  • 项目之家app佛山网站优化好
  • dw如何做网站后台如何做外贸品牌网站
  • 有没有专门做特产的网站河南国基建设集团--官方网站
  • 东莞住房和城乡建设局网站wordpress的网站好用吗
  • 教育加盟培训网站建设给网站做路由
  • app 微商城网站建设昆明网络公司收费标准
  • 爱站库免费关键词排名优化软件
  • 无锡高端网站建设公司电商seo什么意思
  • 无锡设计网站找哪家中国建设银行网站查询密码是什么意思
  • 苏州网站制作电话高端网站的特点
  • 网页设计网站的主题wordpress 微博 链接地址
  • 销售网站建设考核指标wordpress rss文件
  • 如何制作公司网站米绘花型设计师服务平台
  • 一些网站只能在微信打开怎么做的有名的产品设计公司
  • 江苏网站设计公司电话合肥做网站价格是多少
  • 广州建筑公司网站专业重庆房产网站建设
  • 网站优化目录数码科技网站