| <?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>JUDDIAuthenticator.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 - OpenJPA</a> > <a href="index.source.html" class="el_package">org.apache.juddi.v3.auth</a> > <span class="el_source">JUDDIAuthenticator.java</span></div><h1>JUDDIAuthenticator.java</h1><pre class="source lang-java linenums">/* |
| * Copyright 2001-2008 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.xml.ws.WebServiceContext; |
| |
| 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.UnknownUserException; |
| |
| /** |
| * This is the default implementation of jUDDI's Authenticator interface. If the |
| * user id does not have an associated publisher, it adds the publisher. Please |
| * do NOT use this class in production. |
| * |
| * @author Steve Viens (sviens@apache.org) |
| * @author <a href="mailto:kstam@apache.org">Kurt T Stam</a> |
| * @author <a href="mailto:jfaath@apache.org">Jeff Faath</a> |
| */ |
| <span class="fc" id="L43">public class JUDDIAuthenticator implements Authenticator {</span> |
| |
| <span class="fc" id="L45"> private Log log = LogFactory.getLog(this.getClass());</span> |
| |
| /** |
| * @return the userId that came in on the request providing the user has |
| * a publishing account in jUDDI. |
| * @param authorizedName |
| * @param credential |
| * @return authorizedName |
| * @throws AuthenticationException |
| */ |
| public String authenticate(String authorizedName, String credential) throws AuthenticationException { |
| <span class="pc bpc" id="L56" title="2 of 4 branches missed."> if (authorizedName == null || "".equals(authorizedName)) {</span> |
| <span class="nc" id="L57"> throw new UnknownUserException(new ErrorMessage("errors.auth.NoPublisher", authorizedName));</span> |
| } |
| <span class="fc" id="L59"> log.warn("DO NOT USE JUDDI AUTHENTICATOR FOR PRODUCTION SYSTEMS - DOES NOT VALIDATE PASSWORDS, AT ALL!");</span> |
| <span class="fc" id="L60"> int MaxBindingsPerService = -1;</span> |
| <span class="fc" id="L61"> int MaxServicesPerBusiness = -1;</span> |
| <span class="fc" id="L62"> int MaxTmodels = -1;</span> |
| <span class="fc" id="L63"> int MaxBusinesses = -1;</span> |
| try { |
| <span class="fc" id="L65"> MaxBindingsPerService = AppConfig.getConfiguration().getInt(Property.JUDDI_MAX_BINDINGS_PER_SERVICE, -1);</span> |
| <span class="fc" id="L66"> MaxServicesPerBusiness = AppConfig.getConfiguration().getInt(Property.JUDDI_MAX_SERVICES_PER_BUSINESS, -1);</span> |
| <span class="fc" id="L67"> MaxTmodels = AppConfig.getConfiguration().getInt(Property.JUDDI_MAX_TMODELS_PER_PUBLISHER, -1);</span> |
| <span class="fc" 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! " + authorizedName, ex);</span> |
| <span class="fc" id="L75"> }</span> |
| <span class="fc" id="L76"> EntityManager em = PersistenceManager.getEntityManager();</span> |
| <span class="fc" id="L77"> EntityTransaction tx = em.getTransaction();</span> |
| try { |
| <span class="fc" id="L79"> tx.begin();</span> |
| <span class="fc" id="L80"> Publisher publisher = em.find(Publisher.class, authorizedName);</span> |
| <span class="fc bfc" id="L81" title="All 2 branches covered."> if (publisher == null) {</span> |
| <span class="fc" id="L82"> log.warn("Publisher \"" + authorizedName + "\" was not found, adding the publisher in on the fly.");</span> |
| <span class="fc" id="L83"> publisher = new Publisher();</span> |
| <span class="fc" id="L84"> publisher.setAuthorizedName(authorizedName);</span> |
| <span class="fc" id="L85"> publisher.setIsAdmin("false");</span> |
| <span class="fc" id="L86"> publisher.setIsEnabled("true");</span> |
| <span class="fc" id="L87"> publisher.setMaxBindingsPerService(MaxBindingsPerService);</span> |
| <span class="fc" id="L88"> publisher.setMaxBusinesses(MaxBusinesses);</span> |
| <span class="fc" id="L89"> publisher.setMaxServicesPerBusiness(MaxServicesPerBusiness);</span> |
| <span class="fc" id="L90"> publisher.setMaxTmodels(MaxTmodels);</span> |
| <span class="fc" id="L91"> publisher.setPublisherName("Unknown");</span> |
| <span class="fc" id="L92"> em.persist(publisher);</span> |
| <span class="fc" id="L93"> tx.commit();</span> |
| } |
| <span class="fc" id="L95"> return authorizedName;</span> |
| <span class="nc" id="L96"> } catch (Exception ex) {</span> |
| //note: we saw an ArrayIndexOutOfBounds exception when using github actions for CI |
| //with hibernate on derby, root cause is still tbd |
| <span class="nc" id="L99"> log.error("error during authentication routine, could indicate a database issue", ex);</span> |
| <span class="nc" id="L100"> throw ex;</span> |
| } finally { |
| <span class="pc bpc" id="L102" title="2 of 4 branches missed."> if (tx.isActive()) {</span> |
| <span class="pc" id="L103"> tx.rollback();</span> |
| } |
| <span class="pc" id="L105"> em.close();</span> |
| } |
| } |
| |
| public UddiEntityPublisher identify(String authInfo, String authorizedName, WebServiceContext ctx) throws AuthenticationException { |
| <span class="fc" id="L110"> EntityManager em = PersistenceManager.getEntityManager();</span> |
| <span class="fc" id="L111"> EntityTransaction tx = em.getTransaction();</span> |
| try { |
| <span class="fc" id="L113"> tx.begin();</span> |
| <span class="fc" id="L114"> Publisher publisher = em.find(Publisher.class, authorizedName);</span> |
| <span class="pc bpc" id="L115" title="1 of 2 branches missed."> if (publisher == null) {</span> |
| <span class="nc" id="L116"> throw new UnknownUserException(new ErrorMessage("errors.auth.NoPublisher", authorizedName));</span> |
| } |
| |
| <span class="fc" id="L119"> return publisher;</span> |
| } finally { |
| <span class="pc bpc" id="L121" title="3 of 4 branches missed."> if (tx.isActive()) {</span> |
| <span class="pc" id="L122"> tx.rollback();</span> |
| } |
| <span class="pc" id="L124"> 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> |