All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.chutneytesting.security.infra.SpringUserService Maven / Gradle / Ivy

There is a newer version: 3.0.0
Show newest version
package com.chutneytesting.security.infra;

import com.chutneytesting.security.api.UserDto;
import com.chutneytesting.security.domain.CurrentUserNotFoundException;
import java.util.Optional;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Component;

@Component
public class SpringUserService {

    public UserDto currentUser() {
        final Optional authentication = Optional.ofNullable(SecurityContextHolder.getContext().getAuthentication());
        return (UserDto) authentication
            .map(Authentication::getPrincipal)
            .orElseThrow(CurrentUserNotFoundException::new);
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy