Search in sources :

Example 26 with AuthnProviderRestRep

use of com.emc.storageos.model.auth.AuthnProviderRestRep in project coprhd-controller by CoprHD.

the class ApiTestAuthnProviders method testAuthnProviderEditByRemovingLDAPGroupProperties.

@Test
public void testAuthnProviderEditByRemovingLDAPGroupProperties() {
    final String testName = "testAuthnProviderEditByRemovingLDAPGroupProperties - ";
    AuthnCreateParam createParam = getDefaultAuthnCreateParam(testName + TRACE_AUTHN_PROVIDER_SUCCESSFUL);
    AuthnProviderRestRep createResp = rSys.path(getTestApi()).post(AuthnProviderRestRep.class, createParam);
    validateAuthProviderCreateSuccess(createParam, createResp);
    // Now edit the created authn provider.
    final String editAPI = getTestEditApi(createResp.getId());
    AuthnUpdateParam editParam = getAuthnUpdateParamFromAuthnProviderRestResp(createResp);
    Set<String> addedGroupObjectClasses = new LinkedHashSet<String>();
    addedGroupObjectClasses.addAll(editParam.getGroupObjectClassChanges().getAdd());
    Set<String> addedGroupMemberAttributes = new LinkedHashSet<String>();
    addedGroupMemberAttributes.addAll(editParam.getGroupMemberAttributeChanges().getAdd());
    // Remove everything from the add list
    editParam.getGroupObjectClassChanges().getAdd().clear();
    editParam.getGroupMemberAttributeChanges().getAdd().clear();
    // Add everything to the remove list.
    editParam.getGroupObjectClassChanges().getRemove().addAll(addedGroupObjectClasses);
    editParam.getGroupMemberAttributeChanges().getRemove().addAll(addedGroupMemberAttributes);
    editParam.setDescription(testName + "Edit by removing the ldap group properties");
    // Now, Send the put request to edit the auth provider with duplicate ldap group properties.
    // The request should be be successful and ldap group properties should not have any duplicates.
    AuthnProviderRestRep editResp = rSys.path(editAPI).put(AuthnProviderRestRep.class, editParam);
    validateAuthProviderEditSuccess(editParam, editResp);
    editParam = getAuthnUpdateParamFromAuthnProviderRestResp(createResp);
    editParam.setDescription(testName + "Edit after removing the ldap group properties to reset with default values");
    // Now, Send the put request to edit the auth provider with duplicate ldap group properties.
    // The request should be be successful and ldap group properties should not have any duplicates.
    editResp = rSys.path(editAPI).put(AuthnProviderRestRep.class, editParam);
    validateAuthProviderEditSuccess(editParam, editResp);
    editParam.getGroupObjectClassChanges().getAdd().clear();
    editParam.getGroupMemberAttributeChanges().getAdd().clear();
    // Add only first two group object classes to the add list.
    editParam.getGroupObjectClassChanges().getAdd().add(this.getGroupObjectClass(0));
    editParam.getGroupObjectClassChanges().getAdd().add(this.getGroupObjectClass(1));
    // Add only last two group object classes to the remove list.
    editParam.getGroupObjectClassChanges().getRemove().add(this.getGroupObjectClass(2));
    editParam.getGroupObjectClassChanges().getRemove().add(this.getGroupObjectClass(3));
    // Add only first two group member attributes to the add list.
    editParam.getGroupMemberAttributeChanges().getAdd().add(this.getGroupMemberAttribute(0));
    editParam.getGroupMemberAttributeChanges().getAdd().add(this.getGroupMemberAttribute(1));
    // Add only last two group member attributes to the remove list.
    editParam.getGroupMemberAttributeChanges().getRemove().add(this.getGroupMemberAttribute(2));
    editParam.getGroupMemberAttributeChanges().getRemove().add(this.getGroupMemberAttribute(3));
    editParam.setDescription(testName + "Edit by removing and adding the ldap group properties in one update");
    // Now, Send the put request to edit the auth provider with duplicate ldap group properties.
    // The request should be be successful and ldap group properties should not have any duplicates.
    editResp = rSys.path(editAPI).put(AuthnProviderRestRep.class, editParam);
    validateAuthProviderEditSuccess(editParam, editResp);
    editParam.getGroupObjectClassChanges().getAdd().clear();
    editParam.getGroupMemberAttributeChanges().getAdd().clear();
    editParam.getGroupObjectClassChanges().getRemove().clear();
    editParam.getGroupMemberAttributeChanges().getRemove().clear();
    editParam.getGroupObjectClassChanges().getRemove().add(this.getGroupObjectClass(0));
    editParam.getGroupObjectClassChanges().getRemove().add(this.getGroupObjectClass(1));
    editParam.setDescription(testName + "Edit by just removing all the group object classes only.");
    // Now, Send the put request to edit the auth provider to remove all the object classes and keep
    // member attributes.
    // The request should fail as both group object classes and member attributes
    // can be empty or both can have values. Just only one containing values is
    // not allowed.
    ClientResponse clientEditResp = rSys.path(editAPI).put(ClientResponse.class, editParam);
    // Since the createParam does not contain group object classes, the request
    // should fail with the below error.
    String partialExpectedErrorMsg = AUTHN_PROVIDER_ADD_UPDATE_PARTIAL_ERROR + "modified because of the following error: Group object classes are not provided.";
    validateAuthProviderBadRequest(HttpStatus.SC_BAD_REQUEST, partialExpectedErrorMsg, clientEditResp);
    editParam.getGroupObjectClassChanges().getAdd().clear();
    editParam.getGroupMemberAttributeChanges().getAdd().clear();
    editParam.getGroupObjectClassChanges().getRemove().clear();
    editParam.getGroupMemberAttributeChanges().getRemove().clear();
    editParam.getGroupMemberAttributeChanges().getRemove().add(this.getGroupMemberAttribute(0));
    editParam.getGroupMemberAttributeChanges().getRemove().add(this.getGroupMemberAttribute(1));
    editParam.setDescription(testName + "Edit by just removing all the group member attributes only.");
    // Now, Send the put request to edit the auth provider to remove all the member attributes and keep
    // object classes.
    // The request should fail as both group object classes and member attributes
    // can be empty or both can have values. Just only one containing values is
    // not allowed.
    clientEditResp = rSys.path(editAPI).put(ClientResponse.class, editParam);
    // Since the createParam does not contain group member attributes, the request
    // should fail with the below error.
    partialExpectedErrorMsg = AUTHN_PROVIDER_ADD_UPDATE_PARTIAL_ERROR + "modified because of the following error: Group member attributes are not provided.";
    validateAuthProviderBadRequest(HttpStatus.SC_BAD_REQUEST, partialExpectedErrorMsg, clientEditResp);
}
Also used : LinkedHashSet(java.util.LinkedHashSet) ClientResponse(com.sun.jersey.api.client.ClientResponse) AuthnUpdateParam(com.emc.storageos.model.auth.AuthnUpdateParam) AuthnCreateParam(com.emc.storageos.model.auth.AuthnCreateParam) AuthnProviderRestRep(com.emc.storageos.model.auth.AuthnProviderRestRep) Test(org.junit.Test)

