rspec/rules/S4433/java/rule.adoc

82 lines
1.9 KiB
Plaintext
Raw Permalink Normal View History

include::../common/rationale.adoc[]
== Why is this an issue?
include::../common/description.adoc[]
=== What is the potential impact?
include::../common/impact.adoc[]
== How to fix it
=== Code examples
2020-06-30 12:49:37 +02:00
include::../common/fix/code-rationale.adoc[]
2020-06-30 12:49:37 +02:00
==== Noncompliant code example
[source,java,diff-id=1,diff-type=noncompliant]
2020-06-30 12:49:37 +02:00
----
// Set up the environment for creating the initial context
Hashtable<String, Object> env = new Hashtable<String, Object>();
env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
env.put(Context.PROVIDER_URL, "ldap://localhost:389/o=JNDITutorial");
// Use anonymous authentication
env.put(Context.SECURITY_AUTHENTICATION, "none"); // Noncompliant
// Create the initial context
DirContext ctx = new InitialDirContext(env);
----
==== Compliant solution
[source,java,diff-id=1,diff-type=compliant]
2020-06-30 12:49:37 +02:00
----
// Set up the environment for creating the initial context
Hashtable<String, Object> env = new Hashtable<String, Object>();
env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
env.put(Context.PROVIDER_URL, "ldap://localhost:389/o=Example");
2020-06-30 12:49:37 +02:00
// Use simple authentication
env.put(Context.SECURITY_AUTHENTICATION, "simple");
env.put(Context.SECURITY_PRINCIPAL, "cn=local, ou=Unit, o=Example");
2020-06-30 12:49:37 +02:00
env.put(Context.SECURITY_CREDENTIALS, getLDAPPassword());
// Create the initial context
DirContext ctx = new InitialDirContext(env);
----
//=== How does this work?
//=== Pitfalls
//=== Going the extra mile
== Resources
//=== Documentation
include::../common/resources/documentation.adoc[]
//=== Articles & blog posts
//=== Conference presentations
//=== Standards
include::../common/resources/standards.adoc[]
//=== Benchmarks
ifdef::env-github,rspecator-view[]
'''
== Implementation Specification
(visible only on this page)
include::../message.adoc[]
include::../highlighting.adoc[]
endif::env-github,rspecator-view[]