Spring Boot application with Actuator The Next CEO of Stack OverflowWhat's the difference between @Component, @Repository & @Service annotations in Spring?How do I POST JSON data with Curl from a terminal/commandline to Test Spring REST?How to configure port for a Spring Boot applicationSecurity configuration with Spring-bootSpring boot actuator secure services does not work fineSpring (Boot) application and csrfSpring boot security consider case insensitive username check for loginCustomize Spring Security for trusted spaceSpring-Security 5 always 302Spring boot security cannot log in after invalid credentials

What flight has the highest ratio of time difference to flight time?

How fast would a person need to move to trick the eye?

Elegant way to replace substring in a regex with optional groups in Python?

What connection does MS Office have to Netscape Navigator?

Non-deterministic sum of floats

Why is the US ranked as #45 in Press Freedom ratings, despite its extremely permissive free speech laws?

Why am I allowed to create multiple unique pointers from a single object?

Can I equip Skullclamp on a creature I am sacrificing?

Extending anchors in TikZ

What was the first Unix version to run on a microcomputer?

Is micro rebar a better way to reinforce concrete than rebar?

How to avoid supervisors with prejudiced views?

Skipping indices in a product

Can we say or write : "No, it'sn't"?

If/When UK leaves the EU, can a future goverment conduct a referendum to join the EU?

How are problems classified in Complexity Theory?

Disadvantage of gaining multiple levels at once in a short milestone-XP game

SOQL: Aggregate, Grouping By and WHERE Clauses not working

Written every which way

How to transpose the 1st and -1th levels of arbitrarily nested array?

How do we know the LHC results are robust?

How to start emacs in "nothing" mode (`fundamental-mode`)

multiple labels for a single equation

What does convergence in distribution "in the Gromov–Hausdorff" sense mean?



Spring Boot application with Actuator



The Next CEO of Stack OverflowWhat's the difference between @Component, @Repository & @Service annotations in Spring?How do I POST JSON data with Curl from a terminal/commandline to Test Spring REST?How to configure port for a Spring Boot applicationSecurity configuration with Spring-bootSpring boot actuator secure services does not work fineSpring (Boot) application and csrfSpring boot security consider case insensitive username check for loginCustomize Spring Security for trusted spaceSpring-Security 5 always 302Spring boot security cannot log in after invalid credentials










1















I have an SpringBoot app. 2.1.3.RELEASE securized by JWT, I want to add an actuator. I added this dependency



<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>


this is my configFile:



@Profile("api")
@Configuration
@EnableWebSecurity
@EnableGlobalMethodSecurity(prePostEnabled = true)
public class ApiWebSecurityConfig extends WebSecurityConfigurerAdapter

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

@Autowired
private JwtAuthenticationEntryPoint unauthorizedHandler;

@Autowired
private JwtTokenUtil jwtTokenUtil;


@Autowired
private UserSecurityService userSecurityService;

@Value("$jwt.header")
private String tokenHeader;


@Value("$server.servlet.context-path")
private String serverContextPath;

/** The encryption SALT. */
private static final String SALT = "fd&eekj§sfs23#$1*(_)nof";


@Autowired
public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception
auth
.userDetailsService(userSecurityService)
.passwordEncoder(passwordEncoder());



@Bean
public BCryptPasswordEncoder passwordEncoder()
return new BCryptPasswordEncoder(12, new SecureRandom(SALT.getBytes()));



@Bean
@Override
public AuthenticationManager authenticationManagerBean() throws Exception
return super.authenticationManagerBean();



@Override
protected void configure(HttpSecurity httpSecurity) throws Exception

httpSecurity
// we don't need CSRF because our token is invulnerable
.csrf().disable()

.exceptionHandling().authenticationEntryPoint(unauthorizedHandler).and()

// don't create session
.sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS).and()
.authorizeRequests()

// Un-secure H2 Database
.antMatchers("/h2-console/**/**").permitAll()
.antMatchers("/auth/**").permitAll()
.anyRequest().authenticated();


// Custom JWT based security filter
JwtAuthorizationTokenFilter authenticationTokenFilter = new JwtAuthorizationTokenFilter(userDetailsService(), jwtTokenUtil, tokenHeader);
httpSecurity
.addFilterBefore(authenticationTokenFilter, UsernamePasswordAuthenticationFilter.class);


