();
+ properties.put("userOrganisation.userOrganisationId", uo.getUserOrganisationId());
+ for (Integer roleId : roleIds) {
+ properties.put("role.roleId", roleId);
+ List list = userManagementService.findByProperties(UserOrganisationRole.class, properties);
+ if ((list == null) || (list.size() == 0)) {
+ UserOrganisationRole uor = new UserOrganisationRole(uo, (Role) userManagementService.findById(
+ Role.class, roleId));
+ userManagementService.save(uor);
}
+ }
+ LoginRequestServlet.log.debug("Session Id - " + hses.getId());
+ // connect to DB and get password here
+ String pass = getUserPassword(userMap.getUser().getLogin());
+ // should post the parameters back so it's little more secure,
+ // but forward doesn't work, use this until a better method is found
+ hses.setAttribute("extUser", login);
+ hses.setAttribute(AttributeNames.USER, user.getUserDTO());
+ response.sendRedirect("j_security_check?j_username=" + login + "&j_password=" + pass);
+ } catch (AuthenticationException e) {
+ LoginRequestServlet.log.error("Authentication error: ", e);
+ response.sendError(HttpServletResponse.SC_UNAUTHORIZED, "Login Failed - authentication error");
+ } catch (UserInfoFetchException e) {
+ LoginRequestServlet.log.error("User fetch info error: ", e);
+ response.sendError(HttpServletResponse.SC_BAD_GATEWAY,
+ "Login Failed - failed to fetch user info from the third party server");
+ } catch (FailedLoginException e) {
+ LoginRequestServlet.log.error("Login error: ", e);
+ response.sendError(HttpServletResponse.SC_UNAUTHORIZED, "Login Failed - user was not found");
+ } catch (NamingException e) {
+ LoginRequestServlet.log.error("Naming error: ", e);
+ response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, e.getMessage());
+ } catch (SQLException e) {
+ LoginRequestServlet.log.error("Database error: ", e);
+ response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, e.getMessage());
}
+ }
- // using JDBC connection to prevent the caching of passwords by hibernate
- private String getUserPassword(String username) throws FailedLoginException, NamingException, SQLException {
- InitialContext ctx = new InitialContext();
+ // using JDBC connection to prevent the caching of passwords by hibernate
+ private String getUserPassword(String username) throws FailedLoginException, NamingException, SQLException {
+ InitialContext ctx = new InitialContext();
- DataSource ds = (DataSource) ctx.lookup(JNDI_DATASOURCE);
- Connection conn = null;
- String password = null;
- try {
- conn = ds.getConnection();
- PreparedStatement ps = conn.prepareStatement(PASSWORD_QUERY);
- ps.setString(1, username);
- ResultSet rs = ps.executeQuery();
+ DataSource ds = (DataSource) ctx.lookup(LoginRequestServlet.JNDI_DATASOURCE);
+ Connection conn = null;
+ String password = null;
+ try {
+ conn = ds.getConnection();
+ PreparedStatement ps = conn.prepareStatement(LoginRequestServlet.PASSWORD_QUERY);
+ ps.setString(1, username);
+ ResultSet rs = ps.executeQuery();
- // check if there is any result
- if (rs.next() == false)
- throw new FailedLoginException("invalid username");
+ // check if there is any result
+ if (rs.next() == false) {
+ throw new FailedLoginException("invalid username");
+ }
- password = rs.getString(1);
- rs.close();
- } finally {
- if (conn != null && !conn.isClosed())
- conn.close();
- }
- return password;
+ password = rs.getString(1);
+ rs.close();
+ } finally {
+ if ((conn != null) && !conn.isClosed()) {
+ conn.close();
+ }
}
+ return password;
+ }
- private IntegrationService getService() {
- if (integrationService == null) {
- integrationService = (IntegrationService) WebApplicationContextUtils.getRequiredWebApplicationContext(
- getServletContext()).getBean("integrationService");
+ private HttpSession recreateSession(HttpServletRequest request, HttpServletResponse response) {
+ HttpSession hses = request.getSession(false);
+ hses.invalidate();
+ hses = request.getSession(true);
+
+ Cookie cookies[] = request.getCookies();
+ if (cookies != null) {
+ for (int i = 0; i < cookies.length; i++) {
+ if (Constants.SINGLE_SIGN_ON_COOKIE.equals(cookies[i].getName())) {
+ Cookie cookie = new Cookie(cookies[i].getName(), "");
+ cookie.setPath("/");
+ cookie.setMaxAge(0);
+ response.addCookie(cookie);
+ break;
}
- return integrationService;
+ }
}
+ return hses;
+ }
+
+ private IntegrationService getService() {
+ if (LoginRequestServlet.integrationService == null) {
+ LoginRequestServlet.integrationService = (IntegrationService) WebApplicationContextUtils
+ .getRequiredWebApplicationContext(getServletContext()).getBean("integrationService");
+ }
+ return LoginRequestServlet.integrationService;
+ }
}
Index: lams_common/src/java/org/lamsfoundation/lams/integration/security/SingleSignOn.java
===================================================================
RCS file: /usr/local/cvsroot/lams_common/src/java/org/lamsfoundation/lams/integration/security/SingleSignOn.java,v
diff -u -r1.3 -r1.4
--- lams_common/src/java/org/lamsfoundation/lams/integration/security/SingleSignOn.java 24 Jan 2008 05:57:21 -0000 1.3
+++ lams_common/src/java/org/lamsfoundation/lams/integration/security/SingleSignOn.java 26 Oct 2011 17:47:34 -0000 1.4
@@ -34,6 +34,7 @@
import org.apache.catalina.connector.Request;
import org.apache.catalina.connector.Response;
import org.apache.log4j.Logger;
+import org.lamsfoundation.lams.web.session.SystemSessionFilter;
/**
*
@@ -110,12 +111,15 @@
request.setAuthType(entry.getAuthType());
request.setUserPrincipal(entry.getPrincipal());
}
- } else {
-// if (log.isDebugEnabled())
-// log.debug(" No cached principal found, erasing SSO cookie");
- cookie.setMaxAge(0);
- response.addCookie(cookie);
- }
+ } else {
+ // if (log.isDebugEnabled())
+ // log.debug(" No cached principal found, erasing SSO cookie");
+ deregister(cookie.getValue());
+ cookie = new Cookie(cookie.getName(), "");
+ cookie.setPath("/");
+ cookie.setMaxAge(0);
+ response.addCookie(cookie);
+ }
// Invoke the next Valve in our pipeline
getNext().invoke(request, response);