在基于 Spring Security 3.2 的应用程序中,我需要根据用户名和远程 IP 地址中的特定模式,针对两个不同的提供者对用户进行身份验证。
如果它们符合某些规则,则应根据 进行身份验证,否则应使用使用现有自定义实现的ActiveDirectoryLdapAuthenticationProvider
标准进行身份验证。AuthenticationProvider
UserDetailsService
我需要延长什么?AuthenticationManager
或者AuthenticationProvider
?任何示例代码将不胜感激:-)
注意:我已经成功尝试<authentication-provider />
在 中添加两个节点<authentication-manager />
,并且效果很好。但令我困扰的是,我的 Ldap 服务器每次身份验证尝试都会受到攻击(即使是那些不适合它的尝试)
我有一个大字符串,其中包含两个常量标记字符串之间的多行子序列,我可以用正则表达式识别.
为了简化我叫他们abcdef
和fedcba
这里:
abcdef Sed lobortis nisl sed malesuada bibendum. fedcba
...
abcdef Fusce odio turpis, accumsan non posuere placerat.
1
2
3
fedcba
abcdef Aliquam erat volutpat. Proin ultrices fedcba
Run Code Online (Sandbox Code Playgroud)
如何从大字符串中获取包括标记在内的所有事件?
我想用 cdk-virtual-scroll-viewport
在时间线视图中使用不同高度的项目。
因此itemSize="x"
,根据文档参考设置列表中项目的大小(以像素为单位)是不切实际的。
autosize
尚不可用。
可以使用cdk-virtual-scroll-viewport
可变大小的虚拟/无限滚动吗?
更新资料
我一直在寻找替代的虚拟/无限滚动解决方案,而且我几乎无法相信,似乎没有解决方案可用于动态行高,即使使用https://github.com/rintoj/ngx-virtual-scroller也不推荐使用。
更新2,2019年7月
由于与此同时仍然没有解决方案,因此我认为解决此问题的“足够好”的方法是加载固定数量的项目,并在列表底部添加一个按钮以加载更多项目,如本示例所示:https://stackblitz.com/edit/ang-mat-load-more
我想有一个控制器方法从JasperReports jrxml文件返回PDF,而不使用任何xml配置.
我想用一个JasperReportsPdfView
.这有可能吗?我知道只能在这个博客中使用Java代码来完成它:
http://krams915.blogspot.com/2010/12/spring-3-mvc-jasper-integration_22.html
但我相信一定可以用更少的代码:-)
这里是一些例子,代码并没有很遗憾工作.
@RequestMapping(value = "/test/pdfreport", method = RequestMethod.GET, produces = "application/pdf")
public JasperReportsPdfView getPdf() {
// does not work like this, unfortunately
final Person p = userService.getUserById("the id");
final JasperReportsPdfView view = new JasperReportsPdfView();
view.setReportDataKey("person");
view.addStaticAttribute("person", p); // ??
view.setUrl("report.jrxml");
return view;
}
Run Code Online (Sandbox Code Playgroud)
谢谢你的指针.
编辑:这是我的工作解决方案:
@Autowired
private ApplicationContext appContext;
@RequestMapping(value = "/test/pdfreport", method = RequestMethod.GET, produces = "application/pdf")
public ModelAndView getPdf() {
final List<Map<String, Object>> users = userService.getUsers();
final JasperReportsPdfView view …
Run Code Online (Sandbox Code Playgroud) 我正在尝试使用pi4j从DHT11温度传感器读取温度数据.我按照c和python编写的代码访问了这个站点:http: //www.uugear.com/portfolio/dht11-h ... or-module /但是它没有用.当我测试指令'dht11Pin.getState()'时,它总是处于HIGH状态,永远不会改变.我的代码有什么问题吗?
以下是我的代码:
import java.util.concurrent.TimeUnit;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import com.pi4j.component.ObserveableComponentBase;
import com.pi4j.io.gpio.GpioController;
import com.pi4j.io.gpio.GpioFactory;
import com.pi4j.io.gpio.GpioPinDigitalMultipurpose;
import com.pi4j.io.gpio.Pin;
import com.pi4j.io.gpio.PinMode;
import com.pi4j.io.gpio.PinPullResistance;
import com.pi4j.io.gpio.PinState;
import com.pi4j.io.gpio.RaspiPin;
public class DHT11 extends ObserveableComponentBase {
private static final Pin DEFAULT_PIN = RaspiPin.GPIO_04;
private static final int MAXTIMINGS = 85;
private int[] dht11_dat = { 0, 0, 0, 0, 0 };
private GpioPinDigitalMultipurpose dht11Pin;
private static final Logger LOGGER = LogManager.getLogger(DHT11.class
.getName());
public DHT11() {
final …
Run Code Online (Sandbox Code Playgroud) 在我的 Spring Boot 应用程序中,我访问我的 Hibernate 会话,如以下答案所示: https: //stackoverflow.com/a/33881946/272180
现在我还想在单元测试中访问 Hibernate Session。
如何在 Spring Boot 应用程序的单元测试中设置数据源并访问 Hibernate Session?
当我简单地自动装配它时,我得到org.hibernate.HibernateException: Could not obtain transaction-synchronized Session for current thread.
自动装配和使用@Service
工作完美无缺。
我的单元测试类看起来像这样:
@RunWith(SpringJUnit4ClassRunner.class)
@SpringApplicationConfiguration(classes = App.class)
@WebIntegrationTest
public class WebTest {
@Autowired
private SessionFactory sessionFactory;
@Autowired
private UserService userService;
@Test
public void testService() {
final List<User> users = userService.getUsers();
// do something with users
// ...
}
}
Run Code Online (Sandbox Code Playgroud)
App.class
指的是具有用于运行 Spring Boot 应用程序的 main 方法的类。
在一个Hibernate
托管实体中考虑这个属性:
@JsonFormat(pattern = "HH:mm")
@Column(name = "start_time")
private java.sql.Time startTime;
Run Code Online (Sandbox Code Playgroud)
我张贴JSON
-object为@RequestBody
到一个Spring控制器Jackson
应该映射到实体(POJO)的一个实例.
Jackson
显然没有设法将时间字符串反序列化为a java.sql.Time
,因为我得到了这个例外:
.w.s.m.s.DefaultHandlerExceptionResolver : Failed to read HTTP message:
org.springframework.http.converter.HttpMessageNotReadableException:
Could not read document: Can not construct instance of java.sql.Time,
problem: null
Run Code Online (Sandbox Code Playgroud)
我该如何指导Jackson
理解该怎么做?
是否可以在没有spring -data-jpa 的情况下使用 spring-data-rest?
在我的应用程序中我使用JdbcTemplate
. 这可以以某种方式连接到 spring-data-rest 吗?
4年后更新:
同时还有spring-data-jdbc看起来它回答了原来的问题。
请参阅: https: //spring.io/projects/spring-data-jdbc
我MimeMessageHelper
在 Spring Boot 应用程序中发送邮件。
我如何告诉它对包含字母的文件名进行编码à
,以便正确显示?
UTF-8
在构造时将编码设置为MimeMessageHelper
似乎没有帮助。在 Gmail 中,生成的附件显示为
=?UTF-8?Q?ex-comp_s.=C3=A0_r.l.?= =?UTF-8?Q?-201\"; filename*1=\"7-07-12_=E2=80=95_2017-07-18
Run Code Online (Sandbox Code Playgroud) 我有一个可以在 PostgreSQL 上正常运行的查询,并且我需要在 H2Database 上使用它。
对于表来说重要的基本上只是一个id integer
字段。
PostgreSQL 上的示例查询及其结果如下:
select id,
array_to_string(
array(select id from table1)
,',')
from table2
order by id
Run Code Online (Sandbox Code Playgroud)
结果:
id | array_to_string
2 | 1,3,4,5,2
3 | 1,3,4,5,2
4 | 1,3,4,5,2
6 | 1,3,4,5,2
7 | 1,3,4,5,2
8 | 1,3,4,5,2
9 | 1,3,4,5,2
10 | 1,3,4,5,2
Run Code Online (Sandbox Code Playgroud)
对于H2,我实现了用户定义的函数array_to_string
,array
如下:
public class H2Functions {
public static String arrayToString(final Object[] array, final String separator) {
return StringUtils.join(array, separator);
}
public static Object array(final Object …
Run Code Online (Sandbox Code Playgroud) java ×7
spring ×3
spring-boot ×2
angular ×1
angular7 ×1
arrays ×1
email ×1
encoding ×1
h2 ×1
hibernate ×1
jackson ×1
jdbctemplate ×1
json ×1
junit4 ×1
pi4j ×1
raspberry-pi ×1
regex ×1
sensor ×1
spring-data ×1
spring-ldap ×1
spring-mvc ×1
sql ×1