diff options
author | Devan Goodwin <dgoodwin@redhat.com> | 2009-11-24 13:36:20 -0400 |
---|---|---|
committer | Devan Goodwin <dgoodwin@redhat.com> | 2009-11-24 13:36:20 -0400 |
commit | 2aa9936d8ac1434a6bc870c0f4779e6785488c71 (patch) | |
tree | 204d82ff1598f022d3dfaac506b6494918be4163 | |
parent | 1b4a97f23cee693d465a04737ed3913194476ffb (diff) | |
download | candlepin-2aa9936d8ac1434a6bc870c0f4779e6785488c71.tar.gz candlepin-2aa9936d8ac1434a6bc870c0f4779e6785488c71.tar.xz candlepin-2aa9936d8ac1434a6bc870c0f4779e6785488c71.zip |
Drop ApiHandler and ApiTest.
Not used.
-rw-r--r-- | proxy/code/src/org/fedoraproject/candlepin/resource/ApiHandler.java | 99 | ||||
-rw-r--r-- | proxy/code/src/org/fedoraproject/candlepin/resource/test/ApiTest.java | 77 |
2 files changed, 0 insertions, 176 deletions
diff --git a/proxy/code/src/org/fedoraproject/candlepin/resource/ApiHandler.java b/proxy/code/src/org/fedoraproject/candlepin/resource/ApiHandler.java deleted file mode 100644 index e1ad297..0000000 --- a/proxy/code/src/org/fedoraproject/candlepin/resource/ApiHandler.java +++ /dev/null @@ -1,99 +0,0 @@ -/** - * Copyright (c) 2009 Red Hat, Inc. - * - * This software is licensed to you under the GNU General Public License, - * version 2 (GPLv2). There is NO WARRANTY for this software, express or - * implied, including the implied warranties of MERCHANTABILITY or FITNESS - * FOR A PARTICULAR PURPOSE. You should have received a copy of GPLv2 - * along with this software; if not, see - * http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt. - * - * Red Hat trademarks are not licensed under GPLv2. No permission is - * granted to use or replicate Red Hat trademarks that are incorporated - * in this software or its documentation. - */ -package org.fedoraproject.candlepin.resource; - -import org.fedoraproject.candlepin.model.BaseModel; -import org.fedoraproject.candlepin.model.ObjectFactory; -import org.fedoraproject.candlepin.model.Owner; -import org.fedoraproject.candlepin.model.User; - -import org.apache.log4j.Logger; - -import java.util.HashSet; -import java.util.Set; -/** - * API gateway for authentication - * TODO: do we still need this? - */ -public class ApiHandler { - - private static ApiHandler instance = new ApiHandler(); - private Set authTokens; - - /** - * Logger for this class - */ - private static Logger logger = Logger.getLogger(ApiHandler.class); - - private ApiHandler() { - authTokens = new HashSet(); - } - - /** - * returns instance of this singleton. - * @return instance of this singleton. - */ - public static ApiHandler get() { - return instance; - } - - /** - * Auth - * @param login username - * @param password password - * @return token - */ - public String login(String login, String password) { - User u = (User) ObjectFactory.get(). - lookupByFieldName(User.class, "login", login); - if (u == null) { - return null; - } - if (u.getPassword().equals(password)) { - String newtoken = BaseModel.generateUUID(); - authTokens.add(newtoken); - return newtoken; - } - else { - return null; - } - } - - private void checkToken(String token) throws AuthenticationException { - if (!authTokens.contains(token)) { - throw new AuthenticationException("token not valid: " + token); - } - } - - /** Owners */ - - /** - * Fetch an owner - * @param authToken token - * @param uuid unique id of owner - * @return owner - */ - public Owner getOwner(String authToken, String uuid) { - checkToken(authToken); - logger.debug("getOrg(String) - start: " + uuid); - Owner retval = (Owner) ObjectFactory.get() - .lookupByUUID(Owner.class, uuid); - if (logger.isDebugEnabled()) { - logger.debug("getOrg(String) - end. returning: " + retval); - } - return retval; - } - -} diff --git a/proxy/code/src/org/fedoraproject/candlepin/resource/test/ApiTest.java b/proxy/code/src/org/fedoraproject/candlepin/resource/test/ApiTest.java deleted file mode 100644 index 5b5b4e9..0000000 --- a/proxy/code/src/org/fedoraproject/candlepin/resource/test/ApiTest.java +++ /dev/null @@ -1,77 +0,0 @@ -/** - * Copyright (c) 2009 Red Hat, Inc. - * - * This software is licensed to you under the GNU General Public License, - * version 2 (GPLv2). There is NO WARRANTY for this software, express or - * implied, including the implied warranties of MERCHANTABILITY or FITNESS - * FOR A PARTICULAR PURPOSE. You should have received a copy of GPLv2 - * along with this software; if not, see - * http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt. - * - * Red Hat trademarks are not licensed under GPLv2. No permission is - * granted to use or replicate Red Hat trademarks that are incorporated - * in this software or its documentation. - */ -package org.fedoraproject.candlepin.resource.test; - -import org.fedoraproject.candlepin.model.BaseModel; -import org.fedoraproject.candlepin.model.ObjectFactory; -import org.fedoraproject.candlepin.model.Owner; -import org.fedoraproject.candlepin.model.User; -import org.fedoraproject.candlepin.resource.ApiHandler; -import org.fedoraproject.candlepin.resource.OwnerResource; - -import org.junit.Test; -import static org.junit.Assert.*; - -/** - * @author mmccune - * - */ -public class ApiTest { - - @Test - public void testAuthentication() throws Exception { - User u = new User(); - u.setLogin("admin"); - u.setPassword("password"); - - ObjectFactory.get().store(u); - - ApiHandler handler = ApiHandler.get(); - String token = handler.login(u.getLogin(), "bad-password"); - assertNull(token); - token = handler.login(u.getLogin(), u.getPassword()); - assertNotNull(token); - } - - @Test - public void testLookupOwner() throws Exception { - Owner o = new Owner(BaseModel.generateUUID()); - ObjectFactory.get().store(o); - - User u = new User(); - u.setLogin("admin"); - u.setPassword("password"); - ObjectFactory.get().store(u); - - String token = ApiHandler.get().login(u.getLogin(), u.getPassword()); - - OwnerResource oapi = new OwnerResource(); - Owner lookedup = (Owner) oapi.get("BAD-UUID-NOTFOUND"); - assertNull(lookedup); - lookedup = ApiHandler.get().getOwner(token, o.getUuid()); - assertNotNull(lookedup); - - // Check bad token - boolean failed = false; - try { - lookedup = ApiHandler.get().getOwner("BAD-TOKEN", o.getUuid()); - } - catch (Exception e) { - failed = true; - } - assertTrue(failed); - - } -} |