/*
 * This program is part of the OpenLMIS logistics management information system platform software.
 * Copyright © 2017 VillageReach
 *
 * This program is free software: you can redistribute it and/or modify it under the terms
 * of the GNU Affero General Public License as published by the Free Software Foundation, either
 * version 3 of the License, or (at your option) any later version.
 *  
 * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 
 * See the GNU Affero General Public License for more details. You should have received a copy of
 * the GNU Affero General Public License along with this program. If not, see
 * http://www.gnu.org/licenses.  For additional information contact info@OpenLMIS.org. 
 */

package org.openlmis.referencedata.service;

import org.openlmis.referencedata.domain.User;
import org.openlmis.referencedata.exception.NotFoundException;
import org.openlmis.referencedata.repository.UserRepository;
import org.openlmis.referencedata.util.messagekeys.UserMessageKeys;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Component;

import java.util.UUID;

@Component
public class AuthenticationHelper {

  @Autowired
  private UserRepository userRepository;

  /**
   * Method returns current user based on Spring context.
   *
   * @return User entity of current user.
   * @throws NotFoundException if user cannot be found.
   */
  public User getCurrentUser() {
    UUID userId =
        (UUID) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
    User user = userRepository.findOne(userId);

    if (user == null) {
      throw new NotFoundException(UserMessageKeys.ERROR_NOT_FOUND);
    }

    return user;
  }

}

@@ -1321,32 +1321,8 @@
 t;%0A%0A
-import java.util.UUID;%0A%0A
 @Com
@@ -1634,19 +1634,23 @@
     
-UUID
+String
  user
-Id
+name
  =%0A 
@@ -1661,12 +1661,14 @@
    (
-UUID
+String
 ) Se
@@ -1778,15 +1778,27 @@
 dOne
+ByUsername
 (user
-Id
+name
 );%0A%0A

Revert "OLMIS-3135: Authentication principal has type UUID (FEOLMIS-2276)"