2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 - 2018 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
21 package org.onap.so.security;
23 import org.springframework.boot.context.properties.ConfigurationProperties;
24 import org.springframework.security.core.userdetails.User;
25 import org.springframework.security.core.userdetails.UserDetails;
26 import org.springframework.security.core.userdetails.UserDetailsService;
27 import org.springframework.security.core.userdetails.UsernameNotFoundException;
28 import java.util.List;
30 @ConfigurationProperties(prefix = "spring.security")
31 public class UserDetailsServiceImpl implements UserDetailsService {
33 private List<UserCredentials> usercredentials;
35 public List<UserCredentials> getUsercredentials() {
36 return usercredentials;
39 public void setUsercredentials(List<UserCredentials> usercredentials) {
40 this.usercredentials = usercredentials;
44 public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
46 for (int i = 0; usercredentials != null && i < usercredentials.size(); i++) {
47 if (usercredentials.get(i).getUsername().equals(username)) {
48 return User.withUsername(username).password(usercredentials.get(i).getPassword())
49 .roles(usercredentials.get(i).getRole()).build();
53 throw new UsernameNotFoundException("User not found, username: " + username);