keycloak-service
公開メンバ関数 | 非公開メンバ関数 | 非公開変数類 | 全メンバ一覧
org.keycloak.authentication.authenticators.x509.CertificateValidator.CRLFileLoader クラス
org.keycloak.authentication.authenticators.x509.CertificateValidator.CRLFileLoader の継承関係図
Inheritance graph
org.keycloak.authentication.authenticators.x509.CertificateValidator.CRLFileLoader 連携図
Collaboration graph

公開メンバ関数

 CRLFileLoader (String cRLPath)
 
 CRLFileLoader (String cRLPath, LdapContext ldapContext)
 
Collection< X509CRL > getX509CRLs () throws GeneralSecurityException
 

非公開メンバ関数

Collection< X509CRL > loadFromURI (CertificateFactory cf, URI remoteURI) throws GeneralSecurityException
 
Collection< X509CRL > loadCRLFromLDAP (CertificateFactory cf, URI remoteURI) throws GeneralSecurityException
 
Collection< X509CRL > loadCRLFromFile (CertificateFactory cf, String relativePath) throws GeneralSecurityException
 
X509CRL loadFromStream (CertificateFactory cf, InputStream is) throws IOException, CRLException
 

非公開変数類

final String cRLPath
 
final LdapContext ldapContext
 

詳解

構築子と解体子

◆ CRLFileLoader() [1/2]

org.keycloak.authentication.authenticators.x509.CertificateValidator.CRLFileLoader.CRLFileLoader ( String  cRLPath)
inline
206  {
207  this.cRLPath = cRLPath;
208  ldapContext = new LdapContext();
209  }
final LdapContext ldapContext
Definition: CertificateValidator.java:204
final String cRLPath
Definition: CertificateValidator.java:203

◆ CRLFileLoader() [2/2]

org.keycloak.authentication.authenticators.x509.CertificateValidator.CRLFileLoader.CRLFileLoader ( String  cRLPath,
LdapContext  ldapContext 
)
inline
211  {
212  this.cRLPath = cRLPath;
213  this.ldapContext = ldapContext;
214 
215  if (ldapContext == null)
216  throw new NullPointerException("Context cannot be null");
217  }
final LdapContext ldapContext
Definition: CertificateValidator.java:204
final String cRLPath
Definition: CertificateValidator.java:203

関数詳解

◆ getX509CRLs()

Collection<X509CRL> org.keycloak.authentication.authenticators.x509.CertificateValidator.CRLFileLoader.getX509CRLs ( ) throws GeneralSecurityException
inline
218  {
219  CertificateFactory cf = CertificateFactory.getInstance("X.509");
220  Collection<X509CRL> crlColl = null;
221 
222  if (cRLPath != null) {
223  if (cRLPath.startsWith("http") || cRLPath.startsWith("https")) {
224  // load CRL using remote URI
225  try {
226  crlColl = loadFromURI(cf, new URI(cRLPath));
227  } catch (URISyntaxException e) {
228  logger.error(e.getMessage());
229  }
230  } else if (cRLPath.startsWith("ldap")) {
231  // load CRL from LDAP
232  try {
233  crlColl = loadCRLFromLDAP(cf, new URI(cRLPath));
234  } catch(URISyntaxException e) {
235  logger.error(e.getMessage());
236  }
237  } else {
238  // load CRL from file
239  crlColl = loadCRLFromFile(cf, cRLPath);
240  }
241  }
242  if (crlColl == null || crlColl.size() == 0) {
243  String message = String.format("Unable to load CRL from \"%s\"", cRLPath);
244  throw new GeneralSecurityException(message);
245  }
246  return crlColl;
247  }
Collection< X509CRL > loadCRLFromLDAP(CertificateFactory cf, URI remoteURI)
Definition: CertificateValidator.java:266
Collection< X509CRL > loadFromURI(CertificateFactory cf, URI remoteURI)
Definition: CertificateValidator.java:249
static final ServicesLogger logger
Definition: CertificateValidator.java:63
final String cRLPath
Definition: CertificateValidator.java:203
Collection< X509CRL > loadCRLFromFile(CertificateFactory cf, String relativePath)
Definition: CertificateValidator.java:294

◆ loadCRLFromFile()

