6165N/A/*
6165N/A * CDDL HEADER START
6165N/A *
6165N/A * The contents of this file are subject to the terms of the
6165N/A * Common Development and Distribution License, Version 1.0 only
6165N/A * (the "License"). You may not use this file except in compliance
6165N/A * with the License.
6165N/A *
6165N/A * You can obtain a copy of the license at
6165N/A * trunk/opends/resource/legal-notices/OpenDS.LICENSE
6165N/A * or https://OpenDS.dev.java.net/OpenDS.LICENSE.
6165N/A * See the License for the specific language governing permissions
6165N/A * and limitations under the License.
6165N/A *
6165N/A * When distributing Covered Code, include this CDDL HEADER in each
6165N/A * file and include the License file at
6165N/A * trunk/opends/resource/legal-notices/OpenDS.LICENSE. If applicable,
6165N/A * add the following below this CDDL HEADER, with the fields enclosed
6165N/A * by brackets "[]" replaced with your own identifying information:
6165N/A * Portions Copyright [yyyy] [name of copyright owner]
6165N/A *
6165N/A * CDDL HEADER END
6165N/A *
6165N/A *
6165N/A * Copyright 2013 ForgeRock AS
6165N/A */
6165N/Apackage org.opends.server.protocols.http;
6165N/A
6165N/Aimport org.forgerock.opendj.ldap.DN;
6165N/Aimport org.forgerock.opendj.ldap.SearchScope;
6165N/A
6165N/A/**
6165N/A * Class holding the configuration for HTTP authentication. This is extracted
6165N/A * from the JSON config file or the config held in LDAP.
6165N/A */
6165N/Aclass HTTPAuthenticationConfig
6165N/A{
6165N/A
6165N/A private boolean basicAuthenticationSupported;
6165N/A private boolean customHeadersAuthenticationSupported;
6165N/A private String customHeaderUsername;
6165N/A private String customHeaderPassword;
6165N/A private DN searchBaseDN;
6165N/A private SearchScope searchScope;
6165N/A private String searchFilterTemplate;
6165N/A
6165N/A /**
6165N/A * Returns whether HTTP basic authentication is supported.
6165N/A *
6165N/A * @return true if supported, false otherwise
6165N/A */
6165N/A public boolean isBasicAuthenticationSupported()
6165N/A {
6165N/A return basicAuthenticationSupported;
6165N/A }
6165N/A
6165N/A /**
6165N/A * Sets whether HTTP basic authentication is supported.
6165N/A *
6165N/A * @param supported
6165N/A * the supported value
6165N/A */
6165N/A public void setBasicAuthenticationSupported(boolean supported)
6165N/A {
6165N/A this.basicAuthenticationSupported = supported;
6165N/A }
6165N/A
6165N/A /**
6165N/A * Returns whether HTTP authentication via custom headers is supported.
6165N/A *
6165N/A * @return true if supported, false otherwise
6165N/A */
6165N/A public boolean isCustomHeadersAuthenticationSupported()
6165N/A {
6165N/A return customHeadersAuthenticationSupported;
6165N/A }
6165N/A
6165N/A /**
6165N/A * Sets whether HTTP authentication via custom headers is supported.
6165N/A *
6165N/A * @param supported
6165N/A * the supported value
6165N/A */
6165N/A public void setCustomHeadersAuthenticationSupported(boolean supported)
6165N/A {
6165N/A this.customHeadersAuthenticationSupported = supported;
6165N/A }
6165N/A
6165N/A /**
6165N/A * Returns the expected HTTP header for the username. This setting is only
6165N/A * used when HTTP authentication via custom headers is supported.
6165N/A *
6165N/A * @return the HTTP header for the username
6165N/A */
6165N/A public String getCustomHeaderUsername()
6165N/A {
6165N/A return customHeaderUsername;
6165N/A }
6165N/A
6165N/A /**
6165N/A * Sets the expected HTTP header for the username. This setting only takes
6165N/A * effect when HTTP authentication via custom headers is supported.
6165N/A *
6165N/A * @param customHeaderUsername
6165N/A * the HTTP header for the username
6165N/A */
6165N/A public void setCustomHeaderUsername(String customHeaderUsername)
6165N/A {
6165N/A this.customHeaderUsername = customHeaderUsername;
6165N/A }
6165N/A
6165N/A /**
6165N/A * Returns the expected HTTP header for the password. This setting is only
6165N/A * used when HTTP authentication via custom headers is supported.
6165N/A *
6165N/A * @return the HTTP header for the password
6165N/A */
6165N/A public String getCustomHeaderPassword()
6165N/A {
6165N/A return customHeaderPassword;
6165N/A }
6165N/A
6165N/A /**
6165N/A * Sets the expected HTTP header for the password. This setting only takes
6165N/A * effect when HTTP authentication via custom headers is supported.
6165N/A *
6165N/A * @param customHeaderPassword
6165N/A * the HTTP header for the password
6165N/A */
6165N/A public void setCustomHeaderPassword(String customHeaderPassword)
6165N/A {
6165N/A this.customHeaderPassword = customHeaderPassword;
6165N/A }
6165N/A
6165N/A /**
6165N/A * Returns the base DN to use when searching the entry corresponding to the
6165N/A * authenticating user.
6165N/A *
6165N/A * @return the base DN to use when searching the authenticating user
6165N/A */
6165N/A public DN getSearchBaseDN()
6165N/A {
6165N/A return searchBaseDN;
6165N/A }
6165N/A
6165N/A /**
6165N/A * Sets the base DN to use when searching the entry corresponding to the
6165N/A * authenticating user.
6165N/A *
6165N/A * @param searchBaseDN
6165N/A * the base DN to use when searching the authenticating user
6165N/A */
6165N/A public void setSearchBaseDN(DN searchBaseDN)
6165N/A {
6165N/A this.searchBaseDN = searchBaseDN;
6165N/A }
6165N/A
6165N/A /**
6165N/A * Returns the search scope to use when searching the entry corresponding to
6165N/A * the authenticating user.
6165N/A *
6165N/A * @return the search scope to use when searching the authenticating user
6165N/A */
6165N/A public SearchScope getSearchScope()
6165N/A {
6165N/A return searchScope;
6165N/A }
6165N/A
6165N/A /**
6165N/A * Sets the search scope to use when searching the entry corresponding to the
6165N/A * authenticating user.
6165N/A *
6165N/A * @param searchScope
6165N/A * the search scope to use when searching the authenticating user
6165N/A */
6165N/A public void setSearchScope(SearchScope searchScope)
6165N/A {
6165N/A this.searchScope = searchScope;
6165N/A }
6165N/A
6165N/A /**
6165N/A * Returns the search filter template to use when searching the entry
6165N/A * corresponding to the authenticating user.
6165N/A *
6165N/A * @return the search filter template to use when searching the authenticating
6165N/A * user
6165N/A */
6165N/A public String getSearchFilterTemplate()
6165N/A {
6165N/A return searchFilterTemplate;
6165N/A }
6165N/A
6165N/A /**
6165N/A * Sets the search filter template to use when searching the entry
6165N/A * corresponding to the authenticating user.
6165N/A *
6165N/A * @param searchFilterTemplate
6165N/A * the search filter template to use when searching the
6165N/A * authenticating user
6165N/A */
6165N/A public void setSearchFilterTemplate(String searchFilterTemplate)
6165N/A {
6165N/A this.searchFilterTemplate = searchFilterTemplate;
6165N/A }
6165N/A
6165N/A /** {@inheritDoc} */
6165N/A @Override
6165N/A public String toString()
6165N/A {
6165N/A StringBuilder sb = new StringBuilder();
6165N/A sb.append("basicAuth: ");
6165N/A if (!basicAuthenticationSupported)
6165N/A {
6165N/A sb.append("not ");
6165N/A }
6165N/A sb.append("supported, ");
6165N/A sb.append("customHeadersAuth: ");
6165N/A if (customHeadersAuthenticationSupported)
6165N/A {
6165N/A sb.append("usernameHeader=\"").append(customHeaderUsername).append("\",");
6165N/A sb.append("passwordHeader=\"").append(customHeaderPassword).append("\"");
6165N/A }
6165N/A else
6165N/A {
6165N/A sb.append("not supported, ");
6165N/A }
6165N/A sb.append("searchBaseDN: \"").append(searchBaseDN).append("\"");
6165N/A sb.append("searchScope: \"").append(searchScope).append("\"");
6165N/A sb.append("searchFilterTemplate: \"").append(searchFilterTemplate).append(
6165N/A "\"");
6165N/A return sb.toString();
6165N/A }
6165N/A}