因为我想介绍一些数据安全性,所以我想知道是否可以加密/解密 Grails 域类中的特定列,如果可以,最简单的方法是什么来实现这样的事情?
假设我有一个 User 类,想要加密 ssn 号或银行帐号,这样它们就不会以纯文本形式存储在数据库中。最好的方法是什么?
如何使用Spring Security Core强制为登录用户注销程序?我不想重定向到注销页面等..但需要在服务中进行.
我有一个关于命名查询的继承可能性的问题.我们想在我们的抽象域类中存储一些命名查询.
abstract class AbstractDomain {
boolean state
static namedQueries = {
isActive{
eq("state", true)
}
}
}
class Person extends AbstractDomain {
String name
Integer age
static namedQueries = {
age18 {
eq("age", 18)
}
}
}
Run Code Online (Sandbox Code Playgroud)
当我们尝试在Abstract域中调用namedquery时,由于覆盖块被覆盖的事实而失败.
由于isActive不存在,Person.isActive.age18失败.
我们可以在Abstract Domain类中重用命名查询吗?
我正在尝试使用最新版本的 Smack 4.1.0-beta 创建 XMPP 客户端。但是我在尝试登录本地运行的 OpenFire 服务器时遇到错误。
org.jivesoftware.smack.SmackException: SASL Authentication failed. No known authentication mechanisims.
Run Code Online (Sandbox Code Playgroud)
我尝试了各种用户凭据组合,但到目前为止还没有运气。当尝试使用 Pidgin 或 Adium al 连接到服务器时是可以的。任何线索我在代码中遗漏了什么?
XMPPTCPConnectionConfiguration config = XMPPTCPConnectionConfiguration.builder()
.setUsernameAndPassword("admin", "admin")
.setServiceName("localhost")
.setHost("localhost")
.setSecurityMode(ConnectionConfiguration.SecurityMode.disabled)
.setPort(5222)
.build();
AbstractXMPPConnection connection = new XMPPTCPConnection(config);
try {
connection.connect();
connection.login();
connection.disconnect();
} catch (SmackException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (XMPPException e) {
e.printStackTrace();
}
Run Code Online (Sandbox Code Playgroud) 我在Spring Boot应用程序中使用自定义过滤器,似乎有2种方法可以注册过滤器.
- >使用@Bean注册过滤器
@Bean
public Filter AuthenticationFilter() {
return new AuthenticationFilter();
}
Run Code Online (Sandbox Code Playgroud)
- >使用@Component对Filter进行Anotate
@Component
public class AuthenticationFilter implements Filter {}
Run Code Online (Sandbox Code Playgroud)
我很困惑的是,差异是什么以及为什么我应该使用一个而不是另一个?
我试图在Groovy源中设置最终属性(在Grails项目中使用)并遵循一些示例但不知何故我似乎无法工作,我无法找出原因..
class Foo {
final x
Foo(Map m=[:]) {
m.each { key, value -> this.@"$key" = value }
}
}
def foo = new Foo(x:1)
Run Code Online (Sandbox Code Playgroud)
我收到错误:
Cannot set the property 'x' because the backing field is final.
根据在互联网上发现的一些帖子,这应该工作.为什么失败怎么能在使用最终字段时通过地图设置属性?
我是Spring Boot的新手,想要从Rest Controller中的不同包中自动装配存储库.似乎当我将接口和实现放在不同的包中时,实际控制器的自动装置似乎失败了.
引起:org.springframework.beans.factory.NoSuchBeanDefinitionException:找不到[com.acme.repository.RawDataRepository]类型的限定bean用于依赖:
控制器:
package com.acme.controller;
import com.acme.repository.RawDataRepository;
// imports removed!
@RestController
@EnableAutoConfiguration
@ComponentScan("com.acme")
public class DataCollectionController {
@Autowired
private RawDataRepository repository;
// code removed!
}
Run Code Online (Sandbox Code Playgroud)
我试图使用@ComponentScan注释,但这没有给出解决方案.知道我错过了什么吗?每当我将接口放入控制器所在的包中时,一切顺利.

我正在尝试测试应该使用自定义错误属性的Spring Boot RestController.
@Bean
public ErrorAttributes errorAttributes() {
return new DefaultErrorAttributes() {
@Override
public Map<String, Object> getErrorAttributes(
RequestAttributes requestAttributes,
boolean includeStackTrace) {
Map<String, Object> errorAttributes = super.getErrorAttributes(requestAttributes, includeStackTrace);
Throwable error = getError(requestAttributes);
return errorAttributes;
}
};
}
Run Code Online (Sandbox Code Playgroud)
但是当我尝试使用简单测试来测试自定义错误属性时,不会考虑这些属性.下面的测试实际上会触发一个请求,除了使用自定义属性.但无论我做什么,代码似乎都没有被考虑在内.
class TestSpec extends Specification {
MockMvc mockMvc
def setup() {
mockMvc = MockMvcBuilders.standaloneSetup(new HelloWorldController()).build()
}
def "Test simple action"() {
when:
def response = mockMvc.perform(post("/hello")
.contentType(MediaType.APPLICATION_JSON)
.content('{"sayHelloTo": ""}')
)
then:
response.andExpect(status().isOk())
}
}
Run Code Online (Sandbox Code Playgroud)
关于我如何测试自定义属性的任何线索?
我需要获取发布到RestController的原始内容,这是对原始输入进行一些处理.为了实现这一目标,我正在寻找一种方法来获取原始内容而不会干扰过滤器链.这可能吗?
在我目前的Asciidoctor文档中,我有一个我想在代码块中使用的属性.有没有办法在代码块中进行字符串插值?
标题中的属性..
:api_version: 1.0
Run Code Online (Sandbox Code Playgroud)
代码块
{
"api_version" : "{api_version}",
}
Run Code Online (Sandbox Code Playgroud)
我似乎无法进行字符串替换,任何提示或提示在代码块中进行字符串替换?
grails ×4
spring ×4
spring-boot ×4
grails-orm ×2
asciidoc ×1
asciidoctor ×1
encryption ×1
groovy ×1
java ×1
openfire ×1
rest ×1
security ×1
smack ×1
spring-data ×1
xmpp ×1