You are viewing a plain text version of this content. The canonical link for it is here.
Posted to slide-dev@jakarta.apache.org by df...@apache.org on 2004/09/30 22:09:40 UTC
cvs commit: jakarta-slide/projector/src/java/org/apache/slide/projector/processor/security CreateUser.java
dflorey 2004/09/30 13:09:40
Modified: projector/src/java/org/apache/slide/projector/repository/webdav
WebdavRepository.java
projector/src/java/org/apache/slide/projector/repository
RoleExistsException.java RepositoryException.java
UserExistsException.java
projector/src/java/org/apache/slide/projector/processor/security
CreateUser.java
Added: projector/src/java/org/apache/slide/projector/repository/webdav
WebdavException.java
projector/src/java/org/apache/slide/projector/repository
AccessDeniedException.java NotFoundException.java
Log:
Improved localized exception handling
All default exceptions will be wrapped by localized exception in future releases
Revision Changes Path
1.7 +30 -22 jakarta-slide/projector/src/java/org/apache/slide/projector/repository/webdav/WebdavRepository.java
Index: WebdavRepository.java
===================================================================
RCS file: /home/cvs/jakarta-slide/projector/src/java/org/apache/slide/projector/repository/webdav/WebdavRepository.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- WebdavRepository.java 30 Sep 2004 19:25:10 -0000 1.6
+++ WebdavRepository.java 30 Sep 2004 20:09:40 -0000 1.7
@@ -24,7 +24,9 @@
import org.apache.slide.projector.ContentType;
import org.apache.slide.projector.Projector;
import org.apache.slide.projector.i18n.ErrorMessage;
+import org.apache.slide.projector.repository.AccessDeniedException;
import org.apache.slide.projector.repository.Configurable;
+import org.apache.slide.projector.repository.NotFoundException;
import org.apache.slide.projector.repository.Repository;
import org.apache.slide.projector.repository.RepositoryException;
import org.apache.slide.projector.repository.RoleExistsException;
@@ -105,13 +107,12 @@
}
public URI createUser(String username, String password, Credentials credentials) throws RepositoryException {
- Object userExists = getResource(new URIValue(users+username), credentials);
- if ( userExists != null ) {
- throw new UserExistsException(new ErrorMessage("userExists", new String[] { username }));
- } else {
- URI userUri = new URIValue(users+username);
- MkcolMethod mkcolMethod = new MkcolMethod(domain+userUri);
- mkcolMethod.setDoAuthentication(true);
+ try {
+ getResource(new URIValue(users+username), credentials);
+ } catch ( NotFoundException exception ) {
+ URI userUri = new URIValue(users+username);
+ MkcolMethod mkcolMethod = new MkcolMethod(domain+userUri);
+ mkcolMethod.setDoAuthentication(true);
HttpState httpState = new HttpState();
httpState.setCredentials(null, host, credentials);
int state;
@@ -121,23 +122,23 @@
throw new RepositoryException(new ErrorMessage("repositoryException"), e);
}
if ( state == HttpStatus.SC_CREATED ) {
- changePassword(userUri, null, password, credentials);
- return userUri;
+ changePassword(userUri, null, password, credentials);
+ return userUri;
} else if ( state == HttpStatus.SC_FORBIDDEN ) {
- throw new RepositoryException(new ErrorMessage("userCreationForbidden", new String[] { username }));
+ throw new AccessDeniedException(new ErrorMessage("userCreationForbidden", new String[] { username }));
}
- throw new RepositoryException(new ErrorMessage("httpError", new Object[] { new Integer(state) }));
+ throw new WebdavException(new ErrorMessage("httpError", new Object[] { new Integer(state) }), state);
}
+ throw new UserExistsException(new ErrorMessage("userAlreadyExists", new String[] { username }));
}
public URI createRole(String rolename, Credentials credentials) throws RepositoryException {
- Object userExists = getResource(new URIValue(domain+roles+rolename), credentials);
- if ( userExists != null ) {
- throw new RoleExistsException(new ErrorMessage("roleExists", new String[] { rolename }));
- } else {
- URI roleUri = new URIValue(roles+rolename);
- MkcolMethod mkcolMethod = new MkcolMethod(domain+roleUri);
- mkcolMethod.setDoAuthentication(true);
+ try {
+ getResource(new URIValue(users+rolename), credentials);
+ } catch ( NotFoundException exception ) {
+ URI roleUri = new URIValue(users+rolename);
+ MkcolMethod mkcolMethod = new MkcolMethod(domain+roleUri);
+ mkcolMethod.setDoAuthentication(true);
HttpState httpState = new HttpState();
httpState.setCredentials(null, host, credentials);
int state;
@@ -147,10 +148,13 @@
throw new RepositoryException(new ErrorMessage("repositoryException"), e);
}
if ( state == HttpStatus.SC_CREATED ) {
- return roleUri;
+ return roleUri;
+ } else if ( state == HttpStatus.SC_FORBIDDEN ) {
+ throw new AccessDeniedException(new ErrorMessage("roleCreationForbidden", new String[] { rolename }));
}
- throw new RepositoryException(new ErrorMessage("httpError", new Object[] { new Integer(state) }));
+ throw new WebdavException(new ErrorMessage("httpError", new Object[] { new Integer(state) }), state);
}
+ throw new RoleExistsException(new ErrorMessage("userExists", new String[] { rolename }));
}
public void deleteRole(URI role, Credentials credentials) throws RepositoryException {
@@ -221,8 +225,12 @@
httpState.setCredentials(null, host, credentials);
try {
int state = getMethod.execute(httpState, new HttpConnection(host, port, protocol));
- if ( state != HttpStatus.SC_OK ) {
- throw new RepositoryException(new ErrorMessage("httpError", new Object[] { new Integer(state) }));
+ if ( state == HttpStatus.SC_NOT_FOUND ) {
+ throw new NotFoundException(new ErrorMessage("resourceNotFound", new Object[] { uri }));
+ } else if ( state == HttpStatus.SC_FORBIDDEN ) {
+ throw new AccessDeniedException(new ErrorMessage("readAccessDenied", new Object[] { uri }));
+ } else if ( state != HttpStatus.SC_OK ) {
+ throw new WebdavException(new ErrorMessage("httpError", new Object[] { new Integer(state) }), state);
}
InputStream stream = getMethod.getResponseBodyAsStream();
String contentType = getMethod.getResponseHeader("Content-type").getValue();
1.1 jakarta-slide/projector/src/java/org/apache/slide/projector/repository/webdav/WebdavException.java
Index: WebdavException.java
===================================================================
/*
* $Header: /home/cvs/jakarta-slide/projector/src/java/org/apache/slide/projector/repository/webdav/WebdavException.java,v 1.1 2004/09/30 20:09:40 dflorey Exp $
* $Revision: 1.1 $
* $Date: 2004/09/30 20:09:40 $
*
* ====================================================================
*
* Copyright 2004 The Apache Software Foundation
*
* 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.apache.slide.projector.repository.webdav;
import org.apache.slide.projector.i18n.ErrorMessage;
import org.apache.slide.projector.repository.RepositoryException;
public class WebdavException extends RepositoryException {
private int statusCode;
public WebdavException(ErrorMessage errorMessage, int statusCode, Throwable cause) {
super(errorMessage, cause);
this.statusCode = statusCode;
}
public WebdavException(ErrorMessage errorMessage, int statusCode) {
super(errorMessage);
this.statusCode = statusCode;
}
}
1.4 +3 -7 jakarta-slide/projector/src/java/org/apache/slide/projector/repository/RoleExistsException.java
Index: RoleExistsException.java
===================================================================
RCS file: /home/cvs/jakarta-slide/projector/src/java/org/apache/slide/projector/repository/RoleExistsException.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- RoleExistsException.java 30 Sep 2004 19:25:10 -0000 1.3
+++ RoleExistsException.java 30 Sep 2004 20:09:40 -0000 1.4
@@ -25,10 +25,6 @@
import org.apache.slide.projector.i18n.ErrorMessage;
-/**
- * The UserExistsException class
- *
- */
public class RoleExistsException extends RepositoryException {
public RoleExistsException(ErrorMessage errorMessage, Throwable cause) {
super(errorMessage, cause);
1.2 +3 -7 jakarta-slide/projector/src/java/org/apache/slide/projector/repository/RepositoryException.java
Index: RepositoryException.java
===================================================================
RCS file: /home/cvs/jakarta-slide/projector/src/java/org/apache/slide/projector/repository/RepositoryException.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- RepositoryException.java 30 Sep 2004 19:25:10 -0000 1.1
+++ RepositoryException.java 30 Sep 2004 20:09:40 -0000 1.2
@@ -26,10 +26,6 @@
import org.apache.slide.projector.i18n.ErrorMessage;
import org.apache.slide.projector.processor.ProcessException;
-/**
- * The ForbiddenException class
- *
- */
public class RepositoryException extends ProcessException {
public RepositoryException(ErrorMessage errorMessage, Throwable cause) {
super(errorMessage, cause);
1.4 +3 -7 jakarta-slide/projector/src/java/org/apache/slide/projector/repository/UserExistsException.java
Index: UserExistsException.java
===================================================================
RCS file: /home/cvs/jakarta-slide/projector/src/java/org/apache/slide/projector/repository/UserExistsException.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- UserExistsException.java 30 Sep 2004 19:25:10 -0000 1.3
+++ UserExistsException.java 30 Sep 2004 20:09:40 -0000 1.4
@@ -25,10 +25,6 @@
import org.apache.slide.projector.i18n.ErrorMessage;
-/**
- * The UserExistsException class
- *
- */
public class UserExistsException extends RepositoryException {
public UserExistsException(ErrorMessage errorMessage, Throwable cause) {
super(errorMessage, cause);
1.1 jakarta-slide/projector/src/java/org/apache/slide/projector/repository/AccessDeniedException.java
Index: AccessDeniedException.java
===================================================================
/*
* $Header: /home/cvs/jakarta-slide/projector/src/java/org/apache/slide/projector/repository/AccessDeniedException.java,v 1.1 2004/09/30 20:09:40 dflorey Exp $
* $Revision: 1.1 $
* $Date: 2004/09/30 20:09:40 $
*
* ====================================================================
*
* Copyright 2004 The Apache Software Foundation
*
* 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.apache.slide.projector.repository;
import org.apache.slide.projector.i18n.ErrorMessage;
public class AccessDeniedException extends RepositoryException {
public AccessDeniedException(ErrorMessage errorMessage, Throwable cause) {
super(errorMessage, cause);
}
public AccessDeniedException(ErrorMessage errorMessage) {
super(errorMessage);
}
}
1.1 jakarta-slide/projector/src/java/org/apache/slide/projector/repository/NotFoundException.java
Index: NotFoundException.java
===================================================================
/*
* $Header: /home/cvs/jakarta-slide/projector/src/java/org/apache/slide/projector/repository/NotFoundException.java,v 1.1 2004/09/30 20:09:40 dflorey Exp $
* $Revision: 1.1 $
* $Date: 2004/09/30 20:09:40 $
*
* ====================================================================
*
* Copyright 2004 The Apache Software Foundation
*
* 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.apache.slide.projector.repository;
import org.apache.slide.projector.i18n.ErrorMessage;
public class NotFoundException extends RepositoryException {
public NotFoundException(ErrorMessage errorMessage, Throwable cause) {
super(errorMessage, cause);
}
public NotFoundException(ErrorMessage errorMessage) {
super(errorMessage);
}
}
1.5 +3 -7 jakarta-slide/projector/src/java/org/apache/slide/projector/processor/security/CreateUser.java
Index: CreateUser.java
===================================================================
RCS file: /home/cvs/jakarta-slide/projector/src/java/org/apache/slide/projector/processor/security/CreateUser.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- CreateUser.java 30 Sep 2004 19:25:07 -0000 1.4
+++ CreateUser.java 30 Sep 2004 20:09:40 -0000 1.5
@@ -16,7 +16,7 @@
import org.apache.slide.projector.i18n.ParameterMessage;
import org.apache.slide.projector.processor.Processor;
import org.apache.slide.projector.processor.Result;
-import org.apache.slide.projector.repository.UserExistsException;
+import org.apache.slide.projector.repository.RepositoryException;
/**
* @version $Revision$
@@ -58,14 +58,10 @@
} else {
try {
user = Projector.getRepository().createUser(username, password, context.getCredentials());
- } catch ( UserExistsException exception ) {
+ } catch ( RepositoryException exception ) {
context.addInformation(new Information(Information.ERROR, exception.getErrorMessage(), new String[] { USERNAME }));
state = FAILED;
}
- }
- if ( user == null ) {
- context.addInformation(new Information(Information.ERROR, new ErrorMessage("register/failed"), new String[0]));
- state = FAILED;
}
return new Result(state, USER, user);
}
---------------------------------------------------------------------
To unsubscribe, e-mail: slide-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: slide-dev-help@jakarta.apache.org