gpt4 book ai didi

javascript - 使用 spring 保护单页应用程序

转载 作者:行者123 更新时间:2023-12-03 09:57:54 25 4
gpt4 key购买 nike

我用 js 创建了一个单页应用程序,我还使用了一些 jquery 命令和 twitter bootstrap。

我用这种方式为我的页面充电

$('#contact').click(function () {
$('#main').load('contact.html');
});

我在服务器上使用 spring java 和其余完整架构。

有没有一种简单的方法可以使用这些框架来保护我的网页?

最佳答案

我认为对您来说最好的方法是添加 spring security 依赖项,您将完全控制您的服务 REST 并与 OAuth、社交(Facebook、Twitter ...)等多个模块集成。使用 Spring Security,您可以通过 Java 类或 XML 来配置权限

享受示例:

@配置 @EnableWebSecurity @Import({ConfigDAO.class, ConfigService.class}) 公共(public)类 WebSecurityConfig 扩展 WebSecurityConfigurerAdapter {

@Autowired
private DataSource datasource;

@Autowired
private PasswordEncoder passwordEncoder;

@Autowired
public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
auth
.jdbcAuthentication()
.dataSource(datasource)
.passwordEncoder(passwordEncoder)
.usersByUsernameQuery("select usuario, senha as password, habilitado as enabled from cds_usuario where usuario = ? ")
.authoritiesByUsernameQuery("select usuario, perfil as authority from cds_usuario where usuario = ?")
.getUserDetailsService();
}

@Override
protected void configure(HttpSecurity http) throws Exception {
http.authorizeRequests()
.antMatchers("/admin/**").access("hasRole('ROLE_ADMIN')")
.antMatchers("/painel**").access("hasRole('ROLE_ALUNO')")
.antMatchers("/").access("permitAll")
.antMatchers("/cadastro**").access("permitAll")
.antMatchers("/error/**").access("permitAll")
.and().formLogin().usernameParameter("username").passwordParameter("senha")
.loginPage("/").loginProcessingUrl("/autenticar")
.failureUrl("/")
.defaultSuccessUrl("/painel")
.and().logout().deleteCookies("remove")
.invalidateHttpSession(false)
.logoutUrl("/logout").logoutSuccessUrl("/")
.and().csrf().disable()
.exceptionHandling().accessDeniedPage("/403");
http.sessionManagement().maximumSessions(1).expiredUrl("/logout");
}

}

关于javascript - 使用 spring 保护单页应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30672752/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com