Example 27 with AuthnProviderRestRep

use of com.emc.storageos.model.auth.AuthnProviderRestRep in project coprhd-controller by CoprHD.

the class ApiTestAuthnProviders method validateAuthProviderEditSuccessForGroupObjectClassOnly.

private void validateAuthProviderEditSuccessForGroupObjectClassOnly(AuthnUpdateParam expected, AuthnProviderRestRep actual) {
    validateAuthProviderCommon(expected, actual);
    Assert.assertArrayEquals(expected.getGroupObjectClassChanges().getAdd().toArray(), actual.getGroupObjectClasses().toArray());
    // Query the APIService about the new edited resource and make
    // sure the properties are right in the DB too.
    final String getObjectURL = this.getTestEditApi(actual.getId());
    AuthnProviderRestRep createResp = rSys.path(getObjectURL).get(AuthnProviderRestRep.class);
    Assert.assertNotNull(createResp);
    Assert.assertArrayEquals(expected.getGroupObjectClassChanges().getAdd().toArray(), createResp.getGroupObjectClasses().toArray());
}
Also used : AuthnProviderRestRep(com.emc.storageos.model.auth.AuthnProviderRestRep)

Example 28 with AuthnProviderRestRep

use of com.emc.storageos.model.auth.AuthnProviderRestRep in project coprhd-controller by CoprHD.

the class ApiTestAuthnProviders method testAuthnProviderCreateWithLDAPGroupProperties.

@Test
public void testAuthnProviderCreateWithLDAPGroupProperties() {
    final String testName = "testAuthnProviderCreateWithLDAPGroupProperties - ";
    AuthnCreateParam createParam = getDefaultAuthnCreateParam(testName + "Invalid group objectClasses and memberAttributes");
    // Add some invalid group objectclasses and memberAttributes.
    createParam.getGroupObjectClasses().add("some0");
    createParam.getGroupObjectClasses().add("some0");
    createParam.getGroupObjectClasses().add("some2");
    createParam.getGroupObjectClasses().add("some3");
    createParam.getGroupMemberAttributes().add("someAttribute0");
    createParam.getGroupMemberAttributes().add("someAttribute0");
    createParam.getGroupMemberAttributes().add("someAttribute2");
    createParam.getGroupMemberAttributes().add("someAttribute3");
    createParam.getGroupMemberAttributes().add("someAttribute4");
    createParam.getGroupMemberAttributes().add("someAttribute5");
    ClientResponse clientCreateResp = rSys.path(getTestApi()).post(ClientResponse.class, createParam);
    // Since the createParam contains invalid group ObjectClasses and memberAttributes
    // the post request should fail with the below errors. Here the failure will be only for the
    // objectClasses. So validate the error message against only the objectClasses error.
    String partialExpectedErrorMsg = AUTHN_PROVIDER_ADD_UPDATE_PARTIAL_ERROR + "modified because of the following error: Could not find objectClasses";
    validateAuthProviderBadRequest(HttpStatus.SC_BAD_REQUEST, partialExpectedErrorMsg, clientCreateResp);
    // Remove the invalid values from group objectClasses and set with default values.
    createParam.getGroupObjectClasses().clear();
    createParam.setGroupObjectClasses(getDefaultGroupObjectClasses());
    createParam.setDescription(testName + "Invalid memberAttributes");
    clientCreateResp = rSys.path(getTestApi()).post(ClientResponse.class, createParam);
    // After we removal of invalid objectClasses from createParam, it contains only
    // invalid group member attributes. So, the post request should fail with the below errors.
    // Here the failure will be only for the member attributes.
    // So validate the error message against only the member attributes error.
    partialExpectedErrorMsg = "The authentication provider could not be added or modified because of the following error: Could not find attributes";
    validateAuthProviderBadRequest(HttpStatus.SC_BAD_REQUEST, partialExpectedErrorMsg, clientCreateResp);
    // Remove the invalid values from group member attributes and set with default values.
    createParam.getGroupMemberAttributes().clear();
    createParam.setGroupMemberAttributes(getDefaultGroupMemberAttributes());
    createParam.setDescription(testName + TRACE_SUCCESSFUL);
    // Now, all the paramaters in the post payload is valid. So the request should be successful.
    AuthnProviderRestRep createResp = rSys.path(getTestApi()).post(AuthnProviderRestRep.class, createParam);
    validateAuthProviderCreateSuccess(createParam, createResp);
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) AuthnCreateParam(com.emc.storageos.model.auth.AuthnCreateParam) AuthnProviderRestRep(com.emc.storageos.model.auth.AuthnProviderRestRep) Test(org.junit.Test)

