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
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
add a comment |
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
Do you useGETorPOST?
– dur
Mar 22 at 10:27
add a comment |
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
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
rest spring-boot spring-mvc restful-authentication spring-boot-actuator
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 useGETorPOST?
– dur
Mar 22 at 10:27
add a comment |
Do you useGETorPOST?
– 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
add a comment |
2 Answers
2
active
oldest
votes
By default the URL is:
http://localhost:8080/actuator
try to change your config from
.antMatchers(
HttpMethod.GET,
"/actuator"
)
to
.antMatchers(
HttpMethod.GET,
"/actuator/**"
)
add a comment |
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/**"
)
add a comment |
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
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
By default the URL is:
http://localhost:8080/actuator
try to change your config from
.antMatchers(
HttpMethod.GET,
"/actuator"
)
to
.antMatchers(
HttpMethod.GET,
"/actuator/**"
)
add a comment |
By default the URL is:
http://localhost:8080/actuator
try to change your config from
.antMatchers(
HttpMethod.GET,
"/actuator"
)
to
.antMatchers(
HttpMethod.GET,
"/actuator/**"
)
add a comment |
By default the URL is:
http://localhost:8080/actuator
try to change your config from
.antMatchers(
HttpMethod.GET,
"/actuator"
)
to
.antMatchers(
HttpMethod.GET,
"/actuator/**"
)
By default the URL is:
http://localhost:8080/actuator
try to change your config from
.antMatchers(
HttpMethod.GET,
"/actuator"
)
to
.antMatchers(
HttpMethod.GET,
"/actuator/**"
)
edited Mar 21 at 19:37
answered Mar 21 at 19:02
Gui AlencarGui Alencar
1014
1014
add a comment |
add a comment |
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/**"
)
add a comment |
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/**"
)
add a comment |
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/**"
)
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/**"
)
answered Mar 24 at 9:39
Kabiru AhmedKabiru Ahmed
313
313
add a comment |
add a comment |
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.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
Do you use
GETorPOST?– dur
Mar 22 at 10:27