2aac0b03cf74fcb94b00eee6c35c6a469d189eaa
[controller.git] / opendaylight / web / root / src / main / java / org / opendaylight / controller / web / ControllerUserDetailsService.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.core.userdetails.UserDetails;
15 import org.springframework.security.core.userdetails.UserDetailsService;
16 import org.springframework.security.core.userdetails.UsernameNotFoundException;
17
18 import org.opendaylight.controller.sal.utils.ServiceHelper;
19 import org.opendaylight.controller.usermanager.IUserManager;
20
21
22 public class ControllerUserDetailsService implements UserDetailsService {
23
24     private static final Logger logger = LoggerFactory
25             .getLogger(ControllerUserDetailsService.class);
26
27     ControllerUserDetailsService() {
28     }
29
30     @Override
31     public UserDetails loadUserByUsername(String username)
32             throws UsernameNotFoundException {
33         return getUserManagerRef().loadUserByUsername(username);
34     }
35
36     private IUserManager getUserManagerRef() {
37         IUserManager userManager = (IUserManager) ServiceHelper
38                 .getGlobalInstance(IUserManager.class, this);
39         if (userManager != null) {
40             return userManager;
41         } else {
42             logger.error("UserManager Ref is null. ");
43             throw new RuntimeException("UserManager Ref is null. ");
44         }
45     }
46
47 }