# Java Security Bug

**URL:** <https://community.auth0.com/t/java-security-bug/65367>\
**Category:** Get Help\
**Created:** [June 30, 2021, 8:41pm UTC](https://community.auth0.com/t/java-security-bug/65367 "2021-06-30T20:41:48Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![jorge.vazquez](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/jorge.vazquez/32/25731_2.png) [@jorge.vazquez](https://community.auth0.com/u/jorge.vazquez)\
**Post date:** [June 30, 2021, 8:41pm UTC](https://community.auth0.com/t/java-security-bug/65367/1 "2021-06-30T20:41:48Z")

</div>

Hi everyone,

Im using this tutorial [Auth0 Spring Boot API SDK Quickstarts: Authorization](https://auth0.com/docs/quickstart/backend/java-spring-security)  
to protect my rest-api with auth, and call the services from angular, but I have a strange bug, because when my call si a “put” or “post” the java application validate the access\_token, but when my call is a get the services dont try to validate the access\_token

This is my security config:

@Configuration  
@EnableWebSecurity  
public class SecurityConfig extends WebSecurityConfigurerAdapter {

```
@Value("${auth0.audience}")
private String audience;

@Value("${spring.security.oauth2.resourceserver.jwt.issuer-uri}")
private String issuer;

@Override
public void configure(HttpSecurity http) throws Exception {

	http.authorizeRequests().mvcMatchers(" **/public/**").permitAll().mvcMatchers("/my_proyect_name/**").authenticated()
			.and().cors().and().oauth2ResourceServer().jwt();
}

@Bean
JwtDecoder jwtDecoder() {

	NimbusJwtDecoder jwtDecoder = (NimbusJwtDecoder) JwtDecoders.fromOidcIssuerLocation(issuer);

	OAuth2TokenValidator<Jwt> audienceValidator = new AudienceValidator(audience);
	OAuth2TokenValidator<Jwt> withIssuer = JwtValidators.createDefaultWithIssuer(issuer);
	OAuth2TokenValidator<Jwt> withAudience = new DelegatingOAuth2TokenValidator<>(withIssuer, audienceValidator);

	jwtDecoder.setJwtValidator(withAudience);

	return jwtDecoder;
}

```

}

And this is my services controller:

@RestController  
@CrossOrigin(origins = “\*”)  
@RequestMapping(path = “empresa”, produces = MediaType.APPLICATION\_JSON\_VALUE)  
public class EmpresaController {

```
@Autowired
EmpresaServiceImpl empresaService;

@PostMapping(value = "/crear")
public ResponseEntity<Empresa> crearEmpresa() {
	try {
		Empresa _empresa = empresaService.crear();
		return new ResponseEntity<>(_empresa, HttpStatus.CREATED);
	} catch (Exception e) {
		return new ResponseEntity<>(null, HttpStatus.INTERNAL_SERVER_ERROR);
	}
}

@PutMapping(value = "/actualizar/{id}")
public ResponseEntity<Empresa> actualizarEmpresa(@PathVariable Long id) {
	try {
		Empresa e = empresaService.buscarPorId(id);
		Empresa _empresa = empresaService.editarEmpresa(e);
		return new ResponseEntity<>(_empresa, HttpStatus.CREATED);
	} catch (Exception e) {
		return new ResponseEntity<>(null, HttpStatus.INTERNAL_SERVER_ERROR);
	}
}

@GetMapping(value = "/buscar/{id}")
public ResponseEntity<Empresa> buscar(@PathVariable Long id) {
	try {
		Empresa _empresa = empresaService.buscarPorId(id);
		return new ResponseEntity<>(_empresa, HttpStatus.CREATED);
	} catch (Exception e) {
		return new ResponseEntity<>(null, HttpStatus.INTERNAL_SERVER_ERROR);
	}
}

```

Thanks for your help!

**UPDATE**  
The problem was in my application.properties  
It had the property server.servlet.context-path: / my\_proyect\_name and AUTH0 recognizes from that PATH

My solution was:

```
@Override
public void configure(HttpSecurity http) throws Exception {
    http.authorizeRequests()
            .mvcMatchers("/public/**").permitAll()
            .mvcMatchers("/private/**").authenticated()
            .mvcMatchers("/private-scoped/**").hasAuthority("SCOPE_read:messages")
            .and().cors()
            .and().oauth2ResourceServer().jwt();
}

```

and in my controller, something like that

@RestController  
@CrossOrigin(origins = “\*”)  
@RequestMapping(path = “private/empresa”, produces = MediaType.APPLICATION\_JSON\_VALUE)

---

<div class="post-metadata">

**Author:** ![konrad.sopala](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/konrad.sopala/32/13516_2.png) [@konrad.sopala](https://community.auth0.com/u/konrad.sopala)\
**Post date:** [July 1, 2021, 11:33am UTC](https://community.auth0.com/t/java-security-bug/65367/2 "2021-07-01T11:33:08Z")

</div>

Sharing the solution down here from the user:

The problem was in my application.properties  
It had the property server.servlet.context-path: / my\_proyect\_name and AUTH0 recognizes from that PATH

My solution was:

```auto
@Override
public void configure(HttpSecurity http) throws Exception {
    http.authorizeRequests()
            .mvcMatchers("/public/**").permitAll()
            .mvcMatchers("/private/**").authenticated()
            .mvcMatchers("/private-scoped/**").hasAuthority("SCOPE_read:messages")
            .and().cors()
            .and().oauth2ResourceServer().jwt();
}

```

and in my controller, something like that

@RestController  
@CrossOrigin(origins = “\*”)  
@RequestMapping(path = “private/empresa”, produces = MediaType.APPLICATION\_JSON\_VALUE)

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/auth0/original/3X/b/5/b560f266932fcce5d57f09a6595bd50518cae3f3.jpeg) [@system](https://community.auth0.com/u/system)\
**Post date:** [July 16, 2021, 11:33am UTC](https://community.auth0.com/t/java-security-bug/65367/3 "2021-07-16T11:33:58Z")

</div>

This topic was automatically closed 15 days after the last reply. New replies are no longer allowed.
