I have a domain Guest which has a belongsTo association with Person and User domains as follows :
class Guest {
static belongsTo = [
person:Person,
user : User // owner for guest
]
}
In my service GuestService.groovy , i am trying to update associated Person info associated with a given guest :
#Transactional
def updateGuests(def guestArray) {
guestArray.each { data ->
User user = User.findById(data["userId"])
Guest guest = Guest.findByIdAndUser(data["guestId"] , user)
if( ! guest )
throw new NotFoundException("Invalid input parameters")
println(" email : " + guest.person.email + " new email " + data["email"])
Person person = guest.person
//person = Person.findById(person.id)
person.email = data["email"]
person.phoneNumber = data["phoneNumber"]
person.save(flush:true)
//guest.save(flush: true)
}
}
I am unable to update Person info and i don't receive any errors too.
I Debugged the code and all the values are present till exit of the debug point .I searched on internet and other related questions on this stack but no question is related to this kind of problem .
Have you tried person.save(flush: true, failOnError: true)?
It should overwrite a default behavior of returning null on save error and return exception instead.
Related
Looking at the documentation I am unable to find a data source which gives me
the current user (preferably the email) logged in to az when using the azurerm provider in terraform.
This information is available when I run az ad signed-in-user and I would like to use it to tag the resources created by terraform in azure.
Is this not possible right now?
You can use azurerm_client_config to get the AD object ID for the current user and then look up the returned object id with azuread_user to get the user principal name (UPN). Then, the UPN can be assigned to a tag. In the code below, outputs are not necessary but are helpful for validation because their values appear in the plan.
data "azurerm_client_config" "current" { }
data "azuread_user" "current_user" {
object_id = data.azurerm_client_config.current.object_id
}
resource "azurerm_resource_group" "example-rg" {
name = "example-rg"
location = "westus"
tags = {
userCreated = data.azuread_user.current_user.user_principal_name
}
}
output "object_id" {
value = data.azurerm_client_config.current.object_id
}
output "user_principal_name" {
value = data.azuread_user.current_user.user_principal_name
}
I am trying to make a proof of concept application that allows the user with administration permission to grant and revoke permissions of other users. While granting and revoking works with only username (unique identifier) getting the permission to display in the UI proves to be out of my reach. Is it possible to get a list of other user's permissions from within a service method?
I've tried to search the web but I couldn't find any solution that would apply to my problem. I have tried using SwitchUserAuthorityChanger, RunAsManager and aclService.readAclsById. None of those worked.
I am using Grails 3.3.2 with Spring-Security 3.2.0 and ACL 3.2.0.
Cheers folks!
I ended up solving this myself. I'll post the answer here in case some poor soul would run into a similar problem.
After digging a bit in the ACL database tables, I created a separate service in which I get AclObjectIdentity by its id, I get users sid. Using these variables I find all related variables from AclEntry. After that its just a matter of getting permissions by their mask.
Here is the method in case it might help anyone:
def getPermissions(Object domainObject, String sid) {
Map<String, String> returnValue = [
"status": "success"
]
def aclObject = AclObjectIdentity.findByObjectId(domainObject.id)
def userAclSid = AclSid.findBySid(sid)
if (null == userAclSid || null == aclObject) {
returnValue["status"] = "failed"
return returnValue
}
def aclEntries = AclEntry.findAllBySidAndAclObjectIdentity(userAclSid, aclObject)
returnValue["permissions"] = []
def tempMap = [:]
if (null == aclEntries) {
returnValue["permissions"] = "null"
return returnValue
}
def counter = 0
for (entry in aclEntries) {
int mask = entry.mask
BasePermission permission
for (BasePermission perm in PermissionEnum.toList()) {
int test = 1 << mask
if (perm.getMask() == test) {
permission = perm
break;
}
}
def permString = PermissionEnum.getPermission(permission)
tempMap["$counter"] = permString
counter++
}
returnValue["permissions"] = tempMap
return returnValue
}
1.I had read https://www.igniterealtime.org/builds/smack/docs/latest/documentation/extensions /filetransfer.html
snippet code from this guide, it not need resource part
// Create the file transfer manager
FileTransferManager manager = new FileTransferManager(connection);
// Create the outgoing file transfer
OutgoingFileTransfer transfer = manager.createOutgoingFileTransfer("romeo#montague.net");
// Send the file
transfer.sendFile(new File("shakespeare_complete_works.txt"), "You won't believe this!");
2.so I read spark source code org.jivesoftware.spark.PresenceManager find this method , so the documentation long time no to update;
/**
* Returns the fully qualified jid of a user.
*
* #param jid the users bare jid (ex. derek#jivesoftware.com)
* #return the fully qualified jid of a user (ex. derek#jivesoftware.com --> derek#jivesoftware.com/spark)
*/
public static String getFullyQualifiedJID(String jid) {
System.out.println("getFullyQualifiedJID : " + jid);
final Roster roster = SparkManager.getConnection().getRoster();
Presence presence = roster.getPresence(jid);
System.out.println("getFullyQualifiedJID : " + presence.getFrom());
return presence.getFrom();
}
I find this method not work for asmack , so google it found this
Smack's FileTransferManager.createOutgoingFileTransfer only accepts full JIDs. How can I determine the full JID of a user in Smack?
//snippet code from my project
Roster roster = connection.getRoster();
List presenceList = roster.getPresences(jid);
Log.d(TAG, "bareJid : " + jid);
for (Presence presence : presenceList) {
Log.d(TAG, "fullJID : " + presence.getFrom());
}
why the code can not get the fullJID.
the output:
12-23 06:55:35.840: D/MChat(1805): bareJid : test#tigereye-pc
12-23 06:55:35.840: D/MChat(1805): fullJID : test#tigereye-pc
4.the result is the same, so how can I get the fullJID
Thanks & Regards
You have to supply Full user id as : user#serveripaddress/Smack
For Example :
xyz#192.168.1.1/Smack
The need the full JID and the client resource.
You can do something like that:
String fullJID = xmppConnection.getRoster().getPresence(JID).getFrom();
My JID variable is the full JID without the resource.
I am using grails,and i have web application.in which when call for update user profile,then i have service for it,in which i set current user properties by request parameters
user.properties = params (params-request parameters),
and in my user domain class i have onChange method(of audit plugins).
So when this method called after setting properties to user profile when control goes to user domain onChange method it gives error
org.hibernate.StaleObjectStateException: Row was updated or deleted by another transaction (or unsaved-value mapping was incorrect): [com.web.User#3].
I am still finding solution how to update row.
Thanks in advance.
//userController update method -
def user = User.get(params.id)
user.properties = params
user.save(flush:true)
//and in user domain onChange method-
def onChange = { oldMap,newMap ->
try{
Msg.append("Your profile has been updated successfully with the following changes: ");
oldMap.each({ key, oldVal ->
if(oldVal != newMap[key]) {
if(key =="firstName" || key =="gender" || key =="lastName" || key =="phoneNo" || key =="city"){
Msg.append(" * $key changed from $oldVal to " + newMap[key])
}
}
sendMail(Msg,newMap.email)
})
}
}
After sending email it gives an error.
I think if you try to set all the fields on the user object, then it will work:
def user = User.get(params.id)
user.refresh()
user.firstName= params.firstName
user.lastName= params.lastName
user.gender= params.gender
user.phno= params.phno
user.city= params.city
if(user.save(flush:true, failOnError:true)){
// Now send success email
}
Now it should work.
I think your params map is having id as a property and on setting
user.properties = params
It tries to set id for the user object, that's why you are getting the issue.
I am working in grails application, I was been asked to create a test user for our site. I did write the code in admin controller and gave the link in his page. The code worked and also I can see the details of this test user. But when I try to login using test user details, I am not able to login.
def createTestUser = {
String timeStr = System.currentTimeMillis() + ''
//def user = userService.createQuickUser(timeStr + '#test.supjam.com', timeStr, 'test-user') // TODO requires supajam-domain 2011.12.5.1
def user = userService.createQuickUser(timeStr + '#test.supajam.com', 'test-user')
user.passwd = timeStr
user.dailyNews = false
user.offers = false
user.emailConfirmed = true
user.enabled = true
user.save(failOnError: true)
}
This was the code. If anybody can please help, I would be thankful to them.
This similar question has some debugging tips:
Grails spring security login issue: /auth?login_error=1
i liked putting log.debug() statements in the authfail() if blocks.
if (exception instanceof AccountExpiredException) {
msg = SpringSecurityUtils.securityConfig.errors.login.expired
log.debug "exception - ${msg}" // added this
}