spring / oauth / token,AuthorizationFailureEvent - > AuthenticationSuccessEvent

时间:2017-12-01 12:06:24

标签: spring-boot spring-security oauth spring-security-oauth2 spring-boot-actuator

Spring Boot 2,OAuth2,我使用InMemoryTokenStore。

我定义了以下设置:

@Configuration
@EnableWebSecurity
@EnableGlobalMethodSecurity(prePostEnabled = true)
public class WebSecurityConfig extends WebSecurityConfigurerAdapter
{
...
    @Override
    protected void configure(HttpSecurity http) throws Exception
    {
        http
                .authorizeRequests()
                .anyRequest().permitAll();
        ;
    }
...
}

要获得令牌,请发出以下请求:

curl Standard:Login@localhost:8080/oauth/token -d grant_type=password -d username=user -d password=passUser

接下来,发生以下事件链:

1)引发的第一个事件是 AuthorizationFailureEvent

principal = anonymousUser
configAttributes = [fullyAuthenticated]
details = org.springframework.security.web.authentication.WebAuthenticationDetails@957e: RemoteIpAddress: 127.0.0.1; SessionId: null
exceptionClass = AccessDeniedException
source = FilterInvocation: URL: /oauth/token?username=user&password=passUser&grant_type=password
authorities = [ROLE_ANONYMOUS]
exceptionMessage = Access is denied
timestamp = 2017-12-01 14:45:34

2)然后 AuthenticationSuccessEvent

details = remoteAddress=127.0.0.1, tokenType=BearertokenValue=<TOKEN>
source = org.springframework.security.oauth2.provider.OAuth2Authentication@eb5a2d91: Principal: {
 "id":" user",
 "password": "****",
 "authorities": ["USER"],
 "firstName": "",
 "lastName": "",
 "accountNonExpired": "true",
 "credentialsNonExpired": "true",
 "accountNonLocked": "true",
 "enabled": "true"
}; Credentials: [PROTECTED]; Authenticated: true; Details: remoteAddress=127.0.0.1, tokenType=BearertokenValue=<TOKEN>; Granted Authorities: "USER"
timestamp = 2017-12-01 14:45:36

3)最后服务器成功返回一个令牌:

{
  "access_token" : "2d37dd06-0f35-441f-a851-96d145836eed",
  "token_type" : "bearer",
  "expires_in" : 863999,
  "scope" : "all"
}

请帮助我理解: 我应该进行哪些设置才能发生 AuthorizationFailureEvent 事件?

0 个答案:

没有答案