Author: lhazlewood
Date: Mon Apr 4 23:47:13 2011
New Revision: 1088824
URL: http://svn.apache.org/viewvc?rev=1088824&view=rev
Log:
SHIRO-281: added initial implementations
Added:
shiro/trunk/core/src/main/java/org/apache/shiro/dao/
shiro/trunk/core/src/main/java/org/apache/shiro/dao/DataAccessException.java
shiro/trunk/core/src/main/java/org/apache/shiro/dao/InvalidResourceUsageException.java
shiro/trunk/core/src/main/java/org/apache/shiro/dao/package-info.java
shiro/trunk/core/src/main/java/org/apache/shiro/functor/
shiro/trunk/core/src/main/java/org/apache/shiro/functor/Translator.java
shiro/trunk/core/src/main/java/org/apache/shiro/functor/package-info.java
shiro/trunk/core/src/main/java/org/apache/shiro/ldap/
shiro/trunk/core/src/main/java/org/apache/shiro/ldap/UnsupportedAuthenticationMechanismException.java
shiro/trunk/core/src/main/java/org/apache/shiro/ldap/package-info.java
Modified:
shiro/trunk/core/src/main/java/org/apache/shiro/realm/ldap/JndiLdapRealm.java
Added:
shiro/trunk/core/src/main/java/org/apache/shiro/dao/DataAccessException.java
URL:
http://svn.apache.org/viewvc/shiro/trunk/core/src/main/java/org/apache/shiro/dao/DataAccessException.java?rev=1088824&view=auto
==============================================================================
---
shiro/trunk/core/src/main/java/org/apache/shiro/dao/DataAccessException.java
(added)
+++
shiro/trunk/core/src/main/java/org/apache/shiro/dao/DataAccessException.java
Mon Apr 4 23:47:13 2011
@@ -0,0 +1,51 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.shiro.dao;
+
+import org.apache.shiro.ShiroException;
+
+/**
+ * Generic exception representing a problem when attempting to access data.
+ * <p/>
+ * The idea was borrowed from the Spring Framework, which has a nice model for
a generic DAO exception hierarchy.
+ * Unfortunately we can't use it as we can't force a Spring API usage on all
Shiro end-users.
+ *
+ * @since 1.2
+ */
+public abstract class DataAccessException extends ShiroException {
+
+ /**
+ * Constructs a DataAccessException with a message explaining the cause of
the exception.
+ *
+ * @param message the message explaining the cause of the exception
+ */
+ public DataAccessException(String message) {
+ super(message);
+ }
+
+ /**
+ * Constructs a DataAccessException with a message explaining the cause of
the exception.
+ *
+ * @param message the explanation
+ * @param cause the root cause of the exception, typically an
API-specific exception
+ */
+ public DataAccessException(String message, Throwable cause) {
+ super(message, cause);
+ }
+}
Added:
shiro/trunk/core/src/main/java/org/apache/shiro/dao/InvalidResourceUsageException.java
URL:
http://svn.apache.org/viewvc/shiro/trunk/core/src/main/java/org/apache/shiro/dao/InvalidResourceUsageException.java?rev=1088824&view=auto
==============================================================================
---
shiro/trunk/core/src/main/java/org/apache/shiro/dao/InvalidResourceUsageException.java
(added)
+++
shiro/trunk/core/src/main/java/org/apache/shiro/dao/InvalidResourceUsageException.java
Mon Apr 4 23:47:13 2011
@@ -0,0 +1,47 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.shiro.dao;
+
+/**
+ * Root exception indicating invalid or incorrect usage of a data access
resource. This is thrown
+ * typically when incorrectly using the resource or its API.
+ *
+ * @since 1.2
+ */
+public class InvalidResourceUsageException extends DataAccessException {
+
+ /**
+ * Constructs an InvalidResourceUsageException with a message explaining
the cause of the exception.
+ *
+ * @param message the message explaining the cause of the exception
+ */
+ public InvalidResourceUsageException(String message) {
+ super(message);
+ }
+
+ /**
+ * Constructs a InvalidResourceUsageException with a message explaining
the cause of the exception.
+ *
+ * @param message the explanation
+ * @param cause the root cause of the exception, typically an
API-specific exception
+ */
+ public InvalidResourceUsageException(String message, Throwable cause) {
+ super(message, cause);
+ }
+}
Added: shiro/trunk/core/src/main/java/org/apache/shiro/dao/package-info.java
URL:
http://svn.apache.org/viewvc/shiro/trunk/core/src/main/java/org/apache/shiro/dao/package-info.java?rev=1088824&view=auto
==============================================================================
--- shiro/trunk/core/src/main/java/org/apache/shiro/dao/package-info.java
(added)
+++ shiro/trunk/core/src/main/java/org/apache/shiro/dao/package-info.java Mon
Apr 4 23:47:13 2011
@@ -0,0 +1,26 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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 containing various components useful when building Data Access
Objects (DAOs), including a generic
+ * Data Access Exception hierarchy. As {@link org.apache.shiro.realm.Realm
Realm} instances are typically viewed as
+ * security-specific DAOs, this package is often useful when implementing
Realms.
+ *
+ * @since 1.2
+ */
+package org.apache.shiro.dao;
\ No newline at end of file
Added: shiro/trunk/core/src/main/java/org/apache/shiro/functor/Translator.java
URL:
http://svn.apache.org/viewvc/shiro/trunk/core/src/main/java/org/apache/shiro/functor/Translator.java?rev=1088824&view=auto
==============================================================================
--- shiro/trunk/core/src/main/java/org/apache/shiro/functor/Translator.java
(added)
+++ shiro/trunk/core/src/main/java/org/apache/shiro/functor/Translator.java Mon
Apr 4 23:47:13 2011
@@ -0,0 +1,45 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.shiro.functor;
+
+/**
+ * Generic <a href="http://en.wikipedia.org/wiki/Functor">functor</a>
interface representing a data translation (or
+ * conversion) operation. For a given input, a Translator can translate an
input argument into a potentially different
+ * output value.
+ * <p/>
+ * One example of where this is particularly convenient is API translation:
translating a 3rd-party framework Exception
+ * to a Shiro Exception or vice-versa.
+ *
+ * @param <I> The input type
+ * @param <O> The output type
+ *
+ * @since 1.2
+ */
+public interface Translator<I,O> {
+
+ /**
+ * Translates the input argument into the required output instance.
+ *
+ * @param input the input data to translate
+ * @return the translated output data
+ * @since 1.2
+ */
+ O translate(I input);
+
+}
Added: shiro/trunk/core/src/main/java/org/apache/shiro/functor/package-info.java
URL:
http://svn.apache.org/viewvc/shiro/trunk/core/src/main/java/org/apache/shiro/functor/package-info.java?rev=1088824&view=auto
==============================================================================
--- shiro/trunk/core/src/main/java/org/apache/shiro/functor/package-info.java
(added)
+++ shiro/trunk/core/src/main/java/org/apache/shiro/functor/package-info.java
Mon Apr 4 23:47:13 2011
@@ -0,0 +1,30 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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 containing <a
href="http://en.wikipedia.org/wiki/Functor">functor</a> components used for
data translation
+ * or conversion. Of particular note is the {@link Translator} interface and
its implementations.
+ * <p/>
+ * Translators are useful in a framework like Shiro which can integrate with
many other 3rd-party APIs and
+ * frameworks. A {@code Translator} is convenient when translating from one
API concept into another, for
+ * example, translating a 3rd-party framework Exception to a Shiro Exception
or vice-versa.
+ *
+ * @since 1.2
+ * @see Translator
+ */
+package org.apache.shiro.functor;
\ No newline at end of file
Added:
shiro/trunk/core/src/main/java/org/apache/shiro/ldap/UnsupportedAuthenticationMechanismException.java
URL:
http://svn.apache.org/viewvc/shiro/trunk/core/src/main/java/org/apache/shiro/ldap/UnsupportedAuthenticationMechanismException.java?rev=1088824&view=auto
==============================================================================
---
shiro/trunk/core/src/main/java/org/apache/shiro/ldap/UnsupportedAuthenticationMechanismException.java
(added)
+++
shiro/trunk/core/src/main/java/org/apache/shiro/ldap/UnsupportedAuthenticationMechanismException.java
Mon Apr 4 23:47:13 2011
@@ -0,0 +1,39 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.shiro.ldap;
+
+import org.apache.shiro.dao.InvalidResourceUsageException;
+
+/**
+ * Exception thrown when a configured LDAP
+ * <a
href="http://download.oracle.com/javase/jndi/tutorial/ldap/security/auth.html">
+ * Authentication Mechanism</a> is unsupported by the target LDAP server.
(e.g. DIGEST-MD5, simple, etc)
+ *
+ * @since 1.2
+ */
+public class UnsupportedAuthenticationMechanismException extends
InvalidResourceUsageException {
+
+ public UnsupportedAuthenticationMechanismException(String message) {
+ super(message);
+ }
+
+ public UnsupportedAuthenticationMechanismException(String message,
Throwable cause) {
+ super(message, cause);
+ }
+}
Added: shiro/trunk/core/src/main/java/org/apache/shiro/ldap/package-info.java
URL:
http://svn.apache.org/viewvc/shiro/trunk/core/src/main/java/org/apache/shiro/ldap/package-info.java?rev=1088824&view=auto
==============================================================================
--- shiro/trunk/core/src/main/java/org/apache/shiro/ldap/package-info.java
(added)
+++ shiro/trunk/core/src/main/java/org/apache/shiro/ldap/package-info.java Mon
Apr 4 23:47:13 2011
@@ -0,0 +1,23 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.
+ */
+/**
+ * Support for accessing <a href="http://en.wikipedia.org/wiki/LDAP">LDAP</a>
data sources.
+ *
+ * @since 1.2
+ */
\ No newline at end of file
Modified:
shiro/trunk/core/src/main/java/org/apache/shiro/realm/ldap/JndiLdapRealm.java
URL:
http://svn.apache.org/viewvc/shiro/trunk/core/src/main/java/org/apache/shiro/realm/ldap/JndiLdapRealm.java?rev=1088824&r1=1088823&r2=1088824&view=diff
==============================================================================
---
shiro/trunk/core/src/main/java/org/apache/shiro/realm/ldap/JndiLdapRealm.java
(original)
+++
shiro/trunk/core/src/main/java/org/apache/shiro/realm/ldap/JndiLdapRealm.java
Mon Apr 4 23:47:13 2011
@@ -31,6 +31,7 @@ import org.apache.shiro.util.StringUtils
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import javax.naming.AuthenticationNotSupportedException;
import javax.naming.NamingException;
import javax.naming.ldap.LdapContext;
@@ -291,6 +292,9 @@ public class JndiLdapRealm extends Autho
AuthenticationInfo info;
try {
info = queryForAuthenticationInfo(token, getContextFactory());
+ } catch (AuthenticationNotSupportedException e) {
+ String msg = "Unsupported configured authentication mechanism";
+ throw new UnsupportedAuthenticationMechanismException(msg, e);
} catch (javax.naming.AuthenticationException e) {
throw new AuthenticationException("LDAP authentication failed.",
e);
} catch (NamingException e) {