I want to create an entity (called StudentInfo) that has a one-to-one relationship to the User entity (generated my jhipster). How can I do this using JDL-studio ? Do I just declare a relationship to the User like so :
relationship OneToOne {
StudentInfo{user} to User
}
Will jhipster recognize the "User" in my jdl schema as the User used for authentication or will there be a conflict ?
Here's how I've done it in one of my JDL's for a blog app.
relationship ManyToOne {
Blog{user(login)} to User
Post{blog(name)} to Blog
}
relationship ManyToMany {
Post{tag(name)} to Tag{entry}
}
In your case, I think you'll need to do:
relationship OneToOne {
StudentInfo{user(login)} to User
}
login is the field that will show up in the dropdown. Yes, it will recognize the "User" in your JDL schema. Note that this only works with monoliths and microservices with OAuth. It's not supported if you use microservices with JWT or UAA.
The following code worked for me with jhipster 7.0 beta, monoliths and JWT:
relationship OneToOne {
StudentInfo{user(login)} to User }
Related
I'm using Spring Data REST to expose my Entity's and their relationships. I have a OneToOne relationship between two Entity's and I'm trying to update/change the relationship with PUT and PATCH.
I noticed that Spring Data REST will only allow you to update linked resources - JPA mapped Entity's (OneToMany, ManyToOne, etc) which are also AggregateRoots (has a Repository) - via a PATCH and are ignored with a PUT.
This can be seen in the LinkedAssociationSkippingAssociationHandler class:
if (associationLinks.isLinkableAssociation(association)) {
return;
}
Why is this? What is the reasoning behind this?
Is it because the design wants us to treat the associations as resources themselves as seen in this part of the documentation? I can alter the relationship via a PUT with Content-Type text/uri-list but it feels unnatural and require an additional HTTP request.
From the Spring data REST 2.5.9.RELEASE the associations are not update on PUT request and only update using PATCH.
Changes in version 2.5.9.RELEASE (2017-04-19)
DATAREST-1030 - PATCH requests do not handle links to associations properly.
Other links about this:
DATAREST-1061: PUT-request with application/json media type payload cannot update association #OneToOne by URI
Domain Driven Design and Spring
I have an application that uses a LDAP server to authenticate. It works fine. But, there is a problem: in this LDAP server, I don't have the user roles. I have them in another server, in a database my application access. And I need to add the user roles to the application from now on.
I'd like to know how to get those roles and add them to the AuthenticationManagerBuilder auth at configureGlobal method. Is it possible?
Some information:
My configureGlobal method is:
#Autowired
public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
auth.ldapAuthentication().userSearchFilter("uid={0}").contextSource().url(host);
}
I'm using hibernate 4.3.8 and Spring Security 4.1.1.
The table with the roles was created like this:
create table UserGroup (
user varchar2(250),
role varchar2(250)
);
And the records are something like this:
[user1, role1]
[user1, role2]
[user1, role3]
[user1, role4]
[user2, role1]
[user2, role2]
As you can see, the same user can have more than one role. The same role can be assigned to many users. I know it needs normalization, but I think that's not important at this point.
What I have done in the past is implement a UserDetailsService that populates the user name and roles from the application's database & AbstractUserDetailsAuthenticationProvider that does an LDAP bind check inside additionalAuthenticationChecks.
Works like a charm.
In fact, the UserDetails contains a flag that tells me where to validate the user and inside the additionalAuthenticationChecks, we validated the user against one of multiple validation sources, such as the local database, or various multi-tenant LDAP servers.
I need to develop a custom RoleProvider for a MultiTenant web app.
At the DB level, we have a table that relates Users with Roles with Tenants.
My problem is that RoleProvider gets user roles just passing the User as parameter, and we need to take the Tenant into account.
In RoleProvider implementation we have:
public override string[] GetRolesForUser(string username)
{
//Code to retrieve roles from repo
}
As the roles are for a user in an specific Tenant, we need:
public override string[] GetRolesForUser(string username, int tenantId)
{
//Code to retrieve roles from repo
}
The current tenant is stored in the ControllerBase class (the one that all controllers inhereted from).
The Membership and Role Providers are in a separate project, so I don't see a way to use the current Tenant. I think I could create my custom RoleProvider in the web app project.
Any idea on how to implement the RoleProvider interface taking the Tenant as part of the input ?
Well, just to inform you what I did in my case:
As our routes are in the form of http://[tenantName].[domain]/[App]/[Area] we ended up getting the [tenantName] from the Request, since it is unique, and with the Tenant and the UserName that came as a parameter I can do my select on our UsersInTenants' table.
The very same can be done using cookies as a way to pass aditional information.
So you can access the request, with the cookies, but for what I research the Session is not yet initialized in most cases.
Hope it helps!
How to make relationship between two domain classes in grails . I already have one domain class from the plugin (spring security plugin) and i want to link USER domain class from plugin to the Profile domain class . What is the best way to do it?
See the GORM documentation for a good overview. For a one-to-one relationship as I assume a profile would be, you could simply do the following:
class User {
Profile profile
}
class Profile {
// only needed if you need to refer to user from the Profile instance
static belongsTo = [user:User]
}
Dear All,
I am using the membership provider of MVC framework, Now i want to implement the Role and Right on My project, All the Role and Right is available on database so how can i implement the Role and Right? is there is any built in function which can i use? also i am using the Ado .net Data Entity Framework..
If I'm understanding what you want to do correctly, you have to annotate your Controller class or ActionResult with the Authorize attribute like this:
[Authorize(Roles="Domain Admins", Users="testuser")]
public class TestController : Controller {
}
Then as long as your membership provider is setup you should be good to go.
It may be worth mentioning that you can always check if a user is in a role with the following code.
User.IsInRole("Domain Admins");
If your using MVC2 then the default project template makes it easy. You should check out the AccountController and AccountModels in a default MVC2 template.
It sounds like you need a custom role provider:
http://davidhayden.com/blog/dave/archive/2007/10/17/CreateCustomRoleProviderASPNETRolePermissionsSecurity.aspx
http://msdn.microsoft.com/en-us/library/8fw7xh74.aspx
http://www.codeproject.com/KB/aspnet/WSSecurityProvider.aspx