我有一个使用spring boot 1.0.0.RC5和tomcat 8.0.3的web socket(ws)非安全实现应用程序的工作示例.现在我想切换到wss,即使用我已经由tomcat加载的自签名证书.
这个问题分为理论部分和实践部分两部分:
理论=>我需要在两个端口上监听tomcat吗?即在http和https上.我问这个的原因是因为我读到在网络套接字通信期间,连接的第一部分是通过http进行的,然后所谓的"升级"到websockets.我发布了我的测试示例
GET /hello HTTP/1.1
Host: 127.0.0.5:8080
User-Agent: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:28.0) Gecko/20100101 Firefox/28.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: en,en-gb;q=0.5
Accept-Encoding: gzip, deflate
DNT: 1
Sec-WebSocket-Version: 13
Origin: http://localhost:8080
Sec-WebSocket-Key: wIKSOMgaHbEmkaRuEHZ6IA==
Connection: keep-alive, Upgrade
Pragma: no-cache
Cache-Control: no-cache
Upgrade: websocket
HTTP/1.1 101 Switching Protocols
Server: Apache-Coyote/1.1
Upgrade: websocket
Connection: upgrade
Sec-WebSocket-Accept: 8trj6dyzlYdDUA3nAuwiM7SijRM=
Date: Mon, 31 Mar 2014 10:29:19 GMT
..,O.do..*i..nM,..\;..I=.
C!.U.~.U....I....-..Xu.T...H...T.E.d
.'
CONNECTED
heart-beat:0,0
version:1.1
.
.....]..M...F...f9..z?...9..{4..{4..5r...4..h/..{4..|W..
Run Code Online (Sandbox Code Playgroud)
这种沟通在wss上的表现如何?我们是否也有"升级"部分,如果是这样的话,我们需要http才能使该构造工作.
实际=>我面临的问题是,负责创建stomp消息的代码部分不起作用,即当我打开页面时
https://127.0.0.5:8888/wsTest
Run Code Online (Sandbox Code Playgroud)
firefox告诉我"这个连接是不可信的"然后我告诉firefox"我理解风险"并将证书添加为"安全例外".从那时起,证书存储在firefox"servers"选项卡下.一切都好到现在为止.然而,当我改为wss时,这个游戏不起作用,因为我预计它会起作用.即,这是在客户端创建套接字的功能.
function connect() {
var …Run Code Online (Sandbox Code Playgroud) 我有一个正在运行的应用程序spring boot 1.3 + hibernate 5 + java 8 + ZonedDateTime + postgresql并且在其中一个表中我有以下字段.
@Column(name = "DATE_ENABLED")
@Type(type="java.time.ZonedDateTime")
private ZonedDateTime dateEnabled;
@Column(name = "DATE_DISABLED")
@Type(type="java.time.ZonedDateTime")
private ZonedDateTime dateDisabled;
Run Code Online (Sandbox Code Playgroud)
如果我运行该应用程序,那么我发现默认情况下会生成"没有时区的时间戳"
testDB=# \d type
Table "public.type"
Column | Type | Modifiers
--------------------------------+-----------------------------+-----------
type_id | bytea | not null
date_disabled | timestamp without time zone |
date_enabled | timestamp without time zone |
Run Code Online (Sandbox Code Playgroud)
我知道如果我将columnDefinition ="TIMESTAMP WITH TIME ZONE"添加到列中,例如
@Column(name = "DATE_DISABLED", columnDefinition= "TIMESTAMP WITH TIME ZONE")
Run Code Online (Sandbox Code Playgroud)
然后它正常工作,我能够看到hibernate创建了一个带有时区的列,但是如果我正确理解这将只适用于postgres,即如果我明天将数据库更改为mysql,则hibernate将抛出错误.
因此,我的问题是如何一般地这样做,即告诉hibernate创建一个应包括时区和偏移量的列.我认为,由于故意创建java类型"ZonedDateTime"以包括时区和UTC时间偏移,因此hibernate默认会创建一个包含时区的列.因此问题再次出现:告诉hibernate包含时区和偏移的正确方法是什么.
这是我的pom的一部分:
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.3.0.RELEASE</version>
<hibernate.version>5.0.4.Final</hibernate.version>
<dependency> …Run Code Online (Sandbox Code Playgroud) 好吧,我有一个正常运行的spring-boot应用程序在本地计算机上运行.但是我注意到当我做mvn包时,我的css或java脚本都找不到
/src/main/wepapp/css
Run Code Online (Sandbox Code Playgroud)
正被复制到目标目录中创建的jar文件(包)中.
弹簧靴参考指南说
65.3将现有应用程序转换为Spring Boot"可以在类路径根目录中将静态资源移动到/ public(或/ static或/ resources或/ META-INF/resources)."
24.1.4静态内容"如果你的应用程序打包为jar,请不要使用src/main/webapp文件夹.虽然这个文件夹是一个通用的标准,但它只适用于war包装,大多数构建都会默默地忽略它如果你生成一个jar的工具."
这意味着我可以将所有js和css文件夹放入文件夹中
/src/main/resources/static
Run Code Online (Sandbox Code Playgroud)
即现在我的结构看起来像那样
/src/main/resources/static/css/
/src/main/resources/static/js/
Run Code Online (Sandbox Code Playgroud)
然而,我所有的百里叶模板仍然位于
/src/main/resources/templates/
Run Code Online (Sandbox Code Playgroud)
我做到了,据我所知,我需要将ResourceHandler添加到我的ResourceHandlerRegistry.以前当我的所有cc都在"/ src/main/wepapp/css /"中时,我的ResourceHandlers看起来就像那样,它对我来说效果很好.
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.addResourceHandler("/pdfs/**").addResourceLocations("/pdfs/").setCachePeriod(0);
registry.addResourceHandler("/img/**").addResourceLocations("/img/").setCachePeriod(0);
registry.addResourceHandler("/js/**").addResourceLocations("/js/").setCachePeriod(0);
registry.addResourceHandler("/css/**").addResourceLocations("/css/").setCachePeriod(0);
}
Run Code Online (Sandbox Code Playgroud)
我尝试过添加多个处理程序
registry.addResourceHandler("/css/**").addResourceLocations("/css/").setCachePeriod(0);
Run Code Online (Sandbox Code Playgroud)
要么
registry.addResourceHandler("/css/**").addResourceLocations("/static/css/").setCachePeriod(0);
Run Code Online (Sandbox Code Playgroud)
要么
registry.addResourceHandler("/css/**").addResourceLocations("/").setCachePeriod(0);
Run Code Online (Sandbox Code Playgroud)
等等
但他们都没有为我工作.显示html模板,但在尝试查找/css/corresponing.css或/js/corresponing.js时,Web浏览器控制台正在重新编辑404
我故意在我的测试项目中禁用Spring安全性,以简化此问题的调试.
我还没有完全理解的另一件事是部署程序集.我已经阅读了一篇文章说当我想将特定文件夹放入maven生成的目标包jar文件中时,我确实需要将这些文件夹包含到我的部署程序集中,但是我确实做了"mvn package"仍然没有进行将my/src/main/static文件夹的所有内容(包含子文件夹)放入目标jar文件中.然而,我看到"templates"文件夹被复制到jar文件中.所以现场背后还有其他一些魔法.

这是我如何在我的百里香布局中声明css即
/src/main/resources/templates/layout.html
<!DOCTYPE html>
<html>
<head>
<title layout:title-pattern="$DECORATOR_TITLE - $CONTENT_TITLE">Task List</title>
<link rel="stylesheet" type="text/css" media="all" th:href="@{/css/syncServer.css}" href="../css/syncServer.css" />
...
</head>
<body>
...
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
我的问题是:到目前为止我完成的配置是否正确,如果是这样,我需要注意哪些其他选项/设置才能让应用程序找到css文件位于/ src/main/static/css /
另外一个
测试项目
git@github.com:TheDictator/sArchitecture.git
Run Code Online (Sandbox Code Playgroud) 假设弹簧安全和弹簧mvc的工作问候世界的例子.
当我使用wireshark进行跟踪时,我在http请求中看到以下标志
X-Content-Type-Options: nosniff
X-XSS-Protection: 1; mode=block
Cache-Control: no-cache, no-store, max-age=0, must-revalidate
Pragma: no-cache
Expires: 0
Strict-Transport-Security: max-age=31536000 ; includeSubDomains
X-Frame-Options: DENY
Set-Cookie: JSESSIONID=XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX; Path=/; Secure; HttpOnly
Run Code Online (Sandbox Code Playgroud)
我想将此添加到我的标题:
Content-Security-Policy: script-src 'self'
Run Code Online (Sandbox Code Playgroud)
我知道X-Frame-Options几乎完成了同样的工作,但它仍然让我睡得更好.现在我想我需要在我的spring安全配置的配置功能下进行,但我不知道究竟是怎么回事,即我想.headers().something.something(self)
@Override
protected void configure(HttpSecurity http) throws Exception {
http
// .csrf().disable()
// .headers().disable()
.authorizeRequests()
.antMatchers( "/register",
"/static/**",
"/h2/**",
"/resources/**",
"/resources/static/css/**",
"/resources/static/img/**" ,
"/resources/static/js/**",
"/resources/static/pdf/**"
).permitAll()
.anyRequest().authenticated()
.and()
.formLogin()
.loginPage("/login")
.permitAll()
.and()
.logout()
.permitAll();
}
Run Code Online (Sandbox Code Playgroud) 对于websockets,MockHttpServletRequestBuilder的等价物是什么.即在我想测试Websockets的情况下,我想测试一个运行时间很长的websocket应用程序,并避免在第一次应该进行升级的http get调用之后SecurityContextPersistenceFilter覆盖SecurityContex的情况.对于普通休息的http应用程序,这是通过利用SecurityMockMvcRequestPostProcessors到目前为止完成的.这里使用SecurityMockMvcRequestPostProcessors的示例
但是当我想测试一个长期运行的websocket应用程序时该怎么做.即我想要为websockets创建类似MockHttpServletRequestBuilder的东西.春天有类似的东西吗?或者有没有办法为此目的使用MockHttpServletRequestBuilder?即目标是创建websocket端点并避免升级后SecurityContex被清除的情况.
我找到了一些替代方法,例如传递会话,如此处所述 ,但这对我来说不是一个替代方案,因为使用方法级安全性的代码不起作用,因为SecurityContex正在被更改.
我有多个类,我总是在定义表的主键的字段上使用相同的注释,例如:
@Id
@Type(type = "uuid-binary")
@GeneratedValue(generator = "uuid")
@GenericGenerator(name = "uuid", strategy = "uuid2",
parameters = { @Parameter(
name = "uuid_gen_strategy_class",
value = "org.hibernate.id.UUIDGenerationStrategy")
})
@Column(name="PROFILE_ID", unique = true)
@NotNull(message = "we have one message" , payload =Severity.Info.class)
private UUID profileId;
Run Code Online (Sandbox Code Playgroud)
现在我正在寻找一种方法,在我进行验证时将所有这些注释聚合到一个单独的注释,比如注释聚合,即我可以将@NotNull和@Size从(javax.validation.constraints)聚合到以下注释"Name" .
package org.StudentLib.CustomeAnnotations;
import …
@Target( {FIELD, ANNOTATION_TYPE, CONSTRUCTOR, PARAMETER})
@Retention(RUNTIME)
@Constraint(validatedBy = {})
@Documented
@NotNull
@Id
@Size(message = "The size of the name should be between {min} and {max} caracters",
min = 1, max = 50,
payload …Run Code Online (Sandbox Code Playgroud) 将 OpenSSL 链接到 webassembly
在问这个问题之前,我只想说我做了一些功课。这个问题与这里已经提出的问题非常相似,即 如何将 OpenSSL 与 emscripten 链接?
在我找到了一个非常好的详细手册后,如何将 OpenSSL 编译为 webassemly 在这里 https://www.ip6.li/node/129
我能够成功运行所有步骤,即
1)首先进入下载最新emscripten的目录,设置一些路径变量:
~/emscripten/emsdk$ source ./emsdk_env.sh
Run Code Online (Sandbox Code Playgroud)
2)然后执行上面手册中的脚本
./mk-openssl-webassemby.sh:
Run Code Online (Sandbox Code Playgroud)
基本上,它全部编译没有任何错误,但有一个特定的警告。编译后,我可以 cd 到 crypto/sha 目录,看到文件被编译为所谓的中间表示:
/openssl/openssl-1.1.0h/openssl/crypto/sha$ file sha256.o
sha256.o: LLVM IR bitcode
Run Code Online (Sandbox Code Playgroud)
在阅读其他在线资源时,我希望该文件具有 .bc 扩展名,但似乎 .o 也是正确的。不确定。
我在编译过程中看到以下警告:
make[2]: Entering directory '/openssl/openssl-1.1.0h/openssl'
( :; LIBDEPS="${LIBDEPS:--L. -lssl -L. -lcrypto -lsocket -lnsl }"; LDCMD="${LDCMD:-emcc}"; LDFLAGS="${LDFLAGS:--DNDEBUG -DOPENSSL_NO_DYNAMIC_ENGINE -DOPENSSL_API_COMPAT=0x10100000L -DOPENSSLDIR="\"/tmp\"" -DENGINESDIR="\"/usr/local/lib/engines-1.1\"" -g -Wall }"; LIBPATH=`for x in $LIBDEPS; do echo $x; done | sed -e 's/^ *-L//;t' -e d | uniq`; …Run Code Online (Sandbox Code Playgroud) 在提出这个问题时,我正在寻找实施我自己的AuthenticationProvider的指导.我的意思是:
到目前为止,我已经了解到,如果用户已经过身份验证,Spring Security会询问AuthenticationProvider对象.目前我正在使用DaoAuthenticationProvider来处理我自己的用户UserDetailService返回的用户名和密码.一切都很棒!Spring支持很多不同的AuthenticationProvider,例如有一个用于LDAP,Jdbc,DAO(如上所述),我甚至可以找到一个用于Kerberos.但是,SRP没有身份验证提供程序,因此需要编写一个.
我的问题如下:
当我们使用DaoAuthenticationProvider即用户/密码认证时,我们有一个html表单,其中输入用户名和密码,然后一个按钮负责提交这两个参数.买入的barameteres通过某些传输通道传输到服务器,即只需点击一下,我们就能够在同一个http请求中发送所有数据,即验证所需的全部数据.这可以在UsernamePasswordAuthenticationFilter中看到.这里的方法"attemptAuthentication"采用"HttpServletRequest request",其中包括用户名和密码.直到现在一切都好.
public Authentication attemptAuthentication(HttpServletRequest request, HttpServletResponse response) throws AuthenticationException {
...
}
Run Code Online (Sandbox Code Playgroud)
好吧,在简单的SRP中我们还有一个用户名和密码的表单,除了密码!!!必须!不能通过网络转移.为了实现该约束,必须在客户端和服务器之间进行"讨论",即必须交换以下参数.
1)用户名(I),
2)一个名为"A"的值
3)一个名为"B"的值
4)一个名为"M1"的值
5)一个名为"M2"的值
那么,让我们假设有一个名为"SrpAuthenticationProcessingFilter"的过滤器,如果新的身份验证协议更像是我在RFC 5054中的对话,那么过滤器应该如何.
Client Server
Client Hello (I) -------->
Server Hello
Certificate*
Server Key Exchange (N, g, s, B)
<-------- Server Hello Done
Client Key Exchange (A) -------->
[Change cipher spec]
Finished -------->
[Change cipher spec]
<-------- Finished
Application Data <-------> Application Data
Run Code Online (Sandbox Code Playgroud)
在这里,我们有一个需要的客户
与用户名和密码身份验证相反,这些是7个步骤而不是1个步骤.其中3个需要在SrpAuthenticationProcessingFilter之前发生.现在我知道有可能将用户名与"值A"一起发送,从而缩短了步骤数,但我想严格遵循RFC.从来没有采取简单的方法吗?
问题实际上是我在哪里放置可以响应客户端和服务器之间的乒乓(对话)的代码,即上面提到的前3个步骤a,b和c.它应该将它们放在SrpEntryPoint对象中还是其他位置.if else然后是在SpringSecurity的背景下?
我可以解决这个问题的一种方法是使用websockets,但我还想使该身份验证独立于任何第5-7层协议,如websockets,http,spdy等.这意味着第一个实现应该是简单的http请求/响应,然后是任何其他协议.
因此,目前实施SRP可能是正确的结构是:
SRPAuthenticationEntryPoint实现了org.springframework.security.web.AuthenticationEntryPoint - …
我有一个使用带有websockets的tomcat的spring应用程序.每当tomcat创建一个新线程时,我想使用DelegatingSecurityContextRunnable,即warp tomcat线程.有谁知道这是怎么做的.可以找到问题的原因.这里
也许这可以通过使用AOP和一些建议来完成?
我有一个Spring Boot应用程序,它通过二进制websocket交换消息。即没有STOMP,AMQP等或任何其他消息传递协议!!!现在,我需要用“ websocket”的范围标记我的一个班级。像下面这样:
@Service("session")
@Scope(scopeName = "websocket", proxyMode = ScopedProxyMode.TARGET_CLASS)
public class Session {
...
}
Run Code Online (Sandbox Code Playgroud)
我在这里阅读了 引用该文档的文档:
“可以将WebSocket范围的bean注入到控制器以及在“ clientInboundChannel”上注册的任何通道拦截器中。
我想在那句话中强调“和”一词。
好吧,我确实有一个控制器,但是我没有任何channelInterceptor。我将其注入为:
@Controller("entryPoint")
public class EntryPoint {
@Autowired
private ApplicationContext applicationContext;
private ApplicationEventPublisher applicationEventPublisher;
@Autowired
private Session session;
...
@PostConstruct
public void init() {
// Invoked after dependencies injected
logger.info("EntryPoint init method i.e. @PostConstruct invoked");
}
...
}
Run Code Online (Sandbox Code Playgroud)
现在,我发现很有趣的第一个想法是,我需要注释@EnableWebSocketMessageBroker,即@EnableWebSocket似乎还不够,但是接着问为什么。无论我是否使用消息传递协议,我都应该能够独立定义该范围。至少那是我所相信的。
反正没有它我得到错误
java.lang.IllegalStateException: No Scope registered for scope name 'websocket'
Run Code Online (Sandbox Code Playgroud)
我说好,让我们为消息代理创建一个虚拟的配置文件,它带来了更多的依赖性,例如:
<dependency>
<groupId>io.projectreactor</groupId>
<artifactId>reactor-core</artifactId>
</dependency>
<dependency>
<groupId>io.projectreactor</groupId>
<artifactId>reactor-net</artifactId> …Run Code Online (Sandbox Code Playgroud) spring ×6
spring-boot ×4
security ×2
websocket ×2
aggregation ×1
annotations ×1
css ×1
duplicates ×1
emscripten ×1
hibernate ×1
java ×1
java-8 ×1
junit ×1
maven ×1
openssl ×1
postgresql ×1
spring-mvc ×1
srp-protocol ×1
stomp ×1
webassembly ×1