3 import javax
.security
.auth
.Subject
;
4 import javax
.security
.auth
.login
.LoginContext
;
5 import javax
.security
.auth
.login
.LoginException
;
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
;
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
;
21 // private String systemKey = KernelConstants.DEFAULT_SECURITY_KEY;
23 public void logInAsAnonymous() {
24 Subject subject
= new Subject();
25 final LoginContext loginContext
;
27 loginContext
= new ArgeoLoginContext(
28 KernelHeader
.LOGIN_CONTEXT_ANONYMOUS
, subject
);
30 } catch (LoginException e1
) {
31 throw new ArgeoException("Cannot authenticate anonymous", e1
);
35 public void logInWithPassword(String username
, char[] password
) {
36 NodeAuthenticationToken token
= new NodeAuthenticationToken(username
,
38 Authentication authentication
= authenticationManager
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
);
48 public void setAuthenticationManager(
49 AuthenticationManager authenticationManager
) {
50 this.authenticationManager
= authenticationManager
;
53 // public void setSystemKey(String systemKey) {
54 // this.systemKey = systemKey;