]> git.argeo.org Git - lgpl/argeo-commons.git/blob - org.argeo.cms/src/org/argeo/cms/CmsLogin.java
Clean up code
[lgpl/argeo-commons.git] / org.argeo.cms / src / org / argeo / cms / CmsLogin.java
1 package org.argeo.cms;
2
3 import javax.security.auth.Subject;
4 import javax.security.auth.login.LoginContext;
5 import javax.security.auth.login.LoginException;
6
7 import org.apache.commons.logging.Log;
8 import org.apache.commons.logging.LogFactory;
9 import org.argeo.ArgeoException;
10 import org.argeo.cms.auth.ArgeoLoginContext;
11 import org.argeo.security.NodeAuthenticationToken;
12 import org.springframework.security.authentication.AuthenticationManager;
13 import org.springframework.security.core.Authentication;
14 import org.springframework.security.core.context.SecurityContextHolder;
15
16 /** Gateway for user login, can also generate the related UI. */
17 public class CmsLogin {
18 private final static Log log = LogFactory.getLog(CmsLogin.class);
19 private AuthenticationManager authenticationManager;
20
21 // private String systemKey = KernelConstants.DEFAULT_SECURITY_KEY;
22
23 public void logInAsAnonymous() {
24 Subject subject = new Subject();
25 final LoginContext loginContext;
26 try {
27 loginContext = new ArgeoLoginContext(
28 KernelHeader.LOGIN_CONTEXT_ANONYMOUS, subject);
29 loginContext.login();
30 } catch (LoginException e1) {
31 throw new ArgeoException("Cannot authenticate anonymous", e1);
32 }
33 }
34
35 public void logInWithPassword(String username, char[] password) {
36 NodeAuthenticationToken token = new NodeAuthenticationToken(username,
37 password);
38 Authentication authentication = authenticationManager
39 .authenticate(token);
40 SecurityContextHolder.getContext().setAuthentication(authentication);
41 // HttpSession httpSession = RWT.getRequest().getSession();
42 // httpSession.setAttribute(SPRING_SECURITY_CONTEXT_KEY,
43 // SecurityContextHolder.getContext());
44 if (log.isDebugEnabled())
45 log.debug("Authenticated as " + authentication);
46 }
47
48 public void setAuthenticationManager(
49 AuthenticationManager authenticationManager) {
50 this.authenticationManager = authenticationManager;
51 }
52
53 // public void setSystemKey(String systemKey) {
54 // this.systemKey = systemKey;
55 // }
56
57 }