class SAMLUserDetailsServiceImpl implements SAMLUserDetailsService {

    @Override
    public UserContext loadUserBySAML(SAMLCredential credential) {
        final String userName = credential.getNameID().getValue().toUpperCase();
        final List<String> groups = readAuthorities(credential);
        final Map<String, String> attributes = readAttributes(credential);
        final UserContext userContext = Optional.ofNullable(userManager.loadUserByName(userName))
            .map(loadedUser -> processRegisteredUser(userName, groups, attributes, loadedUser))
            .orElseGet(() -> processNewUser(userName, groups, attributes));
        accessService.validateUserGroupsBlockStatus(userContext.toPipelineUser());
        if (hasBlockedStatusAttribute(credential)) {
            Optional.ofNullable(userContext.getUserId())
                    .ifPresent(id -> userManager.updateUserBlockingStatus(id, true));
            accessService.throwUserIsBlocked(userName);
        }
        LOGGER.info("Successfully authenticate user: " + userContext.getUsername());
        return userContext;
    }

}