示例#1
0
func (uv *UAAVerifier) Membership(user goth.User, c *http.Client) (map[string]interface{}, error) {
	var filterGroups []string
	for _, g := range uv.Groups {
		filterGroups = append(filterGroups, fmt.Sprintf("displayName=%%22%s%%22", g))
	}
	filter := strings.Join(filterGroups, "+or+")
	botta.SetClient(c)
	req, err := botta.Get(fmt.Sprintf("%s/Groups?attributes=displayName,members&filter=%s", uv.UAA, filter))
	if err != nil {
		return nil, err
	}

	resp, err := botta.Issue(req)
	if err != nil {
		return nil, err
	}

	groups, err := resp.ArrayVal("resources")
	if err != nil {
		return nil, err
	}

	var membership []string
	for _, g := range groups {
		group, ok := g.(map[string]interface{})
		if !ok {
			return nil, fmt.Errorf("Unexpected data type for group returned from UAA: %#v", g)
		}

		name, ok := group["displayName"].(string)
		if !ok {
			return nil, fmt.Errorf("Unexpected data type for group name returned form UAA: %#v", g)
		}

		members, ok := group["members"].([]interface{})
		if !ok {
			return nil, fmt.Errorf("Unexpected data type for group membership returned from UAA: %#v", group["members"])
		}

		for _, m := range members {
			member, ok := m.(map[string]interface{})
			if !ok {
				return nil, fmt.Errorf("Unexpected data type for group member returned from UAA: %#v", m)
			}

			uid, ok := member["value"].(string)
			if !ok {
				return nil, fmt.Errorf("Unexpected data type for group member uid returned from UAA: %#v", member)
			}
			if uid == user.UserID {
				membership = append(membership, name)
			}
		}
	}
	return map[string]interface{}{"Groups": membership}, nil
}
示例#2
0
				Expect(resp.Data).Should(BeNil())
				Expect(resp.Raw).Should(Equal([]byte("404 page not found\n")))
			})
		})
	})
	Context("Client()", func() {
		It("should return a generic client by default", func() {
			Expect(botta.Client()).Should(Equal(&http.Client{}))
		})
		It("should allow setting a custom http.Client()", func() {
			client := &http.Client{
				Transport: &http.Transport{
					TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
				},
			}
			botta.SetClient(client)

			Expect(botta.Client()).Should(Equal(client))
		})
	})
	Context("BadResponseCode", func() {
		Context("Error()", func() {
			It("returns an error message", func() {
				err := botta.BadResponseCode{
					StatusCode: 123,
					Message:    "this is an error",
					URL:        "https://localhost/test",
				}
				Expect(err.Error()).Should(Equal("https://localhost/test returned 123: this is an error"))

				err = botta.BadResponseCode{