Example 29 with AuthnProviderRestRep

use of com.emc.storageos.model.auth.AuthnProviderRestRep in project coprhd-controller by CoprHD.

the class ApiTestAuthnProviders method testAuthnProviderEditWithLDAPGroupMemberAttributesOnly.

@Test
public void testAuthnProviderEditWithLDAPGroupMemberAttributesOnly() {
    final String testName = "testAuthnProviderEditWithLDAPGroupMemberAttributesOnly - ";
    AuthnCreateParam createParam = getDefaultAuthnCreateParam(testName + TRACE_AUTHN_PROVIDER_SUCCESSFUL);
    AuthnProviderRestRep createResp = rSys.path(getTestApi()).post(AuthnProviderRestRep.class, createParam);
    validateAuthProviderCreateSuccess(createParam, createResp);
    // Now edit the created authn provider.
    final String editAPI = getTestEditApi(createResp.getId());
    AuthnUpdateParam editParam = getAuthnUpdateParamFromAuthnProviderRestResp(createResp);
    // Remove the objectClasses from the editParam.
    editParam.getGroupObjectClassChanges().getAdd().clear();
    editParam.setDescription(testName + "Edit with only group memberAttributes");
    // Now, Send the put request to edit the auth provider with duplicate ldap group properties.
    // The reqeust should be be successful and ldap group properties should not have any duplicates.
    AuthnProviderRestRep editResp = rSys.path(editAPI).put(AuthnProviderRestRep.class, editParam);
    validateAuthProviderEditSuccessForGroupMemberAttributeOnly(editParam, editResp);
    // Validate the counts separately to make sure that the counts are removed.
    // GroupObjectClasses wont change here as the edit did not change
    // the GroupObjectClasses
    final int expected = 4;
    Assert.assertEquals(expected, editResp.getGroupObjectClasses().size());
    Assert.assertEquals(expected, editResp.getGroupMemberAttributes().size());
}
Also used : AuthnUpdateParam(com.emc.storageos.model.auth.AuthnUpdateParam) AuthnCreateParam(com.emc.storageos.model.auth.AuthnCreateParam) AuthnProviderRestRep(com.emc.storageos.model.auth.AuthnProviderRestRep) Test(org.junit.Test)

Aggregations

AuthnProviderRestRep (com.emc.storageos.model.auth.AuthnProviderRestRep)29 AuthnCreateParam (com.emc.storageos.model.auth.AuthnCreateParam)18 AuthnUpdateParam (com.emc.storageos.model.auth.AuthnUpdateParam)12 ClientResponse (com.sun.jersey.api.client.ClientResponse)11 Test (org.junit.Test)11 FlashException (controllers.util.FlashException)2 RestLinkRep (com.emc.storageos.model.RestLinkRep)1 AuthnProviderList (com.emc.storageos.model.auth.AuthnProviderList)1 TenantCreateParam (com.emc.storageos.model.tenant.TenantCreateParam)1 UserMappingAttributeParam (com.emc.storageos.model.tenant.UserMappingAttributeParam)1 UserMappingParam (com.emc.storageos.model.tenant.UserMappingParam)1 Gson (com.google.gson.Gson)1 ClientHandlerException (com.sun.jersey.api.client.ClientHandlerException)1 UniformInterfaceException (com.sun.jersey.api.client.UniformInterfaceException)1 URI (java.net.URI)1 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)1 HashSet (java.util.HashSet)1 LinkedHashSet (java.util.LinkedHashSet)1 Random (java.util.Random)1 OpenStackTenantsDataTable (models.datatable.OpenStackTenantsDataTable)1