From f7b9803b203b7832a9ff761f025d9a3978dd4da4 Mon Sep 17 00:00:00 2001 From: Sebastian Sdorra Date: Thu, 13 Jan 2011 20:26:20 +0100 Subject: [PATCH] fix login bug with enabled anonymous access --- .../resources/AuthenticationResource.java | 69 ++++++++++--------- 1 file changed, 35 insertions(+), 34 deletions(-) diff --git a/scm-webapp/src/main/java/sonia/scm/api/rest/resources/AuthenticationResource.java b/scm-webapp/src/main/java/sonia/scm/api/rest/resources/AuthenticationResource.java index 52e9c71ad7..3fc33f20c7 100644 --- a/scm-webapp/src/main/java/sonia/scm/api/rest/resources/AuthenticationResource.java +++ b/scm-webapp/src/main/java/sonia/scm/api/rest/resources/AuthenticationResource.java @@ -41,6 +41,7 @@ import com.google.inject.Singleton; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import sonia.scm.SCMContext; import sonia.scm.ScmState; import sonia.scm.Type; import sonia.scm.repository.RepositoryManager; @@ -78,6 +79,40 @@ public class AuthenticationResource //~--- methods -------------------------------------------------------------- + /** + * Method description + * + * + * @param request + * @param response + * @param username + * @param password + * + * @return + */ + @POST + @Path("login") + public ScmState authenticate(@Context HttpServletRequest request, + @Context HttpServletResponse response, + @FormParam("username") String username, + @FormParam("password") String password) + { + ScmState state = null; + User user = securityContext.authenticate(request, response, username, + password); + + if ((user != null) &&!SCMContext.USER_ANONYMOUS.equals(user.getName())) + { + state = new ScmState(securityContext, repositoryManger.getTypes()); + } + else + { + throw new WebApplicationException(Response.Status.UNAUTHORIZED); + } + + return state; + } + /** * Method description * @@ -112,40 +147,6 @@ public class AuthenticationResource //~--- get methods ---------------------------------------------------------- - /** - * Method description - * - * - * @param request - * @param response - * @param username - * @param password - * - * @return - */ - @POST - @Path("login") - public ScmState getState(@Context HttpServletRequest request, - @Context HttpServletResponse response, - @FormParam("username") String username, - @FormParam("password") String password) - { - ScmState state = null; - User user = securityContext.authenticate(request, response, username, - password); - - if (user != null) - { - state = new ScmState(securityContext, repositoryManger.getTypes()); - } - else - { - throw new WebApplicationException(Response.Status.UNAUTHORIZED); - } - - return state; - } - /** * Method description *