1 package org
.argeo
.cms
.auth
;
3 import java
.io
.IOException
;
6 import javax
.security
.auth
.Subject
;
7 import javax
.security
.auth
.callback
.Callback
;
8 import javax
.security
.auth
.callback
.CallbackHandler
;
9 import javax
.security
.auth
.callback
.UnsupportedCallbackException
;
10 import javax
.security
.auth
.login
.LoginException
;
11 import javax
.security
.auth
.spi
.LoginModule
;
12 import javax
.servlet
.http
.HttpServletRequest
;
14 import org
.apache
.commons
.logging
.Log
;
15 import org
.apache
.commons
.logging
.LogFactory
;
16 import org
.argeo
.cms
.internal
.kernel
.Activator
;
17 import org
.argeo
.ident
.IdentClient
;
19 public class IdentLoginModule
implements LoginModule
{
20 private final static Log log
= LogFactory
.getLog(IdentLoginModule
.class);
22 private Subject subject
= null;
23 private CallbackHandler callbackHandler
= null;
24 private Map
<String
, Object
> sharedState
= null;
27 public void initialize(Subject subject
, CallbackHandler callbackHandler
, Map
<String
, ?
> sharedState
,
28 Map
<String
, ?
> options
) {
29 this.subject
= subject
;
30 this.callbackHandler
= callbackHandler
;
31 this.sharedState
= (Map
<String
, Object
>) sharedState
;
35 public boolean login() throws LoginException
{
36 if (callbackHandler
== null)
38 HttpRequestCallback httpCallback
= new HttpRequestCallback();
40 callbackHandler
.handle(new Callback
[] { httpCallback
});
41 } catch (IOException e
) {
42 throw new LoginException("Cannot handle http callback: " + e
.getMessage());
43 } catch (UnsupportedCallbackException e
) {
46 HttpServletRequest request
= httpCallback
.getRequest();
47 IdentClient identClient
= Activator
.getIdentClient(request
.getRemoteAddr());
48 if (identClient
== null)
52 identUsername
= identClient
.getUsername(request
.getLocalPort(), request
.getRemotePort());
53 } catch (Exception e
) {
57 if (identUsername
!= null) {
58 if (log
.isDebugEnabled())
59 log
.debug("Ident username: " + identUsername
);
60 sharedState
.put(CmsAuthUtils
.SHARED_STATE_NAME
, identUsername
);
61 sharedState
.put(CmsAuthUtils
.SHARED_STATE_REMOTE_ADDR
, request
.getRemoteAddr());
62 sharedState
.put(CmsAuthUtils
.SHARED_STATE_REMOTE_PORT
, request
.getRemotePort());
70 public boolean commit() throws LoginException
{
75 public boolean abort() throws LoginException
{
80 public boolean logout() throws LoginException
{