我有一个创建了一个包含这个方法的类JwtAuthenticationFilter:
@Override
public Authentication attemptAuthentication(HttpServletRequest request, HttpServletResponse response) throws AuthenticationException {
Authentication authentication = null;
if(hasJsonToken(request)) {
JwtAuthenticationToken jwtAuthenticationToken = new JwtAuthenticationToken(getJsonToken(request));
authentication = getAuthenticationManager().authenticate(jwtAuthenticationToken);
} else {
throw new AuthenticationCredentialsNotFoundException(AUTHENTICATION_CREDENTIALS_NOT_FOUND_MSG);
}
return authentication;
}
Run Code Online (Sandbox Code Playgroud)
如果未提供JWT,则抛出AuthenticationCredentialsNotFoundException.我希望这会在我的AuthenticationEntryPoint中触发begin方法 - 看起来像这样:
@Override
public void commence(HttpServletRequest request, HttpServletResponse response,
AuthenticationException authException) throws IOException, ServletException {
response.sendError(HttpStatus.UNAUTHORIZED.value(),HttpStatus.UNAUTHORIZED.getReasonPhrase());
}
Run Code Online (Sandbox Code Playgroud)
开始方法没有被调用.这在我的spring安全配置(或其中的一部分)中:
@Bean
public RestAuthenticationEntryPoint restAuthenticationEntryPoint() {
return new RestAuthenticationEntryPoint();
}
protected void configure(HttpSecurity http) throws Exception {
http.addFilterBefore(jwtAuthenticationFilter(), UsernamePasswordAuthenticationFilter.class)
.exceptionHandling().authenticationEntryPoint(restAuthenticationEntryPoint()).and()
.csrf().disable()
.authorizeRequests().antMatchers(AUTHORISED_SERVICE_REQUESTS_ANT_MATCHER).authenticated()
.anyRequest().permitAll();
}
Run Code Online (Sandbox Code Playgroud)
我不确定这里有什么错误,我希望有人指出我.谢谢
我的SecurityConfig类扩展了WebSecurityConfigurerAdapter,并使用@Configuration和@EnableWebSecurity进行了注释.
@Configuration …Run Code Online (Sandbox Code Playgroud) 有很多关于spring boot没有加载静态资源并且已经全部读过的问题(几乎)我仍然无法解决这个问题.在这个阶段,我选择不使用弹簧靴,但我仍然想知道问题是什么.我正在使用Eclipse,Java 8和Maven.
我有一个如下所示的应用程序类:
@SpringBootApplication
public class Application extends SpringBootServletInitializer {
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
return application.sources(Application.class);
}
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}
Run Code Online (Sandbox Code Playgroud)
我创建了一个css文件 - src/main/resources/static/style.css
并从jsp中引用它:
<link href="<c:url value='style.css'/>" rel="stylesheet">
Run Code Online (Sandbox Code Playgroud)
页面加载但不加载css.这是错误 - 405方法不允许
我认为思考是正确的但不确定.所有帮助赞赏.
基于下面的一些评论,这就是现在的情况.
我的jsp文件在src/main/resources/application.properties中配置如下:
spring.mvc.view.prefix:/WEB-INF/views/
spring.mvc.view.suffix:.jsp
Run Code Online (Sandbox Code Playgroud)
我的Jsp非常简单,位于/WEB-INF/views/home.jsp
<!DOCTYPE html>
<%@ page pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<html>
<head>
<link href="public/style.css" rel="stylesheet" type="text/css"/>
</head>
<body>
<p>Hello world!</p>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
我也试过像这样链接我的css文件:
<link href="style.css" rel="stylesheet" type="text/css"/>
Run Code Online (Sandbox Code Playgroud)
我的css文件位于webapp/public/style.css中,也非常简单
p {
color: red;
}
Run Code Online (Sandbox Code Playgroud)
我的jsp加载但不是css.我使用各种方法运行我的应用程序,包括: …
我有一个服务器应用程序,我正在尝试识别该服务器上当前登录的用户.我已经在我的网络应用程序上成功验证了用户,如下所示:
var provider = new firebase.auth.GoogleAuthProvider();
firebase.auth().signInWithPopup(provider).then(function(result) {
userJsonToken = result.credential.accessToken;
user = result.user;
}).catch(function(error) {
// Handle Errors here.
var errorCode = error.code;
var errorMessage = error.message;
// The email of the user's account used.
var email = error.email;
// The firebase.auth.AuthCredential type that was used.
var credential = error.credential;
});
Run Code Online (Sandbox Code Playgroud)
然后我通过ajax调用将userJsonToken发送到我的服务器,我可以在调试时看到令牌,因此令牌正确地发送到服务器.
在我的服务器应用程序中,我这样做:
try (InputStream is = FirebaseUtil.class.getClassLoader().getResourceAsStream(FIREBASE_CREDENTIALS_JSON_FILE)) {
FirebaseOptions options = new FirebaseOptions.Builder().setServiceAccount(is).setDatabaseUrl(FIREBASE_DATABASE_URL).build();
FirebaseApp.initializeApp(options);
} catch (IOException e) {
e.printStackTrace(System.err);
}
Run Code Online (Sandbox Code Playgroud)
然后我做:
FirebaseAuth.getInstance().verifyIdToken(idToken).addOnFailureListener(new OnFailureListener() {
@Override
public void …Run Code Online (Sandbox Code Playgroud)