As I found when asking this post to have #ManyToOne association work I need to add
backward #OneToMany entity.
But after that I found that I cannot now find these entities specifying it's own id.
I need to specify also parent's id.
Here's how my id looks like:
User(1)/Issue(2)
So, I need to find in such way:
entityManager.find(Issue.class, KeyFactory.createKey(KeyFactory.createKey("User",1),"Issue",2))
And I wonder, what will be if I have several ManyToOne fields.
Please, follow me to the exact instructions on how to deal with #ManyToOne fields in GAE.
Related
I have a question regarding an application that I am developing, I try to implement a Kanban solution.
I have separated the IdentityServer (Users, Roles, etc), from the module/app that I am implementing. (Tiered)
I would like to know how I should do to have user data in the module/app.
I mean, it should have the "duplicate" users table or from the module/app can refer to the context of the identityServer database...
I am a bit lost...
For trying to give an example.
IdentityDbContext { Users, Roles, etc }
ApplicationDbContext { Board, Columns, Tags, Cards, CardUser, ¿User? }
In CardUser I would like to have the users related to Card (an N-M relationship).
But I don't know if I should create an entity/DbSet in the ApplicationDbContext or just save the UserId and then for each UserId query data to db or do call to api to the IdentityServer.
I think it's hard for me to explain myself, I'm sorry if it doesn't make sense, I appreciate any kind of help/comment.
Thank you very much.
As per best practices, aggregate root can be referenced by its id, but it is recommended not to reference it with the navigation property.
We have implemented a similar case for EventHub. You can see how we implemented it from the links below.
https://github.com/abpframework/eventhub/blob/e19c32731655df8c78d082a84cb336263c5f081a/src/EventHub.Domain/Events/Speaker.cs#L10
https://github.com/abpframework/eventhub/blob/e19c32731655df8c78d082a84cb336263c5f081a/src/EventHub.Application/Events/EventAppService.cs#L366
You can try to create an Event to better understand the requirements of EventHub.
https://www.openeventhub.com/
I need to declare 2 IDPs in spring-security-saml having the same entity id.
My webapp uses spring-security-saml.
This webapp is accessible by 2 differents URLs behind a reverse proxy.
The first URL is public, the second URL is filtered.
So, I declared 2 SP (one for each URL).
Everything was working properly with a single IDP (ADFS or Gsuite).
I also run the application properly with 2 SPs and 2 IDPs with an affinity SP1/IDP1 and SP2/IDP2 when IDP1 and IDP2 had a different entity ID.
Unfortunately by wanting to use Azure Active Directory, each SAML application in Azure results in its own IDP metadata with its own certificate, but with the same entity id.
So I need to declare 2 IDPs in spring-security-saml having the same entity id.
Reading the code shows that it is not intended to work like this (the entity id is used as key).
Do you have an idea to work around this problem?
Should Azure provide a unique entity id ?
I know it is too old but just found it but you can not use the same Entity ID per tenant for 2 different apps, so it makes sense that the apps have a different certificate even if they have same Entity ID because both apps are in different tenants
How it worked for me!!
As Spring saml works only for unique IDP entityIds. So to make it unique for 2 different IDP having same entity Ids, I prexied one of it with alias as i know what is that alias is for.
So now I have to hack entityID at certain places of initialization, validation during metadata loading AND in SAML response verification.
For metadata(one that has prefixed entity Id) loading to be successful especially one with signed metadata..
Created new child class MySAMLSignatureProfileValidator that overrides
SAMLSignatureProfileValidator.validateReferenceURI.
To use this I need to create another custom class SamlSignatureValidationFilter that extends MYSamlSignatureValidationFilter and initialise MySAMLSignatureProfileValidator in their constructor.
Use this SamlSignatureValidationFilter when we add metadata to metadata manager like this..
metadataProvider.setMetadataFilter(new MYSamlSignatureValidationFilter(metadata.getTrustEngine(metadataProvider)));
And now add another custom class MYSAMLCachingMetadataManager to override initializeProviderFilters and remove the logic to setMetadataFilter as its already set as in above code.
Use MYSAMLCachingMetadataManager in your config for MetadataManager.
This should take care of saml metadata loading.
Then coming to SAML Response that has the issuer as the original entityId, we need to add prefixed alias to the context here so that it verifies with our prefixed_entityId stored in metadatamanager entity list.
In this case I added MySamlHttpPostDecoder that overrides HttpPostDecoder.extractResponseInfo to add alias to messageIssuer.
And, MySamlWebSSOProfileConsumerImpl to overirde WebSSOProfileConsumerImpl.verifyIssuer to set issuer.getValue with alias. so later verification with stored entitId will match.
Use this MySamlWebSSOProfileConsumerImpl and MySamlHttpPostDecoder in your config. To use MySamlHttpPostDecoder I need to add new class MySamlHTTPPostBinding(ParserPool parserPool, VelocityEngine velocityEngine, MessageDecoder decoder) that extends HTTPPostBinding and pass MySamlHttpPostDecoder for decoder.
Hope it works for you too!!!
In a Google App Engine app, I have this model:
#PersistenceCapable(identityType = IdentityType.APPLICATION)
public class Message {
#PrimaryKey
#Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
private Long id;
#Persistent
private Date timestamp;
#Persistent
private String text;
#Unowned
#Persistent(defaultFetchGroup = "true")
private User sender;
...
}
The model has an #Unowned relation to a sender, since a user can exist independently of a message.
What I want to do is persist Message objects with partial User objects (e.g. I'm only interested in storing the user id and username). In my endpoint class I'm storing messages just fine, however, if I don't include all fields for the given user in the relationship, the user object is updated with the fields missing (e.g. user in question no longer has a password etc.). What is the best way of achieving what I want, without 'corrupting' the original object?
PS
My endpoints method is dead simple. Basically just calling pm.makePersistent(message); on the message (given as a method parameter).
You are using the #Unowned annotation which means that only a reference to the actual User entity will be stored in the sender variable under your Message class.
When you access the sender variable, the Datastore will execute a get query to retrieve the User entity that is linked to the message.
You can confirm this for yourself by navigating to your project's Datastore dashboard (https://console.cloud.google.com/datastore for production, and http://localhost:8080/_ah/admin for local) and browsing the Message entities.
You should see the field where the User is stored named something like user_id_OID with a value of Key(User/XXXXX).
As a side note, Google recommends moving away from JDO/JPA to Objectify or the Datastore API.
Warning: We think most developers will have a better experience using
the low-level Datastore API, or one of the open-source APIs developed
specifically for Datastore, such as Objectify. JDO was designed for
use with traditional relational databases, and so has no way to
explicitly represent some of the aspects of Datastore that make it
different from relational databases, such as entity groups and
ancestor queries. This can lead to subtle issues that are difficult to
understand and fix.
See here:
https://cloud.google.com/appengine/docs/java/datastore/jdo/overview-dn2
I'm using
#GeneratedValue(strategy = GenerationType.IDENTITY)
in my JPA Entities to let Google AppEngine generate id's for my entities.
Now I wonder if the generated a unique per entity or for my app's complete datastore.
The reason I'm asking is I want to use the entity's id as identifier for search documents.
As per docs: IDs are allocated within a namespace defined by a parent key and a kind
I am using Google App Engine with Google's JDO implementation to save an entity for which I wish to provide an URL that a user can navigate to to view information about that entity. The problem I have is that the key generating strategy IdGeneratorStrategy.IDENTITY produces very long keys while the INCREMENT and SEQUENCE strategies are not implemented. I was planning to use the key as part of the URL to link to the entity, however since the only option I have to create a system generated key would result in an unwieldy URL I'm looking for suggestions how how to create a manageable URL to link directly to an entity in my datastore.
Is there any other option other than to create and maintain my own id generator?
Don't use the whole key - just the ID field. You can construct a key from the model name and the ID.