Skip to content

Commit b4cf524

Browse files
committed
Add JoseHeader.builder()
1 parent 8dc8539 commit b4cf524

File tree

1 file changed

+21
-0
lines changed
  • oauth2/oauth2-jose/src/main/java/org/springframework/security/oauth2/jwt

1 file changed

+21
-0
lines changed

oauth2/oauth2-jose/src/main/java/org/springframework/security/oauth2/jwt/JoseHeader.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,14 @@ public <T> T getHeader(String name) {
176176
return (T) getHeaders().get(name);
177177
}
178178

179+
/**
180+
* Returns a new {@link Builder}.
181+
* @return the {@link Builder}
182+
*/
183+
public static Builder builder() {
184+
return new Builder();
185+
}
186+
179187
/**
180188
* Returns a new {@link Builder}, initialized with the provided {@link JwaAlgorithm}.
181189
* @param jwaAlgorithm the {@link JwaAlgorithm}
@@ -201,6 +209,9 @@ public static final class Builder {
201209

202210
private final Map<String, Object> headers = new HashMap<>();
203211

212+
private Builder() {
213+
}
214+
204215
private Builder(JwaAlgorithm jwaAlgorithm) {
205216
Assert.notNull(jwaAlgorithm, "jwaAlgorithm cannot be null");
206217
header(JoseHeaderNames.ALG, jwaAlgorithm);
@@ -211,6 +222,16 @@ private Builder(JoseHeader headers) {
211222
this.headers.putAll(headers.getHeaders());
212223
}
213224

225+
/**
226+
* Sets the {@link JwaAlgorithm JWA algorithm} used to digitally sign the JWS or
227+
* encrypt the JWE.
228+
* @param jwaAlgorithm the {@link JwaAlgorithm}
229+
* @return the {@link Builder}
230+
*/
231+
public Builder algorithm(JwaAlgorithm jwaAlgorithm) {
232+
return header(JoseHeaderNames.ALG, jwaAlgorithm);
233+
}
234+
214235
/**
215236
* Sets the JWK Set URL that refers to the resource of a set of JSON-encoded
216237
* public keys, one of which corresponds to the key used to digitally sign the JWS

0 commit comments

Comments
 (0)