Skip to content

Commit

Permalink
CFID-200: duplicate user is now 409 (CONFLICT)
Browse files Browse the repository at this point in the history
Change-Id: If4d874aa6221876ba9c382f56c7bca3cbd5c44f9
  • Loading branch information
dsyer committed Mar 15, 2012
1 parent ea86e50 commit b461c61
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,21 @@
*/
package org.cloudfoundry.identity.uaa.scim;

import org.springframework.http.HttpStatus;

/**
* Unchecked exception to signal that a user has an invalid field, e.g. username.
*
* @author Dave Syer
*
*/
public class InvalidUserException extends RuntimeException {
public class InvalidUserException extends ScimException {

/**
* @param message a message for the caller
*/
public InvalidUserException(String message) {
super(message);
super(message, HttpStatus.BAD_REQUEST);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import org.cloudfoundry.identity.uaa.security.DefaultSecurityContextAccessor;
import org.cloudfoundry.identity.uaa.security.SecurityContextAccessor;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.dao.OptimisticLockingFailureException;
import org.springframework.expression.Expression;
import org.springframework.expression.spel.SpelParseException;
import org.springframework.expression.spel.standard.SpelExpressionParser;
Expand Down Expand Up @@ -120,7 +121,11 @@ public ScimUser updateUser(@RequestBody ScimUser user, @PathVariable String user
}
int version = getVersion(userId, etag);
user.setVersion(version);
return dao.updateUser(userId, user);
try {
return dao.updateUser(userId, user);
} catch (OptimisticLockingFailureException e) {
throw new ScimException(e.getMessage(), HttpStatus.CONFLICT);
}
}

@RequestMapping(value = "/User/{userId}/password", method = RequestMethod.PUT)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,21 @@
*/
package org.cloudfoundry.identity.uaa.scim;

import org.springframework.http.HttpStatus;

/**
* Unchecked exception signalling that a user account already exists.
*
* @author Dave Syer
*
*/
public class UserAlreadyExistsException extends RuntimeException {
public class UserAlreadyExistsException extends ScimException {

/**
* @param message a message for the caller
*/
public UserAlreadyExistsException(String message) {
super(message);
super(message, HttpStatus.CONFLICT);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import org.cloudfoundry.identity.uaa.scim.PasswordChangeRequest;
import org.cloudfoundry.identity.uaa.scim.ScimException;
import org.cloudfoundry.identity.uaa.scim.ScimUser;
import org.cloudfoundry.identity.uaa.scim.UserAlreadyExistsException;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
Expand Down Expand Up @@ -189,7 +190,7 @@ public void createUserTwiceFails() throws Exception {
Map<String, String> error = response.getBody();

// System.err.println(error);
assertEquals(ScimException.class.getName(), error.get("error"));
assertEquals(UserAlreadyExistsException.class.getName(), error.get("error"));

}

Expand Down

0 comments on commit b461c61

Please sign in to comment.