// disable page caching
httpSecurity
.headers()
.frameOptions().sameOrigin() // required to set for H2 else H2 Console will be blank.
.cacheControl();



@Override
public void configure(WebSecurity web) throws Exception
// AuthenticationTokenFilter will ignore the below paths
web
.ignoring()
.antMatchers(
HttpMethod.POST,
"/auth"
)

.antMatchers(
HttpMethod.GET,
"/actuator"
)


.antMatchers(
HttpMethod.POST,
"/reg"
);




but when I access in the postman to http://127.0.0.1:8080/myApp/actuator/



I got a




"timestamp": "2019-03-21T16:39:47.877+0000",
"status": 401,
"error": "Unauthorized",
"message": "Unauthorized",
"path": "/myApp/actuator/"



and HTTP Status 404 – Not Found



when accessing http://127.0.0.1:8080/actuator/










share|improve this question
























  • Do you use GET or POST?

    – dur
    Mar 22 at 10:27















1















I have an SpringBoot app. 2.1.3.RELEASE securized by JWT, I want to add an actuator. I added this dependency



<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>


this is my configFile:



@Profile("api")
@Configuration
@EnableWebSecurity
@EnableGlobalMethodSecurity(prePostEnabled = true)
public class ApiWebSecurityConfig extends WebSecurityConfigurerAdapter

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

@Autowired
private JwtAuthenticationEntryPoint unauthorizedHandler;

@Autowired
private JwtTokenUtil jwtTokenUtil;


@Autowired
private UserSecurityService userSecurityService;

@Value("$jwt.header")
private String tokenHeader;


@Value("$server.servlet.context-path")
private String serverContextPath;

/** The encryption SALT. */
private static final String SALT = "fd&eekj§sfs23#$1*(_)nof";


@Autowired
public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception
auth
.userDetailsService(userSecurityService)
.passwordEncoder(passwordEncoder());



@Bean
public BCryptPasswordEncoder passwordEncoder()
return new BCryptPasswordEncoder(12, new SecureRandom(SALT.getBytes()));



@Bean
@Override
public AuthenticationManager authenticationManagerBean() throws Exception
return super.authenticationManagerBean();



@Override
protected void configure(HttpSecurity httpSecurity) throws Exception

httpSecurity
// we don't need CSRF because our token is invulnerable
.csrf().disable()

.exceptionHandling().authenticationEntryPoint(unauthorizedHandler).and()

// don't create session
.sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS).and()
.authorizeRequests()

// Un-secure H2 Database
.antMatchers("/h2-console/**/**").permitAll()
.antMatchers("/auth/**").permitAll()
.anyRequest().authenticated();


// Custom JWT based security filter
JwtAuthorizationTokenFilter authenticationTokenFilter = new JwtAuthorizationTokenFilter(userDetailsService(), jwtTokenUtil, tokenHeader);
httpSecurity
.addFilterBefore(authenticationTokenFilter, UsernamePasswordAuthenticationFilter.class);


// disable page caching
httpSecurity
.headers()
.frameOptions().sameOrigin() // required to set for H2 else H2 Console will be blank.
.cacheControl();



@Override
public void configure(WebSecurity web) throws Exception
// AuthenticationTokenFilter will ignore the below paths
web
.ignoring()
.antMatchers(
HttpMethod.POST,
"/auth"
)

.antMatchers(
HttpMethod.GET,
"/actuator"
)


.antMatchers(
HttpMethod.POST,
"/reg"
);




but when I access in the postman to http://127.0.0.1:8080/myApp/actuator/



I got a




"timestamp": "2019-03-21T16:39:47.877+0000",
"status": 401,
"error": "Unauthorized",
"message": "Unauthorized",
"path": "/myApp/actuator/"



and HTTP Status 404 – Not Found



when accessing http://127.0.0.1:8080/actuator/










share|improve this question
























  • Do you use GET or POST?

    – dur
    Mar 22 at 10:27













1












1








1


1






I have an SpringBoot app. 2.1.3.RELEASE securized by JWT, I want to add an actuator. I added this dependency



<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>


this is my configFile:



@Profile("api")
@Configuration
@EnableWebSecurity
@EnableGlobalMethodSecurity(prePostEnabled = true)
public class ApiWebSecurityConfig extends WebSecurityConfigurerAdapter

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

