use of io.quarkus.security.runtime.QuarkusSecurityIdentity in project quarkus by quarkusio.
the class OidcUtils method validateAndCreateIdentity.
static QuarkusSecurityIdentity validateAndCreateIdentity(RoutingContext vertxContext, TokenCredential credential, TenantConfigContext resolvedContext, JsonObject tokenJson, JsonObject rolesJson, UserInfo userInfo, TokenIntrospection introspectionResult) {
OidcTenantConfig config = resolvedContext.oidcConfig;
QuarkusSecurityIdentity.Builder builder = QuarkusSecurityIdentity.builder();
builder.addCredential(credential);
AuthorizationCodeTokens codeTokens = vertxContext != null ? vertxContext.get(AuthorizationCodeTokens.class.getName()) : null;
if (codeTokens != null) {
RefreshToken refreshTokenCredential = new RefreshToken(codeTokens.getRefreshToken());
builder.addCredential(refreshTokenCredential);
builder.addCredential(new AccessTokenCredential(codeTokens.getAccessToken(), refreshTokenCredential));
}
JsonWebToken jwtPrincipal;
try {
JwtClaims jwtClaims = JwtClaims.parse(tokenJson.encode());
jwtClaims.setClaim(Claims.raw_token.name(), credential.getToken());
jwtPrincipal = new OidcJwtCallerPrincipal(jwtClaims, credential, config.token.principalClaim.isPresent() ? config.token.principalClaim.get() : null);
} catch (InvalidJwtException e) {
throw new AuthenticationFailedException(e);
}
builder.addAttribute(QUARKUS_IDENTITY_EXPIRE_TIME, jwtPrincipal.getExpirationTime());
builder.setPrincipal(jwtPrincipal);
setRoutingContextAttribute(builder, vertxContext);
setSecurityIdentityRoles(builder, config, rolesJson);
setSecurityIdentityUserInfo(builder, userInfo);
setSecurityIdentityIntrospecton(builder, introspectionResult);
setSecurityIdentityConfigMetadata(builder, resolvedContext);
setBlockinApiAttribute(builder, vertxContext);
setTenantIdAttribute(builder, config);
return builder.build();
}
use of io.quarkus.security.runtime.QuarkusSecurityIdentity in project quarkus by quarkusio.
the class TestIdentityProvider method authenticate.
@Override
public Uni<SecurityIdentity> authenticate(UsernamePasswordAuthenticationRequest request, AuthenticationRequestContext context) {
TestIdentityController.TestIdentity ident = TestIdentityController.identities.get(request.getUsername());
if (ident == null) {
return Uni.createFrom().optional(Optional.empty());
}
if (!ident.password.equals(new String(request.getPassword().getPassword()))) {
return Uni.createFrom().failure(new AuthenticationFailedException());
}
QuarkusSecurityIdentity identity = QuarkusSecurityIdentity.builder().setPrincipal(new QuarkusPrincipal(ident.username)).addRoles(ident.roles).addCredential(request.getPassword()).build();
return Uni.createFrom().item(identity);
}
use of io.quarkus.security.runtime.QuarkusSecurityIdentity in project corrigeExamBack by barais.
the class UserJWTController method authorize.
@POST
@Path("/authenticate")
@PermitAll
public Response authorize(@Valid LoginVM loginVM) {
try {
QuarkusSecurityIdentity identity = authenticationService.authenticate(loginVM.username, loginVM.password);
boolean rememberMe = (loginVM.rememberMe == null) ? false : loginVM.rememberMe;
String jwt = tokenProvider.createToken(identity, rememberMe);
return Response.ok().entity(new JWTToken(jwt)).header("Authorization", "Bearer " + jwt).build();
} catch (SecurityException e) {
return Response.status(401).build();
}
}
use of io.quarkus.security.runtime.QuarkusSecurityIdentity in project corrigeExamBack by barais.
the class AuthenticationService method createQuarkusSecurityIdentity.
private QuarkusSecurityIdentity createQuarkusSecurityIdentity(User user) {
QuarkusSecurityIdentity.Builder builder = QuarkusSecurityIdentity.builder();
builder.setPrincipal(new QuarkusPrincipal(user.login));
builder.addCredential(new io.quarkus.security.credential.PasswordCredential(user.password.toCharArray()));
builder.addRoles(user.authorities.stream().map(authority -> authority.name).collect(Collectors.toSet()));
return builder.build();
}
Aggregations