小编Pra*_*ngi的帖子

我们什么时候需要多个 Dispatcher Servlet?

在哪些场景中,我们需要多个Dispatcher-Servlets?
谁能告诉我多个 Dispatcher-Servlets.
我认为每个用例都可以通过使用single 来解决Dispatcher Servlet

java spring spring-mvc spring-boot

5
推荐指数
1
解决办法
2478
查看次数

Spring Starter 项目中的服务 url 是什么?默认服务 URL 的替代方案 https://start.spring.io

我是 Spring 启动新手。
在 STS 中创建新的 Spring Starter 项目时,有一个默认的服务 URL 下拉列表,https://start.spring.io如下所示。

在此输入图像描述

我在堆栈溢出中搜索但没有找到任何有关它的信息。指定这个有什么用呢?为什么它被赋予可编辑状态?有什么替代方案可以代替吗https://start.spring.io

我注意到尝试使用任何其他 URL,它会尝试解析为 json 并给出下面给出的异常。

JSONException: A JSONObject text must begin with '{' at character 3
Run Code Online (Sandbox Code Playgroud)

需要澄清一下,背景发生了什么?

ide spring new-project sts-springsourcetoolsuite spring-boot

5
推荐指数
1
解决办法
4329
查看次数

我可以在 Spring Security 中有多个配置来保护 Web 应用程序和 Rest API 吗?

我正在尝试在 Spring 中创建 REST API 和 web/MVC 应用程序。他们都应该使用相同的服务层。我可以以某种方式在 Spring 中使用两种完全不同的配置(API 的令牌认证、Web 的 cookie、Web 的 404 页面等)?或者我应该制作两个独立的 Spring 应用程序?

java rest spring web-applications spring-security

5
推荐指数
1
解决办法
1217
查看次数

多个具有不同 UsernamePasswordAuthToken 的 AuthenticationProvider 来验证不同的登录表单,无需回退验证

在使用 spring security 时,我查看了 stackoverflow 中有趣的线程,需要针对不同的身份验证提供者两组用户进行身份验证,例如员工反对LDAP和客户反对DATABASE。Thread 提出了一个公认的解决方案,使用一个单选按钮来区分员工和客户,并具有自定义身份验证过滤器,该过滤器根据用户类型区分登录请求并设置不同的身份验证令牌(customerAuthToken / employeeAuthToken),然后请求进行身份验证。会有两个AuthenticationProvider实现和认证是通过支持令牌完成和决定的。通过这种方式,线程能够提供有趣的解决方案来避免 spring security 默认提供的回退身份验证。

查看线程配置 Spring Security 3.x 以具有多个入口点

由于答案完全在 xml 配置中。我只是想让解决方案在 java 配置中可用。我将在回答中发布该内容。

现在我的问题是随着 spring 版本的发展,除了我的答案之外,是否有可能通过任何新功能/最小配置来具有相同的功能

java spring spring-mvc spring-security jakarta-ee

4
推荐指数
1
解决办法
631
查看次数

混合身份验证 - 基于 Spring MVC 会话 + 基于 JWT 令牌

我有一种情况,我正在使用 Spring MVC(jsp、控制器、服务、dao)和基于会话的身份验证。但是现在我将几个 url 用作用于集成目的的 RESTful Web 服务。

仅对于那些请求,我需要使用基于令牌(例如 JWT)的身份验证。

那么,我是否有可能在同一个项目中使用两种类型的身份验证。

java spring spring-mvc spring-security jwt

2
推荐指数
1
解决办法
2751
查看次数

spring security HTTP状态403-访问被拒绝

登录成功,但即使我授予了USER 的访问权限,Spring Security 也会阻止 url 。我该如何管理这件事?

@Configuration
@EnableWebSecurity
public class SecurityConfiguration extends WebSecurityConfigurerAdapter {

    @Autowired
    public void configureGlobalSecurity(AuthenticationManagerBuilder auth)
            throws Exception {
        auth.inMemoryAuthentication().withUser("sahil").password("123")
                .roles("ADMIN","USER");
    }

    @Override
    protected void configure(HttpSecurity http) throws Exception {

        http.authorizeRequests()
        .antMatchers("/login").permitAll()
        .antMatchers("/welcome","/inventory/**","/sales/**").access("hasRole('USER')")
        .and()
        .csrf().disable();
    }
Run Code Online (Sandbox Code Playgroud)

登录控制器.java

    @Controller
public class LoginController {

    @RequestMapping(value = { "/", "/login" }, method = RequestMethod.GET)
    public String showLoginPage() {
        return "login";
    }

    @RequestMapping(value = "/login", method = RequestMethod.POST)
    public String handleUserLogin(ModelMap model, @RequestParam String name, @RequestParam String password) { …
Run Code Online (Sandbox Code Playgroud)

java spring spring-mvc spring-security access-denied

1
推荐指数
1
解决办法
1万
查看次数