Skip to content

Commit

Permalink
Remove redundant logging and unused method in Altinn3 consumer
Browse files Browse the repository at this point in the history
#deploy-idporten-frontend

Cleaned up unnecessary logging and eliminated the unused `getUserId` method to streamline code and reduce noise. This enhances maintainability and ensures more focused logging for traceability.
  • Loading branch information
krharum committed Dec 18, 2024
1 parent 9f17161 commit ba89616
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,6 @@
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;

import java.util.Arrays;
import java.util.Base64;

@Slf4j
@Component
public class Altinn3PersonOrganisasjonTilgangConsumer {
Expand Down Expand Up @@ -61,22 +58,9 @@ public Flux<OrganisasjonDTO> getOrganisasjoner(ServerWebExchange exchange) {

return getAuthenticatedUserId
.call()
.doOnNext(pid -> log.info("getOrganisasjoner userid {}", pid))
.flatMap(Altinn3PersonOrganisasjonTilgangConsumer::getUserId)
.flatMapMany(userId ->
accessService.getAccessToken(serverProperties, exchange)
.flatMapMany(accessToken -> new PostPersonOrganisasjonTilgangCommand(webClient, userId, accessToken).call()));
}

public static Mono<String> getUserId(String token) {

if (token.length() == 11) {
return Mono.just(token);
} else {
var info = Arrays.toString(Base64.getDecoder().decode(token.split("\\.")[1]));
var start = info.indexOf("\"pid\":") + 7;
return Mono.just(info.substring(start, start + 11));
}
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ public class PostPersonOrganisasjonTilgangCommand implements Callable<Flux<Organ
@Override
public Flux<OrganisasjonDTO> call() {

log.info("ident {}", ident);
return webClient
.post()
.uri(builder -> builder.path("/api/v1/brukertilgang").build())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,19 +29,18 @@ public Mono<String> call() {
private Mono<String> getTokenAttribute(String attribute) {

return getJwtAuthenticationToken()
.map(authentication -> {
.map(authentication ->

log.info("GetAuthenticatedUserId context.authentication {}, {}", authentication.getClass().getPackageName(), authentication);
return switch (authentication) {
switch (authentication) {

case JwtAuthenticationToken jwtAuthenticationToken ->
jwtAuthenticationToken.getTokenAttributes().get(attribute).toString();
case JwtAuthenticationToken jwtAuthenticationToken ->
jwtAuthenticationToken.getTokenAttributes().get(attribute).toString();

case OAuth2AuthenticationToken oauth2AuthenticationToken ->
oauth2AuthenticationToken.getPrincipal().getAttributes().get("pid").toString();
case OAuth2AuthenticationToken oauth2AuthenticationToken ->
oauth2AuthenticationToken.getPrincipal().getAttributes().get("pid").toString();

default -> "";
};
});
default -> "";
}
);
}
}

0 comments on commit ba89616

Please sign in to comment.