目前我的应用程序中有一个身份验证机制,即使用LDAP进行身份验证和授权.我的安全配置如下所示
@Configuration
@EnableWebMvcSecurity
public class SecurityConfig extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
http
.csrf().disable()
.authorizeRequests()
.anyRequest().fullyAuthenticated()
.and()
.httpBasic();
}
@Configuration
protected static class AuthenticationConfiguration extends GlobalAuthenticationConfigurerAdapter {
@Value("${ldap-${env}.manager.dn}")
private String managerDn;
@Value("${ldap-${env}.manager.pass}")
private String managerPass;
@Value("${ldap-${env}.server.url}")
private String url;
@Value("${ldap.password.attribute:userPassword}")
private String passwordAttr;
@Override
public void init(AuthenticationManagerBuilder auth) throws Exception {
auth.ldapAuthentication().userDnPatterns("uid={0},ou=people").groupSearchBase("ou=groups")
.groupSearchFilter("(member={0})").userSearchBase("ou=people").userSearchFilter("(uid={0})")
.userDetailsContextMapper(new CustomLdapPersonContextMapper())
// .passwordCompare()
// .passwordAttribute(passwordAttr)
// .passwordEncoder(new PlaintextPasswordEncoder())
// .and()
.contextSource().managerDn(managerDn).managerPassword(managerPass).url(url);
}
}
}
Run Code Online (Sandbox Code Playgroud)
在某些情况下,用户可能会使用会话令牌进入会话令牌,该会话令牌可以从会话密钥服务器进行身份验证,并且有效令牌会返回用户名,然后可以使用该用户名从LDAP为该用户加载身份验证信息.所以我的第二个身份验证机制应该首先发生,如果http头中存在会话令牌,它应该执行令牌身份验证然后执行ldap查找,如果没有会话令牌,它应该属于当前的身份验证机制.如何添加第二层身份验证.
我正在使用传统方式加载log4j.xml
<context-param>
<param-name>log4jConfigLocation</param-name>
<param-value>classpath:conf/log4j.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.util.Log4jConfigListener</listener-class>
</listener>
Run Code Online (Sandbox Code Playgroud)
这工作正常,但现在我需要根据环境变量/ jndi条目定义的环境加载不同的log4j.xml文件.所以我希望通过新的Spring 3.1属性管理我可以改变这个至
<context-param>
<param-name>log4jConfigLocation</param-name>
<param-value>classpath:conf/log4j-${ENV-NAME}.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.util.Log4jConfigListener</listener-class>
</listener>
Run Code Online (Sandbox Code Playgroud)
和spring将在每个环境中加载正确的log4j文件,但这不起作用,因为web.xml是在spring之前加载的.我遇到过这种方法
<bean id="log4jInitialization" class="org.springframework.beans.factory.config.MethodInvokingFactoryBean">
<property name="targetClass" value="org.springframework.util.Log4jConfigurer" />
<property name="targetMethod" value="initLogging" />
<property name="arguments">
<list>
<value>log4j-${ENV-NAME}.xml</value>
</list>
</property>
</bean>
Run Code Online (Sandbox Code Playgroud)
所以基本上将log4j的配置移动到spring上下文文件而不是web.xml.但是,由于某种原因,日志记录以一切都记录的方式启用,因此无法正常工作.那么如何基于环境变量使用不同的log4j.xml文件或者在servletcontextlistener中以编程方式加载它.
我正在尝试使用spring集成设置一个简单的应用程序.目标是简单地使用文件入站通道适配器来监视目录中的新文件和处理文件.为简单起见,此时处理文件只是记录一些输出(正在处理的文件的名称).但我想以多线程方式处理文件.因此,假设有10个文件被拾取并且应该并行处理,一旦完成这些文件,我们就会转到接下来的10个文件.
为此我尝试了两种不同的方法,两者似乎都工作方式相似,我想了解使用poller或dispatcher之间的区别.
方法#1 - 使用轮询器
<int-file:inbound-channel-adapter id="filesIn" directory="in">
<int:poller fixed-rate="1" task-executor="executor" />
</int-file:inbound-channel-adapter>
<int:service-activator ref="moveToStage" method="move" input-channel="filesIn" />
<task:executor id="executor" pool-size="5" queue-capacity="0" rejection-policy="DISCARD" />
Run Code Online (Sandbox Code Playgroud)
所以在这里,我理解的想法是我们不断轮询目录,一旦收到文件,它就会发送到filesIn通道,直到达到池限制.然后,直到池被占用,即使我假设轮询仍在后台继续,也不会发送其他文件.这似乎有效,但我不确定使用每次轮询的最大消息是否有助于降低轮询频率.通过将每个轮询的最大消息数设置为接近池大小.
方法#2 - 使用调度程序
<int-file:inbound-channel-adapter id="filesIn" directory="in">
<int:poller fixed-rate="5000" max-messages-per-poll="3" />
</int-file:inbound-channel-adapter>
<int:bridge input-channel="filesIn" output-channel="filesReady" />
<int:channel id="filesReady">
<int:dispatcher task-executor="executor"/>
</int:channel>
<int:service-activator ref="moveToStage" method="move" input-channel="filesInReady" />
<task:executor id="executor" pool-size="5" queue-capacity="0" rejection-policy="CALLER_RUNS" />
Run Code Online (Sandbox Code Playgroud)
好吧所以这里轮询器没有使用执行器,所以我假设它以顺序方式进行轮询.应该拾取每个poll 3文件,然后发送到filesReady通道,然后使用调度程序将文件传递给服务激活器,因为它使用执行程序进行调度,它立即返回控制并允许filesIn通道发送更多文件.
我想我的问题是我是否正确理解这两种方法,如果一种方法比其他方法更好.
谢谢
我试图找出以这样的方式设置spring启动应用程序的最佳方法,即它具有自己的jar依赖关系,但是当它作为java -jar命令运行时,在运行时将额外的jar添加到classpath.什么方法更有意义
使用原始jar(不添加依赖项)并将所有jar(应用程序和运行时)放在文件系统上的文件夹中,并使用PropertiesLauncher指定jars文件夹的loader.path.
使用fat jar(带有应用程序jar)将额外的jar放在文件系统上,并以某种方式包含那些需要添加到classpath的额外jar.不知道如何做到这一点.
有没有更好的方法来做到这一点
我在一个有角度的2+应用程序中使用反应式表单,并且需要将主FormGroup传递给多个组件,以便表单的不同部分(例如页眉,页脚等)可以在单独的组件中进行管理,并由这些不同的组件填充.这就是我现在这样做的方式:
<div class="container-fluid">
<form [formGroup]="orderForm">
<order-header [orderForm]="orderForm"></order-header>
<order-items [orderForm]="orderForm"></order-items>
<order-footer [orderForm]="orderForm"></order-footer>
</form>
</div>
Run Code Online (Sandbox Code Playgroud)
我想知道,如果这是一个正确的方法因为我看到这个代码的警告/错误:
错误:ExpressionChangedAfterItHasBeenCheckedError:表达式在检查后发生了变化.上一个值:'true'.当前值:'false'.
在这一行:
<form [formGroup]="orderForm">
有什么建议?谢谢.
我正在尝试创建简单的表单,如http://angularjs.blogspot.no/2015/03/forms-in-angular-2.html中所述,但是当我添加时
import {forms, required} from 'angular2/forms';
在与崩溃
TypeError: Cannot read property 'annotations' of undefined
TypeError: Cannot read property 'annotations' of undefined
at ReflectionCapabilities.System.register.execute.$__export.annotations (http://localhost:9090/node_modules/angular/dist/js/prod/es6/angular2/src/reflection/reflection_capabilities.es6!eval:81:40)
at Reflector.System.register.execute.$__export.annotations (http://localhost:9090/node_modules/angular/dist/js/prod/es6/angular2/src/reflection/reflector.es6!eval:81:50)
at DirectiveMetadataReader.System.register.execute.$__export.read (http://localhost:9090/node_modules/angular/dist/js/prod/es6/angular2/src/core/compiler/directive_metadata_reader.es6!eval:31:41)
at eval (http://localhost:9090/node_modules/angular/dist/js/prod/es6/angular2/src/core/compiler/compiler.es6!eval:127:35)
at Array.map (native)
at Function.System.register.execute.$__export.map (http://localhost:9090/node_modules/angular/dist/js/prod/es6/angular2/src/facade/collection.es6!eval:172:26)
at Compiler.System.register.execute.$__export.createSteps (http://localhost:9090/node_modules/angular/dist/js/prod/es6/angular2/src/core/compiler/compiler.es6!eval:126:43)
at Compiler.System.register.execute.$__export._compileTemplate (http://localhost:9090/node_modules/angular/dist/js/prod/es6/angular2/src/core/compiler/compiler.es6!eval:164:53)
at eval (http://localhost:9090/node_modules/angular/dist/js/prod/es6/angular2/src/core/compiler/compiler.es6!eval:154:29)
at Zone.run (http://localhost:9090/node_modules/zone.js/zone.js:87:19)
-----async gap-----
Error
at Function.System.register.execute.$__export.then (http://localhost:9090/node_modules/angular/dist/js/prod/es6/angular2/src/facade/async.es6!eval:35:28)
at Compiler.System.register.execute.$__export._compile (http://localhost:9090/node_modules/angular/dist/js/prod/es6/angular2/src/core/compiler/compiler.es6!eval:153:42)
at Compiler.System.register.execute.$__export.compile (http://localhost:9090/node_modules/angular/dist/js/prod/es6/angular2/src/core/compiler/compiler.es6!eval:134:34)
at eval (http://localhost:9090/node_modules/angular/dist/js/prod/es6/angular2/src/core/application.es6!eval:73:23)
at Function.System.register.execute.$__export.apply (http://localhost:9090/node_modules/angular/dist/js/prod/es6/angular2/src/facade/lang.es6!eval:317:23)
-----async gap-----
Error
at _AsyncInjectorStrategy.System.register.execute._AsyncInjectorStrategy.instantiate (http://localhost:9090/node_modules/angular/dist/js/prod/es6/angular2/src/di/injector.es6!eval:297:17)
at Injector.System.register.execute.$__export._getByKey (http://localhost:9090/node_modules/angular/dist/js/prod/es6/angular2/src/di/injector.es6!eval:138:33) …Run Code Online (Sandbox Code Playgroud) 我们如何从CommandLineRunner类访问ApplicationContext.有没有比使用ApplicationContextAware更好的新方法
我正在将 spring data jpa 与遗留数据库模式一起使用,并且在映射关系之一时遇到一些问题。数据库中有 2 个实体buyer和employee。一名员工可以有多个买家,因此这是ManyToOne买家与员工的关系。
这就是我配置 jpa/hibernate 实体的方式:
@Entity
@Table(name = "BUYER")
public class BuyerEntity {
@Id
@Column(name = "BUYER")
private Long id;
@ManyToOne
@JoinColumn(name = "EMPLOYEE_ID")
private EmployeeEntity employee;
....
Run Code Online (Sandbox Code Playgroud)
和
@Entity
@Table(name = "EMPLOYEE")
public class EmployeeEntity {
@Id
@Column(name = "EMPLOYEE_ID")
private Long id;
....
Run Code Online (Sandbox Code Playgroud)
基本上,buyer表的外键Employee_Id指向表的主键employee。
当我查找买家时,jpa/hibernate 首先执行查询以获取所有买家,然后对于每个买家,它运行另一个查询以检索相应的员工信息。这是非常低效的,因为我们可以通过在第一个查询中添加员工表列来轻松检索员工信息以及买家信息。
因此,不要首先执行如下所示的查询:
select buyer.id from buyer join employee ...
Run Code Online (Sandbox Code Playgroud)
然后对每个买家进行另一个查询:
select employee.* from employee where employee.id …Run Code Online (Sandbox Code Playgroud) 我有一个 gradle 项目,结构如下所示
>
> main (one project)
> shared (another project)
> api
>> shared2 (another project)
Run Code Online (Sandbox Code Playgroud)
main 项目依赖于 shared 和 shared2 项目。shared 和 shared2 项目在其 src/ test/resources 文件夹中都有一个 logback-test.xml,主项目在其 src/ main/resources 文件夹中有一个 logback.xml 。
当我使用主 Application 类在 Eclipse 中运行主项目时,我期望在类路径中只加载 logback.xml。相反,我看到了发现多个 slf4j 绑定的警告,更重要的是,日志设置是从 logback-test.xml 而不是 logback.xml 应用的。这是进一步说明的文件夹结构
>
> main
> > src/main/resources
> > > logback.xml
> shared
> > src/test/resources
> > > logback-test.xml
> api/shared2
> > src/test/resources
> > > logback-test.xml
Run Code Online (Sandbox Code Playgroud)
在两个 logback-test.xml …
我不理解spring-boot-loader的README文件中提供的信息
https://github.com/spring-projects/spring-boot/tree/master/spring-boot-tools/spring-boot-loader
除了弹簧启动内部用于创建嵌入式服务器jar文件之外,spring boot loader的目的究竟是什么.我们是否可以利用这个过程并从文件路径加载额外的jar,以便在类路径中加入
我正在尝试使用弹簧启动属性启动器
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<archive>
<manifest>
<mainClass>org.springframework.boot.loader.PropertiesLauncher</mainClass>
</manifest>
<manifestEntries>
<Start-Class>com.att.hadoop.loader.run.Application</Start-Class>
</manifestEntries>
</archive>
</configuration>
</plugin>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
Run Code Online (Sandbox Code Playgroud)
当我查看清单文件时,它看起来像这样
$ unzip -q -c hdfsloader-0.0.1-SNAPSHOT.jar META-INF/MANIFEST.MF
Manifest-Version: 1.0
Built-By: aq728y
Build-Jdk: 1.7.0_25
Start-Class: org.springframework.boot.loader.PropertiesLauncher
Created-By: Apache Maven 3.1.0
Spring-Boot-Version: 1.0.0.RC1
Main-Class: org.springframework.boot.loader.JarLauncher
Archiver-Version: Plexus Archiver
Run Code Online (Sandbox Code Playgroud)
关于为什么我的mainclass和startclass错误的任何想法
我想把它设置为
Main-Class:org.springframework.boot.loader.PropertiesLauncher
Start-Class:com.att.hadoop.loader.run.Application
我正在尝试用方解石做一些基本的事情来理解框架。我设置了一个简单的示例,应该从 2 个 json 文件中读取。我的模型看起来像
{
version: '1.0',
defaultSchema: 'PEOPLE',
schemas: [
{
name: 'PEOPLE',
type: 'custom',
factory: 'demo.JsonSchemaFactory',
operand: {
directory: '/..../calcite-json/src/test/resources/files'
}
}
]
}
Run Code Online (Sandbox Code Playgroud)
在我的测试中,模型似乎加载得很好,因为当我提取数据库元数据信息时,我可以看到我的文件正在作为 PEOPLE 模式下的表加载。但是在该语句之后,我尝试select *从该表中执行操作,但收到一条错误,表示未找到表。
Run Code Online (Sandbox Code Playgroud)> -- null PEOPLE a TABLE --> Jun 29, 2015 8:53:30 AM org.apache.calcite.sql.validate.SqlValidatorException <init> SEVERE: org.apache.calcite.sql.validate.SqlValidatorException: Table 'A' not found Jun 29, 2015 8:53:30 AM org.apache.calcite.runtime.CalciteException <init> SEVERE: org.apache.calcite.runtime.CalciteContextException: At line 1, column 26: Table 'A' not found
输出中的第一行显示数据库元数据“-- null PEOPLE a TABLE -->”中的表。这表明表“a”存在于模式“people”下并且类型为“table”。
我的测试代码如下所示
@Test
public …Run Code Online (Sandbox Code Playgroud) 我理解如何指定要禁用的被动表单控件的初始状态.
someControl: [{value: '', disabled: true}]
如何根据表单中另一个值的选择,以编程方式稍后更改禁用状态.因此,例如,someControl如果anotherControl在下拉列表中选择了某个值,则应禁用,否则启用.
谢谢
spring-boot ×5
angular ×3
java ×2
spring ×2
typescript ×2
atscript ×1
build.gradle ×1
ecmascript-6 ×1
gradle ×1
hibernate ×1
javascript ×1
jpa ×1
log4j ×1
logback ×1
slf4j ×1