Spring SAML Extension - Programmatically setting entityBaseURL - saml-2.0

I am using the Spring SAML extension with WSO2 IS as the IdP. Currently I set the entityBaseURL property for the MetadataGenerator inside the Spring XML config. For now, this works fine going against a single server since the entityBaseURL matches the servername. Since I have several environments (dev, test, and UAT) I need to programmatically set the entityBaseURL because each environment has a different server name and that servername won't match the entityBaseURL prop. It is undesirable to rebuild the WAR artifact for every environment. We keep our config for each environment in a database. So settings and properties specific to a particular stack of machines can be read at runtime. I would like to read the servername for the entityBaseURL property from our DB and set it programmatically. Should I replace the MetadataGenerator with my own class? It is unclear to me where the entityBaseURL property is initialized.

I have found a workable path to solve this. I ended up extending the MetadataGeneratorFilter class and overriding the getDefaultBaseURL method. The default implementation of the getDefaultBaseURL method is to compute the value using properties found in the HTTP request. I changed this behavior to do a DB lookup and return the value stored in the database. I could be short-sited here, but this does work. I was able to verify that the AssertionConsumerServiceURL attribute of the SAML AuthnRquest is getting set properly. The generated metadata is also correct.
Note: the entityBaseURL property can still be set manually in the Spring config. If it is then the value returned from the getDefaultBaseURL method is not used.

Related

How to retrieve custom properties of Solr cores

I'm bit new with Solr 7.0.
With Solr CoreAdmin APIs it is possible to create new cores with custom properties:
solr/admin/cores?action=CREATE&name=mycore&configSet=myconfigset&property.version=1.2.3
The command above creates a new core with a core.properties file containing the specified custom property "version" with value "1.2.3"
The defined custom properites may be used as replacement in Solr configuration files, but I could not be able to retrieve (and eventually update) a specific custom property using the Solr CoreAdmin APIs.
How is it possible to retrive or update a specific core custom property?
Thanks a lot
To create user defined property, you can use below command.
curl http://localhost:8983/solr/<core-name>/config -H'Content-type:application/json' -d '{
"set-user-property" : {"custom_property":"some_value"}}'
And, to retrieve it.
curl http://localhost:8983/solr//config/overlay?omitHeader=true
Though, these properties will be removed, once you have restarted the server. So I would suggest you to add these properties in core.properties file.
For more information :- https://lucene.apache.org/solr/guide/6_6/config-api.html#ConfigAPI-CreatingandUpdatingUser-DefinedProperties

Where to find the OSB Business service configuration details in the underlying database?

In OSB Layer when the endpoint uri is changed, I need to alert the core group that the endpoint has changed and to review it. I tried SLA Alert rules but it does not have options for it. My question is, the endpoint uri should be saved somewhere in the underlying database. If so what is the schema and the table name to query it.
URI or in fact any other part of OSB artifact is not stored in relational database but rather kept in memory in it's original XML structure. It can be only accessed thru dedicated session management API. Interfaces you will need to use are part o com.bea.wli.sb.management.configuration and com.bea.wli.sb.management.query packages. Unfortunately it is not as straightforward as it sounds, in short, to extract URI information you will need to:
Create session instance(SessionManagementMBean)
Obtain ALSBConfigurationMBean instance that operates on SessionManagementMBean
Create Query object instance(BusinessServiceQuery) an run it on ALSBConfigurationMBean to get ref object to osb artifact of your interest
Invoke getServiceDefinition on your ref object to get XML service
definition
Extract URI from XML service definition with XPath
Downside of this approach is that you are basically pooling configuration each time you want to check if anything has changed.
More information including JAVA/WLST examples can be found in Oracle Fusion Middleware Java API Reference for Oracle Service Bus
There is also a good blog post describing OSB customization with WLST ALSB/OSB customization using WLST
The information about services and all its properties can be obtained via Java API. The API documentation contains sample code, so you can get it up and running quite quickly, see the Querying resources paragraph when following the given link.
We use the API to read the service (both proxy and business) configuration and for simple management.
As long as you only read the properties you do not need to handle management sessions. Once you change the values, you need to start a session and activate it once you are done -- a very similar approach to Service bus console.

Cookies for inferHtmlResources

I want to use Gatling for testing that I can access html resources.
In order to access given HTML, and its resources, I have to have some cookies defined.
I can set Cookies in http call with simple .header("Cookie","test=test"), but that way, it doesn't set cookie to inferred resources.
According to docs, you should be able to set cookies as:
One might want to manually add or compute a cookie:
exec(addCookie(Cookie("name", "value")))
but that doesn't work for me at all when used like this:
val someScenario = scenario("scenario").exec(
exec(addCookie(Cookie("test","test"))),
exec(http("httpcall").get("someUrl")))
Is there a way to set cookies for inferHtmlResources?
Cookies are bound to a domain. If you don't specify one with withDomain, Gatling will use the one of the HttpProtocol baseUrl, and crash if you don't have one. So, a possible explanation is that this default domain doesn't match the one of your resources. If that's the case, set a proper domain on your cookie.
Otherwise, it could be a bug. Check the bug tracker, upgrade your Gatling version if you use an old one (as you don't specify the version you're using, which is bad), and give the latest snapshot a try. If nothing works, open an issue where you provide a way to reproduce.

EFCodeFirst 4.2 and Provider Manifest tokens

I have a library that I have created that depends on EF Codefirst for DB interaction. I am also using EntityMigrations Alpha 3. When I use the library in my main application (WPF) everything works fine and as expected. Another part of the system uses Excel and retrieves information using the same library via an additional COM class in between.
In the Excel scenario, as soon as it tries to connect to the database, it throws up an exception to do with "The Provider did not return a ProviderManifestToken".
I'm really not sure why I'm only getting the error when I go through Excel/COM. In both scenarios I can confirm that the same DB connection string is being used. THe method to retrieve the DB Connection string is also the same - they use a shared config file & loader class.
Any suggestions welcome.
Issue resolved.
I had also created a custom DBIntializer and part of the intialization calls upon EntityMigrations to ensure the DB is up to date. The custom migration calls the default constructor on your context. By convention this will either dynamically use it's own connection string for SQLExpress(I don't have installed) or try to look for an entry in your config file (I don't have this either for the dll - config comes from hosting apps).
This is what is causing the failure when being used from Excel(In my scenario). The Migration will be newing up an instance of the context using the default constructor. This means that a config entry for the connection string is required or it uses the default process(SQLExpress). When being used from Excel in a COM env – no config file exists.
Moving the migration out of the Initialization strategy means I no longer have a problem.

Reference a remote site setting URL in Apex class?

I have a webservice class that will be in a managed package and distributed to multiple clients. The class currently has a variable with the hardcoded value of the server it's hitting.
The problem: the server will be different for each client, so a hardcoded value will not work.
I figured since each client will have to add their server to their remote site settings, the easiest way might be to grab the correct URL from their setting. Is this possible? Or is there another "right" way to accomplish this? Thanks
The best way I've found to save configuration values is to use Apex Custom Settings. To set the Remote Site settings programmatically you could use the Metadata API.

Resources