有没有办法为同一个REST服务设置基本身份验证和表单登录?我想让登录用户在登录后从命令行运行后通过Web浏览器触发此服务curl -u username:password hostname.com/api/process
现在我已经看过这篇文章:使用Spring安全Javaconfig进行基本和基于表单的身份验证
但是它与我的略有不同试图做.有没有办法用弹簧设置它?我现在拥有的是:
package com.my.company.my.app.security;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
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.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.security.provisioning.JdbcUserDetailsManager;
import javax.sql.DataSource;
@Configuration
@EnableWebSecurity
public class SecurityConfig extends WebSecurityConfigurerAdapter {
@Autowired
DataSource dataSource;
private static final org.slf4j.Logger logger = LoggerFactory.getLogger(SecurityConfig.class);
@Override
protected void configure(HttpSecurity http) throws Exception {
http
.authorizeRequests()
.antMatchers("/js/**", "/css/**")
.permitAll();
http
.authorizeRequests()
.antMatchers("/api/**")
.authenticated()
.and()
.httpBasic();
http
.authorizeRequests()
.antMatchers("/","/index")
.authenticated()
.and()
.formLogin()
.loginPage("/login")
.loginProcessingUrl("/j_spring_security_check")
.defaultSuccessUrl("/monitor") …
Run Code Online (Sandbox Code Playgroud) 使用logback我想在每次异步作业启动时启动新日志,所以我需要手动调用rollover.但是当我试图获得appender时,我会得到null.以下是我的配置:
<configuration scan="true">
<timestamp key="time" datePattern="yyyy-MM-dd_HH_mm"/>
<logger name="com.my.com.pany" level="DEBUG">
<appender name="TEST" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>logs/log_TEST_${time}.log</file>
<triggeringPolicy
class="com.my.com.pany.myapp.logging.ManualRollingPolicy">
</triggeringPolicy>
<append>true</append>
<encoder>
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>
</encoder>
</appender>
</logger>
</configuration>
Run Code Online (Sandbox Code Playgroud)
我这样称为翻转:
ch.qos.logback.classic.Logger logF = (ch.qos.logback.classic.Logger) LoggerFactory.getLogger("com.my.com.pany");
RollingFileAppender<ILoggingEvent> appender = (RollingFileAppender<ILoggingEvent>) logF.getAppender("test");
appender.rollover();
Run Code Online (Sandbox Code Playgroud)
我进行了扩展,TimeBasedRollingPolicy<E>
以便在触发异步作业时启动我的日志:
@NoAutoStart
public class ManualRollingPolicy<E> extends TimeBasedRollingPolicy<E> {
}
Run Code Online (Sandbox Code Playgroud)
可以帮我解决这个问题吗?编辑:在一些进一步的调查,我可以看到LogF
有appenderList
哪个有我的自定义尺寸1的RollingPolicy
设置正确.但是name
这个appender的属性被设置为null,我认为这就是为什么我不能通过名字得到它的原因.
我正在和vimtutor学习vim.我想知道命令运动编号和编号命令运动之间是否存在差异.例如:
2dw
在我看来工作完全一样d2w
,同样2dd
如此d2d
.
我一直在尝试使用Spring Boot,Hibernate和PostgreSQL来设置应用程序.但我一直在努力org.springframework.beans.BeanInstantiationException
.
这就是我得到的痕迹.
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.boot.autoconfigure.web.WebMvcAutoConfiguration$WebMvcAutoConfigurationAdapter': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private org.springframework.boot.autoconfigure.web.HttpMessageConverters org.springframework.boot.autoconfigure.web.WebMvcAutoConfiguration$WebMvcAutoConfigurationAdapter.messageConverters; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.boot.autoconfigure.web.HttpMessageConvertersAutoConfiguration': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private final java.util.List org.springframework.boot.autoconfigure.web.HttpMessageConvertersAutoConfiguration.converters; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'mappingJackson2HttpMessageConverter' defined in class path resource [org/springframework/boot/autoconfigure/web/JacksonHttpMessageConvertersConfiguration$MappingJackson2HttpMessageConverterConfiguration.class]: Unsatisfied dependency expressed through constructor argument with …
Run Code Online (Sandbox Code Playgroud) 遵循此文档:
To automatically run Liquibase database migrations on startup, add the org.liquibase:liquibase-core to your classpath.
The master change log is by default read from db/changelog/db.changelog-master.yaml but can be set using liquibase.change-log. In addition to YAML, Liquibase also supports JSON, XML, and SQL change log formats.
Run Code Online (Sandbox Code Playgroud)
我将我的应用程序配置为使用liquibase迁移.我添加了liquibase.change-log
属性,所以我的整个application.properties
文件看起来像这样:
spring.jpa.hibernate.ddl-auto=none
spring.datasource.url=jdbc:mysql://192.168.0.1/db_name
spring.datasource.username=db_username
spring.datasource.password=super_secret_secret!123
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
spring.datasource.testOnBorrow=true
spring.datasource.timeBetweenEvictionRunsMillis = 60000
spring.datasource.validationQuery=SELECT 1
liquibase.change-log=db.changelog-master.xml
Run Code Online (Sandbox Code Playgroud)
这是我pom.xml
的liquibase-core
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.my.application</groupId>
<artifactId>application-name</artifactId>
<version>0.0.1-SNAPSHOT</version> …
Run Code Online (Sandbox Code Playgroud) 我在使用Cassandra建模数据时遇到问题.我想将它用作活动商店.我的事件有创建时间戳.这些事件属于由id标识的分区.
现在,我想查看每个id的最新事件,然后根据时间戳过滤此ID.
所以我有这样的事情:
ID | CREATION_TIMESTAMP | CONTENT
---+---------------------------------+----------------
1 | 2018-11-09 12:15:45.841000+0000 | {SOME_CONTENT}
1 | 2018-11-09 12:15:55.654656+0000 | {SOME_CONTENT}
2 | 2018-11-09 12:15:35.982354+0000 | {SOME_CONTENT}
2 | 2018-11-09 12:35:25.321655+0000 | {SOME_CONTENT}
2 | 2018-11-09 13:15:15.068498+0000 | {SOME_CONTENT}
Run Code Online (Sandbox Code Playgroud)
我尝试按分区ID分组并查询最大值,creation_timestamp
但这是不允许的,我应该使用EQ或IN指定分区ID.额外的阅读让我相信这是解决这个问题的完全错误的方法,但我不知道NoSQL是不适合这项工作的工具还是我只是从错误的角度处理这个问题?