Spring Boot Actuator hides property values in env endpoint - configuration

My problem is, that my Spring-Boot Actuator endpoint for env actually replaces some properties with starts like this:
"applicationConfig: [classpath:/config/application.properties]" : {
"rest.baseurl" : "http://85.214.247.80:9912",
"projectKey" : "******",
And I have no clue why. I did not have any hint in my application thats he should hide it. I guess there is some heuristic to hide it based on the property name.
any Ideas how to avoid the masking?

By default the /env endpoint will hide the value of any property with a key that, ignoring case, ends with password, secret, or key. You can customize this using the endpoints.env.keys-to-sanitize property. The value of this property should be a comma-separated list of suffixes or regexes to match against property names. For example, if you don't care about keys ending in key you could set it to:
endpoints.env.keys-to-sanitize=password,secret
This is what the documentation says:
endpoints.env.keys-to-sanitize=password,secret,key,token,.credentials.,vcap_services
Keys that should be sanitized. Keys can be simple strings that the property ends with or regex expressions.

Now from Spring boot version 3, by default the value of all properties are hidden.
To display the value in /env endpoint, below configuration needs to be added in application.properties file.
management.endpoint.env.show-values=ALWAYS
Valid values for the Property is as below
ALWAYS
NEVER
WHEN_AUTHORIZED

You can do it as #Andy Wilkinson mention. But you will see "endpoints.env.keys-to-sanitize" property with value "password,secret" in the applicationConfig section of /env endpoint.
To avoid this you can set the property using code as well:
public class MyApp {
#Autowired
private EnvironmentEndpoint envEndPnt;
#PostConstruct
public void initApplication() {
envEndPnt.setKeysToSanitize("password","secret");
}
}
So once all the initializations are done and the initApplication is called you will have the EnvironmentEndPoint to which you set the property manually.

The property to set now is management.endpoint.env.keys-to-sanitize. To reveal all properties just set it to nothing, e.g. management.endpoint.env.keys-to-sanitize=

For Spring Boot 3, put in pom.xml management.endpoint.env.show-values=ALWAYS

Related

Why #PetiteInject cannot inject service in DecoraManager?

I have a DecoraManager implementation : AppDecoraManager, and want to inject a service e.g.: FooService as:
#PetiteInject
FooService fooService;
When resolveDecorator() is called I want to use fooService to determine some parameters, but it has null value.
What could be the reason for this, and how could I resolve it?
DecoraManager is created by the servlet container, in DecoraServletFilter.
At the moment, there is no integration with existing Petite IOC, so you have to do the following:
First, you need to have a public static reference to PetiteContainer. Store it during the creation of container, for example.
Override createDecoraManager() in your implementation
Use PetiteContainer.wire(this) in your implementation of DecoraManager.
That is the only way to do so, so far.
The alternative would be this:
Register DecoraManager as #PetiteBean.
Again, get the static reference to PetiteContainer
In createDecoraManager use PetiteContainer.get() to get the instance.
In the first example, DecoraManager gets just wired; in the second example, it gets stored in Petite container, too.

JMSSerializerBundle Show blank value instead of null value

We are using Symfony2 FOSRestBundle with JMSSerializerBundle for developing REST APIs to be consumed by mobile developers.
The API response in JSON format returns 'null' as value of properties wherever applicable, which is generating an exception for the 3rd party library being used by mobile developers.
I don't see a solution from JMSSerializerBundle or FOSRestBundle to overwrite the value as per our requirement.
Workaround so far
I can set default value in entity so that the fresh data will have some default value in database, instead of null. But this doesn't work for a one-to-one/many-to-one relationship objects, as those will return null by default instead of blank object.
Any solution to overwrite the json after serialization ?
You can use a custom visitor to do that:
<?php
namespace Project\Namespace\Serializer;
use JMS\Serializer\Context;
use JMS\Serializer\JsonSerializationVisitor;
class BlankSerializationVisitor extends JsonSerializationVisitor
{
/**
* {#inheritdoc}
*/
public function visitNull($data, array $type, Context $context)
{
return '';
}
}
And then, set it to your serializer with the setSerializationVisitor method or in your config file:
# app/config/config.yml
parameters:
jms_serializer.json_serialization_visitor.class: Project\Namespace\Serializer\BlankSerializationVisitor
When using the FOSRestBundle, in your configuration file (generally app/config/config.yml) you can use this settings to avoid having null values:
fos_rest:
serializer:
serialize_null: false
If you want a custom value, you can use the serializer.post_serialize event.
PS: To have all possible options provided by the bundle, type this command:
php bin/console config:dump-reference fos_rest

Binding custom dependency property gets databinding to string cannot convert exception

I need to set the Xaml property of a RichTextBox user control via a binding expression in Windows Phone 8, and I found that it is not a DP, so I have decided to inherit from a RichTextBox and add a DP that will change the Xaml property with PropertyChanged event, anyways the code looks like this, stripped out irrelevant parts.
public class RichTextBoxWithBindableXaml : RichTextBox
{
public string BindableXaml
{
get { return (string)GetValue(BindableXamlProperty); }
set { SetValue(BindableXamlProperty, value); }
}
public static readonly DependencyProperty BindableXamlProperty =
DependencyProperty.Register("BindableXaml",
typeof(string),
typeof(RichTextBoxWithBindableXaml),
new PropertyMetadata(0));
}
//xaml code
<local:RichTextBoxWithBindableXaml BindableXaml="{Binding PageContent , Mode=OneWay}"> </local:RichTextBoxWithBindableXaml>
And I get the following dreaded exception message:
Object of type 'System.Windows.Data.Binding' cannot be converted to type 'System.String'.
I have checked many solutions to these exceptions and similar problems with data binding, and still going through the suggested similar questions on the right, and still cannot see why a simple thing wont work for me. The code I listed above is just the simplest implementations of a DP with a binding expression. Btw, the source PageContent is from a INotifyPropertyChanged object, and it works, I know because, it can bind to TextBlock's Text property.
Am I missing out something so obvious? I wouldn't want to post question for such a straightforward thing, but I cant seem to solve in any way.
EDIT:
Following P.S note turned out to be completely irrelevant.
P.S. My final doubt was on the way xmlns namespace local is loaded. It is loaded as clr assembly, could xaml parser think my custom inherited class as clr-only and confuse since clr properties are not dependency properties. Hope it doesnt sound stupid, i'm desperate. It is as such :
xmlns:local="clr-namespace:RumCli"
I found out that I should either provide a null PropertyMetadata (new PropertyMetadata(null) instead of 0), or a metadata with a default value type if the DP is supposed to be used in Xaml. For my sceneario, since I will make use of the PropertyChangedCallback, the propertymetadata that will passed to the Register method looks like this.
new PropertyMetadata(default(string), new PropertyChangedCallback(OnBindableXamlChanged))
hope, it helps to others.
For each dependency property one must supply a non subscribed value (not a C# term here) which suites the type of object which the consumer will access.
To quote MSDN Dependency Property Metadata
Dependency property metadata exists as an object that can be queried to examine the characteristics of a dependency property.
So for the value type results, a default for the different value types, such as a double is to use double.NaN. A decimal use decimal.Zero. While a string, string.empty is good as a base.
That allows whatever operation which may blindly reflect off of the property, it can determine what its true property type is and access it accordingly.
So assigning 0 to a string makes no sense in identifying that the property is a string which 0 identifies it as an integer. So the int as string is setting up a future runtime failures when objects try to assign bindings, styles and other items to it.

how to add annotations to method/constructor parameters without touching the source code?

I am trying to de/seralize framework objects (no source code access) into JSON using jackson 2.
class Item {
public Item(Long id) {}
}
I found this Add annotation to a parameter on a new method created with Javassist but this solution is based on JavaAssist and does not fully apply :(
The underlying issue is the lack of DefaultConstructors which can be solved using the #JsonCreator annotation together with a matching #JsonProperty annotation for the parameter.
#JsonCreator
class Item {
public Item(#JsonProperty("id") Long id) {}
}
I managed to achieve this for one of the many item subclasses using a mixin class.
public abstract class ItemChildMixin {
#JsonCreator
public ItemChildMixin(#JsonProperty("objId") final Long objId) {
}
}
However, writing mixin classes for all the relevant objects with almost the same content seems the wrong approach, so I started looking at aspects.
Adding the Annotation to the classes in the Item's hierarchy was easy:
aspect DeclareJsonCreatorAspect {
declare #constructor: Item+.new(Long): #JsonCreator;
}
However, I cannot seem to find a way to add an annotation to the constructor parameters using Aspects!
Aspectj in Action as well as google did not provide an answer yet.
Is this at all possible?
Currently AFAIK AspectJ (currently v1.8.4) is unable to deal with annotations on method parameters, be it in pointcuts or in ITD (inter-type definition) statements.
I am sorry that I do not have any better news, but this is the status quo. If you have a chance to declare whole methods via ITD you can influence the full signature, but adding parameter annotations on existing methods is impossible today. You might also be able to also declare default constructors via ITD, if that helps. I am pretty sure there is a way to achieve what you want, just maybe not the way you imagine.

Octave plots: set box off by default, override factory defaults

I seek to override a default setting in Octave concerning plots. For instance, I always set box off; when plotting, so I would like to set the box off by default. Perhaps factoryaxesbox is the involved setting (are those factory settings documented anywhere?).
When I see a setting returned by get(0, "factory"), how can I assign a new default to override this?
I have been through this section of the Octave manual, section 15.3.5: Managing Default Properties, but it says little and I find it rather confusing. Object type, root object, child object, … Huh?
Figured it out after some amount of trial and error.
The name of available properties for plots are those returned by get(0, "factory"), without the factory prefix. In order to override any of these, you must prefix the property name with default, in the format set(0, "defaultNameOfProperty", "newsetting").
To set box off by default for all plots:
set(0, "defaultaxesbox", "off")
Before doing this, if you check for the existence of this property defaultaxesbox, using get(0, "default"), you will find nothing, making you wonder if you can set a setting which does not seem to exist. After the assignment has been made with set(), it will show up in get(0, "default").
If the first argument of set() was gca() or some other number, then replace zero with that in the above get().