@Autowired
private JwtAuthenticationEntryPoint unauthorizedHandler;

@Autowired
private JwtTokenUtil jwtTokenUtil;


@Autowired
private UserSecurityService userSecurityService;

@Value("$jwt.header")
private String tokenHeader;


@Value("$server.servlet.context-path")
private String serverContextPath;

/** The encryption SALT. */
private static final String SALT = "fd&eekj§sfs23#$1*(_)nof";


@Autowired
public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception
auth
.userDetailsService(userSecurityService)
.passwordEncoder(passwordEncoder());



@Bean
public BCryptPasswordEncoder passwordEncoder()
return new BCryptPasswordEncoder(12, new SecureRandom(SALT.getBytes()));



@Bean
@Override
public AuthenticationManager authenticationManagerBean() throws Exception
return super.authenticationManagerBean();



@Override
protected void configure(HttpSecurity httpSecurity) throws Exception

httpSecurity
// we don't need CSRF because our token is invulnerable
.csrf().disable()

.exceptionHandling().authenticationEntryPoint(unauthorizedHandler).and()

// don't create session
.sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS).and()
.authorizeRequests()

// Un-secure H2 Database
.antMatchers("/h2-console/**/**").permitAll()
.antMatchers("/auth/**").permitAll()
.anyRequest().authenticated();


// Custom JWT based security filter
JwtAuthorizationTokenFilter authenticationTokenFilter = new JwtAuthorizationTokenFilter(userDetailsService(), jwtTokenUtil, tokenHeader);
httpSecurity
.addFilterBefore(authenticationTokenFilter, UsernamePasswordAuthenticationFilter.class);


// disable page caching
httpSecurity
.headers()
.frameOptions().sameOrigin() // required to set for H2 else H2 Console will be blank.
.cacheControl();



@Override
public void configure(WebSecurity web) throws Exception
// AuthenticationTokenFilter will ignore the below paths
web
.ignoring()
.antMatchers(
HttpMethod.POST,
"/auth"
)

.antMatchers(
HttpMethod.GET,
"/actuator"
)


.antMatchers(
HttpMethod.POST,
"/reg"
);




but when I access in the postman to http://127.0.0.1:8080/myApp/actuator/



I got a




"timestamp": "2019-03-21T16:39:47.877+0000",
"status": 401,
"error": "Unauthorized",
"message": "Unauthorized",
"path": "/myApp/actuator/"



and HTTP Status 404 – Not Found



when accessing http://127.0.0.1:8080/actuator/










share|improve this question
















I have an SpringBoot app. 2.1.3.RELEASE securized by JWT, I want to add an actuator. I added this dependency



<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>


this is my configFile:



@Profile("api")
@Configuration
@EnableWebSecurity
@EnableGlobalMethodSecurity(prePostEnabled = true)
public class ApiWebSecurityConfig extends WebSecurityConfigurerAdapter

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

@Autowired
private JwtAuthenticationEntryPoint unauthorizedHandler;

@Autowired
private JwtTokenUtil jwtTokenUtil;


@Autowired
private UserSecurityService userSecurityService;

@Value("$jwt.header")
private String tokenHeader;


@Value("$server.servlet.context-path")
private String serverContextPath;

/** The encryption SALT. */
private static final String SALT = "fd&eekj§sfs23#$1*(_)nof";


@Autowired
public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception
auth
.userDetailsService(userSecurityService)
.passwordEncoder(passwordEncoder());



@Bean
public BCryptPasswordEncoder passwordEncoder()
return new BCryptPasswordEncoder(12, new SecureRandom(SALT.getBytes()));



@Bean
@Override
public AuthenticationManager authenticationManagerBean() throws Exception
return super.authenticationManagerBean();



@Override
protected void configure(HttpSecurity httpSecurity) throws Exception

httpSecurity
// we don't need CSRF because our token is invulnerable
.csrf().disable()

.exceptionHandling().authenticationEntryPoint(unauthorizedHandler).and()

// don't create session
.sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS).and()
.authorizeRequests()

// Un-secure H2 Database
.antMatchers("/h2-console/**/**").permitAll()
.antMatchers("/auth/**").permitAll()
.anyRequest().authenticated();


