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 /** Use an ident service to identify. */
20 public class IdentLoginModule
implements LoginModule
{
21 private final static Log log
= LogFactory
.getLog(IdentLoginModule
.class);
23 private CallbackHandler callbackHandler
= null;
24 private Map
<String
, Object
> sharedState
= null;
26 @SuppressWarnings("unchecked")
28 public void initialize(Subject subject
, CallbackHandler callbackHandler
, Map
<String
, ?
> sharedState
,
29 Map
<String
, ?
> options
) {
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();
49 IdentClient identClient
= Activator
.getIdentClient(request
.getRemoteAddr());
50 if (identClient
== null)
54 identUsername
= identClient
.getUsername(request
.getLocalPort(), request
.getRemotePort());
55 } catch (Exception e
) {
59 if (identUsername
!= null) {
60 if (log
.isDebugEnabled())
61 log
.debug("Ident username: " + identUsername
+ " (local port: " + request
.getLocalPort()
62 + ", remote port: " + request
.getRemotePort() + ")");
63 sharedState
.put(CmsAuthUtils
.SHARED_STATE_NAME
, identUsername
);
64 sharedState
.put(CmsAuthUtils
.SHARED_STATE_REMOTE_ADDR
, request
.getRemoteAddr());
65 sharedState
.put(CmsAuthUtils
.SHARED_STATE_REMOTE_PORT
, request
.getRemotePort());
73 public boolean commit() throws LoginException
{
78 public boolean abort() throws LoginException
{
83 public boolean logout() throws LoginException
{