-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add JwtCreator for signing and encrypting JWT
- Loading branch information
Showing
13 changed files
with
760 additions
and
234 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
shared/src/main/java/org/pac4j/lagom/javadsl/transport/RequestHeaderHelper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package org.pac4j.lagom.javadsl.transport; | ||
|
||
import com.lightbend.lagom.javadsl.api.transport.RequestHeader; | ||
import com.nimbusds.jwt.JWT; | ||
|
||
import java.util.function.Function; | ||
|
||
import static org.pac4j.core.context.HttpConstants.AUTHORIZATION_HEADER; | ||
import static org.pac4j.core.context.HttpConstants.BEARER_HEADER_PREFIX; | ||
|
||
/** | ||
* Helper functions for {@link RequestHeader}. | ||
* | ||
* @author Sergey Morgunov | ||
* @since 2.2.1 | ||
*/ | ||
public final class RequestHeaderHelper { | ||
|
||
/** | ||
* Puts {@code Authorization} header to {@link RequestHeader}. | ||
* @param jwt JWT | ||
*/ | ||
public static Function<RequestHeader, RequestHeader> authorizationBearer(String jwt) { | ||
return header -> header.withHeader(AUTHORIZATION_HEADER, BEARER_HEADER_PREFIX.concat(jwt)); | ||
} | ||
|
||
/** | ||
* Puts {@code Authorization} header to {@link RequestHeader}. | ||
* @param jwt JWT | ||
*/ | ||
public static Function<RequestHeader, RequestHeader> authorizationBearer(JWT jwt) { | ||
return authorizationBearer(jwt.serialize()); | ||
} | ||
|
||
/** | ||
* Copies specified header from sourced {@link RequestHeader} to target. | ||
* @param source sourced {@link RequestHeader} | ||
* @param name name of copying header | ||
*/ | ||
public static Function<RequestHeader, RequestHeader> forwardHeader(RequestHeader source, String name) { | ||
return header -> source.getHeader(name).map(value -> header.withHeader(name, value)).orElse(header); | ||
} | ||
|
||
/** | ||
* Copies {@code Authorization} header from sourced {@link RequestHeader} to target. | ||
* @param source sourced {@link RequestHeader} | ||
*/ | ||
public static Function<RequestHeader, RequestHeader> forwardAuthorization(RequestHeader source) { | ||
return forwardHeader(source, AUTHORIZATION_HEADER); | ||
} | ||
|
||
private RequestHeaderHelper() { | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.