我使用Spring 4创建一个简单的应用程序.最近,我将Spring Security 3添加到项目中,但总是得到错误代码302(因此它总是重定向到主页).
这是我的SecurityConfig:
@Configuration
@EnableWebMvcSecurity
@ComponentScan(basePackages = { "com.moon.repository" })
public class SecurityConfig extends WebSecurityConfigurerAdapter {
@Override
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
auth.inMemoryAuthentication().withUser("hello").password("world").roles("USER");
}
@Override
public void configure(WebSecurity web) throws Exception {
web
.ignoring().antMatchers("/resources/**", "/views/**");
}
@Override
protected void configure(HttpSecurity http) throws Exception {
http.authorizeRequests()
.antMatchers("/","/home").permitAll()
.anyRequest().authenticated()
.and()
.formLogin()
.loginPage("/home")
.loginProcessingUrl("/acct/signin")
.and()
.logout()
.permitAll();
}
}
Run Code Online (Sandbox Code Playgroud)
我有一个名为AccountController的Controller :
@Controller
@RequestMapping(value = "/acct")
public class AccountController {
private final Logger logger …
Run Code Online (Sandbox Code Playgroud) 我正在使用JMeter执行负载测试,用户可以在其中执行启动 - 登录 - clk仪表板页面 - clk登陆页面(登录后的页面即主页)其中clk仪表板和clk登陆页面是重复操作5倍.
直到30个用户我增加用户负载时没有收到任何错误我开始收到错误
响应代码:非HTTP响应代码:org.apache.http.conn.HttpHostConnectException响应消息:非HTTP响应消息:拒绝连接到https://stage.ideas.com
Run Code Online (Sandbox Code Playgroud)Response headers: HTTPSampleResult fields: ContentType: DataEncoding: null
在样本结果中.
任何人都可以建议我为什么会收到这个错误?有时它适用于100个用户,有时我会收到错误.
非常感谢提前.
我有一个使用Spring Security保护的Spring MVC Web应用程序,我正在编写测试.我很难在SpringContextHolder中获取Spring Security检索到的一个(自定义)用户.一旦我的用户被"插入"(java配置),其中:
auth.inMemoryAuthentication().getUserDetailsService().createUser(myCustomUser);
Run Code Online (Sandbox Code Playgroud)
然后,我可以创建相关的令牌(UsernamePasswordAuthenticationToken)并要求Spring使用此令牌对我的用户进行身份验证.问题是Spring不检索自定义用户实例,而是检索其User类的实例.当Spring在以下方法中查找这样的用户时(来自Spring的InMemoryUserDetailsManager):
public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
UserDetails user = users.get(username.toLowerCase());
if (user == null) {
throw new UsernameNotFoundException(username);
}
return new User(user.getUsername(), user.getPassword(), user.isEnabled(), user.isAccountNonExpired(),
user.isCredentialsNonExpired(), user.isAccountNonLocked(), user.getAuthorities());
}
Run Code Online (Sandbox Code Playgroud)
它使用我的配置提供的详细信息实例化一个新用户.
我没有看到让InMemoryUserDetailsManager直接返回通过"getUserDetailsService(..createUser"调用发送给他的内容的问题,但是肯定有一个......无论如何,我可能在这里做错了,任何想法?
我想使用swift语言在ios中集成flurry.我添加了flurry sdk的两个文件:flurrylib.a和flurry.h然后在项目TestProject4-Bridging-Header.h中输入我的api密钥
#import "Flurry.h"
Run Code Online (Sandbox Code Playgroud) 我试着关闭它,但我不知道把 input.close(); 放在哪里,我对这一切真的很陌生,问我的教授有失去积分的风险。此外,我不确定我是否应该保留倒数第二个 system.out 每月付款,或者摆脱它。它甚至对我的其余代码有意义吗?
import java.util.Scanner;
public class Project2 {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner input = new Scanner(System.in);
//Yearly interest rate
System.out.print("Enter annual interest rate, for example 0.5, no percent sign:");
double annualInterestRate = input.nextDouble();
//Monthly interest rate
double monthlyInterestRate = annualInterestRate / 1200;
//Number of years
System.out.print("Enter number of years, for example 5: ");
int numberOfYears = input.nextInt() ;
//Loan amount
System.out.print("Enter investment amount, for example 145000.95: ");
double loanAmount …
Run Code Online (Sandbox Code Playgroud) 我试图在春天使用基于声明的AOP运行JUnit测试用例.当我运行测试时,我得到ClassNotFound Exception(已清除),还有一个例外java.lang.IllegalStateException:无法加载ApplicationContext.异常似乎很简单,但我无法解决它.
它是一个Junit测试用例,所以不需要main方法,因为我没有运行客户端代码,测试用例没有运行.如果我错了,请告诉我.
有人可以帮我解决这个错误,我试图重建,清理构建项目,删除并重新添加所有可执行jar文件.
这是代码
package declarativeBeans.test;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import declarativeBeans.Performer1;
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration("/applicationContext_declarative_based_AOP.xml")
public class AspectTest1 {
@Autowired
ApplicationContext context;
@Test
public void audienceShouldApplaud() throws Exception{
Performer1 eddie = (Performer1) context.getBean("eddie");
eddie.perform1();
}
}
Run Code Online (Sandbox Code Playgroud)
applicationContext.xml中
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:aop="http://www.springframework.org/schema/aop"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-3.0.xsd">
<!-- Target class -->
<bean id="target" class="declarativeBeans.InstrumentList1">
<property name="instr">
<bean class="declarativeBeans.Guitar1" />
</property>
</bean>
<!-- Advice/Advisor -->
<bean id="Audience" class="declarativeBeans.Audience1" /> …
Run Code Online (Sandbox Code Playgroud)