Merge "Web UI Branding support This fix provides an extensible branding support with...
[controller.git] / opendaylight / web / root / src / main / java / org / opendaylight / controller / web / 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
10 package org.opendaylight.controller.web;
11
12 import org.slf4j.Logger;
13 import org.slf4j.LoggerFactory;
14 import org.springframework.security.authentication.AuthenticationProvider;
15 import org.springframework.security.core.Authentication;
16 import org.springframework.security.core.AuthenticationException;
17
18 import org.opendaylight.controller.sal.utils.ServiceHelper;
19 import org.opendaylight.controller.usermanager.IUserManager;
20
21
22 public class AuthenticationProviderWrapper implements
23         AuthenticationProvider {
24
25     private static final Logger logger = LoggerFactory
26             .getLogger(AuthenticationProviderWrapper.class);
27
28     @Override
29     public Authentication authenticate(Authentication authentication)
30             throws AuthenticationException {
31         return ((AuthenticationProvider) getUserManagerRef())
32                 .authenticate(authentication);
33     }
34
35     @Override
36     public boolean supports(Class<?> authentication) {
37         return ((AuthenticationProvider) getUserManagerRef())
38                 .supports(authentication);
39     }
40
41     private IUserManager getUserManagerRef() {
42         IUserManager userManager = (IUserManager) ServiceHelper
43                 .getGlobalInstance(IUserManager.class, this);
44         if (userManager != null) {
45             return userManager;
46         } else {
47             logger.error("UserManager Ref is null. ");
48             throw new RuntimeException("UserManager Ref is null. ");
49         }
50     }
51
52 }