playframework 2.0 - How do I add add an additional role to a user? -
i started tutorial site play-authenticate-usage. have play 2.1, deadbolt 2.1 , play authenticate 1.0
unfortunately jdbc guy , new jpa , annotations.
everything works fine, understand how use @restrict roles. don't see how programmatically assign user additional role. expected see function in user class, along line of user.addrole( string role )
i tried followingin class user didn't work (no errors, didn't update tables)...
change public list<? extends role> public list<securityrole> public void addrole( string rolename ) { securityrole grrole = securityrole.findbyrolename( application.new_role ); this.getroles().add( grrole ); this.save(); this.savemanytomanyassociations("roles"); } thanks, chet
this seems work, modifications model/auth/user...
change public list<? extends role> public list<securityrole> public void addrole( string rolename ) { securityrole newrole = securityrole.findbyrolename( rolename ); if ( newrole == null ) { newrole = new securityrole(); newrole.rolename = rolename; newrole.save(); } if ( ! this.getroles().contains( newrole ) ) { this.getroles().add( newrole ); this.save(); this.savemanytomanyassociations("roles"); } }
Comments
Post a Comment