// Custom JWT based security filter
JwtAuthorizationTokenFilter authenticationTokenFilter = new JwtAuthorizationTokenFilter(userDetailsService(), jwtTokenUtil, tokenHeader);
httpSecurity
.addFilterBefore(authenticationTokenFilter, UsernamePasswordAuthenticationFilter.class);


// disable page caching
httpSecurity
.headers()
.frameOptions().sameOrigin() // required to set for H2 else H2 Console will be blank.
.cacheControl();



@Override
public void configure(WebSecurity web) throws Exception
// AuthenticationTokenFilter will ignore the below paths
web
.ignoring()
.antMatchers(
HttpMethod.POST,
"/auth"
)

.antMatchers(
HttpMethod.GET,
"/actuator"
)


.antMatchers(
HttpMethod.POST,
"/reg"
);




but when I access in the postman to http://127.0.0.1:8080/myApp/actuator/



I got a




"timestamp": "2019-03-21T16:39:47.877+0000",
"status": 401,
"error": "Unauthorized",
"message": "Unauthorized",
"path": "/myApp/actuator/"



and HTTP Status 404 – Not Found



when accessing http://127.0.0.1:8080/actuator/







rest spring-boot spring-mvc restful-authentication spring-boot-actuator






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 23 at 8:01







Nuñito de la Calzada

















asked Mar 21 at 16:45









Nuñito de la CalzadaNuñito de la Calzada

1,5561272145




1,5561272145












  • Do you use GET or POST?

    – dur
    Mar 22 at 10:27

















  • Do you use GET or POST?

    – dur
    Mar 22 at 10:27
















Do you use GET or POST?

– dur
Mar 22 at 10:27





Do you use GET or POST?

– dur
Mar 22 at 10:27












2 Answers
2






active

oldest

votes


















1














By default the URL is:



http://localhost:8080/actuator


try to change your config from



 .antMatchers(
HttpMethod.GET,
"/actuator"
)


to



 .antMatchers(
HttpMethod.GET,
"/actuator/**"
)





