我想创建一个实现令牌进行身份验证的Web服务。
我收到此错误:
Advertencia:StandardWrapperValve [jersey-serlvet]:servlet jersey-serlvet的Servlet.service()抛出异常java.lang.ClassNotFoundException:com.auth0.jwt.JWTSigner
这是我的代码:
import com.auth0.jwt.JWTSigner;
import com.auth0.jwt.JWTVerifier;
import com.auth0.jwt.JWTVerifyException;
import java.util.HashMap;
import java.util.Map;
//....
...//
public String crearToken(String username) {
String token = null;
final long iat = System.currentTimeMillis() / 1000l; // issued at claim
final long exp = iat + 60L; // expires claim. In this case the token expires in 60 seconds
final JWTSigner signer = new JWTSigner(this.key);
final HashMap<String, Object> claims = new HashMap<String, Object>();
claims.put("iss", username);
claims.put("exp", exp);
claims.put("iat", iat);
claims.put("aud",aud);
token = signer.sign(claims);
return token;
}
public void validarToken(String token)throws Exception{
try {
JWTVerifier jwtVerifier1 = new JWTVerifier(key);
jwtVerifier1.verify(token);}
catch(Exception e){
}
}
我的终点:
@POST
@Produces("application/json")
@Consumes("application/json")
public Response authenticateUser(Credentials credentials) {
String username = credentials.getUsername();
String password = credentials.getPassword();
try {
Authenticate auth= new Authenticate();
//Authenticate the user using the credentials provided
auth.authenticateUser(username, password);
Token tok= new Token();
// Issue a token for the user
String token = tok.crearToken(username);
// Return the token on the response
return Response.ok(token).build();
} catch (Exception e) {
return Response.status(Response.Status.UNAUTHORIZED).build();
}
}
有人知道为什么它会给我这个错误或我做错了吗?