
de.yourinspiration.spring.jwt.JwtService Maven / Gradle / Ivy
package de.yourinspiration.spring.jwt;
import java.util.Optional;
import javax.servlet.http.HttpServletRequest;
/**
* Provides access to JWT tokens in web requests and generates JWT token for a
* given subject.
*
* @author Marcel Härle - [email protected]
*
*/
public interface JwtService {
/**
* Creates a JWT token for the given subject.
*
* @param subject
* the subject must not be null
* @return returns a token object containing the JWT token
*/
Token createTokenFromSubject(final String subject);
/**
* Parses the subject from a JWT token. The JWT token must be provided as a
* HTTP header named x-access-token.
*
* @param request
* the request containing the JWT token
* @return returns the parsed subject, or an empty optional if the token
* could not be found or parsed
*/
Optional getJwtSubject(HttpServletRequest request);
/**
* Authenticates the given request.
*
* @param request
* the request
* @param roles
* the roles for authentication
* @return returns true
if the request was authenticated,
* otherwise false
*/
boolean authenticate(HttpServletRequest request, String[] roles);
/**
* Get the attribute name for the request subject attribute.
*
* @return the attribute name
*/
String getRequestAttribute();
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy