use of io.micronaut.core.annotation.NonNull in project micronaut-security by micronaut-projects.
the class DefaultAuthorizationRedirectHandler method expandedUri.
/**
* @param baseUrl Base Url
* @param queryParams Query Parameters
* @return The Expanded URI
*/
protected String expandedUri(@NonNull String baseUrl, @NonNull Map<String, Object> queryParams) {
UriBuilder builder = UriBuilder.of(baseUrl);
queryParams.entrySet().stream().filter(entry -> entry.getValue() != null).forEach(entry -> builder.queryParam(entry.getKey(), entry.getValue()));
return builder.toString();
}
use of io.micronaut.core.annotation.NonNull in project micronaut-security by micronaut-projects.
the class DefaultAccessRefreshTokenGenerator method generate.
/**
* Generate an {@link AccessRefreshToken} response for the given
* refresh token and claims.
*
* @param refreshToken The refresh token
* @param oldClaims The claims to generate the access token
* @return The http response
*/
@NonNull
public Optional<AccessRefreshToken> generate(@Nullable String refreshToken, @NonNull Map<String, ?> oldClaims) {
Map<String, Object> claims = claimsGenerator.generateClaimsSet(oldClaims, accessTokenExpiration(oldClaims));
Optional<String> optionalAccessToken = tokenGenerator.generateToken(claims);
if (!optionalAccessToken.isPresent()) {
debug(LOG, "tokenGenerator failed to generate access token claims: {}", claims.entrySet().stream().map(entry -> entry.getKey() + "=>" + entry.getValue().toString()).collect(Collectors.joining(", ")));
return Optional.empty();
}
String accessToken = optionalAccessToken.get();
eventPublisher.publishEvent(new AccessTokenGeneratedEvent(accessToken));
return Optional.of(tokenRenderer.render(accessTokenExpiration(oldClaims), accessToken, refreshToken));
}
use of io.micronaut.core.annotation.NonNull in project micronaut-security by micronaut-projects.
the class DefaultAccessRefreshTokenGenerator method generate.
/**
* Generate a new access refresh token.
*
* @param refreshToken The refresh token
* @param authentication The user details to create a new access token
* @return The optional access refresh token
*/
@NonNull
@Override
public Optional<AccessRefreshToken> generate(@Nullable String refreshToken, @NonNull Authentication authentication) {
Optional<String> optionalAccessToken = tokenGenerator.generateToken(authentication, accessTokenExpiration(authentication));
if (!optionalAccessToken.isPresent()) {
debug(LOG, "Failed to generate access token for user {}", authentication.getName());
return Optional.empty();
}
String accessToken = optionalAccessToken.get();
eventPublisher.publishEvent(new AccessTokenGeneratedEvent(accessToken));
return Optional.of(tokenRenderer.render(authentication, accessTokenExpiration(authentication), accessToken, refreshToken));
}
use of io.micronaut.core.annotation.NonNull in project micronaut-security by micronaut-projects.
the class SignedRefreshTokenGenerator method generate.
@NonNull
@Override
public Optional<String> generate(@NonNull Authentication authentication, @NonNull String token) {
try {
JWSObject jwsObject = new JWSObject(new JWSHeader(algorithm), new Payload(token));
jwsObject.sign(signer);
return Optional.of(jwsObject.serialize());
} catch (JOSEException e) {
if (LOG.isWarnEnabled()) {
LOG.warn("JOSEException signing a JWS Object");
}
}
return Optional.empty();
}
use of io.micronaut.core.annotation.NonNull in project micronaut-security by micronaut-projects.
the class X509AuthenticationFetcher method extractName.
/**
* Extracts the name from the certificate using the subject DN regex.
*
* @param certificate the client certificate
* @return the name if found
*/
@NonNull
protected Optional<String> extractName(@NonNull X509Certificate certificate) {
String subjectDN = certificate.getSubjectX500Principal().getName();
Matcher matcher = subjectDnPattern.matcher(subjectDN);
if (!matcher.find()) {
return Optional.empty();
}
if (matcher.groupCount() != 1) {
return Optional.empty();
}
return Optional.of(matcher.group(1));
}
Aggregations