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

com.netgrif.application.engine.impersonation.service.ImpersonationSessionService Maven / Gradle / Ivy

Go to download

System provides workflow management functions including user, role and data management.

There is a newer version: 6.3.3
Show newest version
package com.netgrif.application.engine.impersonation.service;

import com.netgrif.application.engine.impersonation.domain.repository.ImpersonatorRepository;
import com.netgrif.application.engine.impersonation.service.interfaces.IImpersonationSessionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.session.FindByIndexNameSessionRepository;
import org.springframework.session.Session;
import org.springframework.session.security.SpringSessionBackedSessionRegistry;
import org.springframework.stereotype.Service;

import java.util.Collection;

@Service
public class ImpersonationSessionService implements IImpersonationSessionService {

    protected FindByIndexNameSessionRepository sessions;
    protected SpringSessionBackedSessionRegistry registry;
    protected ImpersonatorRepository impersonatorRepository;

    @Override
    public boolean existsSession(String username) {
        Collection usersSessions = this.sessions.findByPrincipalName(username).values();
        return usersSessions.stream().anyMatch(session -> !registry.getSessionInformation(session.getId()).isExpired());
    }

    @Override
    public boolean isImpersonated(String userId) {
        return impersonatorRepository.findByImpersonatedId(userId).isPresent();
    }

    @Autowired
    @Lazy
    public void setSessions(FindByIndexNameSessionRepository sessions) {
        this.sessions = sessions;
    }

    @Autowired
    @Lazy
    public void setRegistry(SpringSessionBackedSessionRegistry registry) {
        this.registry = registry;
    }

    @Autowired
    @Lazy
    public void setImpersonatorRepository(ImpersonatorRepository impersonatorRepository) {
        this.impersonatorRepository = impersonatorRepository;
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy