Search in sources :

Example 26 with Group

use of com.google.monitoring.v3.Group in project google-cloud-java by GoogleCloudPlatform.

the class GroupServiceClientTest method listGroupMembersTest.

@Test
@SuppressWarnings("all")
public void listGroupMembersTest() {
    String nextPageToken = "";
    int totalSize = -705419236;
    MonitoredResource membersElement = MonitoredResource.newBuilder().build();
    List<MonitoredResource> members = Arrays.asList(membersElement);
    ListGroupMembersResponse expectedResponse = ListGroupMembersResponse.newBuilder().setNextPageToken(nextPageToken).setTotalSize(totalSize).addAllMembers(members).build();
    mockGroupService.addResponse(expectedResponse);
    GroupName name = GroupName.create("[PROJECT]", "[GROUP]");
    ListGroupMembersPagedResponse pagedListResponse = client.listGroupMembers(name);
    List<MonitoredResource> resources = Lists.newArrayList(pagedListResponse.iterateAll());
    Assert.assertEquals(1, resources.size());
    Assert.assertEquals(expectedResponse.getMembersList().get(0), resources.get(0));
    List<GeneratedMessageV3> actualRequests = mockGroupService.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    ListGroupMembersRequest actualRequest = (ListGroupMembersRequest) actualRequests.get(0);
    Assert.assertEquals(name, actualRequest.getNameAsGroupName());
}
Also used : GroupName(com.google.monitoring.v3.GroupName) ListGroupMembersResponse(com.google.monitoring.v3.ListGroupMembersResponse) ListGroupMembersRequest(com.google.monitoring.v3.ListGroupMembersRequest) MonitoredResource(com.google.api.MonitoredResource) ListGroupMembersPagedResponse(com.google.cloud.monitoring.spi.v3.PagedResponseWrappers.ListGroupMembersPagedResponse) GeneratedMessageV3(com.google.protobuf.GeneratedMessageV3) Test(org.junit.Test)

Example 27 with Group

use of com.google.monitoring.v3.Group in project google-cloud-java by GoogleCloudPlatform.

the class GroupServiceClientTest method deleteGroupTest.

@Test
@SuppressWarnings("all")
public void deleteGroupTest() {
    Empty expectedResponse = Empty.newBuilder().build();
    mockGroupService.addResponse(expectedResponse);
    GroupName name = GroupName.create("[PROJECT]", "[GROUP]");
    client.deleteGroup(name);
    List<GeneratedMessageV3> actualRequests = mockGroupService.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    DeleteGroupRequest actualRequest = (DeleteGroupRequest) actualRequests.get(0);
    Assert.assertEquals(name, actualRequest.getNameAsGroupName());
}
Also used : GroupName(com.google.monitoring.v3.GroupName) Empty(com.google.protobuf.Empty) GeneratedMessageV3(com.google.protobuf.GeneratedMessageV3) DeleteGroupRequest(com.google.monitoring.v3.DeleteGroupRequest) Test(org.junit.Test)

Example 28 with Group

use of com.google.monitoring.v3.Group in project oxTrust by GluuFederation.

the class Scim2GroupService method updateGroup.

