How to set PasswordProtectedTransport and transient in spring-security-saml2-service-provider? - single-sign-on

In the org.springframework.security.extensions versions of spring-security-saml2-core, we set the nameid-format:transient and classes:PasswordProtectedTransport in our service provider code like so:
WebSSOProfileOptions webSSOProfileOptions = new WebSSOProfileOptions();
webSSOProfileOptions.setIncludeScoping ( false );
webSSOProfileOptions.setNameID ( "urn:oasis:names:tc:SAML:2.0:nameid-format:transient" );
List<String> ac = new ArrayList<String>();
ac.add ( "urn:oasis:names:tc:SAML:2.0:ac:classes:PasswordProtectedTransport" );
webSSOProfileOptions.setAuthnContexts ( ac );
However, in the newer non-extension org.springframework.security implementations of spring-security-saml2-service-provider, there is no longer an WebSSOProfileOptions object.
How do we set nameid-format:transient and classes:PasswordProtectedTransport in the newer versions of Spring SAML? For now, we would like to maintain Java 8 compatibility, so we're interested in Spring security versions 5.6.x and 5.7.x.
I tried Googling, looking at XML metadata samples, browsing Spring classes, reading some Spring documentation, and not much reading newer Spring source code to try to understand where the settings should be specified.

Related

How to Register Interests using 'ALL_KEYS' in Spring Data GemFire with ClientRegionFactoryBean

