Ajax请求localhost返回403错误.但是,当我将控制器requestMethod更改为GET并在浏览器上打开请求"url"时,它会显示从server返回的json数据.我希望使用该数据填充下拉列表.请帮忙.我正在使用带有弹簧MVC框架工作的spring security 4.0.CSRF未禁用.此外,网址固定在弹簧中.
我在这里检查了相关问题,但没有找到帮助我的解决方案.
我在Spring Boot Application中实现了LDAP身份验证.添加的依赖项如下:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-ldap</artifactId>
</dependency>
<dependency>
<groupId>org.apache.directory.server</groupId>
<artifactId>apacheds-all</artifactId>
</dependency>
Run Code Online (Sandbox Code Playgroud)
但是我仍然得到以下ClassNotFoundException:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'springSecurityFilterChain'
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [javax.servlet.Filter]
Caused by: java.lang.NoClassDefFoundError: org/apache/directory/server/core/DirectoryService
Caused by: java.lang.ClassNotFoundException: org.apache.directory.server.core.DirectoryService
Run Code Online (Sandbox Code Playgroud)
我的maven依赖树清楚地显示了apacheds-all成功添加.

为什么我仍然会收到此错误?
我有一个现有的基于SOAP的Web服务,我正在尝试使用'XwsSecurityInterceptor'和'SpringDigestPasswordValidationCallbackHandler'在其中实现Spring Web服务安全性.这就是我的弹簧配置的样子.

