Package com.jalios.jcms.security
Class JwtManager
- java.lang.Object
-
- com.jalios.jcms.security.JwtManager
-
- All Implemented Interfaces:
JPropertiesListener
public class JwtManager extends java.lang.Object implements JPropertiesListener
-
-
Field Summary
-
Fields inherited from interface com.jalios.util.JPropertiesListener
REVISION
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description org.jose4j.jwt.JwtClaims
generateDefaultClaims(Member mbr, java.lang.String issuer, float expiration)
generate default claimsorg.jose4j.jwt.JwtClaims
generateDefaultClaims(Member mbr, java.lang.String issuer, float expiration, java.lang.String url, java.lang.Integer prefixLength, java.util.List<java.lang.String> methodList, java.lang.String ipMask)
generate default claimsjava.lang.String
generateToken(java.security.PrivateKey key, Member mbr, java.lang.String issuer, float expiration, java.lang.String url, java.lang.Integer prefixLength, java.util.List<java.lang.String> methodList, java.lang.String ipMask)
generate default claimsjava.lang.String
generateToken(org.jose4j.jwt.JwtClaims claims, java.io.File privateKeyFile, java.lang.String password)
Generate a Jwt tokenjava.lang.String
generateToken(org.jose4j.jwt.JwtClaims claims, java.security.PrivateKey key)
Generate a Jwt tokenjava.lang.String
generateToken(org.jose4j.jwt.JwtClaims claims, java.security.PrivateKey key, java.security.PublicKey receiverKey)
Generate a encrypted Jwt tokenstatic JwtManager
getInstance()
void
propertiesChange(JProperties properties)
Invoked after properties have been modified in JCMS and save on disk.org.jose4j.jwt.JwtClaims
readToken(java.lang.String token, java.security.PublicKey key)
Read a token against the provided publicKey
-
-
-
Method Detail
-
getInstance
public static JwtManager getInstance()
-
propertiesChange
public void propertiesChange(JProperties properties)
Description copied from interface:JPropertiesListener
Invoked after properties have been modified in JCMS and save on disk.You cannot alter the value received in parameters.
Note that properties parameter may be null, a limited set of site properties, or all site properties.
To check that a property has been modified, reload the "current" property instead using
channel.getProperties
orchannel.getProperty
.- Specified by:
propertiesChange
in interfaceJPropertiesListener
- Parameters:
properties
- the properties which have been submitted to change
-
readToken
public org.jose4j.jwt.JwtClaims readToken(java.lang.String token, java.security.PublicKey key)
Read a token against the provided publicKey- Parameters:
token
- the JWT tokenkey
- the public Key- Returns:
- the
JwtClaims
is token can be read and if it 's valid, null otherwise
-
generateToken
public java.lang.String generateToken(org.jose4j.jwt.JwtClaims claims, java.io.File privateKeyFile, java.lang.String password) throws org.jose4j.lang.JoseException
Generate a Jwt token- Parameters:
claims
- the claimsprivateKeyFile
- thePrivateKey
file to encrypt withpassword
- the password of thePrivateKey
- Returns:
- the JWT token
- Throws:
org.jose4j.lang.JoseException
- thrown if the token cannot be generated
-
generateToken
public java.lang.String generateToken(org.jose4j.jwt.JwtClaims claims, java.security.PrivateKey key) throws org.jose4j.lang.JoseException
Generate a Jwt token- Parameters:
claims
- the claimskey
- thePrivateKey
file to encrypt with- Returns:
- the JWT token
- Throws:
org.jose4j.lang.JoseException
- thrown if the token cannot be generated
-
generateToken
public java.lang.String generateToken(java.security.PrivateKey key, Member mbr, java.lang.String issuer, float expiration, java.lang.String url, java.lang.Integer prefixLength, java.util.List<java.lang.String> methodList, java.lang.String ipMask) throws org.jose4j.lang.JoseException
generate default claims- Parameters:
key
- thePrivateKey
file to encrypt withmbr
- theMember
as subjectissuer
- the issuer of the JWT Claimsexpiration
- the expiration duration in minutesurl
- the url to checkprefixLength
- the length of the prefixmethodList
- theList
of authorized (not null and non empty if the check must be done)ipMask
- the ipMask (a regex) id the ip check must be done- Returns:
- he JWT token
- Throws:
org.jose4j.lang.JoseException
- thrown if the token cannot be generated
-
generateToken
public java.lang.String generateToken(org.jose4j.jwt.JwtClaims claims, java.security.PrivateKey key, java.security.PublicKey receiverKey) throws org.jose4j.lang.JoseException
Generate a encrypted Jwt token- Parameters:
claims
- the claimskey
- thePrivateKey
file to encrypt withreceiverKey
- thePublicKey
of the receiver- Returns:
- the JWT token
- Throws:
org.jose4j.lang.JoseException
- thrown if the token cannot be generated
-
generateDefaultClaims
public org.jose4j.jwt.JwtClaims generateDefaultClaims(Member mbr, java.lang.String issuer, float expiration)
generate default claims- Parameters:
mbr
- theMember
as subjectissuer
- the issuer of the JWT Claimsexpiration
- the expiration duration in minutes- Returns:
- the
JwtClaims
-
generateDefaultClaims
public org.jose4j.jwt.JwtClaims generateDefaultClaims(Member mbr, java.lang.String issuer, float expiration, java.lang.String url, java.lang.Integer prefixLength, java.util.List<java.lang.String> methodList, java.lang.String ipMask)
generate default claims- Parameters:
mbr
- theMember
as subjectissuer
- the issuer of the JWT Claimsexpiration
- the expiration duration in minutesurl
- the url to checkprefixLength
- the length of the prefixmethodList
- theList
of authorized (not null and non empty if the check must be done)ipMask
- (a regex) id the ip check must be done- Returns:
- the
JwtClaims
-
-