Skip to content

Commit

Permalink
Added Javadoc and nullability annotations; adjusted visibility
Browse files Browse the repository at this point in the history
  • Loading branch information
tkrullmann committed Feb 16, 2019
1 parent 3907f9b commit 04ecfc9
Show file tree
Hide file tree
Showing 82 changed files with 435 additions and 160 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

/**
* Stores a blob of binary data.
*
* <p>
* This is essentially a wrapper over {@link ByteBuffer} to ensure immutability.
*/
public final class BinaryData {
Expand Down
14 changes: 6 additions & 8 deletions jwt/src/main/java/org/unbrokendome/jsonwebtoken/Claims.java
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,7 @@ default String getSubject() {
* with a single audience.</p>
*
* @return the value (or the first element) of the audience claim, or
* <code>null</code> if not set
*
* <code>null</code> if not set
* @see #getAudiences()
*/
@Nullable
Expand Down Expand Up @@ -113,7 +112,6 @@ default String getAudience() {
* </blockquote>
*
* @return the value of the audience claim, or <code>null</code> if not set
*
* @see #getAudience()
*/
@Nullable
Expand All @@ -138,7 +136,7 @@ default Set<String> getAudiences() {
* </blockquote>
*
* @return the value of the expiration time claim as an {@link Instant}, or
* <code>null</code> if not set
* <code>null</code> if not set
*/
@Nullable
default Instant getExpiration() {
Expand All @@ -162,7 +160,7 @@ default Instant getExpiration() {
* </blockquote>
*
* @return the value of the not-before claim as an {@link Instant}, or
* <code>null</code> if not set
* <code>null</code> if not set
*/
@Nullable
default Instant getNotBefore() {
Expand All @@ -183,7 +181,7 @@ default Instant getNotBefore() {
* </blockquote>
*
* @return the value of the issued-at claim as an {@link Instant}, or
* <code>null</code> if not set
* <code>null</code> if not set
*/
@Nullable
default Instant getIssuedAt() {
Expand All @@ -208,7 +206,7 @@ default Instant getIssuedAt() {
* </blockquote>
*
* @return the value of the issued-at claim as an {@link Instant}, or
* <code>null</code> if not set
* <code>null</code> if not set
*/
@Nullable
default String getId() {
Expand All @@ -218,7 +216,7 @@ default String getId() {

/**
* Checks whether this set of claims is expired, according to the given {@link Clock}.
*
* <p>
* Returns {@code false} if this instance does not contain an {@linkplain #EXPIRATION expiration} claim.
*
* @param clock a {@link Clock} that provides the current time
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ public interface ClaimsBuilder extends MapDataBuilder<ClaimsBuilder, Claims>, Cl

/**
* Sets the value of the issuer (<code>iss</code>) claim.
*
* @param issuer the value of the issuer claim
* @return the current {@link ClaimsBuilder} instance
*
* @see Claims#getIssuer()
*/
@Nonnull
Expand All @@ -22,9 +22,9 @@ default ClaimsBuilder setIssuer(String issuer) {

/**
* Sets the value of the subject (<code>sub</code>) claim.
*
* @param subject the value of the subject claim
* @return the current {@link ClaimsBuilder} instance
*
* @see Claims#getSubject()
*/
@Nonnull
Expand All @@ -35,9 +35,9 @@ default ClaimsBuilder setSubject(String subject) {

/**
* Sets the value of the audience (<code>aud</code>) claim to a single string.
*
* @param audience the value of the audience claim
* @return the current {@link ClaimsBuilder} instance
*
* @see Claims#getAudience()
*/
@Nonnull
Expand All @@ -48,9 +48,9 @@ default ClaimsBuilder setAudience(String audience) {

/**
* Sets the value of the audience (<code>aud</code>) claim to a set of strings.
*
* @param audiences the value of the audience claim
* @return the current {@link ClaimsBuilder} instance
*
* @see Claims#getAudiences()
*/
@Nonnull
Expand All @@ -61,9 +61,9 @@ default ClaimsBuilder setAudiences(Set<String> audiences) {

/**
* Sets the value of the expiration time (<code>exp</code>) claim.
*
* @param expiration the value of the expiration time claim
* @return the current {@link ClaimsBuilder} instance
*
* @see Claims#getExpiration()
*/
@Nonnull
Expand All @@ -74,9 +74,9 @@ default ClaimsBuilder setExpiration(Instant expiration) {

/**
* Sets the value of the not-before (<code>nbf</code>) claim.
*
* @param notBefore the value of the not-before claim
* @return the current {@link ClaimsBuilder} instance
*
* @see Claims#getNotBefore()
*/
@Nonnull
Expand All @@ -87,9 +87,9 @@ default ClaimsBuilder setNotBefore(Instant notBefore) {

/**
* Sets the value of the issued-at (<code>iat</code>) claim.
*
* @param issuedAt the value of the issued-at claim
* @return the current {@link ClaimsBuilder} instance
*
* @see Claims#getIssuedAt()
*/
@Nonnull
Expand All @@ -100,9 +100,9 @@ default ClaimsBuilder setIssuedAt(Instant issuedAt) {

/**
* Sets the value of the JWT ID (<code>jti</code>) claim.
*
* @param id the value of the JWT ID claim
* @return the current {@link ClaimsBuilder} instance
*
* @see Claims#getId()
*/
@Nonnull
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

/**
* Represents a JOSE (JSON Object Signing and Encryption) token header.
*
* <p>
* A JOSE header is essentially a key-value collection, where the keys are well-known and standardized.
* Commonly used headers are defined as constants in this interface.
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,53 @@
package org.unbrokendome.jsonwebtoken;

import javax.annotation.Nonnull;


public interface JoseHeaderBuilder extends MapDataBuilder<JoseHeaderBuilder, JoseHeader>, JoseHeader {

/**
* Sets the {@value JoseHeader#TYPE} entry for this header.
*
* @param type the value for the {@value JoseHeader#TYPE} entry
* @return the current builder instance
*/
@Nonnull
default JoseHeaderBuilder setType(String type) {
return set(TYPE, type);
}


/**
* Sets the {@value JoseHeader#CONTENT_TYPE} entry for this header.
*
* @param contentType the value for the {@value JoseHeader#CONTENT_TYPE} entry
* @return the current builder instance
*/
@Nonnull
default JoseHeaderBuilder setContentType(String contentType) {
return set(CONTENT_TYPE, contentType);
}


/**
* Sets the {@value JoseHeader#ALGORITHM} entry for this header.
*
* @param algorithm the value for the {@value JoseHeader#ALGORITHM} entry
* @return the current builder instance
*/
@Nonnull
default JoseHeaderBuilder setAlgorithm(String algorithm) {
return set(ALGORITHM, algorithm);
}


/**
* Sets the {@value JoseHeader#KEY_ID} entry for this header.
*
* @param keyId the value for the {@value JoseHeader#KEY_ID} entry
* @return the current builder instance
*/
@Nonnull
default JoseHeaderBuilder setKeyId(String keyId) {
return set(KEY_ID, keyId);
}
Expand Down
7 changes: 7 additions & 0 deletions jwt/src/main/java/org/unbrokendome/jsonwebtoken/Jws.java
Original file line number Diff line number Diff line change
@@ -1,29 +1,36 @@
package org.unbrokendome.jsonwebtoken;

import javax.annotation.Nonnull;
import java.nio.ByteBuffer;


public interface Jws {

@Nonnull
BinaryData getHeader();


@Nonnull
default ByteBuffer getHeaderBytes() {
return getHeader().toByteBuffer();
}


@Nonnull
BinaryData getPayload();


@Nonnull
default ByteBuffer getPayloadBytes() {
return getPayload().toByteBuffer();
}


@Nonnull
BinaryData getSignature();


@Nonnull
default ByteBuffer getSignatureBytes() {
return getSignature().toByteBuffer();
}
Expand Down
5 changes: 5 additions & 0 deletions jwt/src/main/java/org/unbrokendome/jsonwebtoken/Jwt.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import org.unbrokendome.jsonwebtoken.impl.DefaultJoseHeaderBuilder;
import org.unbrokendome.jsonwebtoken.impl.DefaultJwtProcessorBuilder;

import javax.annotation.Nonnull;


/**
* Main entry point to the JSON Web Token library.
Expand All @@ -20,6 +22,7 @@ private Jwt() {
*
* @return a new {@link JoseHeaderBuilder} instance
*/
@Nonnull
public static JoseHeaderBuilder header() {
return new DefaultJoseHeaderBuilder();
}
Expand All @@ -30,6 +33,7 @@ public static JoseHeaderBuilder header() {
*
* @return a new {@link ClaimsBuilder} instance
*/
@Nonnull
public static ClaimsBuilder claims() {
return new DefaultClaimsBuilder();
}
Expand All @@ -40,6 +44,7 @@ public static ClaimsBuilder claims() {
*
* @return a new {@link JwtProcessorBuilder} that can be used to configure and construct the {@link JwtProcessor}
*/
@Nonnull
public static JwtProcessorBuilder processor() {
return new DefaultJwtProcessorBuilder();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@

public interface JwtDecodeOnlyProcessorBuilder
extends JwtDecodingProcessorBuilderBase<JwtDecodingProcessor, JwtDecodeOnlyProcessorBuilder> {

}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import org.unbrokendome.jsonwebtoken.signature.JwsSignatureException;
import org.unbrokendome.jsonwebtoken.signature.JwsUnsupportedAlgorithmException;

import javax.annotation.Nonnull;


/**
* Decodes JSON Web Tokens.
Expand Down Expand Up @@ -51,6 +53,7 @@ public interface JwtDecodingProcessor extends JwtProcessorBase {
* for wrong signatures)
* @throws IllegalArgumentException if the payload could not be deserialized into the desired type
*/
@Nonnull
<T> T decode(String encodedToken, Class<T> payloadType) throws JwtMalformedTokenException,
JwsUnsupportedAlgorithmException, JwsSignatureException;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import org.unbrokendome.jsonwebtoken.signature.SignatureAlgorithms;
import org.unbrokendome.jsonwebtoken.signature.VerificationKeyResolver;

import javax.annotation.Nonnull;
import java.security.Key;


Expand All @@ -30,6 +31,7 @@ public interface JwtDecodingProcessorBuilderBase<T extends JwtDecodingProcessor,
* @param <TVerificationKey> the type of the verification key; must be a subclass of {@link Key}
* @return the current builder instance
*/
@Nonnull
<TVerificationKey extends Key>
B verifyWith(SignatureAlgorithm<?, TVerificationKey> algorithm,
VerificationKeyResolver<TVerificationKey> verificationKeyResolver);
Expand All @@ -44,6 +46,7 @@ B verifyWith(SignatureAlgorithm<?, TVerificationKey> algorithm,
* @param <TVerificationKey> the type of the verification key; must be a subclass of {@link Key}
* @return the current builder instance
*/
@Nonnull
default <TVerificationKey extends Key>
B verifyWith(SignatureAlgorithm<?, TVerificationKey> algorithm, TVerificationKey verificationKey) {
return verifyWith(algorithm, (VerificationKeyResolver<TVerificationKey>) ((h, p) -> verificationKey));
Expand All @@ -56,9 +59,10 @@ B verifyWith(SignatureAlgorithm<?, TVerificationKey> algorithm, TVerificationKey
* This overload does not take a key parameter, and is intended for the {@code NONE} algorithm (which is the only
* algorithm that does not require a key for verification).
*
* @param algorithm the signature algorithm to use; usually {@link SignatureAlgorithms#NONE}
* @param algorithm the signature algorithm to use; usually {@link SignatureAlgorithms#NONE}
* @return the current builder instance
*/
@Nonnull
default B verifyWith(SignatureAlgorithm<?, NoneKey> algorithm) {
return verifyWith(algorithm, NoneKey.getInstance());
}
Expand All @@ -73,6 +77,6 @@ default B verifyWith(SignatureAlgorithm<?, NoneKey> algorithm) {
* @param payloadDeserializer the custom {@link PayloadDeserializer} to register
* @return the current builder instance
*/
@Nonnull
B deserializePayloadWith(PayloadDeserializer<?> payloadDeserializer);

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@

public interface JwtEncodeOnlyProcessorBuilder
extends JwtEncodingProcessorBuilderBase<JwtEncodingProcessor, JwtEncodeOnlyProcessorBuilder> {

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import org.unbrokendome.jsonwebtoken.signature.JwsSignatureException;

import javax.annotation.Nonnull;


/**
* Encodes objects into JSON Web Tokens.
Expand Down Expand Up @@ -39,6 +41,7 @@ public interface JwtEncodingProcessor extends JwtProcessorBase {
* @return the encoded JSON Web Token as a string
* @throws JwsSignatureException if the signature for the token cannot be created
*/
@Nonnull
String encode(Object payload) throws JwsSignatureException;


Expand All @@ -53,6 +56,7 @@ public interface JwtEncodingProcessor extends JwtProcessorBase {
* @return the encoded JSON Web Token as a string
* @throws IllegalStateException if the signature for the token cannot be created
*/
@Nonnull
default String encodeUnchecked(Object payload) {
try {
return encode(payload);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,5 @@
* All {@link JwtProcessor} instances are immutable and safe for use by concurrent threads.
*/
public interface JwtProcessor extends JwtEncodingProcessor, JwtDecodingProcessor {

}
Loading

0 comments on commit 04ecfc9

Please sign in to comment.