2018年7月30日
1.搜索引擎框架
百度
google Lucene 单机操作,就是一堆jar包中的api的使用,自己干预,如何创建索引库,删除索引库,更新索引库,高亮,自己调度API
Solr 支持web应用研发,它封装好了对索引库的操作,直接做高级API编程。
ElasticSearch 默认支持集群的,调度,统一协调,任务派发,ZooKeeper (KeepAlived 简单) Lucene简介
Lucene是apache软件基金会一个开放源代码的全文检索引擎工具包,是一个全文检索引擎的架构,提供了完整的查询引擎和索引引擎,
部分文本分析引擎。
Lucene的目的是为软件开发人员提供一个简单易用的工具包,以方便在目标系统中实现全文检索的功能,或者是以此为基础建立起完整的
全文检索引擎。
Lucene最初是由Doug Cutting 所撰写的,是一位资深全文索引/检索专家,曾经是V-Twin搜索引擎的主要开发者,后来在Excite担任高级
系统架构设计师,目前从事于一些INTERNET底层架构的研究。他贡献出Lucene的目标是为各种中小型应用程式加入全文检索功能。 OSChina使用Lucene实现全文搜索。 索引:
全文索引
SQL Server全文索引
Mysql全文索引 全文搜索是一种将文件中所有文本与搜索项匹配的文字资料检索方法:
建文本库---》建立索引---》执行搜索---》过滤结果 ElasticSearch简介
ElasticSearch是一个基于Lucene实时分布式搜索和分析引擎。设计用于云计算中,能够达到实时搜索,稳定,可靠,快速,
安装使用方便。基于RestFul接口。
ElasticSearch就是为可用和可扩展而生的。可以通过购置性能更强的服务器来完成,称为垂直扩展或者向上扩展,或者增加
更多的服务器来完成,称为水平扩展或者向外扩展。 ES核心概念:
近实时
集群:一个或者多个节点的集合,保存应用的全部数据,并提供基于节点集成式的索引和搜索功能。
节点
分片:每个索引分成多个分片
小Tip: 默认ES每个索引分配5个分片,一个副本(5个分片),共计10个分片。 SpringBoot 整合 ElasticSearch:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-elasticsearch</artifactId>
</dependency> <dependency>
<groupId>com.sun.jna</groupId>
<artifactId>jna</artifactId>
<version>3.0.9</version>
</dependency> 配置文件配置:
spring.data.elasticsearch.cluster-nodes=123.56.20.15:9300
spring.data.elasticsearch.properties.transport.tcp.connect_timeout=1200s ------------------------------------------
ElasticsearchRepository(能力是最强的)---->ElasticsearchCrudRepository--->PagingAndSortingRepository--->CrudRepository ---------------------------------------------------------------------------------
SpringSequrity认证:
步骤一:依赖 <dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency> <!--thymeleaf和springsecurity整合的依赖-->
<dependency>
<groupId>org.thymeleaf.extras</groupId>
<artifactId>thymeleaf-extras-springsecurity4</artifactId>
</dependency> <!--thymeleaf 新的模板引擎,比jsp要出色-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency> 步骤二:
application.properties中需要的配置
##模板引擎的配置
spring.thymeleaf.prefix=classpath:/templates/
spring.thymeleaf.cache = false
spring.thymeleaf.mode=HTML5 步骤三:
准备UI页面
1.1 login.html: <!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org">
<head>
<meta charset="UTF-8">
<title>登录</title>
<script type="text/javascript" th:src="@{/js/jquery-3.3.1.js}"></script>
<script type="text/javascript"> </script>
</head>
<body>
<div>
<form th:action="@{/login}" method="post">
<h2>请登录</h2>
用户名:<input name="username" type="text"/><br/>
密码:<input name="password" type="password"/><br/>
<input type="submit" value="登录"/><br/>
<div th:if="${loginError}"></div>
<div th:text="${errorMsg}"></div>
</form>
</div>
</body>
</html> 1.2 index.html <!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org"
xmlns:sec="http://www.thymeleaf.org/thymeleaf-extras-springsecurity4"> <head>
<meta charset="UTF-8">
<title>博客系统</title>
<script type="text/javascript" th:src="@{/js/jquery-3.3.1.js}"></script>
<script type="text/javascript"> </script>
</head>
<body>
<div>
<!--authorize:认证,授权-->
<div sec:authorize="isAuthenticated()">
<p>登录的用户名为:<span sec:authentication="name"></span></p>
<p>登录的角色为:<span sec:authentication="principal.authorities"></span></p>
</div>
<!--匿名的。未经过认证的-->
<div sec:authorize="isAnonymous()">
<p>未登录</p>
</div>
</div>
</body>
</html> 步骤四:核心配置
在util层创建一个类SecurityConfig,继承了 WebSecurityConfigurerAdapter
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; @EnableWebSecurity
public class SecurityConfig extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
http
.authorizeRequests()
.antMatchers("/css/**","/js/**","/fonts/**","/index").permitAll() //都可以访问
.antMatchers("/users/**").hasRole("ADMIN") //需要相应的角色才能访问
.and()
.formLogin() //基于form表单登录验证
.loginPage("/login") //自定义登录信息
.failureUrl("/login-error");
}
@Autowired
public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception{
auth
.inMemoryAuthentication() //认证信息存储在内存中
.passwordEncoder(new MyPasswordEncoder()) //在此处应用自定义PasswordEncoder
.withUser("happy").password("6375196").roles("ADMIN");
}
} 步骤五:自定义密码编辑器: MyPasswordEncoder
import org.springframework.security.crypto.password.PasswordEncoder; public class MyPasswordEncoder implements PasswordEncoder { @Override
public String encode(CharSequence arg0) {
return arg0.toString();
} @Override
public boolean matches(CharSequence arg0, String arg1) {
return arg1.equals(arg0.toString());
}
} 步骤六:controller中给路径做界面映射和寻址
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping; @Controller
public class MainController {
@GetMapping("/index")
public String index(){
return "index";
} @GetMapping("/login")
public String login(){
return "login";
} @GetMapping("/login-error")
public String loginError(Model model){
model.addAttribute("loginError",true);
model.addAttribute("errorMsg","登录失败,用户名或密码错误");
return "login";
}
}

