mirror of
https://github.com/valitydev/anapi-v2.git
synced 2024-11-06 00:25:17 +00:00
commit
e8a1386088
@ -9,6 +9,7 @@ import dev.vality.bouncer.ctx.ContextFragmentType;
|
||||
import dev.vality.bouncer.decisions.Context;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.SneakyThrows;
|
||||
import org.apache.thrift.TDeserializer;
|
||||
import org.apache.thrift.TSerializer;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@ -25,40 +26,33 @@ public class BouncerContextFactory {
|
||||
|
||||
@SneakyThrows
|
||||
public Context buildContext(AnapiBouncerContext bouncerContext) {
|
||||
var contextFragment = buildContextFragment(bouncerContext);
|
||||
var serializer = new TSerializer();
|
||||
var fragment = new dev.vality.bouncer.ctx.ContextFragment()
|
||||
.setType(ContextFragmentType.v1_thrift_binary)
|
||||
.setContent(serializer.serialize(contextFragment));
|
||||
var userFragment = orgManagerService.getUserAuthContext(
|
||||
var deserializer = new TDeserializer();
|
||||
|
||||
var contextFragment = orgManagerService.getUserAuthContext(
|
||||
keycloakService.getAccessToken().getSubject());
|
||||
var fragment = new ContextFragment();
|
||||
deserializer.deserialize(fragment, contextFragment.getContent());
|
||||
enrichContextFragment(bouncerContext, fragment);
|
||||
|
||||
contextFragment = new dev.vality.bouncer.ctx.ContextFragment()
|
||||
.setType(ContextFragmentType.v1_thrift_binary)
|
||||
.setContent(serializer.serialize(fragment));
|
||||
var context = new Context();
|
||||
context.putToFragments(bouncerProperties.getContextFragmentId(), fragment);
|
||||
context.putToFragments("userorg", userFragment);
|
||||
context.putToFragments(bouncerProperties.getContextFragmentId(), contextFragment);
|
||||
return context;
|
||||
}
|
||||
|
||||
private ContextFragment buildContextFragment(AnapiBouncerContext bouncerContext) {
|
||||
private void enrichContextFragment(AnapiBouncerContext bouncerContext, ContextFragment fragment) {
|
||||
var env = buildEnvironment();
|
||||
var contextAnalyticsApi = buildAnapiContext(bouncerContext);
|
||||
var contextReports = buildReportContext(bouncerContext);
|
||||
return new ContextFragment()
|
||||
.setAuth(buildAuth())
|
||||
.setUser(buildUser())
|
||||
fragment.setAuth(buildAuth())
|
||||
.setEnv(env)
|
||||
.setAnapi(contextAnalyticsApi)
|
||||
.setReports(contextReports);
|
||||
}
|
||||
|
||||
private User buildUser() {
|
||||
var user = new User();
|
||||
var token = keycloakService.getAccessToken();
|
||||
return user
|
||||
.setId(token.getSubject())
|
||||
.setEmail(token.getEmail())
|
||||
.setRealm(new Entity().setId(bouncerProperties.getRealm()));
|
||||
}
|
||||
|
||||
private Auth buildAuth() {
|
||||
var auth = new Auth();
|
||||
var accessToken = keycloakService.getAccessToken();
|
||||
|
@ -16,7 +16,10 @@ import dev.vality.magista.InvoicePaymentFlowHold;
|
||||
import dev.vality.magista.InvoicePaymentFlowInstant;
|
||||
import dev.vality.magista.Payer;
|
||||
import dev.vality.magista.*;
|
||||
import lombok.SneakyThrows;
|
||||
import lombok.experimental.UtilityClass;
|
||||
import org.apache.thrift.TDeserializer;
|
||||
import org.apache.thrift.TSerializer;
|
||||
|
||||
import java.time.Instant;
|
||||
import java.util.HashMap;
|
||||
@ -170,8 +173,11 @@ public class MagistaUtil {
|
||||
return DamselUtil.fillRequiredTBaseObject(new StatInvoiceTemplateResponse(), StatInvoiceTemplateResponse.class);
|
||||
}
|
||||
|
||||
@SneakyThrows
|
||||
public static ContextFragment createContextFragment() {
|
||||
return DamselUtil.fillRequiredTBaseObject(new ContextFragment(), ContextFragment.class);
|
||||
ContextFragment fragment = DamselUtil.fillRequiredTBaseObject(new ContextFragment(), ContextFragment.class);
|
||||
fragment.setContent(new TSerializer().serialize(new dev.vality.bouncer.context.v1.ContextFragment()));
|
||||
return fragment;
|
||||
}
|
||||
|
||||
public static Judgement createJudgementAllowed() {
|
||||
|
Loading…
Reference in New Issue
Block a user