X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=blobdiff_plain;f=opendaylight%2Fadsal%2Fsecurity%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fsecurity%2FControllerCustomRealm.java;fp=opendaylight%2Fadsal%2Fsecurity%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fsecurity%2FControllerCustomRealm.java;h=0000000000000000000000000000000000000000;hp=157909424bb152dab343c15905d9675eb91712fb;hb=50f88249a65c52ba56a48852b71ce432fed2bbeb;hpb=abfa9a03550cbe9fccc4420684dced175dd6d119;ds=sidebyside diff --git a/opendaylight/adsal/security/src/main/java/org/opendaylight/controller/security/ControllerCustomRealm.java b/opendaylight/adsal/security/src/main/java/org/opendaylight/controller/security/ControllerCustomRealm.java deleted file mode 100644 index 157909424b..0000000000 --- a/opendaylight/adsal/security/src/main/java/org/opendaylight/controller/security/ControllerCustomRealm.java +++ /dev/null @@ -1,82 +0,0 @@ -/* - * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0 which accompanies this distribution, - * and is available at http://www.eclipse.org/legal/epl-v10.html - */ -package org.opendaylight.controller.security; - -import java.security.Principal; -import java.util.ArrayList; -import java.util.List; - -import org.apache.catalina.realm.GenericPrincipal; -import org.apache.catalina.realm.RealmBase; -import org.opendaylight.controller.sal.authorization.AuthResultEnum; -import org.opendaylight.controller.sal.authorization.UserLevel; -import org.opendaylight.controller.sal.utils.ServiceHelper; -import org.opendaylight.controller.usermanager.IUserManager; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class ControllerCustomRealm extends RealmBase { - - private static final String name = "ControllerCustomRealm"; - - private static final Logger logger = LoggerFactory - .getLogger(ControllerCustomRealm.class); - - @Override - protected String getName() { - return name; - } - - @Override - protected String getPassword(String username) { - IUserManager userManager = (IUserManager) ServiceHelper - .getGlobalInstance(IUserManager.class, this); - if (userManager != null) { - return userManager.getPassword(username); - } else { - throw new RuntimeException("User Manager reference is null"); - } - } - - @Override - protected Principal getPrincipal(String username) { - IUserManager userManager = (IUserManager) ServiceHelper - .getGlobalInstance(IUserManager.class, this); - if (userManager != null) { - List controllerRoles = new ArrayList(); - for (UserLevel level : userManager.getUserLevels(username)) { - controllerRoles.add(level.toString()); - } - return new GenericPrincipal(username, "", controllerRoles); - } else { - throw new RuntimeException("User Manager reference is null"); - } - } - - @Override - public Principal authenticate(String username, String credentials) { - - IUserManager userManager = (IUserManager) ServiceHelper - .getGlobalInstance(IUserManager.class, this); - if (userManager != null) { - AuthResultEnum result = userManager.authenticate(username, - credentials); - if (result.equals(AuthResultEnum.AUTHOR_PASS) - || result.equals(AuthResultEnum.AUTH_ACCEPT_LOC) - || result.equals(AuthResultEnum.AUTH_ACCEPT)) { - return this.getPrincipal(username); - } else { - logger.debug("Authentication failed for user " + username); - return null; - } - } else { - throw new RuntimeException("User Manager reference is null"); - } - } - -}