I would like to retrieve all groups for a given member.
There is an api interface for this:
https://developers.google.com/admin-sdk/directory/v1/guides/manage-groups#get_all_member_groups
But unfortunately I can't figure out how to do that using java SDK as I was not able to find a method for this.
How can this problem be solved?
You don't need to add methods, you can use Directory.Groups.List and set the userKey parameter, something like
//... imports, initializations etc.
Directory service = new Directory.Builder(httpTransport, jsonFactory,
credential).build();
Groups userGroups = service.groups().list().setUserKey("member#domain.com")
.execute();
Add new method to class com.google.api.services.admin.directory.Directory class to query https://www.googleapis.com/admin/directory/v1/groups?userKey={userKey}. This way you can retrieve the member's groups.
Related
I need some help getting the value and unit of a result from the FHIR Observation DSTU2 resource. I want to map these values to strings but it looks like Observation.value[x] can have different type of data. Any thoughts on how to do this in C#? I tried a few ways but no luck so far because the sandbox I'm using contains results as strings, Quantity and CodeableConcept.
http://hl7.org/fhir/observation-definitions.html#Observation.value_x_
For the Observation.value field you indeed have a choice of type, so the data in the FHIR resource can hold any of the choices listed for that field.
If you use the Hl7.Fhir.Dstu2 library - the official C# reference implementation available through NuGet, you can use it to easily retrieve the resources from your sandbox and get them into a POCO. Here's an example:
using Hl7.Fhir.Model;
using Hl7.Fhir.Rest;
var client = new FhirClient("<your sandbox url>");
var obs = client.Read<Observation>("Observation/<technical id>");
// now you can access obs.Value regardless of the type in it
if you need to serialize the data to xml or json, you use the serializer:
using Hl7.Fhir.Serialization;
var serializer = new FhirJsonSerializer();
Console.WriteLine(serializer.SerializeToString(obs));
I'm trying to set up security on my entities in API Platform and found that I can call a method instead of the property example used in the docs (found this in some example somewhere on the web):
* attributes={"access_control"="is_granted('ROLE_USER') and object.belongsTo(user)"},
This is necessary in my case as I keep the user account data seperate from the user profile data and the entity in question is linked to the profile, not the user entity.
This works like charm on an individual getter (/api/data/{id}) but fails with a server 500 error on the list (/api/data):
"hydra:description": "Unable to call method \"belongsTo\" of object
\"ApiPlatform\Core\Bridge\Doctrine\Orm\Paginator\".",
Wondering what is going wrong and how to fix it.
the "belongsTo()" method is fairly simple:
public function belongsTo(User $user) {
return $user == $this->owner->user;
}
Try this way
Create custom extension
I'm trying to find all users w/ a specific permissions list in Sentry with laravel. The problem is that Sentry::findAllUsersWithAccess() returns an array().
as stated in their github repository i pinpointed their code to be
public function findAllWithAccess($permissions)
{
return array_filter($this->findAll(), function($user) use ($permissions)
{
return $user->hasAccess($permissions);
});
}
right now, it gets all users and filter it out with users with permission list. the big problem would be when I as a developer would get the set of users, it'll show ALL users, i'm developing an app which may hold thousands of users and i only need to get users with sepcific permission lists.
With regards to that would love to use one with a ->paginate() capability.
Any thoughts how to get it without getting all the users.
Why dont you override the findAllWithAccess() method and write your own implementation, which uses mysql where instead of array_filter().
I dont know your project structure and the underlying db schema, so all i can give you atm is the link to the eloquent documentation Querying Relations (whereHas).
In case you dont know where to start: its always a good idea to look at the ServiceProvider (SentryServiceProvider, where the UserProvider, which holds the findAllWidthAccess() method, is registered). Override the registerUserProvider method and return your own implementation of the UserProvider (with the edited findAllWithAccess() method).
Hope that will point you in the right direction.
In Laravel you can do pagination manually on arrays:
$paginator = Paginator::make($items, $totalItems, $perPage);
Check the docs: http://laravel.com/docs/pagination
Is it possible to search LinkedIn Profiles by name within your network using Spring Social?
I've seen the search option defined on profileOperations but there's nothing like that available on connectionOperations. I was thinking something along the line of retrieving all the connection ids and using that as a filter on a profile search.
But I couldn't find any documentation on how to use the search function and since the connectionOperations only retrieves full profiles that's a pretty expensive operation, in any case.
Any suggestions?
Yes. It is possible.
You can use the search() method in org.springframework.social.linkedin.api.ProfileOperations
LinkedInProfiles search(SearchParameters parameters)
Set the firstName and/or lastName attributes in SearchParameters object.
Sample code:
SearchParameters searchParameters = new SearchParameters();
searchParameters.setFirstName("first_name");
searchParameters.setLastName("last_name");
LinkedInProfiles profiles = linkedinApi.profileOperations().search(searchParameters);
Hope this helps. Let me know if you have any further questions.
Praveen
I have to implement access controls in my application and I am using spring ACLs for it. My model has User, groups, permissions.
The problem I am trying to solve is to get permissions on a domain object for a user. I was able to get all the access control entries for that user (principal sid, and group sids), and using that I was able to get a final set of permissions by taking a union over all the permissions. Lets say the combined mask is 111, which would be Read, Write, and Create permissions going by the permissions defined in BasePermissions.
The problem I am facing now is I cant find any way to get a list of all defined base permissions so that I can compare the mask to individual permissions. The base permission class does not seem to provide any such method. I do not want to hardcode cases in an if-then clause, since the number of permissions might increase in future.
Any pointers would be appreciated. Thanks.
You can check for the permission by using the AclPermissionEvaluator by passing an array of Permission instances to hasPermission method as a parameter. Check the source in the given link for implementation.
#Autowired
private PermissionEvaluator permissionEvaluator ;
........
Object permission = new Permission[]{permissionFactory.buildFromName("READ"),permissionFactory.buildFromName("WRITE"), permissionFactory.buildFromName("CREATE")};
permissionEvaluator.hasPermission(authentication, oid, permission);
And as mentioned in this answer do not forget to register the AclPermissionEvaluator in your spring context.
UPDATE: To get all the permission that a user has on a domain object --
private SidRetrievalStrategy sidRetrievalStrategy = new SidRetrievalStrategyImpl();
.......
List<Sid> sids = sidRetrievalStrategy.getSids(authentication);
// Lookup only ACLs for SIDs we're interested in
Acl acl = aclService.readAclById(oid, sids);
List<AccessControlEntry> aces = acl.getEntries();
List<String> permissionsList = new ArrayList<String>();
for (AccessControlEntry ace : aces ) {
permissionsList.add(ace.getPermission().getPattern());
}
As #Ravi said: use the method readAclById from the class JdbcAclService will not work if you use the BasicLookupStrategy.class. Becasuse the LookupStrategy.readAclsById (ignored the second paramter sids). I suggest you write your custom lookupstragey.
What you are trying to do is check if a CumulativePermission has a specific permission. You can do it using this method:
public static boolean containsPermission(Permission cumulativePermission, Permission singlePermission) {
return (cumulativePermission.getMask() & singlePermission.getMask()) == singlePermission.getMask();
}