001/**
002 * Copyright 2014 Tampere University of Technology, Pori Department
003 * 
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 * 
008 *   http://www.apache.org/licenses/LICENSE-2.0
009 * 
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016package core.tut.pori.users;
017
018import org.springframework.security.core.userdetails.UserDetails;
019import org.springframework.security.core.userdetails.UserDetailsService;
020import org.springframework.security.core.userdetails.UsernameNotFoundException;
021
022import service.tut.pori.users.UserCore;
023
024/**
025 * User details service. This is the main bean used by Spring Security for authenticating the user on REST/servlet call.
026 * 
027 * http://docs.spring.io/spring-security/site/docs/3.2.x/reference/html/ns-config.html
028 *
029 */
030public class CoreUserDetailsService implements UserDetailsService{
031
032  @Override
033  public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
034    UserDetails details = UserCore.getUserIdentity(username);
035    if(details == null){
036      throw new UsernameNotFoundException("The requested user does not exist.");
037    }
038    return details;
039  }
040}