public Group updateGroup(String id, Group group) throws Exception {
    GluuGroup gluuGroup = groupService.getGroupByInum(id);
    if (gluuGroup == null) {
        throw new EntryPersistenceException("Scim2GroupService.updateGroup(): " + "Resource " + id + " not found");
    } else {
        // Validate if attempting to update displayName of a different id
        if (gluuGroup.getDisplayName() != null) {
            GluuGroup groupToFind = new GluuGroup();
            groupToFind.setDisplayName(group.getDisplayName());
            List<GluuGroup> foundGroups = groupService.findGroups(groupToFind, 2);
            if (foundGroups != null && foundGroups.size() > 0) {
                for (GluuGroup foundGroup : foundGroups) {
                    if (foundGroup != null && !foundGroup.getInum().equalsIgnoreCase(gluuGroup.getInum())) {
                        throw new DuplicateEntryException("Cannot update displayName of a different id: " + group.getDisplayName());
                    }
                }
            }
        }
    }
    GluuGroup updatedGluuGroup = copyUtils2.copy(group, gluuGroup, true);
    if (group.getMembers().size() > 0) {
        serviceUtil.personMembersAdder(updatedGluuGroup, groupService.getDnForGroup(id));
    }
    log.info(" Setting meta: update group ");
    // Date should be in UTC format
    DateTimeFormatter dateTimeFormatter = ISODateTimeFormat.dateTime().withZoneUTC();
    Date dateLastModified = DateTime.now().toDate();
    updatedGluuGroup.setAttribute("oxTrustMetaLastModified", dateTimeFormatter.print(dateLastModified.getTime()));
    if (updatedGluuGroup.getAttribute("oxTrustMetaLocation") == null || (updatedGluuGroup.getAttribute("oxTrustMetaLocation") != null && updatedGluuGroup.getAttribute("oxTrustMetaLocation").isEmpty())) {
        String relativeLocation = "/scim/v2/Groups/" + id;
        updatedGluuGroup.setAttribute("oxTrustMetaLocation", relativeLocation);
    }
    // For custom script: update group
    if (externalScimService.isEnabled()) {
        externalScimService.executeScimUpdateGroupMethods(updatedGluuGroup);
    }
    groupService.updateGroup(updatedGluuGroup);
    log.debug(" group updated ");
    Group updatedGroup = copyUtils2.copy(updatedGluuGroup, null);
    return updatedGroup;
}
Also used : Group(org.gluu.oxtrust.model.scim2.Group) GluuGroup(org.gluu.oxtrust.model.GluuGroup) EntryPersistenceException(org.gluu.site.ldap.persistence.exception.EntryPersistenceException) DuplicateEntryException(org.gluu.site.ldap.exception.DuplicateEntryException) GluuGroup(org.gluu.oxtrust.model.GluuGroup) DateTimeFormatter(org.joda.time.format.DateTimeFormatter) Date(java.util.Date)

Example 29 with Group

use of com.google.monitoring.v3.Group in project oxTrust by GluuFederation.

the class Scim2GroupService method createGroup.

public Group createGroup(Group group) throws Exception {
    log.debug(" copying gluuGroup ");
    GluuGroup gluuGroup = copyUtils2.copy(group, null, false);
    if (gluuGroup == null) {
        throw new Exception("Scim2GroupService.createGroup(): Failed to create group; GluuGroup is null");
    }
    log.debug(" generating inum ");
    String inum = groupService.generateInumForNewGroup();
    log.debug(" getting DN ");
    String dn = groupService.getDnForGroup(inum);
    log.debug(" getting iname ");
    String iname = groupService.generateInameForNewGroup(group.getDisplayName().replaceAll(" ", ""));
    log.debug(" setting dn ");
    gluuGroup.setDn(dn);
    log.debug(" setting inum ");
    gluuGroup.setInum(inum);
    log.debug(" setting iname ");
    gluuGroup.setIname(iname);
    log.info("group.getMembers().size() : " + group.getMembers().size());
    if (group.getMembers().size() > 0) {
        serviceUtil.personMembersAdder(gluuGroup, dn);
    }
    // As per spec, the SP must be the one to assign the meta attributes
    log.info(" Setting meta: create group ");
    // Date should be in UTC format
    DateTimeFormatter dateTimeFormatter = ISODateTimeFormat.dateTime().withZoneUTC();
    Date dateCreated = DateTime.now().toDate();
    String relativeLocation = "/scim/v2/Groups/" + inum;
    gluuGroup.setAttribute("oxTrustMetaCreated", dateTimeFormatter.print(dateCreated.getTime()));
    gluuGroup.setAttribute("oxTrustMetaLastModified", dateTimeFormatter.print(dateCreated.getTime()));
    gluuGroup.setAttribute("oxTrustMetaLocation", relativeLocation);
    // For custom script: create group
    if (externalScimService.isEnabled()) {
        externalScimService.executeScimCreateGroupMethods(gluuGroup);
    }
    log.debug("adding new GluuGroup");
    groupService.addGroup(gluuGroup);
    Group createdGroup = copyUtils2.copy(gluuGroup, null);
    return createdGroup;
}
Also used : Group(org.gluu.oxtrust.model.scim2.Group) GluuGroup(org.gluu.oxtrust.model.GluuGroup) GluuGroup(org.gluu.oxtrust.model.GluuGroup) DateTimeFormatter(org.joda.time.format.DateTimeFormatter) DuplicateEntryException(org.gluu.site.ldap.exception.DuplicateEntryException) EntryPersistenceException(org.gluu.site.ldap.persistence.exception.EntryPersistenceException) Date(java.util.Date)

Example 30 with Group

use of com.google.monitoring.v3.Group in project oxTrust by GluuFederation.

the class GroupWebService method updateGroup.

