root / client / src / com / gonnatrak / server / LoginServiceImpl.java @ 1

View | Annotate | Download

1
package com.gonnatrak.server;
2
3
import com.google.gwt.user.server.rpc.RemoteServiceServlet;
4
import com.gonnatrak.client.login.LoginService;
5
import com.gonnatrak.middleware.ejb.UserWorker;
6
import com.gonnatrak.middleware.ejb.SessionWorker;
7
import com.gonnatrak.middleware.util.ServiceLocator;
8
import com.gonnatrak.middleware.entity.User;
9
import com.gonnatrak.client.exception.LoginFailedException;
10
11
/**
12
 * Created by Andrey Khalzov
13
 * 23.12.2008 18:55:53
14
 */
15
public class LoginServiceImpl extends RemoteServiceServlet implements LoginService {
16
17
    public String login(String login, String password) throws LoginFailedException {
18
        final UserWorker userWorker = ServiceLocator.lookup(UserWorker.JNDI_NAME);
19
        final SessionWorker sessionWorker = ServiceLocator.lookup(SessionWorker.JNDI_NAME);
20
21
        final String sessionId = getThreadLocalRequest().getSession().getId();
22
23
        try {
24
            userWorker.loginUser(sessionId, login, password);
25
            final User user = sessionWorker.getUser(sessionId);
26
            if (user == null) {
27
                throw new LoginFailedException();
28
            }
29
            return userWorker.authUser(user);
30
        } catch (com.gonnatrak.middleware.exception.LoginFailedException e) {
31
            throw new LoginFailedException();
32
        }
33
    }
34
35
    public String[] tryToLogin() throws LoginFailedException {
36
        final SessionWorker sessionWorker = ServiceLocator.lookup(SessionWorker.JNDI_NAME);
37
        final UserWorker userWorker = ServiceLocator.lookup(UserWorker.JNDI_NAME);
38
39
        final String sessionId = getThreadLocalRequest().getSession().getId();
40
41
        final User user = sessionWorker.getUser(sessionId);
42
        if (user == null) {
43
            throw new LoginFailedException();
44
        }
45
        return new String[] {user.getDisplayLogin(), userWorker.authUser(user)};
46
    }
47
48
    public void logout() {
49
        final SessionWorker sessionWorker = ServiceLocator.lookup(SessionWorker.JNDI_NAME);
50
        final String sessionId = getThreadLocalRequest().getSession().getId();
51
        sessionWorker.removeSession(sessionId);
52
    }
53
}