关于security的简单理解和应用的更多相关文章

  1. 12月13日 什么是help_method,session的简单理解, find_by等finder method

    helper_method Declare a controller method as a helper. For example, helper_method :link_to def link_ ...

  2. input屏蔽历史记录 ;function($,undefined) 前面的分号是什么用处 JSON 和 JSONP 两兄弟 document.body.scrollTop与document.documentElement.scrollTop兼容 URL中的# 网站性能优化 前端必知的ajax 简单理解同步与异步 那些年,我们被耍过的bug——has

    input屏蔽历史记录   设置input的扩展属性autocomplete 为off即可 ;function($,undefined) 前面的分号是什么用处   ;(function($){$.ex ...

  3. git的简单理解及基础操作命令

    前端小白一枚,最近开始使用git,于是花了2天看了廖雪峰的git教程(偏实践,对于学习git的基础操作很有帮助哦),也在看<git版本控制管理>这本书(偏理论,内容完善,很不错),针对所学 ...

  4. 简单理解Struts2中拦截器与过滤器的区别及执行顺序

    简单理解Struts2中拦截器与过滤器的区别及执行顺序 当接收到一个httprequest , a) 当外部的httpservletrequest到来时 b) 初始到了servlet容器 传递给一个标 ...

  5. [转]简单理解Socket

    简单理解Socket 转自 http://www.cnblogs.com/dolphinX/p/3460545.html  题外话 前几天和朋友聊天,朋友问我怎么最近不写博客了,一个是因为最近在忙着公 ...

  6. Js 职责链模式 简单理解

    js 职责链模式 的简单理解.大叔的代码太高深了,不好理解. function Handler(s) { this.successor = s || null; this.handle = funct ...

  7. Deep learning:四十六(DropConnect简单理解)

    和maxout(maxout简单理解)一样,DropConnect也是在ICML2013上发表的,同样也是为了提高Deep Network的泛化能力的,两者都号称是对Dropout(Dropout简单 ...

  8. Deep learning:四十二(Denoise Autoencoder简单理解)

    前言: 当采用无监督的方法分层预训练深度网络的权值时,为了学习到较鲁棒的特征,可以在网络的可视层(即数据的输入层)引入随机噪声,这种方法称为Denoise Autoencoder(简称dAE),由Be ...

  9. 简单理解dropout

    dropout是CNN(卷积神经网络)中的一个trick,能防止过拟合. 关于dropout的详细内容,还是看论文原文好了: Hinton, G. E., et al. (2012). "I ...

随机推荐

  1. Top-Down和Bottom-Up位图的区别

    Top-Down vs. Bottom-Up DIBs If you are new to graphics programming, you might expect that a bitmap w ...

  2. WebService_Demo

    简述 使用IDEA开发webservice服务,从零开始一步一步指引你. 服务端开发 首先创建一个webservice项目,如下图 创建完项目后idea会帮我们创建一个类,helloword,我们把它 ...

  3. react项目构建中的坑—淘宝镜像安装后要设置

    基本的搭建步骤参考博客:https://blog.csdn.net/qq_27727251/article/details/86593415 这里要强调的坑是:安装完淘宝镜像要将其设置为默认Regis ...

  4. 【javascript】2017-9-12 腾讯笔试小Q升序算法

    刚做完笔试,腾讯笔试系统真的不友好,作为一个前端,我只会用js写编程题,然而,然而腾讯笔试系统连js输入函数都没给,还不准跳出页面,那个调试结果一直显示错误,我一直找不到错误在哪,心累. 只做了一道笔 ...

  5. eclipse版本要求修改

    eclipse要求打开的是java1.6,而安装的是java1.7,这个时候需要修改配置 找到JAVA的安装路径, 点击前往-电脑-资源库-Java-javaVCirtualMachines-...- ...

  6. COGS 2566. [51nod 1129] 字符串最大值

    ★★★   输入文件:string_maxval.in   输出文件:string_maxval.out   简单对比时间限制:1 s   内存限制:256 MB [题目描述] 一个字符串的前缀是指包 ...

  7. ActiveMQ消息丢失怎么解决?

    在消息发送过程中消息丢失的话该怎么解决(包括网络原因): 解决思路: 可以把消息唯一ID,存到表里面,当消息接受端可以获取到这个ID,就给服务端一个回复IF,消息发送出去,没有回复,THEN一直循环发 ...

  8. python 基础之运算符

    运算符 a=10 ,b=20 运算符 描述 实例 + 加 - 两个对象相加 a + b 输出结果 30 - 减 - 得到负数或是一个数减去另一个数 a - b 输出结果 -10 * 乘 - 两个数相乘 ...

  9. 结合浅层高层特征的paper总结

    1.ION:在conv3.conv4.conv5和context features上分别进行roi_pooling,在channel那一维进行concat 2.Hypernet:在较浅层max_poo ...

  10. linux_1

    注: 创建软连接: "ln -s xxx 路径1" 在路径1创建xxx的软连接 特点: 1.文件类型 l 2.相当于windows的快捷方式 创建硬链接: "ln xxx ...