-1
I have an application built in Angular2+ and I need to leave an open route for external consultation, without having to log in to the application:
Java resource
@GetMapping("/clientes/consulta/{identificador}")
@PreAuthorize("hasAuthority(\"" + AuthoritiesConstants.ANONYMOUS + "\")")
public ResponseEntity<ClienteDTO> getClienteByIdentificador(@PathVariable String identificador) {
log.debug("REST request to get Cliente by identificador : {}", identificador);
Optional<ClienteDTO> clienteDTO = clienteService.findByIdentificador(identificador);
return ResponseUtil.wrapOrNotFound(clienteDTO);
}
service TS
public resourceUrl = SERVER_API_URL + 'api/clientes';
findByIdentificador(identificador: string): Observable<EntityResponseType> {
return this.http.get<ICliente>(`${this.resourceUrl}/consulta/${identificador}`, { observe: 'response' });}
Security Configuration
.antMatchers("/api/clientes/**").permitAll()
So it works, I found here. You need to put up the line that asks for authenticity for the whole api. Then this route will not ask for more authentication. . antMatchers("/api/clients/").permitAll() . antMatchers("/api/").authenticated()
– Bruno L Monteiro