You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@juddi.apache.org by tc...@apache.org on 2010/02/23 05:38:58 UTC

svn commit: r915175 - in /webservices/juddi/trunk/docs/examples/auth: ./ src/ src/main/ src/main/java/ src/main/java/org/ src/main/java/org/apache/ src/main/java/org/apache/juddi/ src/main/java/org/apache/juddi/v3/ src/main/java/org/apache/juddi/v3/auth/

Author: tcunning
Date: Tue Feb 23 04:38:58 2010
New Revision: 915175

URL: http://svn.apache.org/viewvc?rev=915175&view=rev
Log:
JUDDI-364
Add pom.xml and JBossAuthenticator.

Added:
    webservices/juddi/trunk/docs/examples/auth/pom.xml
    webservices/juddi/trunk/docs/examples/auth/src/
    webservices/juddi/trunk/docs/examples/auth/src/main/
    webservices/juddi/trunk/docs/examples/auth/src/main/java/
    webservices/juddi/trunk/docs/examples/auth/src/main/java/org/
    webservices/juddi/trunk/docs/examples/auth/src/main/java/org/apache/
    webservices/juddi/trunk/docs/examples/auth/src/main/java/org/apache/juddi/
    webservices/juddi/trunk/docs/examples/auth/src/main/java/org/apache/juddi/v3/
    webservices/juddi/trunk/docs/examples/auth/src/main/java/org/apache/juddi/v3/auth/
    webservices/juddi/trunk/docs/examples/auth/src/main/java/org/apache/juddi/v3/auth/JBossAuthenticator.java
Removed:
    webservices/juddi/trunk/docs/examples/auth/JBossAuthenticator.java

Added: webservices/juddi/trunk/docs/examples/auth/pom.xml
URL: http://svn.apache.org/viewvc/webservices/juddi/trunk/docs/examples/auth/pom.xml?rev=915175&view=auto
==============================================================================
--- webservices/juddi/trunk/docs/examples/auth/pom.xml (added)
+++ webservices/juddi/trunk/docs/examples/auth/pom.xml Tue Feb 23 04:38:58 2010
@@ -0,0 +1,60 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ * Copyright 2001-2009 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.
+ *
+ */ -->
+<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
+	<modelVersion>4.0.0</modelVersion>
+	<parent>
+		<groupId>org.apache.juddi</groupId>
+		<artifactId>juddi-parent</artifactId>
+		<version>3.0.1</version>
+	</parent>
+	<artifactId>juddi-auth-example</artifactId>
+	<packaging>jar</packaging>
+	<name>jUDDI Auth Example</name>
+	<dependencies>
+		<dependency>
+			<groupId>org.jboss.security</groupId>
+			<artifactId>jboss-security-spi</artifactId>
+			<version>2.0.1.GA</version>
+			<scope>compile</scope>
+			<exclusions>
+				<exclusion>
+					<groupId>org.jboss.javaee</groupId>
+					<artifactId>jboss-jaspi-api</artifactId>
+				</exclusion>
+			</exclusions>
+		</dependency>
+		<dependency>
+			<groupId>org.jboss.javaee</groupId>
+			<artifactId>jboss-jaspi-api</artifactId>
+			<version>1.0.0.GA</version>
+			<scope>compile</scope>
+		</dependency>
+		<dependency>
+			<groupId>org.apache.juddi</groupId>
+			<artifactId>juddi-core</artifactId>
+			<version>${project.parent.version}</version>
+			<scope>compile</scope>
+		</dependency>
+		<dependency>
+			<groupId>junit</groupId>
+			<artifactId>junit</artifactId>
+			<version>4.5</version>
+			<scope>test</scope>
+		</dependency>
+	</dependencies>
+</project>

