В моем приложении Spring Boot
возникла странная проблема.
После входа мое веб-приложение перенаправляет на страницу JS (bootstrap-table.js
).Эта страница появляется не каждый раз, а только при первом входе в систему, при последующем входе мы перенаправляем на правильную страницу "home.html".
В моем веб-приложении я использую: thymeleaf
и bootstrap4
.
Это моя конфигурация безопасности:
@Configuration
@EnableWebSecurity
@EnableGlobalMethodSecurity(prePostEnabled=true)
public class SecurityConfig extends WebSecurityConfigurerAdapter {
@Autowired
private UserDetailsService userDetailsService;
@Override
protected void configure(HttpSecurity http) throws Exception {
http
.authorizeRequests()
.antMatchers("/").permitAll()
.antMatchers("/resources/**").permitAll()
.antMatchers("/resetpwd/**").permitAll()
.anyRequest().authenticated()
.and()
.formLogin()
.loginPage("/login")
.permitAll()
.failureUrl("/?login_error")
.defaultSuccessUrl("/home")
.and()
.logout()
.logoutUrl("/logout")
.logoutRequestMatcher(new AntPathRequestMatcher("/logout", "GET"))
.permitAll()
.logoutSuccessUrl("/")
.invalidateHttpSession(true)
.deleteCookies("remember-me")
.and()
.rememberMe()
.and()
.sessionManagement();
}
@Override
public void configure(WebSecurity web) throws Exception {
web
.ignoring()
.antMatchers("/resources/**", "/static/**", "/css/**", "/js/**", "/images/**", "/webjars/**");
}
}
Я определил файл css и js в default.html
, форме входанаходится в header.html:
<ul class="nav navbar-nav pull-right ml-auto " sec:authorize="isAnonymous()">
<li class="nav-item">
<a class="nav-link dropdown-toggle " href="#" data-toggle="dropdown" th:text="#{login}"> </a>
<ul class="dropdown-menu form-wrapper">
<li>
<form th:action="@{/login}" data-parsley-validate="" method="POST" class="form login" >
<div class="col-sm-12 text-center" th:text="#{login}" ></div>
<p th:if="${loginError}" style="color: red;" th:text="#{login_unsuccessful}"></p>
<br />
<div class="form-group">
<div class="input-group mb-2">
<div class="input-group-prepend">
<div class="input-group-text"><i class="fas fa-user text-info"></i></div>
</div>
<input type="text" class="form-control" id="username" name='username' placeholder="Username" required>
</div>
</div>
<div class="form-group">
<div class="input-group mb-2">
<div class="input-group-prepend">
<div class="input-group-text"><i class="fas fa-key text-info"></i></div>
</div>
<input type="password" class="form-control" id="password" name="password" placeholder="Password" required>
</div>
</div>
<input type="submit" class="btn btn-primary btn-block text-center" value="Login">
<div class="form-footer">
<a data-target="#modalPwd" data-toggle="modal" href="#modalPwd" id="pwdDmntct" th:text="#{pwdDimenticata}"></a><br/><br/>
</div>
</form>
</li>
</ul>
</li>
</ul>
В теле по умолчанию у меня есть определение JS.
<body>
<!-- page content -->
<div class="container-fluid">
<nav th:replace="~{/fragments/header :: header}"></nav>
<div class="container-fluid">
<div layout:fragment="content"></div>
</div>
</div>
<!-- /page content -->
<script th:src="@{/js/parsley/parsley.js}" type="text/javascript"></script>
<script th:src="@{/js/parsley/it.js}" type="text/javascript"></script>
<script th:src="@{/bootstrap-table/bootstrap-table.min.js}" type="text/javascript"></script>
<script th:src="@{/bootstrap-table/bootstrap-table-it-IT.min.js}" type="text/javascript"></script>
<script th:src="@{/webjars/bootstrap-datepicker/js/bootstrap-datepicker.min.js}" type="text/javascript"></script>
<script th:src="@{/webjars/bootstrap-datepicker/locales/bootstrap-datepicker.it.min.js}" type="text/javascript"></script>
<script th:src="@{/webjars/select2/dist/js/select2.min.js}" type="text/javascript"></script>
<script type="text/javascript" th:inline="javascript">
$(function () {
if($('form').length){
$('form').parsley().on('form:validated', function(e) {
if (e.validationResult) {
$('input[type=submit]').attr('disabled', 'disabled');
}
});
}
$('body').on('click', '[data-toggle="modal"]', function(){
$($(this).data("target")+' .modal-content').load($(this).attr('href'));
});
});
</script>
</body>
Может кто-нибудь помочь мне разобраться в этой проблеме?Спасибо