Browse Source

/oauth2/rest_token impl/ test, comment PASSWORD

pull/4/head
shengzhaoli.shengz 1 year ago
parent
commit
07ad9509e6
  1. 2
      src/main/java/com/monkeyk/sos/config/OAuth2ServerConfiguration.java
  2. 20
      src/main/java/com/monkeyk/sos/web/controller/OAuthRestController.java

2
src/main/java/com/monkeyk/sos/config/OAuth2ServerConfiguration.java

@ -140,7 +140,7 @@ public class OAuth2ServerConfiguration {
strings.add(SignatureAlgorithm.ES256.getName());
}).grantTypes(grantTypes -> {
//向下兼容添加,v3.0.0
grantTypes.add(AuthorizationGrantType.PASSWORD.getValue());
// grantTypes.add(AuthorizationGrantType.PASSWORD.getValue());
grantTypes.add(AuthorizationGrantType.JWT_BEARER.getValue());
})
.scopes(strings -> {

20
src/main/java/com/monkeyk/sos/web/controller/OAuthRestController.java

@ -17,6 +17,7 @@ import jakarta.servlet.http.HttpServletResponse;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.BeanInitializationException;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
@ -25,6 +26,7 @@ import org.springframework.http.converter.HttpMessageConverter;
import org.springframework.http.server.ServletServerHttpResponse;
import org.springframework.security.authentication.AbstractAuthenticationToken;
import org.springframework.security.authentication.AuthenticationManager;
import org.springframework.security.config.annotation.authentication.configuration.AuthenticationConfiguration;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.AuthenticationException;
import org.springframework.security.core.context.SecurityContextHolder;
@ -38,7 +40,9 @@ import org.springframework.security.web.authentication.WebAuthenticationDetails;
import org.springframework.stereotype.Controller;
import org.springframework.util.Assert;
import org.springframework.util.CollectionUtils;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.ResponseBody;
import java.io.IOException;
import java.time.temporal.ChronoUnit;
@ -166,15 +170,21 @@ public class OAuthRestController implements InitializingBean, ApplicationContext
@Override
public void afterPropertiesSet() throws Exception {
// Assert.state(authenticationManager != null, "AuthenticationManager must be provided");
Assert.state(authenticationManager != null, "AuthenticationManager must be provided");
}
@Override
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
// if (this.authenticationManager == null) {
// this.authenticationManager = (AuthenticationManager) applicationContext.getBean("authenticationManagerBean");
// }
if (this.authenticationManager == null) {
AuthenticationConfiguration configuration = applicationContext.getBean(AuthenticationConfiguration.class);
Assert.notNull(configuration, "AuthenticationManagerBuilder is null");
try {
this.authenticationManager = configuration.getAuthenticationManager();
} catch (Exception e) {
throw new BeanInitializationException("Call 'getAuthenticationManager' error", e);
}
}
}
}

Loading…
Cancel
Save