Collection<X509CRL> org.keycloak.authentication.authenticators.x509.CertificateValidator.CRLFileLoader.loadCRLFromFile ( CertificateFactory  cf,
String  relativePath 
) throws GeneralSecurityException
inlineprivate
294  {
295  try {
296  String configDir = System.getProperty("jboss.server.config.dir");
297  if (configDir != null) {
298  File f = new File(configDir + File.separator + relativePath);
299  if (f.isFile()) {
300  logger.debugf("Loading CRL from %s", f.getAbsolutePath());
301 
302  if (!f.canRead()) {
303  throw new IOException(String.format("Unable to read CRL from \"%s\"", f.getAbsolutePath()));
304  }
305  X509CRL crl = loadFromStream(cf, new FileInputStream(f.getAbsolutePath()));
306  return Collections.singleton(crl);
307  }
308  }
309  }
310  catch(IOException ex) {
311  logger.errorf(ex.getMessage());
312  }
313  return Collections.emptyList();
314  }
static final ServicesLogger logger
Definition: CertificateValidator.java:63
X509CRL loadFromStream(CertificateFactory cf, InputStream is)
Definition: CertificateValidator.java:315

◆ loadCRLFromLDAP()

Collection<X509CRL> org.keycloak.authentication.authenticators.x509.CertificateValidator.CRLFileLoader.loadCRLFromLDAP ( CertificateFactory  cf,
URI  remoteURI 
) throws GeneralSecurityException
inlineprivate
266  {
267  Hashtable<String, String> env = new Hashtable<>(2);
268  env.put(Context.INITIAL_CONTEXT_FACTORY, ldapContext.getLdapFactoryClassName());
269  env.put(Context.PROVIDER_URL, remoteURI.toString());
270 
271  try {
272  DirContext ctx = new InitialDirContext(env);
273  try {
274  Attributes attrs = ctx.getAttributes("");
275  Attribute cRLAttribute = attrs.get("certificateRevocationList;binary");
276  byte[] data = (byte[])cRLAttribute.get();
277  if (data == null || data.length == 0) {
278  throw new CertificateException(String.format("Failed to download CRL from \"%s\"", remoteURI.toString()));
279  }
280  X509CRL crl = loadFromStream(cf, new ByteArrayInputStream(data));
281  return Collections.singleton(crl);
282  } finally {
283  ctx.close();
284  }
285  } catch (NamingException e) {
286  logger.error(e.getMessage());
287  } catch(IOException e) {
288  logger.error(e.getMessage());
289  }
290 
291  return Collections.emptyList();
292  }
final LdapContext ldapContext
Definition: CertificateValidator.java:204
static final ServicesLogger logger
Definition: CertificateValidator.java:63
X509CRL loadFromStream(CertificateFactory cf, InputStream is)
Definition: CertificateValidator.java:315
String getLdapFactoryClassName()
Definition: CertificateValidator.java:124

◆ loadFromStream()

X509CRL org.keycloak.authentication.authenticators.x509.CertificateValidator.CRLFileLoader.loadFromStream ( CertificateFactory  cf,
InputStream  is 
) throws IOException, CRLException
inlineprivate
315  {
316  DataInputStream dis = new DataInputStream(is);
317  X509CRL crl = (X509CRL)cf.generateCRL(dis);
318  dis.close();
319  return crl;
320  }

◆ loadFromURI()

Collection<X509CRL> org.keycloak.authentication.authenticators.x509.CertificateValidator.CRLFileLoader.loadFromURI ( CertificateFactory  cf,
URI  remoteURI 
) throws GeneralSecurityException
inlineprivate
249  {
250  try {
251  logger.debugf("Loading CRL from %s", remoteURI.toString());
252 
253  URLConnection conn = remoteURI.toURL().openConnection();
254  conn.setDoInput(true);
255  conn.setUseCaches(false);
256  X509CRL crl = loadFromStream(cf, conn.getInputStream());
257  return Collections.singleton(crl);
258  }
259  catch(IOException ex) {
260  logger.errorf(ex.getMessage());
261  }
262  return Collections.emptyList();
263 
264  }
static final ServicesLogger logger
Definition: CertificateValidator.java:63
X509CRL loadFromStream(CertificateFactory cf, InputStream is)
Definition: CertificateValidator.java:315

メンバ詳解

◆ cRLPath

final String org.keycloak.authentication.authenticators.x509.CertificateValidator.CRLFileLoader.cRLPath
private

◆ ldapContext

final LdapContext org.keycloak.authentication.authenticators.x509.CertificateValidator.CRLFileLoader.ldapContext
private

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