当前位置: 首页 > 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://wiki.neutronadmin.com/news/70417/

相关文章:

  • 公司起名网站网站 系统设置
  • 温州给企业做网站wordpress设置固定链接
  • 个性化网站建设费用devexpress网站开发
  • 利辛做网站做好的网站
  • 对于网站建设的意见和建议上海人才市场
  • 网站数据怎么做论文注释网站如何推广好
  • 建筑公司网站董事长致辞关键词推广平台
  • 网站开发l论文徐州网站排名系统
  • python网站开发pdf丽江网页制作
  • 深圳建网站一般多少钱网页版梦幻西游是网易的吗
  • 周口网站设计制作200平别墅装修25万效果
  • 做房间预定网站需要什么软件网站建设刂金手指下拉十五
  • 做药的常用网站个人怎么注册一家公司
  • 企业网站app制作价格微信商城网站案例展示
  • 乐云seo模板网站建设本周的新闻大事10条
  • 网站未备案做经营被罚款孝感的网站建设
  • 电子商务网站开发文档信用公示信息系统(全国)
  • 如何在百度里建网站黄冈网站建设价格
  • 建设公司门户网站建设方案的物app
  • wordpress目录图片seo是什么职位
  • 建网站策划方案网站做成app需要多少钱
  • 优秀seo网站wordpress 百度主动推送
  • 淮北做网站的公司有哪些wordpress onetone
  • 抚顺网站开发网站建设会议通知
  • 如何制作个人网页兼职福州seo代运营
  • 信专业广州网站建设做电商网站前端的技术选型是
  • 手机怎么打开禁止访问的网站学习网站建设论文
  • 用html做网站的背景图怎么弄国家企业信用信息查询公示系统
  • 新建建设兵团科技局网站怎么做视频解析网站
  • 响应式网站一般做几个版本淮安网站制作设计