| <?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>HTTPContainerAuthenticator.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">HTTPContainerAuthenticator.java</span></div><h1>HTTPContainerAuthenticator.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; |
| |
| /** |
| * This authenticator trust's what's provided by the container, such as HTTP |
| * BASIC, DIGEST, or CLIENT CERT |
| * |
| * @author Alex O'Ree |
| */ |
| <span class="nc" id="L41">public class HTTPContainerAuthenticator implements Authenticator {</span> |
| |
| <span class="nc" id="L43"> private Log log = LogFactory.getLog(this.getClass());</span> |
| @Override |
| public String authenticate(String authorizedName, String cred) throws AuthenticationException, FatalErrorException { |
| <span class="nc" id="L46"> throw new UnknownUserException(new ErrorMessage("errros.UnsupportedAuthenticator"));</span> |
| } |
| |
| @Override |
| public UddiEntityPublisher identify(String authInfoNotused, String authorizedNameNotused, WebServiceContext ctx) throws AuthenticationException, FatalErrorException { |
| <span class="nc" id="L51"> int MaxBindingsPerService = -1;</span> |
| <span class="nc" id="L52"> int MaxServicesPerBusiness = -1;</span> |
| <span class="nc" id="L53"> int MaxTmodels = -1;</span> |
| <span class="nc" id="L54"> int MaxBusinesses = -1;</span> |
| try { |
| <span class="nc" id="L56"> MaxBindingsPerService = AppConfig.getConfiguration().getInt(Property.JUDDI_MAX_BINDINGS_PER_SERVICE, -1);</span> |
| <span class="nc" id="L57"> MaxServicesPerBusiness = AppConfig.getConfiguration().getInt(Property.JUDDI_MAX_SERVICES_PER_BUSINESS, -1);</span> |
| <span class="nc" id="L58"> MaxTmodels = AppConfig.getConfiguration().getInt(Property.JUDDI_MAX_TMODELS_PER_PUBLISHER, -1);</span> |
| <span class="nc" id="L59"> MaxBusinesses = AppConfig.getConfiguration().getInt(Property.JUDDI_MAX_BUSINESSES_PER_PUBLISHER, -1);</span> |
| <span class="nc" id="L60"> } catch (Exception ex) {</span> |
| <span class="nc" id="L61"> MaxBindingsPerService = -1;</span> |
| <span class="nc" id="L62"> MaxServicesPerBusiness = -1;</span> |
| <span class="nc" id="L63"> MaxTmodels = -1;</span> |
| <span class="nc" id="L64"> MaxBusinesses = -1;</span> |
| <span class="nc" id="L65"> log.error("config exception! ", ex);</span> |
| <span class="nc" id="L66"> }</span> |
| <span class="nc" id="L67"> EntityManager em = PersistenceManager.getEntityManager();</span> |
| <span class="nc" id="L68"> EntityTransaction tx = em.getTransaction();</span> |
| try { |
| <span class="nc" id="L70"> String user = null;</span> |
| <span class="nc bnc" id="L71" title="All 2 branches missed."> if (ctx==null)</span> |
| <span class="nc" id="L72"> throw new UnknownUserException(new ErrorMessage("errors.auth.NoPublisher", "no web service context!"));</span> |
| <span class="nc bnc" id="L73" title="All 2 branches missed."> if (ctx.getUserPrincipal() != null) {</span> |
| <span class="nc" id="L74"> user = ctx.getUserPrincipal().getName();</span> |
| } |
| <span class="nc bnc" id="L76" title="All 2 branches missed."> if (user == null) {</span> |
| <span class="nc" id="L77"> MessageContext mc = ctx.getMessageContext();</span> |
| <span class="nc" id="L78"> HttpServletRequest req = null;</span> |
| <span class="nc bnc" id="L79" title="All 2 branches missed."> if (mc != null) {</span> |
| <span class="nc" id="L80"> req = (HttpServletRequest) mc.get(MessageContext.SERVLET_REQUEST);</span> |
| } |
| <span class="nc bnc" id="L82" title="All 4 branches missed."> if (req != null && req.getUserPrincipal()!=null) {</span> |
| <span class="nc" id="L83"> user = req.getUserPrincipal().getName();</span> |
| } |
| } |
| <span class="nc bnc" id="L86" title="All 4 branches missed."> if (user==null || user.length()==0){</span> |
| <span class="nc" id="L87"> throw new UnknownUserException(new ErrorMessage("errors.auth.NoPublisher"));</span> |
| } |
| <span class="nc" id="L89"> tx.begin();</span> |
| <span class="nc" id="L90"> Publisher publisher = em.find(Publisher.class, user);</span> |
| <span class="nc bnc" id="L91" title="All 2 branches missed."> if (publisher == null) {</span> |
| <span class="nc" id="L92"> log.warn("Publisher \"" + user + "\" was not found in the database, adding the publisher in on the fly.");</span> |
| <span class="nc" id="L93"> publisher = new Publisher();</span> |
| <span class="nc" id="L94"> publisher.setAuthorizedName(user);</span> |
| <span class="nc" id="L95"> publisher.setIsAdmin(false);</span> |
| <span class="nc" id="L96"> publisher.setIsEnabled(true);</span> |
| <span class="nc" id="L97"> publisher.setMaxBindingsPerService(MaxBindingsPerService);</span> |
| <span class="nc" id="L98"> publisher.setMaxBusinesses(MaxBusinesses);</span> |
| <span class="nc" id="L99"> publisher.setMaxServicesPerBusiness(MaxServicesPerBusiness);</span> |
| <span class="nc" id="L100"> publisher.setMaxTmodels(MaxTmodels);</span> |
| <span class="nc" id="L101"> publisher.setPublisherName("Unknown");</span> |
| <span class="nc" id="L102"> em.persist(publisher);</span> |
| <span class="nc" id="L103"> tx.commit();</span> |
| } |
| |
| <span class="nc" id="L106"> return publisher;</span> |
| } finally { |
| <span class="nc bnc" id="L108" title="All 4 branches missed."> if (tx.isActive()) {</span> |
| <span class="nc" id="L109"> tx.rollback();</span> |
| } |
| <span class="nc" id="L111"> 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> |