diff --git a/cloudfoundry-client-lib/src/main/java/org/cloudfoundry/client/lib/CloudFoundryClient.java b/cloudfoundry-client-lib/src/main/java/org/cloudfoundry/client/lib/CloudFoundryClient.java index ce14bb6f45d..2840b8b6052 100644 --- a/cloudfoundry-client-lib/src/main/java/org/cloudfoundry/client/lib/CloudFoundryClient.java +++ b/cloudfoundry-client-lib/src/main/java/org/cloudfoundry/client/lib/CloudFoundryClient.java @@ -16,30 +16,6 @@ package org.cloudfoundry.client.lib; -import java.io.ByteArrayInputStream; -import java.io.ByteArrayOutputStream; -import java.io.File; -import java.io.FileInputStream; -import java.io.IOException; -import java.io.InputStream; -import java.io.StringWriter; -import java.net.MalformedURLException; -import java.net.URI; -import java.net.URL; -import java.security.MessageDigest; -import java.security.NoSuchAlgorithmException; -import java.util.ArrayList; -import java.util.Collections; -import java.util.Enumeration; -import java.util.HashMap; -import java.util.HashSet; -import java.util.List; -import java.util.Map; -import java.util.Set; -import java.util.zip.ZipEntry; -import java.util.zip.ZipFile; -import java.util.zip.ZipOutputStream; - import org.cloudfoundry.client.lib.CloudApplication.AppState; import org.codehaus.jackson.JsonParseException; import org.codehaus.jackson.map.ObjectMapper; @@ -67,6 +43,30 @@ import org.springframework.web.client.RestClientException; import org.springframework.web.client.RestTemplate; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.StringWriter; +import java.net.MalformedURLException; +import java.net.URI; +import java.net.URL; +import java.security.MessageDigest; +import java.security.NoSuchAlgorithmException; +import java.util.ArrayList; +import java.util.Collections; +import java.util.Enumeration; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.zip.ZipEntry; +import java.util.zip.ZipFile; +import java.util.zip.ZipOutputStream; + public class CloudFoundryClient { private class ErrorHandler extends DefaultResponseErrorHandler { @@ -168,14 +168,18 @@ public URL getCloudControllerUrl() { return cloudControllerUrl; } - public CloudInfo getCloudInfo() { - if (info == null) { - @SuppressWarnings("unchecked") - Map infoMap = restTemplate.getForObject(getUrl("info"), Map.class); - info = new CloudInfo(infoMap); - } - return info; - } + /** + * Returns the Cloud info. + * Removed the check for info==null, because after setting the proxyUser the CloudInfo changes. + * + * @return the CloudInfo for the (proxy)User. + */ + public CloudInfo getCloudInfo() { + @SuppressWarnings("unchecked") + Map infoMap = restTemplate.getForObject(getUrl("info"), Map.class); + info = new CloudInfo(infoMap); + return info; + } public void register(String email, String password) { Map payload = new HashMap(); @@ -192,6 +196,29 @@ public void updatePassword(String newPassword) { restTemplate.put(getUrl("users/{id}"), userInfo, email); } + /** + * Returns all user accounts. + * + * @return the users + */ + public List getUsers() { + List> servicesAsMap = restTemplate.getForObject(getUrl("users"), List.class); + List users = new ArrayList(); + for (Map serviceAsMap : servicesAsMap) { + users.add(new CloudUser(serviceAsMap)); + } + return users; + } + + /** + * Unregister the specified account. + * + * @param theEmail the user which should be unregistered. + */ + public void unregister(String theEmail) { + restTemplate.delete(getUrl("users/{email}"), theEmail); + } + public void unregister() { restTemplate.delete(getUrl("users/{email}"), email); token = null; @@ -238,7 +265,6 @@ public ApplicationStats getApplicationStats(String appName) { /** * Get choices for application memory quota * - * @param framework * @return memory choices in MB */ public int[] getApplicationMemoryChoices() { diff --git a/cloudfoundry-client-lib/src/main/java/org/cloudfoundry/client/lib/CloudUser.java b/cloudfoundry-client-lib/src/main/java/org/cloudfoundry/client/lib/CloudUser.java new file mode 100644 index 00000000000..970c5e536b9 --- /dev/null +++ b/cloudfoundry-client-lib/src/main/java/org/cloudfoundry/client/lib/CloudUser.java @@ -0,0 +1,55 @@ +/* + * Copyright 2009-2011 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.cloudfoundry.client.lib; + +/** + * Cloud Foundry Account information. + */ +public class CloudUser { + private java.util.Map attributes; + private String email; + private boolean admin; + + /** + * Account constructor. Password will not be set in this object. + * + * @param attributes The attributes to set. + */ + public CloudUser(java.util.Map attributes) { + this.attributes = attributes; + this.email = CloudUtil.parse(String.class, attributes.get("email")); + this.admin = CloudUtil.parse(Boolean.class, attributes.get("admin")); + } + + /** + * The email address for this account. + * + * @return should never be empty + */ + public String getEmail() { + return email; + } + + /** + * If this user is an admin. + * + * @return true if an admin + */ + public boolean isAdmin() { + return admin; + } +}