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

com.netgrif.application.engine.auth.service.AfterRegistrationAuthService Maven / Gradle / Ivy

Go to download

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

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


import com.netgrif.application.engine.auth.service.interfaces.IAfterRegistrationAuthService;
import lombok.Data;
import org.springframework.security.authentication.AuthenticationDetailsSource;
import org.springframework.security.authentication.ProviderManager;
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.web.authentication.WebAuthenticationDetailsSource;
import org.springframework.security.web.authentication.logout.SecurityContextLogoutHandler;

import javax.servlet.http.HttpServletRequest;

@Data
public class AfterRegistrationAuthService implements IAfterRegistrationAuthService {

    private ProviderManager authenticationManager;
    private final AuthenticationDetailsSource authenticationDetailsSource;

    public AfterRegistrationAuthService(ProviderManager authenticationManager) {
        this.authenticationManager = authenticationManager;
        this.authenticationDetailsSource = new WebAuthenticationDetailsSource();
    }

    @Override
    public void authenticateWithUsernameAndPassword(String username, String password) {
        UsernamePasswordAuthenticationToken authToken = new UsernamePasswordAuthenticationToken(username, password);
        authToken.setDetails(SecurityContextHolder.getContext().getAuthentication().getDetails());
        Authentication authResult = this.authenticationManager.authenticate(authToken);
        SecurityContextHolder.getContext().setAuthentication(authResult);
    }

    @Override
    public void logoutAfterRegistrationFinished() {
        SecurityContextHolder.getContext().setAuthentication(null);
    }


}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy