Loading projects/cadcAccessControl-Server/src/ca/nrc/cadc/ac/server/web/users/CreateUserAction.java +2 −2 Original line number Diff line number Diff line Loading @@ -93,8 +93,8 @@ public class CreateUserAction extends UsersAction UserPersistence userPersistence = getUserPersistence(); UserRequest userRequest = UserRequestReader.read(this.inputStream); User<? extends Principal> newUser = userPersistence.addUser(userRequest); this.response.setContentType("application/xml"); UserWriter.write(newUser, this.response.getOutputStream()); this.response.setContentType(acceptedContentType); writeUser(newUser, this.response.getWriter()); logUserInfo(newUser.getUserID().getName()); return null; } Loading projects/cadcAccessControl-Server/src/ca/nrc/cadc/ac/server/web/users/GetUserAction.java +2 −2 Original line number Diff line number Diff line Loading @@ -88,8 +88,8 @@ public class GetUserAction extends UsersAction { UserPersistence userPersistence = getUserPersistence(); User<? extends Principal> user = userPersistence.getUser(userID); this.response.setContentType("application/xml"); UserWriter.write(user, this.response.getOutputStream()); this.response.setContentType(acceptedContentType); writeUser(user, this.response.getWriter()); return null; } Loading projects/cadcAccessControl-Server/src/ca/nrc/cadc/ac/server/web/users/UsersAction.java +25 −0 Original line number Diff line number Diff line Loading @@ -69,6 +69,8 @@ package ca.nrc.cadc.ac.server.web.users; import java.io.IOException; import java.io.OutputStream; import java.io.Writer; import java.security.AccessControlException; import java.security.Principal; import java.security.PrivilegedActionException; Loading @@ -77,6 +79,7 @@ import java.security.PrivilegedExceptionAction; import javax.security.auth.Subject; import javax.servlet.http.HttpServletResponse; import ca.nrc.cadc.ac.User; import org.apache.log4j.Logger; import ca.nrc.cadc.ac.UserNotFoundException; Loading @@ -88,8 +91,12 @@ public abstract class UsersAction implements PrivilegedExceptionAction<Object> { private static final Logger log = Logger.getLogger(UsersAction.class); static final String DEFAULT_CONTENT_TYPE = "text/xml"; static final String JSON_CONTENT_TYPE = "application/json"; protected UserLogInfo logInfo; protected HttpServletResponse response; protected String acceptedContentType = DEFAULT_CONTENT_TYPE; UsersAction(UserLogInfo logInfo) { Loading Loading @@ -204,4 +211,22 @@ public abstract class UsersAction this.logInfo.userName = userName; } public void setAcceptedContentType(final String acceptedContentType) { this.acceptedContentType = acceptedContentType; } protected final <T extends Principal> void writeUser(final User<T> user, final Writer writer) throws IOException { if (acceptedContentType.equals(DEFAULT_CONTENT_TYPE)) { ca.nrc.cadc.ac.xml.UserWriter.write(user, writer); } else if (acceptedContentType.equals(JSON_CONTENT_TYPE)) { ca.nrc.cadc.ac.json.UserWriter.write(user, writer); } } } projects/cadcAccessControl-Server/src/ca/nrc/cadc/ac/server/web/users/UsersServlet.java +24 −1 Original line number Diff line number Diff line Loading @@ -3,7 +3,7 @@ ******************* CANADIAN ASTRONOMY DATA CENTRE ******************* ************** CENTRE CANADIEN DE DONNÉES ASTRONOMIQUES ************** * * (c) 2014. (c) 2014. * (c) 2015. (c) 2015. * Government of Canada Gouvernement du Canada * National Research Council Conseil national de recherches * Ottawa, Canada, K1A 0R6 Ottawa, Canada, K1A 0R6 Loading Loading @@ -75,6 +75,7 @@ import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import ca.nrc.cadc.util.StringUtil; import org.apache.log4j.Logger; import ca.nrc.cadc.auth.AuthenticationUtil; Loading @@ -83,6 +84,7 @@ public class UsersServlet extends HttpServlet { private static final Logger log = Logger.getLogger(UsersServlet.class); /** * Create a UserAction and run the action safely. */ Loading @@ -91,12 +93,14 @@ public class UsersServlet extends HttpServlet { long start = System.currentTimeMillis(); UserLogInfo logInfo = new UserLogInfo(request); try { log.info(logInfo.start()); Subject subject = AuthenticationUtil.getSubject(request); logInfo.setSubject(subject); UsersAction action = UsersActionFactory.getUsersAction(request, logInfo); action.setAcceptedContentType(getAcceptedContentType(request)); action.doAction(subject, response); } catch (IllegalArgumentException e) Loading Loading @@ -158,4 +162,23 @@ public class UsersServlet extends HttpServlet doAction(request, response); } /** * Obtain the requested (Accept) content type. * * @param request The HTTP Request. * @return String content type. */ String getAcceptedContentType(final HttpServletRequest request) { final String requestedContentType = request.getHeader("Accept"); if (!StringUtil.hasText(requestedContentType)) { return UsersAction.DEFAULT_CONTENT_TYPE; } else { return requestedContentType; } } } projects/cadcAccessControl-Server/test/src/ca/nrc/cadc/ac/server/web/users/GetUserIDsActionTest.java +2 −0 Original line number Diff line number Diff line Loading @@ -110,6 +110,7 @@ public class GetUserIDsActionTest @Ignore public void testRun() throws Exception { /* try { Collection<HttpPrincipal> userIDs = new ArrayList<HttpPrincipal>(); Loading Loading @@ -159,6 +160,7 @@ public class GetUserIDsActionTest log.error(t.getMessage(), t); fail("unexpected error: " + t.getMessage()); } */ } } Loading
projects/cadcAccessControl-Server/src/ca/nrc/cadc/ac/server/web/users/CreateUserAction.java +2 −2 Original line number Diff line number Diff line Loading @@ -93,8 +93,8 @@ public class CreateUserAction extends UsersAction UserPersistence userPersistence = getUserPersistence(); UserRequest userRequest = UserRequestReader.read(this.inputStream); User<? extends Principal> newUser = userPersistence.addUser(userRequest); this.response.setContentType("application/xml"); UserWriter.write(newUser, this.response.getOutputStream()); this.response.setContentType(acceptedContentType); writeUser(newUser, this.response.getWriter()); logUserInfo(newUser.getUserID().getName()); return null; } Loading
projects/cadcAccessControl-Server/src/ca/nrc/cadc/ac/server/web/users/GetUserAction.java +2 −2 Original line number Diff line number Diff line Loading @@ -88,8 +88,8 @@ public class GetUserAction extends UsersAction { UserPersistence userPersistence = getUserPersistence(); User<? extends Principal> user = userPersistence.getUser(userID); this.response.setContentType("application/xml"); UserWriter.write(user, this.response.getOutputStream()); this.response.setContentType(acceptedContentType); writeUser(user, this.response.getWriter()); return null; } Loading
projects/cadcAccessControl-Server/src/ca/nrc/cadc/ac/server/web/users/UsersAction.java +25 −0 Original line number Diff line number Diff line Loading @@ -69,6 +69,8 @@ package ca.nrc.cadc.ac.server.web.users; import java.io.IOException; import java.io.OutputStream; import java.io.Writer; import java.security.AccessControlException; import java.security.Principal; import java.security.PrivilegedActionException; Loading @@ -77,6 +79,7 @@ import java.security.PrivilegedExceptionAction; import javax.security.auth.Subject; import javax.servlet.http.HttpServletResponse; import ca.nrc.cadc.ac.User; import org.apache.log4j.Logger; import ca.nrc.cadc.ac.UserNotFoundException; Loading @@ -88,8 +91,12 @@ public abstract class UsersAction implements PrivilegedExceptionAction<Object> { private static final Logger log = Logger.getLogger(UsersAction.class); static final String DEFAULT_CONTENT_TYPE = "text/xml"; static final String JSON_CONTENT_TYPE = "application/json"; protected UserLogInfo logInfo; protected HttpServletResponse response; protected String acceptedContentType = DEFAULT_CONTENT_TYPE; UsersAction(UserLogInfo logInfo) { Loading Loading @@ -204,4 +211,22 @@ public abstract class UsersAction this.logInfo.userName = userName; } public void setAcceptedContentType(final String acceptedContentType) { this.acceptedContentType = acceptedContentType; } protected final <T extends Principal> void writeUser(final User<T> user, final Writer writer) throws IOException { if (acceptedContentType.equals(DEFAULT_CONTENT_TYPE)) { ca.nrc.cadc.ac.xml.UserWriter.write(user, writer); } else if (acceptedContentType.equals(JSON_CONTENT_TYPE)) { ca.nrc.cadc.ac.json.UserWriter.write(user, writer); } } }
projects/cadcAccessControl-Server/src/ca/nrc/cadc/ac/server/web/users/UsersServlet.java +24 −1 Original line number Diff line number Diff line Loading @@ -3,7 +3,7 @@ ******************* CANADIAN ASTRONOMY DATA CENTRE ******************* ************** CENTRE CANADIEN DE DONNÉES ASTRONOMIQUES ************** * * (c) 2014. (c) 2014. * (c) 2015. (c) 2015. * Government of Canada Gouvernement du Canada * National Research Council Conseil national de recherches * Ottawa, Canada, K1A 0R6 Ottawa, Canada, K1A 0R6 Loading Loading @@ -75,6 +75,7 @@ import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import ca.nrc.cadc.util.StringUtil; import org.apache.log4j.Logger; import ca.nrc.cadc.auth.AuthenticationUtil; Loading @@ -83,6 +84,7 @@ public class UsersServlet extends HttpServlet { private static final Logger log = Logger.getLogger(UsersServlet.class); /** * Create a UserAction and run the action safely. */ Loading @@ -91,12 +93,14 @@ public class UsersServlet extends HttpServlet { long start = System.currentTimeMillis(); UserLogInfo logInfo = new UserLogInfo(request); try { log.info(logInfo.start()); Subject subject = AuthenticationUtil.getSubject(request); logInfo.setSubject(subject); UsersAction action = UsersActionFactory.getUsersAction(request, logInfo); action.setAcceptedContentType(getAcceptedContentType(request)); action.doAction(subject, response); } catch (IllegalArgumentException e) Loading Loading @@ -158,4 +162,23 @@ public class UsersServlet extends HttpServlet doAction(request, response); } /** * Obtain the requested (Accept) content type. * * @param request The HTTP Request. * @return String content type. */ String getAcceptedContentType(final HttpServletRequest request) { final String requestedContentType = request.getHeader("Accept"); if (!StringUtil.hasText(requestedContentType)) { return UsersAction.DEFAULT_CONTENT_TYPE; } else { return requestedContentType; } } }
projects/cadcAccessControl-Server/test/src/ca/nrc/cadc/ac/server/web/users/GetUserIDsActionTest.java +2 −0 Original line number Diff line number Diff line Loading @@ -110,6 +110,7 @@ public class GetUserIDsActionTest @Ignore public void testRun() throws Exception { /* try { Collection<HttpPrincipal> userIDs = new ArrayList<HttpPrincipal>(); Loading Loading @@ -159,6 +160,7 @@ public class GetUserIDsActionTest log.error(t.getMessage(), t); fail("unexpected error: " + t.getMessage()); } */ } }