Added: webservices/juddi/trunk/docs/examples/auth/src/main/java/org/apache/juddi/v3/auth/JBossAuthenticator.java
URL: http://svn.apache.org/viewvc/webservices/juddi/trunk/docs/examples/auth/src/main/java/org/apache/juddi/v3/auth/JBossAuthenticator.java?rev=915175&view=auto
==============================================================================
--- webservices/juddi/trunk/docs/examples/auth/src/main/java/org/apache/juddi/v3/auth/JBossAuthenticator.java (added)
+++ webservices/juddi/trunk/docs/examples/auth/src/main/java/org/apache/juddi/v3/auth/JBossAuthenticator.java Tue Feb 23 04:38:58 2010
@@ -0,0 +1,119 @@
+/*
+ * Copyright 2001-2009 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 org.apache.commons.configuration.ConfigurationException;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+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;
+import org.apache.juddi.config.AppConfig;
+import org.apache.juddi.config.PersistenceManager;
+import org.apache.juddi.config.Property;
+import org.apache.log4j.Logger;
+import org.jboss.security.AuthenticationManager;
+
+import javax.naming.Context;
+import javax.naming.InitialContext;
+import javax.naming.NamingException;
+import javax.persistence.EntityManager;
+import javax.persistence.EntityTransaction;
+
+import java.security.Principal;
+
+/**
+ * This is a implementation of jUDDI's Authenticator interface, that uses the
+ * JBoss authentication manager.
+ * 
+ * Usage:
+ * 
+ * To use this class you must add the following properties to the
+ * juddiv3.properties file:
+ * 
+ * # The JBoss Authenticator
+ * juddi.authenticator=org.apache.juddi.auth.JBossAuthenticator
+ * 
+ * # The security-domain, defined in $JBOSS/default/conf/login-config.xml
+ * juddi.securityDomain=java:/jaas/other
+ * 
+ * @author Antoni Reus (areus@ibit.org)
+ */
+public class JBossAuthenticator implements Authenticator {
+	// private reference to the logger
+	private Logger logger = Logger.getLogger(this.getClass());
+
+	// JBoss authentication manager
+	AuthenticationManager authManager;
+
+	public JBossAuthenticator() throws NamingException, ConfigurationException {
+		init();
+	}
+
+	/**
+     *
+     */
+	public String authenticate(final String userID, final String credential)
+			throws AuthenticationException {
+		if (userID == null) {
+			throw new UnknownUserException(new ErrorMessage("errors.auth.InvalidUserId", userID));
+		}
+
+		// Create a principal for the userID
+		Principal principal = new Principal() {
+			public String getName() {
+				return userID;
+			}
+		};
+
+		if (!authManager.isValid(principal, credential)) {
+			throw new UnknownUserException(new ErrorMessage("errors.auth.InvalidCredentials"));
+		}
+		return userID;
+	}
+
+	private void init() throws NamingException, ConfigurationException {
+		String securityDomain = AppConfig.getConfiguration().getString(
+				Property.JUDDI_SECURITY_DOMAIN,
+				Property.DEFAULT_SECURITY_DOMAIN);
+
+		// lookup the authentication manager.
+		Context ctx = new InitialContext();
+		authManager = (AuthenticationManager) ctx.lookup(securityDomain);
+		ctx.close();
+	}
+	
+	public UddiEntityPublisher identify(String authInfo, String authorizedName) throws AuthenticationException {
+		EntityManager em = PersistenceManager.getEntityManager();
+		EntityTransaction tx = em.getTransaction();
+		try {
+			tx.begin();
+			Publisher publisher = em.find(Publisher.class, authorizedName);
+			if (publisher == null)
+				throw new UnknownUserException(new ErrorMessage("errors.auth.NoPublisher", authorizedName));
+			
+			return publisher;
+		} finally {
+			if (tx.isActive()) {
+				tx.rollback();
+			}
+			em.close();
+		}
+	}
+}



---------------------------------------------------------------------
To unsubscribe, e-mail: juddi-cvs-unsubscribe@ws.apache.org
For additional commands, e-mail: juddi-cvs-help@ws.apache.org