@Path("{id}")
@PUT
@Consumes({ Constants.MEDIA_TYPE_SCIM_JSON, MediaType.APPLICATION_JSON })
@Produces({ Constants.MEDIA_TYPE_SCIM_JSON + "; charset=utf-8", MediaType.APPLICATION_JSON + "; charset=utf-8" })
@HeaderParam("Accept")
@DefaultValue(Constants.MEDIA_TYPE_SCIM_JSON)
@ApiOperation(value = "Update group", notes = "Update group (https://tools.ietf.org/html/rfc7644#section-3.5.1)", response = Group.class)
public Response updateGroup(@HeaderParam("Authorization") String authorization, @QueryParam(OxTrustConstants.QUERY_PARAMETER_TEST_MODE_OAUTH2_TOKEN) final String token, @PathParam("id") String id, @ApiParam(value = "Group", required = true) Group group, @QueryParam(OxTrustConstants.QUERY_PARAMETER_ATTRIBUTES) final String attributesArray) throws Exception {
    Response authorizationResponse;
    if (jsonConfigurationService.getOxTrustappConfiguration().isScimTestMode()) {
        log.info(" ##### SCIM Test Mode is ACTIVE");
        authorizationResponse = processTestModeAuthorization(token);
    } else {
        authorizationResponse = processAuthorization(authorization);
    }
    if (authorizationResponse != null) {
        return authorizationResponse;
    }
    try {
        Group updatedGroup = scim2GroupService.updateGroup(id, group);
        // Serialize to JSON
        String json = serializeToJson(updatedGroup, attributesArray);
        URI location = new URI(updatedGroup.getMeta().getLocation());
        return Response.ok(json).location(location).build();
    } catch (EntryPersistenceException ex) {
        log.error("Failed to update group", ex);
        ex.printStackTrace();
        return getErrorResponse(Response.Status.NOT_FOUND, ErrorScimType.INVALID_VALUE, "Resource " + id + " not found");
    } catch (DuplicateEntryException ex) {
        log.error("DuplicateEntryException", ex);
        ex.printStackTrace();
        return getErrorResponse(Response.Status.CONFLICT, ErrorScimType.UNIQUENESS, ex.getMessage());
    } catch (Exception ex) {
        log.error("Failed to update group", ex);
        ex.printStackTrace();
        return getErrorResponse(Response.Status.INTERNAL_SERVER_ERROR, INTERNAL_SERVER_ERROR_MESSAGE);
    }
}
Also used : VirtualListViewResponse(org.xdi.ldap.model.VirtualListViewResponse) ListResponse(org.gluu.oxtrust.model.scim2.ListResponse) Response(javax.ws.rs.core.Response) GluuGroup(org.gluu.oxtrust.model.GluuGroup) Group(org.gluu.oxtrust.model.scim2.Group) EntryPersistenceException(org.gluu.site.ldap.persistence.exception.EntryPersistenceException) DuplicateEntryException(org.gluu.site.ldap.exception.DuplicateEntryException) URI(java.net.URI) EntryPersistenceException(org.gluu.site.ldap.persistence.exception.EntryPersistenceException) DuplicateEntryException(org.gluu.site.ldap.exception.DuplicateEntryException) Path(javax.ws.rs.Path) DefaultValue(javax.ws.rs.DefaultValue) HeaderParam(javax.ws.rs.HeaderParam) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) ApiOperation(com.wordnik.swagger.annotations.ApiOperation) PUT(javax.ws.rs.PUT)

Aggregations

Test (org.junit.Test)11 GroupName (com.google.monitoring.v3.GroupName)8 Group (org.gluu.oxtrust.model.scim2.Group)8 Group (org.openstack4j.model.identity.v3.Group)8 GluuGroup (org.gluu.oxtrust.model.GluuGroup)7 DuplicateEntryException (org.gluu.site.ldap.exception.DuplicateEntryException)7 ArrayList (java.util.ArrayList)6 EntryPersistenceException (org.gluu.site.ldap.persistence.exception.EntryPersistenceException)6 ApiException (com.google.api.gax.grpc.ApiException)5 Group (com.google.monitoring.v3.Group)5 GeneratedMessageV3 (com.google.protobuf.GeneratedMessageV3)5 StatusRuntimeException (io.grpc.StatusRuntimeException)5 ApiOperation (com.wordnik.swagger.annotations.ApiOperation)3 URI (java.net.URI)3 Date (java.util.Date)3 DefaultValue (javax.ws.rs.DefaultValue)3 HeaderParam (javax.ws.rs.HeaderParam)3 Produces (javax.ws.rs.Produces)3 Response (javax.ws.rs.core.Response)3 ListResponse (org.gluu.oxtrust.model.scim2.ListResponse)3