Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for LDAP and SAML groups #314

Merged
merged 25 commits into from
Jun 16, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@
* Add configuration option `WithSamlAdfs` to `NewVCDClient()` to support SAML authentication using
Active Directory Federations Services (ADFS) as IdP using WS-TRUST auth endpoint
"/adfs/services/trust/13/usernamemixed"
[#304](https://github.com/vmware/go-vcloud-director/pull/304)
[#304](https://github.com/vmware/go-vcloud-director/pull/304)
* Add support for group management using `CreateGroup`, `GetGroupByHref`, `GetGroupById`,
`GetGroupByName`, `GetGroupByNameOrId`, `Delete`, `Update`, `NewGroup` functions [#314](https://github.com/vmware/go-vcloud-director/pull/314)
* Add LDAP administration functions for Org `LdapConfigure`, `GetLdapConfiguration`, and `LdapDisable` [#314](https://github.com/vmware/go-vcloud-director/pull/314)
* Added methods `vapp.UpdateNetworkFirewallRules`, `vapp.UpdateNetworkFirewallRulesAsync`, `vapp.GetVappNetworkById`, `vapp.GetVappNetworkByName` and `vapp.GetVappNetworkByNameOrId` [#308](https://github.com/vmware/go-vcloud-director/pull/308)

## 2.7.0 (April 10,2020)
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ default: fmtcheck vet static build
# test runs the test suite and vets the code
test: testunit
@echo "==> Running Functional Tests"
cd govcd && go test -tags "functional" -timeout=200m -check.vv .
cd govcd && go test -tags "functional" -timeout=300m -check.vv .
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please tell more why are you adding additional one hundred minutes to the timeout :)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is not related to this exact group PR. I did hit timeouts in general for full suite runs in slower envs that is why I increased the "default".


# testunit runs the unit tests
testunit: fmtcheck
Expand Down
61 changes: 61 additions & 0 deletions govcd/adminorg_administration.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/*
* Copyright 2020 VMware, Inc. All rights reserved. Licensed under the Apache v2 License.
*/

package govcd

import (
"fmt"
"net/http"

"github.com/vmware/go-vcloud-director/v2/types/v56"
"github.com/vmware/go-vcloud-director/v2/util"
)

// LdapConfigure allows to configure LDAP mode in use by the Org
func (adminOrg *AdminOrg) LdapConfigure(settings *types.OrgLdapSettingsType) (*types.OrgLdapSettingsType, error) {
util.Logger.Printf("[DEBUG] Configuring LDAP mode for Org name %s", adminOrg.AdminOrg.Name)

// Xmlns field is not mandatory when `types.OrgLdapSettingsType` is set as part of whole
// `AdminOrg` structure but it must be set when directly updating LDAP. For that reason
// `types.OrgLdapSettingsType` Xmlns struct tag has 'omitempty' set
settings.Xmlns = types.XMLNamespaceVCloud

href := adminOrg.AdminOrg.HREF + "/settings/ldap"
_, err := adminOrg.client.ExecuteRequest(href, http.MethodPut, types.MimeOrgLdapSettings,
"error updating LDAP settings: %s", settings, nil)
if err != nil {
return nil, fmt.Errorf("error updating LDAP mode for Org name '%s': %s", adminOrg.AdminOrg.Name, err)
}

ldapSettings, err := adminOrg.GetLdapConfiguration()
if err != nil {
return nil, fmt.Errorf("error retrieving LDAP configuration: %s", err)
}

return ldapSettings, nil
}

// LdapDisable wraps LdapConfigure to disable LDAP configuration for org
func (adminOrg *AdminOrg) LdapDisable() error {
vbauzys marked this conversation as resolved.
Show resolved Hide resolved
_, err := adminOrg.LdapConfigure(&types.OrgLdapSettingsType{OrgLdapMode: types.LdapModeNone})
return err
}

// GetLdapConfiguration retrieves LDAP configuration structure
func (adminOrg *AdminOrg) GetLdapConfiguration() (*types.OrgLdapSettingsType, error) {
util.Logger.Printf("[DEBUG] Reading LDAP configuration for Org name %s", adminOrg.AdminOrg.Name)

ldapSettings := &types.OrgLdapSettingsType{}

href := adminOrg.AdminOrg.HREF + "/settings/ldap"

_, err := adminOrg.client.ExecuteRequest(href, http.MethodGet, types.MimeOrgLdapSettings,
"error getting LDAP settings: %s", nil, ldapSettings)

if err != nil {
return nil, err
}

return ldapSettings, nil
}
75 changes: 75 additions & 0 deletions govcd/adminorg_administration_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
// +build org functional ALL

/*
* Copyright 2020 VMware, Inc. All rights reserved. Licensed under the Apache v2 License.
*/

package govcd

import (
"fmt"

"github.com/vmware/go-vcloud-director/v2/types/v56"
. "gopkg.in/check.v1"
)

// Test_LDAP_Configuration tests LDAP configuration functions
func (vcd *TestVCD) Test_LDAP_Configuration(check *C) {
if vcd.skipAdminTests {
check.Skip(fmt.Sprintf(TestRequiresSysAdminPrivileges, check.TestName()))
}

org, err := vcd.client.GetAdminOrgByName(vcd.config.VCD.Org)
check.Assert(err, IsNil)

ldapSettings := &types.OrgLdapSettingsType{
OrgLdapMode: types.LdapModeCustom,
CustomOrgLdapSettings: &types.CustomOrgLdapSettings{
HostName: "1.1.1.1",
Port: 389,
SearchBase: "dc=planetexpress,dc=com",
AuthenticationMechanism: "SIMPLE",
ConnectorType: "OPEN_LDAP",
Username: "cn=admin,dc=planetexpress,dc=com",
Password: "GoodNewsEveryone",
UserAttributes: &types.OrgLdapUserAttributes{
ObjectClass: "inetOrgPerson",
ObjectIdentifier: "uid",
Username: "uid",
Email: "mail",
FullName: "cn",
GivenName: "givenName",
Surname: "sn",
Telephone: "telephoneNumber",
GroupMembershipIdentifier: "dn",
},
GroupAttributes: &types.OrgLdapGroupAttributes{
ObjectClass: "group",
ObjectIdentifier: "cn",
GroupName: "cn",
Membership: "member",
MembershipIdentifier: "dn",
},
},
}
gotSettings, err := org.LdapConfigure(ldapSettings)
check.Assert(err, IsNil)

AddToCleanupList("LDAP-configuration", "orgLdapSettings", org.AdminOrg.Name, check.TestName())

check.Assert(ldapSettings.CustomOrgLdapSettings.GroupAttributes, DeepEquals, gotSettings.CustomOrgLdapSettings.GroupAttributes)
check.Assert(ldapSettings.CustomOrgLdapSettings.UserAttributes, DeepEquals, gotSettings.CustomOrgLdapSettings.UserAttributes)
check.Assert(ldapSettings.CustomOrgLdapSettings.UserAttributes, DeepEquals, gotSettings.CustomOrgLdapSettings.UserAttributes)
check.Assert(ldapSettings.CustomOrgLdapSettings.Username, DeepEquals, gotSettings.CustomOrgLdapSettings.Username)
check.Assert(ldapSettings.CustomOrgLdapSettings.AuthenticationMechanism, DeepEquals, gotSettings.CustomOrgLdapSettings.AuthenticationMechanism)
check.Assert(ldapSettings.CustomOrgLdapSettings.ConnectorType, DeepEquals, gotSettings.CustomOrgLdapSettings.ConnectorType)

err = org.LdapDisable()
check.Assert(err, IsNil)

ldapConfig, err := org.GetLdapConfiguration()
check.Assert(err, IsNil)

check.Assert(ldapConfig.OrgLdapMode, Equals, types.LdapModeNone)

}
Loading