I am going to register interests in ALL_KEYS for my Pivotal GemFire client via Spring Data GemFire, but I find that ClientRegionFactoryBean has one method.
org.springframework.data.gemfire.client.ClientRegionFactoryBean.setInterests(Interest<MyRegionPojo>[] interests)
In this case, I only can set the exact keys, but I want to register interests for all keys. My key is not a simple class like String, or Long, but a complex object MyRegionPojo.
Please help if any method to implement so like GemFire API region.registerInterest("ALL_KEYS");
You problem statement is a bit vague but I assume/suspect you are configuring your Spring (Data GemFire) (SDG) application using Spring JavaConfig?
However, I will quickly add that this is not unlike how you would register interests in all keys using SDG's XML namespace, as shown here.
The JavaConfig approach is similar, but clearly based on "strongly-typed arguments", namely 1 or more sub-type instances of the o.s.d.g.client.Interest class to the o.s.d.g.client.ClientRegionFactoryBean.setInterests(:Interest<K>[]) method.
By way of example, you might do the following...
#Bean("Example")
public ClientRegionFactoryBean<?, ?> exampleRegion(GemFireCache gemfireCache) {
ClientRegionFactoryBean<MyRegionKey, MyRegionValue> exampleRegion =
new ClientRegionFactoryBean<>();
RegexInterest regexInterest = new RegexInterest();
regexInterest.setKey(".*");
exampleRegion.setCache(gemfireCache);
exampleRegion.setShortcut(ClientRegionShortcut.PROXY);
exampleRegion.setInterests(new Interest[] { regexInterest });
exampleRegion.setKeyConstraint(MyRegionKey.class);
exampleRegion.setValueConstraint(MyRegionValue.class);
return exampleRegion;
}
NOTE: updated the example above to reflect the proper way to register (Regex) interests based on SDG 1.9 or earlier. Keep in mind that the `o.s.d.g.client.RegexInterest.getRegex() delegates to getKey() therefore you can set the Regular Expression using setKey(:String) as I have shown above.
Notice the o.s.d.g.client.RegexInterest sub-type registration, which is effectively the same as register interests in "ALL_KEYS", as described here as well.
Hope this helps!
-John

Copy a folder with Smartsheet API - Java SDK 2.0.5

I am trying to copy a folder with the Smartsheet API 2.0 (Java SDK 2.0.5).
Unfortunately the folders and sheets (all sub folders/sheets too) are copied but the sheet data is missing.
I get no errors everything works fine.
I tried several variants of the optional include parameters the ".ALL", "null", ...
This is the example code and the used environment:
Netbeans IDE 8.2
smartsheet-sdk-java-2.0.5.jar (with maven)
// Optional params
EnumSet includes = EnumSet.complementOf(EnumSet.of(FolderCopyInclusion.ALL)); // Copy all fields!
EnumSet skipRemap = EnumSet.noneOf(FolderRemapExclusion.class); // Remap all fields
// Specify destination.
ContainerDestination destination = new ContainerDestination.AddContainerDestinationBuilder()
.setDestinationType(DestinationType.FOLDER)
.setDestinationId(targetFolder.getId())
.setNewName(folder.getName())
.build();
smartsheet.folderResources().copyFolder(folder.getId(), destination, includes, skipRemap);
What am i doing wrong? Thanks a lot for your help.
Perhaps try changing this line:
EnumSet includes = EnumSet.complementOf(EnumSet.of(FolderCopyInclusion.ALL)); // Copy all fields!
To this instead:
EnumSet includes = EnumSet.of(FolderCopyInclusion.ALL);
(I'm not a Java expert, but the change I've suggested is consistent with the code example in the Smartsheet API Documentation.)

Data driven unit test breaking entity framework connection

I have an application that uses entity framework. I am writing a unit test in which I would like to use data driven testing from a CSV file.
However, when I run the test, I get an error that the sqlserver provider cannot be loaded:
Initialization method UnitTest.CalculationTest.MyTestInitialize threw
exception. System.InvalidOperationException:
System.InvalidOperationException: The Entity Framework provider type
'System.Data.Entity.SqlServer.SqlProviderServices,
EntityFramework.SqlServer' registered in the application config file
for the ADO.NET provider with invariant name 'System.Data.SqlClient'
could not be loaded. Make sure that the assembly-qualified name is
used and that the assembly is available to the running application.
If I remove the data driven aspects and just test a single value, then the test works.
If I just use the data driven aspects and remove the Entity Framework stuff, then the test works.
So, its only when I try to use data driven test with entity framework active at the same time do I get the error. So, where am I going wrong here?
Here's my test method:
[TestMethod, TestCategory("Calculations")
, DataSource("Microsoft.VisualStudio.TestTools.DataSource.CSV"
, "ConvertedMeanProfileDepth.csv", "ConvertedMeanProfileDepth#csv"
, Microsoft.VisualStudio.TestTools.UnitTesting.DataAccessMethod.Sequential)
, DeploymentItem("ConvertedMeanProfileDepth.csv")]
public void ConvertedMeanProfileDepthTest()
{
ConvertedMeanProfileDepth target = new ConvertedMeanProfileDepth();
Decimal mpd = decimal.Parse(this.TestContext.DataRow["mpd"].ToString());
Decimal expected = decimal.Parse(this.TestContext.DataRow["converted"].ToString());
Decimal actual;
actual = target.Calculate(mpd);
Assert.AreEqual(expected, actual);
}
So I managed to work it out in the end. For future reference, here's the solution:
Rob Lang's post, Entity Framework upgrade to 6 configuration and nuget magic, reminded me of the issue here:
When a type cannot be loaded for a DLL that is referenced in a
project, it usually means that it has not been copied to the output
bin/ directory. When you're not using a type from a referenced
library, it will not be copied.
And this will raise its ugly head the moment you use deployment items in your tests. If you use a deployment item in your test, then all of the required binaries are copied to the deployment directory. Problem is, if you are using dynamically loaded items, then the test suite does not know it has to copy those items.
With Entity Framework, this means that your providers will not be copied to the deployment location and you will receive the error as per my question.
To resolve the issue, simply ensure that your entity framework provider is also marked as a deployment item.
So, note the inclusion of DeploymentItem(#"EntityFramework.SqlServer.dll") in my test attributes. All works perfectly from here:
[TestMethod, TestCategory("Calculations")
, DataSource("Microsoft.VisualStudio.TestTools.DataSource.CSV"
, "ConvertedMeanProfileDepth.csv", "ConvertedMeanProfileDepth#csv"
, Microsoft.VisualStudio.TestTools.UnitTesting.DataAccessMethod.Sequential)
, DeploymentItem("ConvertedMeanProfileDepth.csv")
, DeploymentItem(#"EntityFramework.SqlServer.dll")]
public void ConvertedMeanProfileDepthTest()
{
ConvertedMeanProfileDepth target = new ConvertedMeanProfileDepth();
Decimal mpd = decimal.Parse(this.TestContext.DataRow["mpd"].ToString());
Decimal expected = decimal.Parse(this.TestContext.DataRow["converted"].ToString());
Decimal actual;
actual = target.Calculate(mpd);
Assert.AreEqual(expected, actual);
}

EclipseLink cache refreshOnlyIfNewer not working

I'm trying to use cache with EclipseLink.
I've enabled shared-cache-mode = ENABLE_SELECTIVE in my persistence.xml so when I use #Cacheable(true) the entity gets cached. Now I want make it work when the version is outdated the the enity gets refreshed.
I've setup a optimistic locking field
#Version
#Column(name="optLock")
private int versionNum ;
this is working when as when I try to save an entity that has a older version number then the database I'll get an exception.
So when I add the annotation to enable caching and refresh
#Cacheable(true)
#Cache(size = 500, alwaysRefresh = true, refreshOnlyIfNewer = true)
the entity won't be cached. I've enabled the eclipselink.profiler and I can see that no cache is made for this entity and lacking the Counter:CacheHits and Counter:CacheMisses log.
When I remove
#Cache(size = 500, alwaysRefresh = true, refreshOnlyIfNewer = true)
the entity is cached again but any changes done directly in the database(and increment the optLock field) won't come through.
What I forgetting her? or what should I take into account to get this working? The documentation I've been reading seems like this should be working.
#Cache overrides #Cacheable, so because you did not enable caching in #Cache it gets the persistence unit default of not caching.
Add,
#Cache(isolation=SHARED, ...)
to your annotation.
Please also log a bug, EclipseLink should be smart enough to see the #Cacheable and use it as the default because there was no isolation setting in the #Cache, or at least report a warning.

Problem with DSL and Business Rules creation in Drools

I am using Eclipse with the Drools plugin to create rules.
I want to create business rules and main aim is to try and provide the user a set of options which he can use to create rules.
For eg:If an Apple can have only 3 colors: I want to provide an option like a drop down so that the user can know before hand which are the options he can use in his rules.
Is it possible?
I am creating a dsl but unable to still provide the above functionality for a business rule.
I am having an error implementing a basic dsl also.
The code to add the dsl is as follows in my RuleRunner class()
InputStream ruleSource = RuleRunner.class.getClassLoader().getResourceAsStream("/Rule1.dslr");
InputStream dslSource = RuleRunner.class.getClassLoader().getResourceAsStream("/sample-dsl.dsl");
//Load the rules , using DSL
addRulesToThisPackage.addPackageFromDrl(
new InputStreamReader(ruleSource),new InputStreamReader(dslSource));
I have both the sample-dsl .dsl and Rule1.dslr in my working directory.
Error encountered at adding the dsl to the package (last line)
Error stack:
Exception in thread "main" java.lang.NullPointerException
at java.io.Reader.<init>(Unknown Source)
at java.io.InputStreamReader.<init>(Unknown Source)
at com.org.RuleRunner.loadRuleFile(RuleRunner.java:96)
at com.org.RuleRunner.loadRules(RuleRunner.java:48)
at com.org.RuleRunner.runStatelessRules(RuleRunner.java:109)
at com.org.RulesTest.main(RulesTest.java:41)
my dsl file has basic mapping as per the online documentations.
The dsl rule I created is:
expander sample-dsl.dsl
rule "A status changes B status"
when
There is an A
- has an address
There is a B
- has name
then
- print updated A and Aaddress
End
I have created DSL in eclipse.
Is the code I added for it to be loaded to my package correct?? Or am I missing something????
It seems like my program is unable to find the dsl?
Please help. Can you point me towards the right direction to create a user friendly business rule ??
Thanks.
J
I am not quite familiar with the method you are trying to use to create a knowledge session, but I will show a example of what's used in my applications.
KnowledgeBase kBase = KnowledgeBaseFactory.newKnowledgeBase(<KnowledgeBaseConfiguration>);
KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
kbuilder.add( ResourceFactory.newClassPathResource( "rules/myRuleFile.drl", getClass() ),
ResourceType.DRL );
kbuilder.add( ResourceFactory.newClassPathResource( "rules/myDslFile.dsl", getClass() ),
ResourceType.DSL );
if ( kbuilder.hasErrors() ) {
System.err.println( builder.getErrors().toString() );
}
kbase.addKnowledgePackages( kbuilder.getKnowledgePackages() );
Now as far as giving your users the ability to author rule files, with built in constraints, have you looked at Drools Guvnor?(http://downloads.jboss.com/drools/docs/5.0.1.26597.FINAL/drools-guvnor/html_single/index.html) I have not incorporated it into my project yet, but have researched it a bit. I think it may provide the functionality your seeking for allowing your users to create and edit rule files. Good luck!