我正在我的应用程序中配置Spring Security以使用自定义login.jsp作为登录表单。我无法使用以下配置获取自定义登录页面:
@Configuration
@EnableWebSecurity
public class SecSpringSecurityConfig extends WebSecurityConfigurerAdapter {
@Autowired
private UserDetailsService userDetailsService;
@Bean
@Override
public Authenticationmanager authenticationmanagerBean() throws Exception {
return super.authenticationmanagerBean();
}
@Override
protected void configure(final AuthenticationmanagerBuilder auth) throws Exception {
auth.authenticationProvider(authProvider());
}
@Override
public void configure(final WebSecurity web) throws Exception {
web.ignoring().antMatchers("/javascript/**");
}
@Bean
public DaoAuthenticationProvider authProvider() {
final IDMSAuthenticationProvider authProvider = new IDMSAuthenticationProvider();
authProvider.setUserDetailsService(userDetailsService);
return authProvider;
}
public SecSpringSecurityConfig() {
super();
}
@Override
protected void configure(final HttpSecurity http) throws Exception {
http
.csrf().disable()
.authorizeRequests()
.antMatchers("/login*").permitAll()
.and()
.formLogin()
.loginPage("/login1")
.defaultSuccessUrl("/homepage.html")
.failureUrl("/login?error=true")
.loginProcessingUrl("/login");
}
}
DaoAuthenticatorProvider实现尚无任何内容:
public class IDMSAuthenticationProvider extends DaoAuthenticationProvider{
}
UserDetailsService实现尚无任何内容:
@Service("userDetailsService")
@Transactional
public class MyUserDetailsService implements UserDetailsService{
@Override
public UserDetails loadUserByusername(final String email) throws usernameNotFoundException {
return new org.springframework.security.core.userdetails.User(email,"n/a",true,null);
}
}
我的文件夹结构是这样的:
-myApp
-WebPages
-WEB-INF
-jsp
-login1.jsp
在应用程序的其他部分中,我具有以下视图解析器设置:
<bean class="org.springframework.web.servlet.view.ContentNegotiatingViewResolver">
<property name="order" value="1" />
<property name="contentNegotiationmanager">
<bean class="org.springframework.web.accept.ContentNegotiationmanager">
<constructor-arg>
<bean class="org.springframework.web.accept.PathExtensionContentNegotiationStrategy">
<constructor-arg>
<map>
<entry key="json" value="application/json" />
<entry key="xml" value="application/xml" />
</map>
</constructor-arg>
</bean>
</constructor-arg>
</bean>
</property>
<property name="defaultViews">
<list>
<bean class="org.springframework.web.servlet.view.json.MappingJackson2JsonView" />
<bean class="org.springframework.web.servlet.view.xml.MarshallingView">
<constructor-arg>
<bean class="org.springframework.oxm.xstream.XStreamMarshaller">
<property name="autodetectAnnotations" value="true" />
</bean>
</constructor-arg>
</bean>
</list>
</property>
</bean>
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/jsp/" />
<property name="suffix" value=".jsp" />
<property name="order" value="2" />
</bean>
我尝试使用访问登录页面
http://localhost:8080/myApp/login
,并显示404错误。我了解在UserDetailsService实现中需要填写很多内容,但是现在我只是想让登录页面显示出来。非常感谢您的帮助。