switch bad identity to AuthorizationException as it helps ensure we don't retry

This commit is contained in:
Adrian Cole 2012-03-22 13:33:14 -07:00
parent 2a4bcf83b0
commit e1f64356d9
2 changed files with 11 additions and 7 deletions

View File

@ -18,8 +18,6 @@
*/ */
package org.jclouds.openstack.keystone.v2_0.functions; package org.jclouds.openstack.keystone.v2_0.functions;
import static com.google.common.base.Preconditions.checkArgument;
import javax.inject.Inject; import javax.inject.Inject;
import javax.inject.Singleton; import javax.inject.Singleton;
@ -27,6 +25,7 @@ import org.jclouds.domain.Credentials;
import org.jclouds.openstack.keystone.v2_0.ServiceClient; import org.jclouds.openstack.keystone.v2_0.ServiceClient;
import org.jclouds.openstack.keystone.v2_0.domain.Access; import org.jclouds.openstack.keystone.v2_0.domain.Access;
import org.jclouds.openstack.keystone.v2_0.domain.ApiAccessKeyCredentials; import org.jclouds.openstack.keystone.v2_0.domain.ApiAccessKeyCredentials;
import org.jclouds.rest.AuthorizationException;
import com.google.common.base.Function; import com.google.common.base.Function;
@ -41,7 +40,10 @@ public class AuthenticateApiAccessKeyCredentials implements Function<Credentials
@Override @Override
public Access apply(Credentials input) { public Access apply(Credentials input) {
checkArgument(input.identity.indexOf(':') != -1, "format is tenantId:accesskey"); if (input.identity.indexOf(':') == -1) {
throw new AuthorizationException(String.format("Identity %s does not match format tenantId:accesskey",
input.identity), null);
}
String tenantId = input.identity.substring(0, input.identity.indexOf(':')); String tenantId = input.identity.substring(0, input.identity.indexOf(':'));
String usernameOrAccessKey = input.identity.substring(input.identity.indexOf(':') + 1); String usernameOrAccessKey = input.identity.substring(input.identity.indexOf(':') + 1);

View File

@ -17,14 +17,13 @@
* under the License. * under the License.
*/ */
package org.jclouds.openstack.keystone.v2_0.functions; package org.jclouds.openstack.keystone.v2_0.functions;
import static com.google.common.base.Preconditions.checkArgument;
import javax.inject.Inject; import javax.inject.Inject;
import org.jclouds.domain.Credentials; import org.jclouds.domain.Credentials;
import org.jclouds.openstack.keystone.v2_0.ServiceClient; import org.jclouds.openstack.keystone.v2_0.ServiceClient;
import org.jclouds.openstack.keystone.v2_0.domain.Access; import org.jclouds.openstack.keystone.v2_0.domain.Access;
import org.jclouds.openstack.keystone.v2_0.domain.PasswordCredentials; import org.jclouds.openstack.keystone.v2_0.domain.PasswordCredentials;
import org.jclouds.rest.AuthorizationException;
import com.google.common.base.Function; import com.google.common.base.Function;
@ -38,7 +37,10 @@ public class AuthenticatePasswordCredentials implements Function<Credentials, Ac
@Override @Override
public Access apply(Credentials input) { public Access apply(Credentials input) {
checkArgument(input.identity.indexOf(':') != -1, "format is tenantId:accesskey"); if (input.identity.indexOf(':') == -1) {
throw new AuthorizationException(String.format("Identity %s does not match format tenantId:username",
input.identity), null);
}
String tenantId = input.identity.substring(0, input.identity.indexOf(':')); String tenantId = input.identity.substring(0, input.identity.indexOf(':'));
String usernameOrAccessKey = input.identity.substring(input.identity.indexOf(':') + 1); String usernameOrAccessKey = input.identity.substring(input.identity.indexOf(':') + 1);