相关疑难解决方法(0)

spring-oauth2登录成功处理程序

有没有办法使用spring-oauth2添加登录成功处理程序?

我尝试使用基本身份验证筛选器,但它只筛选客户端凭据而不是用户凭据.

或者我是否需要创建自定义用户身份验证管理器?

TIA

java spring handler

10
推荐指数
2
解决办法
3209
查看次数

oauth2 spring-security成功和失败处理程序

我正在使用oath2 spring security.它的工作正常,除了登录成功和失败处理程序.就像在春季Web安全性中一样,OAth2没有明确定义的成功和失败处理程序挂钩来更新数据库并相应地设置响应.如果有人能为我提供相同的代码行,我将不胜感激.什么过滤器需要扩展及其在弹簧安全过滤器链中的位置

java spring-security oauth-2.0

7
推荐指数
3
解决办法
5490
查看次数

Spring JWT - 添加自定义声明

你能帮我解决我的问题吗?我使用 Spring OAuth2 为我的客户端生成了 JWT。我已经实现了一个授权和资源服务器以及一些网络安全配置,一切都通过在线指南完成。

它工作正常,但现在我想编辑有效负载并添加自定义属性,例如用户的名字和姓氏等。你能检查我的代码并告诉我我应该怎么做才能将其他属性添加到有效负载中吗?谢谢。

这是我的实现:

@Configuration
@EnableWebSecurity
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
    @Value("${security.signing-key}")
    private String signingKey;

    @Value("${security.encoding-strength}")
    private Integer encodingStrength;

    @Value("${security.security-realm}")
    private String securityRealm;

    @Autowired
    private UserDetailsService userDetailsService;

    @Bean
    @Override
    protected AuthenticationManager authenticationManager() throws Exception {
        return super.authenticationManager();
    }

    @Override
    protected void configure(AuthenticationManagerBuilder auth) throws Exception {
        auth.userDetailsService(userDetailsService)
                .passwordEncoder(new BCryptPasswordEncoder());
    }

    @Override
    protected void configure(HttpSecurity http) throws Exception {
        http
                .sessionManagement()
                .sessionCreationPolicy(SessionCreationPolicy.STATELESS)
                .and()
                .httpBasic()
                .realmName(securityRealm)
                .and()
                .csrf()
                .disable();

    }

    @Bean
    public JwtAccessTokenConverter accessTokenConverter() {
        JwtAccessTokenConverter converter = …
Run Code Online (Sandbox Code Playgroud)

java spring spring-security jwt spring-security-oauth2

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

Spring OAuth/JWT 从访问令牌中获取额外信息

我制作了一个简单的应用程序,它使用带有 oauth/jwt 提供程序的 spring 安全性。我通过自定义 JwtAccessTokenConverter 在 jwt 令牌中添加了额外的信息,并且效果很好。

我的问题是如何在我的 Rest Controller 中获取这些额外信息。

这是我的测试:

@RequestMapping(value = "/test", produces = { "application/json" },method = RequestMethod.GET) 
public String testMethod(OAuth2Authentication authentication,
        OAuth2AccessToken token,
Principal user){
.....
Object a=token.getAdditionalInformation();
Object b=token.getValue();
...
}
Run Code Online (Sandbox Code Playgroud)

结果是:

  • OAuth2Authentication:注入但不包含附加信息或访问令牌对象(它只包含原始的 jwt 令牌字符串)。
  • User 是对 OAuth2Authentication 的引用
  • OAuth2AccessToken:是没有任何信息的 aop 代理,事实上对象 A 和 B 为空。

一些额外的信息:

  • 我通过调试检查了 ResourceService 使用我的 JwtAccessTokenConverter 并从输入的访问令牌字符串中提取附加信息列表。

spring oauth spring-security jwt spring-security-oauth2

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

Spring Security不返回UserDetails对象,仅返回用户名

我以为我的授权实现已经完成,但是当尝试检索UserDetails对象时,我得到的只是用户名。

我正在使用具有以下详细信息的oauth。

配置AuthenticationManager:

@Override
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
auth.userDetailsService(userDetailsService).passwordEncoder(passwordEncoder());
}
Run Code Online (Sandbox Code Playgroud)

完成此操作后,我可以调试到userDetailsS​​ervice中:

@Service
public class UserServiceImpl implements UserService, UserDetailsService {
@Override
    public UserDetails loadUserByUsername(String email) throws UsernameNotFoundException {
        MyUser persistedUser = userRepository.findByEmail(email);

        if (persistedUser == null) {
            throw new UsernameNotFoundException(String.format("The email %s doesn't exist", email));
        }

        List<GrantedAuthority> authorities = new ArrayList<>();

        MyUser inMemoryUser = new MyUser(persistedUser.getEmail(), null, persistedUser.getEnabled(), false,
                false, false, authorities);

        return inMemoryUser;
    }
}
Run Code Online (Sandbox Code Playgroud)

这样就很好了,我的客户又回来了JWT。但是我在调​​试以后的控制器方法时发现了以下问题。

@GetMapping
public @ResponseBody Iterable<Curriculum> getMyCurriculums(@AuthenticationPrincipal MyUser injectedUser) {
    Authentication auth = …
Run Code Online (Sandbox Code Playgroud)

spring oauth spring-security

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