Skip to content

Commit

Permalink
Stramme opp logging ifm integrasjonsfeil (#1207)
Browse files Browse the repository at this point in the history
* Stramme opp logging ifm integrasjonsfeil

* Lenger timeout spøkelse

* Lenger timeout mot spøkelse
  • Loading branch information
jolarsen authored Oct 21, 2022
1 parent 9218b16 commit 159b85b
Show file tree
Hide file tree
Showing 18 changed files with 47 additions and 104 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public XacmlResponse evaluate(XacmlRequest xacmlRequest) {
try {
return send(request);
} catch (IntegrasjonException e) {
LOG.info("F-157387 IntegrasjonException ved kall {} til PDP", 2 - i, e);
LOG.trace("F-157387 IntegrasjonException ved kall {} til PDP", 2 - i, e);
}
}
return send(request);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,6 @@ private static AbacResultat resultatFraResponse(XacmlResponse response) {
return AbacResultat.AVSLÅTT_EGEN_ANSATT;
}
var ukjentadvice = denyAdvice.toString();
// TODO (JOL): fjerne etter midlertidig logging ifm overgang
LOG.info("Deny fra PDP uten kjent årsak, advice var: {}", ukjentadvice);
return AbacResultat.AVSLÅTT_ANNEN_ÅRSAK;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ private HttpResponse<byte[]> doSendExpectBytearrayRetry(HttpRequest httpRequest)
try {
return doSendExpectBytearray(httpRequest);
} catch (IntegrasjonException e) {
LOG.info("F-157390 IntegrasjonException ved kall {} til endepunkt {}", RETRIES - i, httpRequest.uri(), e);
LOG.trace("F-157390 IntegrasjonException ved kall {} til endepunkt {}", RETRIES - i, e);
}
}
return doSendExpectBytearray(httpRequest);
Expand All @@ -83,7 +83,7 @@ private HttpResponse<String> doSendExpectStringRetry(HttpRequest httpRequest) {
try {
return doSendExpectString(httpRequest);
} catch (IntegrasjonException e) {
LOG.info("F-157390 IntegrasjonException ved kall {} til endepunkt {}", RETRIES - i, httpRequest.uri(), e);
LOG.trace("F-157390 IntegrasjonException ved kall {} til endepunkt {}", RETRIES - i, e);
}
}
return doSendExpectString(httpRequest);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,6 @@ public Optional<OpenIDToken> refreshIdToken(OpenIDToken expiredToken, String sco
public OpenIDToken oboExchangeToken(String uid, OpenIDToken incomingToken, String scopes) {
var tokenFromCache = getCachedToken(uid, scopes);
if (tokenFromCache != null && tokenFromCache.isNotExpired()) {
LOG.trace("Fant cached token for scope {}", scopes);
return tokenFromCache.copy();
}
var data = "client_id=" + clientId +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
* (eks. prosesstask) slik at disse er autentisert.
*/
public class ContainerLogin {
private static final Logger log = LoggerFactory.getLogger(ContainerLogin.class);
private static final Logger LOG = LoggerFactory.getLogger(ContainerLogin.class);

private final LoginContext loginContext;

Expand All @@ -52,7 +52,7 @@ public void logout() {
try {
loginContext.logout();
} catch (LoginException e) {
log.warn("Noe gikk galt ved utlogging", e);
LOG.warn("Noe gikk galt ved utlogging", e);
}
MDCOperations.removeUserId();
MDCOperations.removeConsumerId();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,31 +25,26 @@ public class ThreadLocalLoginModule extends LoginModuleBase {

public ThreadLocalLoginModule() {
super(LOG);
LOG.trace("Create");
}

@Override
public void initialize(Subject subject, CallbackHandler callbackHandler, Map<String, ?> sharedState, Map<String, ?> options) {
LOG.trace("Initialize loginmodule");
this.subject = subject;
}

@Override
public boolean login() throws LoginException {
LOG.trace("Enter login method");
setLoginSuccess(true);
return true;
}

@Override
public void doCommit() throws LoginException {
getSubjectHandler().setSubject(subject);
LOG.trace("Login committed");
}

@Override
protected void cleanUpSubject() {
LOG.trace("Cleanup subject");
getSubjectHandler().setSubject(null);
}

Expand All @@ -59,7 +54,6 @@ protected void cleanUpLocalState() throws LoginException {
}

private ThreadLocalSubjectHandler getSubjectHandler() {
LOG.trace("get subject handler");
var subjectHandler = SubjectHandler.getSubjectHandler();
if (!(subjectHandler instanceof ThreadLocalSubjectHandler)) {
throw new IllegalArgumentException(ThreadLocalLoginModule.class.getSimpleName() + " krever subject handler av klasse "
Expand All @@ -68,4 +62,4 @@ private ThreadLocalSubjectHandler getSubjectHandler() {
return (ThreadLocalSubjectHandler) subjectHandler;
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
*/
public class OIDCLoginModule extends LoginModuleBase {

private static final Logger logger = LoggerFactory.getLogger(OIDCLoginModule.class);
private static final Logger LOG = LoggerFactory.getLogger(OIDCLoginModule.class);

// Set during initialize()
private Subject subject;
Expand All @@ -51,12 +51,11 @@ public class OIDCLoginModule extends LoginModuleBase {
private OidcCredential oidcCredential;

public OIDCLoginModule() {
super(logger);
super(LOG);
}

@Override
public void initialize(Subject subject, CallbackHandler callbackHandler, Map<String, ?> sharedState, Map<String, ?> options) {
logger.trace("Initialize loginmodule with {} and {}", subject, callbackHandler);
this.subject = subject;
this.callbackHandler = callbackHandler;
}
Expand All @@ -69,7 +68,6 @@ public boolean login() throws LoginException {
if (OidcLogin.LoginResult.SUCCESS.equals(resultat.loginResult())) {
sluttBruker = resultat.subject();
setLoginSuccess(true);
logger.trace("Login successful for user {}", sluttBruker);
return true;
}
if (OidcLogin.LoginResult.ID_TOKEN_EXPIRED.equals(resultat.loginResult())) {
Expand All @@ -96,8 +94,6 @@ public void doCommit() throws LoginException {
subject.getPrincipals().add(this.consumerId);
subject.getPublicCredentials().add(authenticationLevelCredential);
subject.getPublicCredentials().add(oidcCredential);

logger.trace("Login committed for user {}", sluttBruker);
}

@Override
Expand Down Expand Up @@ -141,8 +137,6 @@ protected void cleanUpLocalState() throws LoginException {
* Called by login() to acquire the ID Token.
*/
protected OpenIDToken getSSOToken() throws LoginException {
logger.trace("Getting the SSO-token from callback");

if (callbackHandler == null) {
throw new LoginException("No callbackhandler provided");
}
Expand All @@ -153,7 +147,7 @@ protected OpenIDToken getSSOToken() throws LoginException {
callbackHandler.handle(new Callback[] { tokenCallback });
return tokenCallback.getToken();
} catch (IOException | UnsupportedCallbackException e) {
logger.debug("Error while handling getting token from callbackhandler: ", e);
LOG.debug("Error while handling getting token from callbackhandler: ", e);
LoginException le = new LoginException();
le.initCause(e);
throw le;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public class KeyStoreTool {

private static RsaJsonWebKey jwk = null;

private static final Logger log = LoggerFactory.getLogger(KeyStoreTool.class);
private static final Logger LOG = LoggerFactory.getLogger(KeyStoreTool.class);

static {

Expand All @@ -44,7 +44,7 @@ public class KeyStoreTool {

//KeyStoreTool.keystore = ks;
} catch (KeyStoreException | NoSuchAlgorithmException | CertificateException | IOException | UnrecoverableEntryException e) {
log.error("Error during loading of keystore. Do you have your keystore in order, soldier?", e);
LOG.error("Error during loading of keystore. Do you have your keystore in order, soldier?", e);
throw new RuntimeException(e);
}

Expand All @@ -53,7 +53,7 @@ public class KeyStoreTool {
jwk.setPrivateKey(myPrivateKey);
jwk.setKeyId("1");
} catch (JoseException e) {
log.error("Error during init of JWK: " + e);
LOG.error("Error during init of JWK: " + e);
throw new RuntimeException(e);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,11 @@ protected AbstractDokArkivKlient(RestClient client) {
@Override
public OpprettJournalpostResponse opprettJournalpost(OpprettJournalpostRequest request, boolean ferdigstill) {
try {
LOG.info("DOKARKIV Oppretter journalpost");
var opprett = ferdigstill ?
UriBuilder.fromUri(restConfig.endpoint()).queryParam("forsoekFerdigstill", "true").build() :
restConfig.endpoint();
var restRequest = RestRequest.newPOSTJson(request, opprett, restConfig);
var res = restKlient.sendExpectConflict(restRequest, OpprettJournalpostResponse.class);
LOG.info("DOKARKIV Opprettet journalpost OK");
return res;
} catch (Exception e) {
LOG.info("DOKARKIV OPPRETT feilet for {}", request, e);
Expand All @@ -53,12 +51,10 @@ public OpprettJournalpostResponse opprettJournalpost(OpprettJournalpostRequest r
@Override
public boolean oppdaterJournalpost(String journalpostId, OppdaterJournalpostRequest request) {
try {
LOG.info("DOKARKIV Oppdaterer journalpost");
var oppdater = URI.create(restConfig.endpoint().toString() + String.format("/%s", journalpostId));
var method = new RestRequest.Method(RestRequest.WebMethod.PUT, RestRequest.jsonPublisher(request));
var restRequest = RestRequest.newRequest(method, oppdater, restConfig);
restKlient.send(restRequest, String.class);
LOG.info("DOKARKIV Oppdatert journalpost OK");
return true;
} catch (Exception e) {
LOG.info("DOKARKIV OPPDATER {} feilet for {}", journalpostId, request, e);
Expand All @@ -69,12 +65,10 @@ public boolean oppdaterJournalpost(String journalpostId, OppdaterJournalpostRequ
@Override
public boolean ferdigstillJournalpost(String journalpostId, String enhet) {
try {
LOG.info("DOKARKIV Ferdigstiller journalpost");
var ferdigstill = URI.create(restConfig.endpoint().toString() + String.format("/%s/ferdigstill", journalpostId));
var method = new RestRequest.Method(RestRequest.WebMethod.PATCH, RestRequest.jsonPublisher(new FerdigstillJournalpostRequest(enhet)));
var request = RestRequest.newRequest(method, ferdigstill, restConfig);
restKlient.send(request, String.class);
LOG.info("DOKARKIV Ferdigstilt journalpost OK");
return true;
} catch (Exception e) {
LOG.info("DOKARKIV FERDIGSTILL {} feilet for {}", journalpostId, enhet, e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,15 +101,13 @@ public <T extends GraphQLResult<?>> T query(GraphQLOperationRequest q, GraphQLRe
}

private <T extends GraphQLResult<?>> T query(GraphQLRequest req, Class<T> clazz) {
LOG.trace("Henter resultat for {} fra {}", clazz.getName(), restConfig.endpoint());
var method = new RestRequest.Method(RestRequest.WebMethod.POST, HttpRequest.BodyPublishers.ofString(req.toHttpJsonBody()));
var restRequest = RestRequest.newRequest(method, restConfig.endpoint(), restConfig)
.header("TEMA", tema.name());
var res = restKlient.send(restRequest, clazz);
if (res.hasErrors()) {
return errorHandler.handleError(res.getErrors(), restConfig.endpoint(), PDL_ERROR_RESPONSE);
}
LOG.trace("Hentet resultat for {} fra {} OK", clazz.getName(), restConfig.endpoint());
return res;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,15 +70,13 @@ public List<Journalpost> hentTilknyttedeJournalposter(TilknyttedeJournalposterQu

@Override
public byte[] hentDokument(HentDokumentQuery q) {
LOG.trace("Henter dokument");
var path = UriBuilder.fromUri(restConfig.endpoint()).path(HENTDOKUMENT)
.resolveTemplate("journalpostId", q.journalpostId())
.resolveTemplate("dokumentInfoId", q.dokumentId())
.resolveTemplate("variantFormat", q.variantFormat())
.build();
var request = RestRequest.newGET(path, restConfig);
var doc = restKlient.sendReturnByteArray(request);
LOG.info("Hentet dokument OK");
return doc;
}

Expand All @@ -88,14 +86,12 @@ public <T extends GraphQLResult<?>> T query(GraphQLOperationRequest req, GraphQL
}

private <T extends GraphQLResult<?>> T query(GraphQLRequest req, Class<T> clazz) {
LOG.trace("Eksekverer GraphQL query {}", req.getClass().getSimpleName());
var method = new RestRequest.Method(RestRequest.WebMethod.POST, HttpRequest.BodyPublishers.ofString(req.toHttpJsonBody()));
var request = RestRequest.newRequest(method, graphql, restConfig);
var res = restKlient.send(request, clazz);
if (res.hasErrors()) {
return errorHandler.handleError(res.getErrors(), restConfig.endpoint(), F_240613);
}
LOG.info("Eksekvert GraphQL query OK");
return res;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package no.nav.vedtak.felles.integrasjon.spokelse;

import java.time.Duration;
import java.util.Arrays;
import java.util.List;

Expand Down Expand Up @@ -42,7 +43,7 @@ public List<SykepengeVedtak> hentGrunnlag(String fnr) {
var path = UriBuilder.fromUri(restConfig.endpoint())
.queryParam("fodselsnummer", fnr)
.build();
var request = RestRequest.newGET(path, restConfig);
var request = RestRequest.newGET(path, restConfig).timeout(Duration.ofSeconds(40));
var grunnlag = restKlient.send(request, SykepengeVedtak[].class);
return Arrays.asList(grunnlag);
} catch (Exception e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

public class SAMLLogoutInterceptor implements PhaseInterceptor<SoapMessage> {

private static final Logger LOGGER = LoggerFactory.getLogger(SAMLLogoutInterceptor.class);
private static final Logger LOG = LoggerFactory.getLogger(SAMLLogoutInterceptor.class);
private LoginContext loginContext;

public SAMLLogoutInterceptor(LoginContext loginContext) {
Expand All @@ -38,7 +38,7 @@ private void logout() {
try {
loginContext.logout();
} catch (LoginException e) {
LOGGER.warn("Feilet utlogging", e);
LOG.warn("Feilet utlogging", e);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

public class VLFaultListener implements FaultListener {

private static final Logger logger = LoggerFactory.getLogger(VLFaultListener.class);
private static final Logger LOG = LoggerFactory.getLogger(VLFaultListener.class);

private final Set<Class<? extends Exception>> unntak = new HashSet<>();

Expand All @@ -28,9 +28,9 @@ public boolean faultOccurred(Exception exception, String description, Message me
}

if (rootCause instanceof VLException) {
logger.warn("VL exception", rootCause);
LOG.warn("VL exception", rootCause);
} else {
logger.error("Uventet exception: {}", LoggerUtils.removeLineBreaks(description), rootCause); // NOSONAR
LOG.error("Uventet exception: {}", LoggerUtils.removeLineBreaks(description), rootCause); // NOSONAR
}
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,32 +3,5 @@
/**
* Contains info from SAML token
*/
class SamlInfo {
private final String uid;
private final String identType;
private final int authLevel;
private final String consumerId;

public SamlInfo(String uid, String identType, int authLevel, String consumerId) {
this.uid = uid;
this.identType = identType;
this.authLevel = authLevel;
this.consumerId = consumerId;
}

public String getUid() {
return uid;
}

public String getIdentType() {
return identType;
}

public int getAuthLevel() {
return authLevel;
}

public String getConsumerId() {
return consumerId;
}
record SamlInfo(String uid, String identType, int authLevel, String consumerId) {
}
Loading

0 comments on commit 159b85b

Please sign in to comment.