mirror of https://github.com/OpenIdentityPlatform/OpenDJ.git

Yannick Lecaillez
18.15.2016 5b7afcc00e450bf639610f27af7a1c3a3562a020
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
/*
 * The contents of this file are subject to the terms of the Common Development and
 * Distribution License (the License). You may not use this file except in compliance with the
 * License.
 *
 * You can obtain a copy of the License at legal/CDDLv1.0.txt. See the License for the
 * specific language governing permission and limitations under the License.
 *
 * When distributing Covered Software, include this CDDL Header Notice in each file and include
 * the License file at legal/CDDLv1.0.txt. If applicable, add the following below the CDDL
 * Header, with the fields enclosed by brackets [] replaced by your own identifying
 * information: "Portions copyright [year] [name of copyright owner]".
 *
 * Copyright 2016 ForgeRock AS.
 */
package org.forgerock.opendj.rest2ldap.authz;
 
import org.forgerock.opendj.ldap.ConnectionFactory;
import org.forgerock.opendj.ldap.DN;
import org.forgerock.opendj.ldap.SearchScope;
import org.forgerock.opendj.ldap.schema.Schema;
 
 
/**
 * Factory methods of {@link AuthenticationStrategy} allowing to perform authentication against LDAP server through
 * different method.
 */
public final class AuthenticationStrategies {
 
    private AuthenticationStrategies() {
    }
 
    /**
     * Creates an {@link AuthenticationStrategy} performing simple BIND authentication against an LDAP server.
     *
     * @param connectionFactory
     *            {@link ConnectionFactory} to the LDAP server used to perform the bind operation.
     * @param bindDNTemplate
     *            Tempalte of the DN to use for the bind operation. The first %s will be replaced by the provided
     *            authentication-id (i.e: uid=%s,dc=example,dc=com)
     * @param schema
     *            {@link Schema} used to validate the DN format.*
     * @return a new simple bind {@link AuthenticationStrategy}
     * @throws NullPointerException
     *             If a parameter is null
     */
    public static AuthenticationStrategy newSimpleBindStrategy(ConnectionFactory connectionFactory,
            String bindDNTemplate, Schema schema) {
        return new SimpleBindStrategy(connectionFactory, bindDNTemplate, schema);
    }
 
    /**
     * Creates an {@link AuthenticationStrategy} performing authentication against an LDAP server by first performing a
     * lookup of the entry to bind with. This is to find the user DN to bind with from its metadata (i.e: email
     * address).
     *
     * @param searchConnectionFactory
     *            {@link ConnectionFactory} to the LDAP server used to perform the lookup of the entry.
     * @param bindConnectionFactory
     *            {@link ConnectionFactory} to the LDAP server used to perform the bind one the user's DN has been
     *            found. Can be the same than the searchConnectionFactory.
     * @param baseDN
     *            Base DN of the search request performed to find the user's DN.
     * @param searchScope
     *            {@link SearchScope} of the search request performed to find the user's DN.
     * @param filterTemplate
     *            Filter of the search request (i.e: (&(email=%s)(objectClass=inetOrgPerson)) where the first %s will be
     *            replaced by the user's provided authentication-id.
     * @return a new search then bind {@link AuthenticationStrategy}
     * @throws NullPointerException
     *             If a parameter is null
     */
    public static AuthenticationStrategy newSearchThenBindStrategy(ConnectionFactory searchConnectionFactory,
            ConnectionFactory bindConnectionFactory, DN baseDN, SearchScope searchScope, String filterTemplate) {
        return new SearchThenBindStrategy(searchConnectionFactory, bindConnectionFactory, baseDN, searchScope,
                filterTemplate);
    }
 
    /**
     * Creates an {@link AuthenticationStrategy} performing authentication against an LDAP server using a plain SASL
     * bind request.
     *
     * @param connectionFactory
     *            {@link ConnectionFactory} to the LDAP server to authenticate with.
     * @param authcIdTemplate
     *            Authentication identity template containing a single %s which will be replaced by the authenticating
     *            user's name. (i.e: (u:%s)
     * @param schema
     *            Schema used to perform DN validation.
     * @return a new SASL plain bind {@link AuthenticationStrategy}
     * @throws NullPointerException
     *             If a parameter is null
     */
    public static AuthenticationStrategy newSASLPlainStrategy(ConnectionFactory connectionFactory, Schema schema,
            String authcIdTemplate) {
        return new SASLPlainStrategy(connectionFactory, schema, authcIdTemplate);
    }
}