com.swordcode.webcore.security.server.SecurityService.java Source code

Java tutorial

Introduction

Here is the source code for com.swordcode.webcore.security.server.SecurityService.java

Source

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package com.swordcode.webcore.security.server;

import com.google.gwt.thirdparty.guava.common.util.concurrent.FutureCallback;
import org.springframework.scheduling.annotation.Async;
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
import org.springframework.security.core.Authentication;
import org.springframework.stereotype.Service;

/**
 *
 * @author euclidesflores
 */
@Service
public class SecurityService {
    private final SecurityConfig _config;

    public SecurityService(SecurityConfig config) {
        _config = config;
    }

    @Async
    public void signIn(String username, String password, FutureCallback<Authentication> callback) {
        try {
            Authentication request = new UsernamePasswordAuthenticationToken(username, password);
            Authentication result = _config.getAuthenticationManager().authenticate(request);
            callback.onSuccess(result);
        } catch (Throwable t) {
            callback.onFailure(t);
        }
    }
}