我在JBoss7.1 AS中部署了这个应用程序.当应用程序启动时,抛出异常.它抱怨找不到'com.sun.xml.wss.XWSSecurityException'.
org.springframework.beans.factory.BeanCreationException:创建名为'org.springframework.ws.soap.addressing.server.AnnotationActionEndpointMapping#0'的bean时出错:init方法的调用失败; 嵌套异常是java.lang.NoClassDefFoundError:com/sun/xml/wss/XWSSecurityException引起:java.lang.ClassNotFoundException:com.sun.xml.wss.XWSSecurityException
现在我试图了解该问题的根本原因.所以我开始使用POM文件.
以下依赖关系是pom.
<dependency>
<groupId>org.springframework.ws</groupId>
<artifactId>spring-ws-core</artifactId>
<version>${org.springframework.ws.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.ws</groupId>
<artifactId>spring-ws-security</artifactId>
<version>${org.springframework.ws.version}</version>
</dependency>
<dependency>
<groupId>com.sun.xml.wss</groupId>
<artifactId>xws-security</artifactId>
<version>3.0</version>
</dependency>
<dependency>
<groupId>javax.activation</groupId>
<artifactId>activation</artifactId>
<version>1.1.1</version>
</dependency>
<dependency>
<groupId>javax.xml</groupId>
<artifactId>xmldsig</artifactId>
<version>1.0</version>
</dependency>
Run Code Online (Sandbox Code Playgroud)
作为我研发的一部分,我选择了'spring-ws-core'和'spring-ws-security'的旧版本(2.1.2)以及'sjsxp'的'1.0.2'版本.应用程序启动后,当我提供无效密码时,我收到了身份验证错误.如果我提供正确的凭据,应用程序响应正常.这是我想用这些罐子的最新版本实现的.
现在我想知道为什么缺少2.3.0/2.4.0.
所以我尝试了'mvn依赖:tree -Dverbose',发现2.1.2版本带来了'xws-security'.
所以我想添加那个依赖.
<dependency>
<groupId>com.sun.xml.wss</groupId>
<artifactId>xws-security</artifactId>
<version>3.0</version>
</dependency>
Run Code Online (Sandbox Code Playgroud)
现在这迫使我再添加两个依赖项.我也加了.
<dependency>
<groupId>javax.activation</groupId>
<artifactId>activation</artifactId>
<version>1.1.1</version>
</dependency>
<dependency>
<groupId>javax.xml</groupId>
<artifactId>xmldsig</artifactId>
<version>1.0</version>
</dependency>
Run Code Online (Sandbox Code Playgroud)
但是maven存储库中缺少第二个'xmldsig'.我可以下载并手动将其添加到我当地的m2 repo.但我想以适当的方式解决它.在搜索时我遇到了这个帖子. http://maven.40175.n5.nabble.com/where-to-get-xmldsig-1-0-jar-td92435.html
有人在谈论另一种选择.
我可以看到这是在'spring-ws-security:jar'的2.3.0版本中可用的.
现在我的问题是,需要避免/添加什么,以便应用程序启动最新版本的jar?手指交叉.....
我正在修改spring-security从spring security-3到spring security-4.x. 我按照这个链接: - 在这里输入链接描述
我的配置是: -
<?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:security="http://www.springframework.org/schema/security"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-4.2.xsd
http://www.springframework.org/schema/security
http://www.springframework.org/schema/security/spring-security-4.0.xsd">
<!-- This is where we configure Spring-Security -->
<security:http entry-point-ref="loginUrlAuthenticationEntryPoint">
<security:custom-filter position="CONCURRENT_SESSION_FILTER" ref="concurrencyFilter" />
<security:custom-filter position="FORM_LOGIN_FILTER" ref="myAuthFilter" />
<security:session-management session-authentication-strategy-ref="sas"/>
<security:custom-filter ref="filter" before="FILTER_SECURITY_INTERCEPTOR" />
<security:logout invalidate-session="true" logout-success-url="/login"/>
</security:http>
<bean id="loginUrlAuthenticationEntryPoint" class="org.springframework.security.web.authentication.LoginUrlAuthenticationEntryPoint">
<property name="loginFormUrl" value="/login"/>
</bean>
<bean id="concurrencyFilter" class="org.springframework.security.web.session.ConcurrentSessionFilter">
<property name="sessionRegistry" ref="sessionRegistry" />
<property name="expiredUrl" value="/login" />
</bean>
<bean id="myAuthFilter" class= "org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter">
<property name="sessionAuthenticationStrategy" ref="sas" />
<property name="authenticationManager" ref="authenticationManager" />
<property name="authenticationFailureHandler" …Run Code Online (Sandbox Code Playgroud) 我使用的是Spring-security 4.0.4.我试图设置响应头的安全配置如下 -
<sec:http use-expressions="true">
<sec:headers defaults-disabled="true"/>
</sec:http>
此设置用于禁用安全标头中的安全组件.但是,如果完成此设置,则在服务器启动期间将引发以下异常.
Caused by: org.springframework.beans.factory.parsing.BeanDefinitionParsingException: Configuration problem: No AuthenticationEntryPoint could be established. Please make sure you have a login mechanism configured through the namespace (such as form-login) or specify a custom AuthenticationEntryPoint with the 'entry-point-ref' attribute
根据错误,设置需要form-login与上述设置一起使用.有人可以告诉我为什么会这样吗?
我需要提供某些角色来访问以下格式的URL:
/connector/{programId}/order/{anything here}
Run Code Online (Sandbox Code Playgroud)
programId整数值在哪里,所以我尝试了以下操作,但它根本不起作用。
/connector/{programId}/order/{anything here}
Run Code Online (Sandbox Code Playgroud)
但是,当我使用它**而不是programId零件时,它运行良好。但是,如何使它与pathVariable(始终为整数)一起使用。
我正在尝试用授权代码流保护我的休息api,但我不明白为什么我收到消息:
User must be authenticated with Spring Security before authorization can be completed.
Run Code Online (Sandbox Code Playgroud)
我有一个具有User和Admin访问权限的应用程序的Web部分,以及带有2个不同授权的REST api部分,/ api/**授权代码和带有client_credentials的/ oauth2/**.
client_credential流程工作,但授权代码nope ...
所以,这是我的授权服务器配置
@Configuration
@EnableAuthorizationServer
public class AuthorizationServerConfig extends AuthorizationServerConfigurerAdapter {
@Autowired
DataSource dataSource;
@Autowired
@Qualifier("authenticationManagerBean")
private AuthenticationManager authManager;
@Override
public void configure(AuthorizationServerSecurityConfigurer oauthServer) throws Exception {
oauthServer.tokenKeyAccess("permitAll()").checkTokenAccess("isAuthenticated()");
}
@Override
public void configure(ClientDetailsServiceConfigurer clients) throws Exception {
clients.jdbc(dataSource);
}
@Override
public void configure(AuthorizationServerEndpointsConfigurer endpoints) throws Exception {
endpoints.tokenStore(tokenStore()).authenticationManager(authManager);
}
@Bean
public TokenStore tokenStore() {
return new JdbcTokenStore(dataSource);
}
}
Run Code Online (Sandbox Code Playgroud)
这是我的资源服务器配置
@Configuration
@EnableResourceServer
@EnableGlobalMethodSecurity(prePostEnabled=true) …Run Code Online (Sandbox Code Playgroud) 我想在登录时获取userName信息.如果用户未登录,则if语句应跳过此操作.我认为暗示是我应该使用但当用户未登录时它当前抛出空指针.
@RequestMapping(value = "/", method = RequestMethod.GET)
public String displayHomePage(Model model, Principal user) {
if(!user.implies(null)){
String name = user.getName();
User currentUser = userService.getUserByName(name);
}
Run Code Online (Sandbox Code Playgroud) 有人可以解释一下在 Java 应用程序中使用 UsernamePasswordAuthenticationToken 的以下代码吗?
UsernamePasswordAuthenticationToken authentication = new UsernamePasswordAuthenticationToken(
userDetails, null,
userDetails == null ?
List.of() : userDetails.getAuthorities()
);
Run Code Online (Sandbox Code Playgroud)
我试图了解此代码中如何使用 UsernamePasswordAuthenticationToken 来处理身份验证,特别是关于 userDetails 参数和作为凭据传递的空值。我也对使用 List.of() 和 userDetails.getAuthorities() 来设置权限感到好奇。任何见解都会有帮助。谢谢你!
我最近将我的 Spring Boot 应用程序Spring Security 5从Spring Security 6. 通常,我们@EnableWebSecurity在配置类中使用注解来启用Web安全。我在 Spring Security 6 中注意到的一件有趣的事情是他们从 @EnableWebSecurity 类中删除了 @Configuration 注释。
为了便于参考,我添加了Spring Security 5和Spring Security 6中的 @EnableWebSecurity 的源代码。
// Spring Security 5
@Retention(RUNTIME)
@Target(TYPE)
@Documented
@Import({WebSecurityConfiguration.class,org.springframework.security.config.annotation.web.configuration.SpringWebMvcImportSelector.class,org.springframework.security.config.annotation.web.configuration.OAuth2ImportSelector.class,org.springframework.security.config.annotation.web.configuration.HttpSecurityConfiguration.class})
@EnableGlobalAuthentication
@Configuration
public @interface EnableWebSecurity
// Spring Security 6
@Retention(RUNTIME)
@Target(TYPE)
@Documented
@Import({WebSecurityConfiguration.class,org.springframework.security.config.annotation.web.configuration.SpringWebMvcImportSelector.class,org.springframework.security.config.annotation.web.configuration.OAuth2ImportSelector.class,org.springframework.security.config.annotation.web.configuration.HttpSecurityConfiguration.class})
@EnableGlobalAuthentication
public @interface EnableWebSecurity
Run Code Online (Sandbox Code Playgroud)
我很好奇的是,在 Spring Security 6 中删除 @Configuration 注解的原因是什么?
编辑:我在 GitHub 上看到这个问题,提到 @Enable* 注释不再需要 @Configuration 注释。但无论如何,它在 Spring Security 6 中被删除了。
spring-security ×10
spring ×6
java ×4
spring-boot ×3
spring-mvc ×2
ajax ×1
header ×1
jwt ×1
ldap ×1
maven ×1
regex ×1
response ×1
spring-ws ×1