ISSUE: Topology does not show Node description as learned by the OFA
[controller.git] / opendaylight / northbound / commons / src / main / java / org / opendaylight / controller / northbound / commons / AuthenticationProviderWrapper.java
1 /*
2  * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8
9 package org.opendaylight.controller.northbound.commons;
10
11 import org.slf4j.Logger;
12 import org.slf4j.LoggerFactory;
13 import org.springframework.security.authentication.AuthenticationProvider;
14 import org.springframework.security.core.Authentication;
15 import org.springframework.security.core.AuthenticationException;
16
17 import org.opendaylight.controller.sal.utils.ServiceHelper;
18 import org.opendaylight.controller.usermanager.IUserManager;
19
20 import org.opendaylight.controller.northbound.commons.exception.InternalServerErrorException;
21
22 public class AuthenticationProviderWrapper implements AuthenticationProvider {
23
24     private static final Logger logger = LoggerFactory
25             .getLogger(AuthenticationProviderWrapper.class);
26
27     @Override
28     public Authentication authenticate(Authentication authentication)
29             throws AuthenticationException {
30         return ((AuthenticationProvider) getUserManagerRef())
31                 .authenticate(authentication);
32     }
33
34     @Override
35     public boolean supports(Class<?> authentication) {
36         return ((AuthenticationProvider) getUserManagerRef())
37                 .supports(authentication);
38     }
39
40     private IUserManager getUserManagerRef() {
41         IUserManager userManager = (IUserManager) ServiceHelper
42                 .getGlobalInstance(IUserManager.class, this);
43         if (userManager != null) {
44             return userManager;
45         } else {
46             logger.error("UserManager Ref is null. ");
47             throw new InternalServerErrorException("UserManager Ref is null. ");
48         }
49     }
50
51 }