| <?xml version="1.0" encoding="UTF-8"?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml" lang="en"><head><meta http-equiv="Content-Type" content="text/html;charset=UTF-8"/><link rel="stylesheet" href="../jacoco-resources/report.css" type="text/css"/><link rel="shortcut icon" href="../jacoco-resources/report.gif" type="image/gif"/><title>HTTPHeaderAuthenticator.java</title><link rel="stylesheet" href="../jacoco-resources/prettify.css" type="text/css"/><script type="text/javascript" src="../jacoco-resources/prettify.js"></script></head><body onload="window['PR_TAB_WIDTH']=4;prettyPrint()"><div class="breadcrumb" id="breadcrumb"><span class="info"><a href="../jacoco-sessions.html" class="el_session">Sessions</a></span><a href="../index.html" class="el_report">jUDDI Core Services</a> > <a href="index.source.html" class="el_package">org.apache.juddi.v3.auth</a> > <span class="el_source">HTTPHeaderAuthenticator.java</span></div><h1>HTTPHeaderAuthenticator.java</h1><pre class="source lang-java linenums">/* |
| * Copyright 2014 The Apache Software Foundation. |
| * |
| * Licensed under the Apache License, Version 2.0 (the "License"); |
| * you may not use this file except in compliance with the License. |
| * You may obtain a copy of the License at |
| * |
| * http://www.apache.org/licenses/LICENSE-2.0 |
| * |
| * Unless required by applicable law or agreed to in writing, software |
| * distributed under the License is distributed on an "AS IS" BASIS, |
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| * See the License for the specific language governing permissions and |
| * limitations under the License. |
| */ |
| package org.apache.juddi.v3.auth; |
| |
| import javax.persistence.EntityManager; |
| import javax.persistence.EntityTransaction; |
| import javax.servlet.http.HttpServletRequest; |
| import javax.xml.ws.WebServiceContext; |
| import javax.xml.ws.handler.MessageContext; |
| import org.apache.commons.logging.Log; |
| import org.apache.commons.logging.LogFactory; |
| import org.apache.juddi.config.AppConfig; |
| import org.apache.juddi.config.PersistenceManager; |
| import org.apache.juddi.config.Property; |
| import org.apache.juddi.model.Publisher; |
| import org.apache.juddi.model.UddiEntityPublisher; |
| import org.apache.juddi.v3.error.AuthenticationException; |
| import org.apache.juddi.v3.error.ErrorMessage; |
| import org.apache.juddi.v3.error.FatalErrorException; |
| import org.apache.juddi.v3.error.UnknownUserException; |
| |
| /** |
| * Authenticates via a trusted web proxy via an HTTP HEADER. <br> |
| * Examples:<ul> |
| * <li>via Apache HTTPD</li> |
| * <li>Bluecoat</li> |
| * <li>Reverse SSL Proxies</li> |
| * </ul> |
| * Requires the config setting: |
| * {@link Property#JUDDI_AUTHENTICATOR_HTTP_HEADER_NAME} |
| * |
| * @author Alex O'Ree |
| */ |
| <span class="nc" id="L47">public class HTTPHeaderAuthenticator implements Authenticator {</span> |
| |
| <span class="nc" id="L49"> private Log log = LogFactory.getLog(this.getClass());</span> |
| |
| @Override |
| public String authenticate(String authorizedName, String cred) throws AuthenticationException, FatalErrorException { |
| <span class="nc" id="L53"> throw new UnknownUserException(new ErrorMessage("errros.UnsupportedAuthenticator"));</span> |
| } |
| |
| @Override |
| public UddiEntityPublisher identify(String notusedauthtoken, String notusedusername, WebServiceContext ctx) throws AuthenticationException, FatalErrorException { |
| <span class="nc" id="L58"> int MaxBindingsPerService = -1;</span> |
| <span class="nc" id="L59"> int MaxServicesPerBusiness = -1;</span> |
| <span class="nc" id="L60"> int MaxTmodels = -1;</span> |
| <span class="nc" id="L61"> int MaxBusinesses = -1;</span> |
| <span class="nc" id="L62"> String http_header_name = null;</span> |
| try { |
| <span class="nc" id="L64"> http_header_name = AppConfig.getConfiguration().getString(Property.JUDDI_AUTHENTICATOR_HTTP_HEADER_NAME);</span> |
| <span class="nc" id="L65"> MaxBindingsPerService = AppConfig.getConfiguration().getInt(Property.JUDDI_MAX_BINDINGS_PER_SERVICE, -1);</span> |
| <span class="nc" id="L66"> MaxServicesPerBusiness = AppConfig.getConfiguration().getInt(Property.JUDDI_MAX_SERVICES_PER_BUSINESS, -1);</span> |
| <span class="nc" id="L67"> MaxTmodels = AppConfig.getConfiguration().getInt(Property.JUDDI_MAX_TMODELS_PER_PUBLISHER, -1);</span> |
| <span class="nc" id="L68"> MaxBusinesses = AppConfig.getConfiguration().getInt(Property.JUDDI_MAX_BUSINESSES_PER_PUBLISHER, -1);</span> |
| <span class="nc" id="L69"> } catch (Exception ex) {</span> |
| <span class="nc" id="L70"> MaxBindingsPerService = -1;</span> |
| <span class="nc" id="L71"> MaxServicesPerBusiness = -1;</span> |
| <span class="nc" id="L72"> MaxTmodels = -1;</span> |
| <span class="nc" id="L73"> MaxBusinesses = -1;</span> |
| <span class="nc" id="L74"> log.error("config exception! ", ex);</span> |
| <span class="nc" id="L75"> }</span> |
| <span class="nc bnc" id="L76" title="All 2 branches missed."> if (http_header_name == null) {</span> |
| <span class="nc" id="L77"> throw new UnknownUserException(new ErrorMessage("errors.auth.NoPublisher", "misconfiguration!"));</span> |
| } |
| <span class="nc" id="L79"> EntityManager em = PersistenceManager.getEntityManager();</span> |
| <span class="nc" id="L80"> EntityTransaction tx = em.getTransaction();</span> |
| try { |
| <span class="nc" id="L82"> String user = null;</span> |
| |
| <span class="nc" id="L84"> MessageContext mc = ctx.getMessageContext();</span> |
| <span class="nc" id="L85"> HttpServletRequest req = null;</span> |
| <span class="nc bnc" id="L86" title="All 2 branches missed."> if (mc != null) {</span> |
| <span class="nc" id="L87"> req = (HttpServletRequest) mc.get(MessageContext.SERVLET_REQUEST);</span> |
| <span class="nc" id="L88"> user = req.getHeader(http_header_name);</span> |
| } |
| |
| <span class="nc bnc" id="L91" title="All 4 branches missed."> if (user == null || user.length() == 0) {</span> |
| <span class="nc" id="L92"> throw new UnknownUserException(new ErrorMessage("errors.auth.NoPublisher"));</span> |
| } |
| <span class="nc" id="L94"> tx.begin();</span> |
| <span class="nc" id="L95"> Publisher publisher = em.find(Publisher.class, user);</span> |
| <span class="nc bnc" id="L96" title="All 2 branches missed."> if (publisher == null) {</span> |
| <span class="nc" id="L97"> log.warn("Publisher \"" + user + "\" was not found in the database, adding the publisher in on the fly.");</span> |
| <span class="nc" id="L98"> publisher = new Publisher();</span> |
| <span class="nc" id="L99"> publisher.setAuthorizedName(user);</span> |
| <span class="nc" id="L100"> publisher.setIsAdmin("false");</span> |
| <span class="nc" id="L101"> publisher.setIsEnabled("true");</span> |
| <span class="nc" id="L102"> publisher.setMaxBindingsPerService(MaxBindingsPerService);</span> |
| <span class="nc" id="L103"> publisher.setMaxBusinesses(MaxBusinesses);</span> |
| <span class="nc" id="L104"> publisher.setMaxServicesPerBusiness(MaxServicesPerBusiness);</span> |
| <span class="nc" id="L105"> publisher.setMaxTmodels(MaxTmodels);</span> |
| <span class="nc" id="L106"> publisher.setPublisherName("Unknown");</span> |
| <span class="nc" id="L107"> em.persist(publisher);</span> |
| <span class="nc" id="L108"> tx.commit();</span> |
| } |
| |
| <span class="nc" id="L111"> return publisher;</span> |
| } finally { |
| <span class="nc bnc" id="L113" title="All 4 branches missed."> if (tx.isActive()) {</span> |
| <span class="nc" id="L114"> tx.rollback();</span> |
| } |
| <span class="nc" id="L116"> em.close();</span> |
| } |
| } |
| |
| } |
| </pre><div class="footer"><span class="right">Created with <a href="http://www.jacoco.org/jacoco">JaCoCo</a> 0.7.9.201702052155</span></div></body></html> |