keycloak-federation
公開メンバ関数 | 限定公開メンバ関数 | 非公開メンバ関数 | 非公開変数類 | 静的非公開変数類 | 全メンバ一覧
org.jvnet.libpam.PAM クラス
org.jvnet.libpam.PAM 連携図
Collaboration graph

公開メンバ関数

 PAM (String serviceName) throws PAMException
 
UnixUser authenticate (String username, String... factors) throws PAMException
 
Set< String > getGroupsOfUser (String username) throws PAMException
 
void dispose ()
 

限定公開メンバ関数

void finalize () throws Throwable
 

非公開メンバ関数

void check (int ret, String msg) throws PAMException
 

非公開変数類

pam_handle_t pht
 
int ret
 
String [] factors
 

静的非公開変数類

static final Logger LOGGER = Logger.getLogger(PAM.class.getName())
 

詳解

PAM authenticator.

Instances are thread unsafe and non reentrant. An instace cannot be reused to authenticate multiple users.

For an overview of PAM programming, refer to the following resources:

著者
Kohsuke Kawaguchi

構築子と解体子

◆ PAM()

org.jvnet.libpam.PAM.PAM ( String  serviceName) throws PAMException
inline

Creates a new authenticator.

引数
serviceNamePAM service name. This corresponds to the service name that shows up in the PAM configuration,
79  {
80  pam_conv conv = new pam_conv(new PamCallback() {
81  public int callback(int num_msg, Pointer msg, Pointer resp, Pointer _) {
82  LOGGER.debug("pam_conv num_msg=" + num_msg);
83  if (factors == null)
84  return PAM_CONV_ERR;
85 
86  // allocates pam_response[num_msg]. the caller will free this
87  Pointer m = libc.calloc(pam_response.SIZE, num_msg);
88  resp.setPointer(0, m);
89 
90  for (int i = 0; i < factors.length; i++) {
91  pam_message pm = new pam_message(msg.getPointer(POINTER_SIZE * i));
92  LOGGER.debug(pm.msg_style + ":" + pm.msg);
93  if (pm.msg_style == PAM_PROMPT_ECHO_OFF) {
94  pam_response r = new pam_response(m.share(pam_response.SIZE * i));
95  r.setResp(factors[i]);
96  r.write(); // write to (*resp)[i]
97  }
98  }
99 
100  return PAM_SUCCESS;
101  }
102  });
103 
104  PointerByReference phtr = new PointerByReference();
105  check(libpam.pam_start(serviceName, null, conv, phtr), "pam_start failed");
106  pht = new pam_handle_t(phtr.getValue());
107  }
void check(int ret, String msg)
Definition: PAM.java:109
static final Logger LOGGER
Definition: PAM.java:187
String [] factors
Definition: PAM.java:71
pam_handle_t pht
Definition: PAM.java:64

関数詳解

◆ authenticate()

UnixUser org.jvnet.libpam.PAM.authenticate ( String  username,
String...  factors 
) throws PAMException
inline

Authenticate the user with a password.

戻り値
Upon a successful authentication, return information about the user.
例外
PAMExceptionIf the authentication fails.
125  {
126  this.factors = factors;
127  try {
128  check(libpam.pam_set_item(pht, PAM_USER, username), "pam_set_item failed");
129  check(libpam.pam_authenticate(pht, 0), "pam_authenticate failed");
130  check(libpam.pam_setcred(pht, 0), "pam_setcred failed");
131  // several different error code seem to be used to represent authentication failures
132  check(libpam.pam_acct_mgmt(pht,0),"pam_acct_mgmt failed");
133 
134  PointerByReference r = new PointerByReference();
135  check(libpam.pam_get_item(pht, PAM_USER, r), "pam_get_item failed");
136  String userName = r.getValue().getString(0);
137  passwd pwd = libc.getpwnam(userName);
138  if (pwd == null)
139  throw new PAMException("Authentication succeeded but no user information is available");
140  return new UnixUser(userName, pwd);
141  } finally {
142  this.factors = null;
143  }
144  }
void check(int ret, String msg)
Definition: PAM.java:109
String [] factors
Definition: PAM.java:71
pam_handle_t pht
Definition: PAM.java:64

◆ check()

void org.jvnet.libpam.PAM.check ( int  ret,
String  msg 
) throws PAMException
inlineprivate
109  {
110  this.ret = ret;
111  if (ret != 0) {
112  if (pht != null)
113  throw new PAMException(msg + " : " + libpam.pam_strerror(pht, ret));
114  else
115  throw new PAMException(msg);
116  }
117  }
pam_handle_t pht
Definition: PAM.java:64
int ret
Definition: PAM.java:65

◆ dispose()

void org.jvnet.libpam.PAM.dispose ( )
inline

After a successful authentication, call this method to obtain the effective user name. This can be different from the user name that you passed to the authenticate(String, String) method. Performs an early disposal of the object, instead of letting this GC-ed. Since PAM may hold on to native resources that don't put pressure on Java GC, doing this is a good idea.

This method is called by finalize(), too, so it's not required to call this method explicitly, however.

173  {
174  if (pht != null) {
175  libpam.pam_end(pht, ret);
176  pht = null;
177  }
178  }
pam_handle_t pht
Definition: PAM.java:64
int ret
Definition: PAM.java:65

◆ finalize()

void org.jvnet.libpam.PAM.finalize ( ) throws Throwable
inlineprotected
182  {
183  super.finalize();
184  dispose();
185  }
void dispose()
Definition: PAM.java:173

◆ getGroupsOfUser()

Set<String> org.jvnet.libpam.PAM.getGroupsOfUser ( String  username) throws PAMException
inline

Returns the groups a user belongs to

引数
username
戻り値
Set of group names
例外
PAMException
非推奨:
Pointless and ugly convenience method.
154  {
155  return new UnixUser(username).getGroups();
156  }

メンバ詳解

◆ factors

String [] org.jvnet.libpam.PAM.factors
private

Temporarily stored to pass a value from authenticate(String, String...) to pam_conv.

◆ LOGGER

final Logger org.jvnet.libpam.PAM.LOGGER = Logger.getLogger(PAM.class.getName())
staticprivate

◆ pht

pam_handle_t org.jvnet.libpam.PAM.pht
private

◆ ret

int org.jvnet.libpam.PAM.ret
private

このクラス詳解は次のファイルから抽出されました: