Skip to content

Commit

Permalink
Retirado foto do token de autorização
Browse files Browse the repository at this point in the history
  • Loading branch information
andrepenteado committed Apr 15, 2024
1 parent 7dfa5fd commit a1f36bf
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,6 @@ public OAuth2TokenCustomizer<JwtEncodingContext> jwtTokenCustomizer() {

context.getClaims().claim("login", userEntity.getUsername());
context.getClaims().claim("nome", userEntity.getNome());
context.getClaims().claim("fotoBase64", Objects.isNull(userEntity.getFotoBase64()) ? "" : userEntity.getFotoBase64());
context.getClaims().claim("perfis", perfis);
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<div class="collapse collapse-horizontal" id="collapseSidebar">
<div class="d-flex flex-column flex-shrink-0 p-3 text-bg-primary" style="width: 280px; min-height: 100vh;">
<a href="#" class="d-flex align-items-center justify-content-center p-3 text-decoration-none">
<img src="{{ this.userLogin.fotoBase64.length === 0 ? '/assets/images/sem-usuario.png' : this.userLogin.fotoBase64 }}" width="128" height="128" class="rounded-circle">
<img src="/assets/images/sem-usuario.png" width="128" height="128" class="rounded-circle">
</a>
<div class="text-center fs-5 fw-bolder">{{ this.userLogin.nome }}</div>
<div class="text-center">{{ this.userLogin.perfilAtual }}</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.security.oauth2.core.oidc.user.OidcUser;
import org.springframework.web.bind.annotation.*;
Expand All @@ -24,6 +25,25 @@ public class UsuarioResource {

private final PermissaoService permissaoService;

@GetMapping("/foto")
public String obtemFoto(@AuthenticationPrincipal OidcUser principal) {
log.info("Obter foto do usuário");
try {
if (!permissaoService.isPermitido(Objects.requireNonNull(principal.getAttribute("perfis"))))
throw new ResponseStatusException(HttpStatus.FORBIDDEN, "Permissão negada");
return usuarioService.buscar(principal.getName()).orElseThrow(() -> new ResponseStatusException(HttpStatus.NOT_FOUND,
String.format("Foto do usuário %s não encontrada", principal.getName()))).getFotoBase64();
}
catch (ResponseStatusException rsex) {
throw rsex;
}
catch (Exception ex) {
log.error("Erro no processamento", ex);
throw new ResponseStatusException(HttpStatus.INTERNAL_SERVER_ERROR, "Erro no processamento");
}

}

@PutMapping("/alterar-senha")
public void alterarSenha(@RequestBody String senha, @AuthenticationPrincipal OidcUser principal) {
log.info("Alterar senha");
Expand Down

0 comments on commit a1f36bf

Please sign in to comment.