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
;
13 import org
.argeo
.api
.cms
.CmsLog
;
14 import org
.argeo
.cms
.auth
.ident
.IdentClient
;
15 import org
.argeo
.cms
.internal
.runtime
.CmsStateImpl
;
17 /** Use an ident service to identify. */
18 public class IdentLoginModule
implements LoginModule
{
19 private final static CmsLog log
= CmsLog
.getLog(IdentLoginModule
.class);
21 private CallbackHandler callbackHandler
= null;
22 private Map
<String
, Object
> sharedState
= null;
24 @SuppressWarnings("unchecked")
26 public void initialize(Subject subject
, CallbackHandler callbackHandler
, Map
<String
, ?
> sharedState
,
27 Map
<String
, ?
> options
) {
28 this.callbackHandler
= callbackHandler
;
29 this.sharedState
= (Map
<String
, Object
>) sharedState
;
33 public boolean login() throws LoginException
{
34 if (callbackHandler
== null)
36 RemoteAuthCallback httpCallback
= new RemoteAuthCallback();
38 callbackHandler
.handle(new Callback
[] { httpCallback
});
39 } catch (IOException e
) {
40 throw new LoginException("Cannot handle http callback: " + e
.getMessage());
41 } catch (UnsupportedCallbackException e
) {
44 RemoteAuthRequest request
= httpCallback
.getRequest();
47 IdentClient identClient
= CmsStateImpl
.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
+ " (local port: " + request
.getLocalPort()
60 + ", remote port: " + request
.getRemotePort() + ")");
61 sharedState
.put(CmsAuthUtils
.SHARED_STATE_NAME
, identUsername
);
62 sharedState
.put(CmsAuthUtils
.SHARED_STATE_REMOTE_ADDR
, request
.getRemoteAddr());
63 sharedState
.put(CmsAuthUtils
.SHARED_STATE_REMOTE_PORT
, request
.getRemotePort());
71 public boolean commit() throws LoginException
{
76 public boolean abort() throws LoginException
{
81 public boolean logout() throws LoginException
{