share|improve this answer
































    0














    The Spring boot actuator contains multiple endpoints which include health, metrics, etc.



    The endpoints are accessed as follows;



    http://baseUrl/autuator/health



    http://baseUrl/autuator/metrics



    so get all the endpoints - http://baseUrl/autuator/** [GET Request]



    so to permit access to this endpoint in your security configuration, change your config from.



     .antMatchers(
    HttpMethod.GET,
    "/actuator"
    )


    to



     .antMatchers(
    HttpMethod.GET,
    "/actuator/**"
    )





    share|improve this answer























      Your Answer






      StackExchange.ifUsing("editor", function ()
      StackExchange.using("externalEditor", function ()
      StackExchange.using("snippets", function ()
      StackExchange.snippets.init();
      );
      );
      , "code-snippets");

      StackExchange.ready(function()
      var channelOptions =
      tags: "".split(" "),
      id: "1"
      ;
      initTagRenderer("".split(" "), "".split(" "), channelOptions);

      StackExchange.using("externalEditor", function()
      // Have to fire editor after snippets, if snippets enabled
      if (StackExchange.settings.snippets.snippetsEnabled)
      StackExchange.using("snippets", function()
      createEditor();
      );

      else
      createEditor();

      );

      function createEditor()
      StackExchange.prepareEditor(
      heartbeatType: 'answer',
      autoActivateHeartbeat: false,
      convertImagesToLinks: true,
      noModals: true,
      showLowRepImageUploadWarning: true,
      reputationToPostImages: 10,
      bindNavPrevention: true,
      postfix: "",
      imageUploader:
      brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
      contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
      allowUrls: true
      ,
      onDemand: true,
      discardSelector: ".discard-answer"
      ,immediatelyShowMarkdownHelp:true
      );



      );













      draft saved

      draft discarded


















      StackExchange.ready(
      function ()
      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55285383%2fspring-boot-application-with-actuator%23new-answer', 'question_page');

      );

      Post as a guest















      Required, but never shown

























      2 Answers
      2






      active

      oldest

      votes








      2 Answers
      2






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes









      1














      By default the URL is:



      http://localhost:8080/actuator


      try to change your config from



       .antMatchers(
      HttpMethod.GET,
      "/actuator"
      )


      to



       .antMatchers(
      HttpMethod.GET,
      "/actuator/**"
      )





      share|improve this answer





























        1














        By default the URL is:



        http://localhost:8080/actuator


        try to change your config from



         .antMatchers(
        HttpMethod.GET,
        "/actuator"
        )


        to



         .antMatchers(
        HttpMethod.GET,
        "/actuator/**"
        )





        share|improve this answer



























          1












          1








          1







          By default the URL is:



          http://localhost:8080/actuator


          try to change your config from



           .antMatchers(
          HttpMethod.GET,
          "/actuator"
          )


          to



           .antMatchers(
          HttpMethod.GET,
          "/actuator/**"
          )





          share|improve this answer















          By default the URL is:



          http://localhost:8080/actuator


          try to change your config from



           .antMatchers(
          HttpMethod.GET,
          "/actuator"
          )


          to



           .antMatchers(
          HttpMethod.GET,
          "/actuator/**"
          )






          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Mar 21 at 19:37

























          answered Mar 21 at 19:02









          Gui AlencarGui Alencar

          1014




          1014























              0














              The Spring boot actuator contains multiple endpoints which include health, metrics, etc.



              The endpoints are accessed as follows;



              http://baseUrl/autuator/health



              http://baseUrl/autuator/metrics



              so get all the endpoints - http://baseUrl/autuator/** [GET Request]



              so to permit access to this endpoint in your security configuration, change your config from.



               .antMatchers(
              HttpMethod.GET,
              "/actuator"
              )


              to



               .antMatchers(
              HttpMethod.GET,
              "/actuator/**"
              )





              share|improve this answer



























                0














                The Spring boot actuator contains multiple endpoints which include health, metrics, etc.



                The endpoints are accessed as follows;



                http://baseUrl/autuator/health



                http://baseUrl/autuator/metrics



                so get all the endpoints - http://baseUrl/autuator/** [GET Request]



                so to permit access to this endpoint in your security configuration, change your config from.



                 .antMatchers(
                HttpMethod.GET,
                "/actuator"
                )


                to



                 .antMatchers(
                HttpMethod.GET,
                "/actuator/**"
                )





                share|improve this answer

























                  0












                  0








                  0







                  The Spring boot actuator contains multiple endpoints which include health, metrics, etc.



                  The endpoints are accessed as follows;



                  http://baseUrl/autuator/health



                  http://baseUrl/autuator/metrics



                  so get all the endpoints - http://baseUrl/autuator/** [GET Request]



                  so to permit access to this endpoint in your security configuration, change your config from.



                   .antMatchers(
                  HttpMethod.GET,
                  "/actuator"
                  )


                  to



                   .antMatchers(
                  HttpMethod.GET,
                  "/actuator/**"
                  )





                  share|improve this answer













                  The Spring boot actuator contains multiple endpoints which include health, metrics, etc.



                  The endpoints are accessed as follows;



                  http://baseUrl/autuator/health



                  http://baseUrl/autuator/metrics



                  so get all the endpoints - http://baseUrl/autuator/** [GET Request]



                  so to permit access to this endpoint in your security configuration, change your config from.



                   .antMatchers(
                  HttpMethod.GET,
                  "/actuator"
                  )


                  to



                   .antMatchers(
                  HttpMethod.GET,
                  "/actuator/**"
                  )






                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Mar 24 at 9:39









                  Kabiru AhmedKabiru Ahmed

                  313




                  313



























                      draft saved

                      draft discarded
















































                      Thanks for contributing an answer to Stack Overflow!


                      • Please be sure to answer the question. Provide details and share your research!

                      But avoid


                      • Asking for help, clarification, or responding to other answers.

                      • Making statements based on opinion; back them up with references or personal experience.

                      To learn more, see our tips on writing great answers.




                      draft saved


                      draft discarded














                      StackExchange.ready(
                      function ()
                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55285383%2fspring-boot-application-with-actuator%23new-answer', 'question_page');

                      );

                      Post as a guest















                      Required, but never shown





















































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown

































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown







                      Popular posts from this blog

                      SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

                      용인 삼성생명 블루밍스 목차 통계 역대 감독 선수단 응원단 경기장 같이 보기 외부 링크 둘러보기 메뉴samsungblueminx.comeh선수 명단용인 삼성생명 블루밍스용인 삼성생명 블루밍스ehsamsungblueminx.comeheheheh

                      155 수학 과학 기타 둘러보기 메뉴eh추가해eh문서를 완성해