+++ /dev/null
-/*\r
- * Copyright 2005, 2008, 2009 Electronic Business Systems Ltd.\r
- *\r
- * This file is part of GSS.\r
- *\r
- * GSS is free software: you can redistribute it and/or modify\r
- * it under the terms of the GNU General Public License as published by\r
- * the Free Software Foundation, either version 3 of the License, or\r
- * (at your option) any later version.\r
- *\r
- * GSS is distributed in the hope that it will be useful,\r
- * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
- * GNU General Public License for more details.\r
- *\r
- * You should have received a copy of the GNU General Public License\r
- * along with GSS. If not, see <http://www.gnu.org/licenses/>.\r
- */\r
-package gr.ebs.gss.server.webdav.login;\r
-\r
-import static gr.ebs.gss.server.configuration.GSSConfigurationFactory.getConfiguration;\r
-import gr.ebs.gss.client.exceptions.RpcException;\r
-import gr.ebs.gss.server.domain.User;\r
-import gr.ebs.gss.server.domain.UserLogin;\r
-import gr.ebs.gss.server.ejb.ExternalAPI;\r
-import gr.ebs.gss.server.ejb.TransactionHelper;\r
-\r
-import java.io.UnsupportedEncodingException;\r
-import java.security.Principal;\r
-import java.security.acl.Group;\r
-import java.util.Date;\r
-import java.util.HashSet;\r
-import java.util.concurrent.Callable;\r
-\r
-import javax.naming.Context;\r
-import javax.naming.InitialContext;\r
-import javax.naming.NamingException;\r
-import javax.rmi.PortableRemoteObject;\r
-import javax.security.auth.login.FailedLoginException;\r
-import javax.security.auth.login.LoginException;\r
-\r
-import org.apache.commons.codec.binary.Base64;\r
-import org.apache.commons.logging.Log;\r
-import org.apache.commons.logging.LogFactory;\r
-import org.jboss.security.auth.spi.UsernamePasswordLoginModule;\r
-\r
-\r
-/**\r
- * The custom login module for the GSS WebDAV implementation.\r
- */\r
-public class GssWebDAVLoginModule extends UsernamePasswordLoginModule {\r
-\r
- /**\r
- * Logger for this class\r
- */\r
- private static final Log logger = LogFactory.getLog(GssWebDAVLoginModule.class);\r
-\r
- /**\r
- * A helper method that retrieves a reference to the ExternalAPI bean and\r
- * stores it for future use.\r
- *\r
- * @return an ExternalAPI instance\r
- * @throws RpcException in case an error occurs\r
- */\r
- private ExternalAPI getService() throws RpcException {\r
- try {\r
- final Context ctx = new InitialContext();\r
- final Object ref = ctx.lookup(getConfiguration().getString("externalApiPath"));\r
- return (ExternalAPI) PortableRemoteObject.narrow(ref, ExternalAPI.class);\r
- } catch (final NamingException e) {\r
- logger.error("Unable to retrieve the ExternalAPI EJB", e);\r
- throw new RpcException("An error occurred while contacting the naming service");\r
- }\r
- }\r
-\r
- @Override\r
- protected String getUsersPassword() throws LoginException {\r
- String username = getUsername();\r
- try {\r
- final User user = getService().findUser(username);\r
- if (user == null) throw new FailedLoginException("User '" + username + "' not found.");\r
- if (!user.isActive()) throw new FailedLoginException("User '" + username + "' is disabled.");\r
- if (user.getWebDAVPassword() != null && user.getWebDAVPassword().length() > 0)\r
- return user.getWebDAVPassword();\r
- // If no password has ever been generated, use token instead\r
- String tokenEncoded = new String(Base64.encodeBase64(user.getAuthToken()), "US-ASCII");\r
- user.setWebDAVPassword(tokenEncoded);\r
- new TransactionHelper<Void>().tryExecute(new Callable<Void>() {\r
- @Override\r
- public Void call() throws Exception {\r
- getService().updateUser(user);\r
- return null;\r
- }\r
- });\r
- return tokenEncoded;\r
- } catch (RpcException e) {\r
- String error = "An error occurred while communicating with the service";\r
- logger.error(error, e);\r
- throw new LoginException(e.getMessage());\r
- } catch (UnsupportedEncodingException e) {\r
- logger.error("", e);\r
- throw new LoginException(e.getMessage());\r
- } catch (Exception e) {\r
- logger.error("", e);\r
- throw new LoginException(e.getMessage());\r
- }\r
- }\r
-\r
- /**\r
- * Overrides parent's implementation by returning only the simpleUser\r
- * role for any successful login.\r
- *\r
- * @return Group[] that contains only the authenticatedUser group (role)\r
- * @throws LoginException\r
- * @see org.jboss.security.auth.spi.AbstractServerLoginModule#getRoleSets()\r
- */\r
- @Override\r
- protected Group[] getRoleSets() throws LoginException {\r
- Principal principal;\r
- try {\r
- principal = createIdentity("simpleUser");\r
- } catch (Exception e) {\r
- logger.error("", e);\r
- throw new LoginException(e.getMessage());\r
- }\r
- Group rolesGroup = null;\r
- rolesGroup = createGroup("Roles", new HashSet());\r
- rolesGroup.addMember(principal);\r
- Group[] roles = new Group[1];\r
- roles[0] = rolesGroup;\r
- // Update the last login.\r
- //TODO: Handle the userlogins via WebDAV\r
-// try {\r
-// new TransactionHelper<Void>().tryExecute(new Callable<Void>() {\r
-// @Override\r
-// public Void call() throws Exception {\r
-// User user = getService().findUser(getUsername());\r
-// UserLogin userLogin = new UserLogin();\r
-// userLogin.setLoginDate(new Date());\r
-// getService().addUserLogin(userLogin);\r
-// getService().updateUser(user);\r
-// return null;\r
-// }\r
-// });\r
-// } catch (Exception e) {\r
-// logger.error("", e);\r
-// throw new LoginException(e.getMessage());\r
-// }\r
- return roles;\r
- }\r
-\r
-}\r