You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@shiro.apache.org by ad...@apache.org on 2010/05/26 20:34:49 UTC
svn commit: r948527 [8/38] - in /incubator/shiro: branches/shiro-root-1.0.x/
branches/shiro-root-1.0.x/all/
branches/shiro-root-1.0.x/core/src/main/java/org/apache/shiro/
branches/shiro-root-1.0.x/core/src/main/java/org/apache/shiro/aop/
branches/shiro...
Propchange: incubator/shiro/branches/shiro-root-1.0.x/core/src/main/java/org/apache/shiro/subject/Subject.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/shiro/branches/shiro-root-1.0.x/core/src/main/java/org/apache/shiro/subject/SubjectContext.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/shiro/branches/shiro-root-1.0.x/core/src/main/java/org/apache/shiro/subject/package-info.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/shiro/branches/shiro-root-1.0.x/core/src/main/java/org/apache/shiro/subject/support/DefaultSubjectContext.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: incubator/shiro/branches/shiro-root-1.0.x/core/src/main/java/org/apache/shiro/subject/support/SubjectCallable.java
URL: http://svn.apache.org/viewvc/incubator/shiro/branches/shiro-root-1.0.x/core/src/main/java/org/apache/shiro/subject/support/SubjectCallable.java?rev=948527&r1=948526&r2=948527&view=diff
==============================================================================
--- incubator/shiro/branches/shiro-root-1.0.x/core/src/main/java/org/apache/shiro/subject/support/SubjectCallable.java (original)
+++ incubator/shiro/branches/shiro-root-1.0.x/core/src/main/java/org/apache/shiro/subject/support/SubjectCallable.java Wed May 26 18:34:28 2010
@@ -1,92 +1,92 @@
-/*
- * 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.subject.support;
-
-import org.apache.shiro.subject.Subject;
-import org.apache.shiro.util.ThreadState;
-
-import java.util.concurrent.Callable;
-
-/**
- * A {@code SubjectCallable} associates a {@link Subject Subject} with a target/delegate
- * {@link Callable Callable} to ensure proper {@code Subject} thread-state management when the {@code Callable} executes.
- * This ensures that any calls to {@code SecurityUtils.}{@link org.apache.shiro.SecurityUtils#getSubject() getSubject()}
- * during the target {@code Callable}'s execution still work correctly even if the {@code Callable} executes on a
- * different thread than the one that created it. This allows {@code Subject} access during asynchronous operations.
- * <p/>
- * When instances of this class execute (typically via a {@link java.util.concurrent.ExecutorService ExecutorService}),
- * the following occurs:
- * <ol>
- * <li>The specified Subject any of its associated thread state is first bound to the thread that executes the
- * {@code Callable}.</li>
- * <li>The delegate/target {@code Callable} is {@link java.util.concurrent.Callable#call() executed}</li>
- * <li>The previous thread state that might have existed before the {@code Subject} was bound is fully restored</li>
- * </ol>
- * <p/>
- * This behavior ensures that the thread that executes this {@code Callable}, which is often a different thread than
- * the one that created the instance, retains a {@code Subject} to support {@code SecurityUtils.getSubject()}
- * invocations. It also guarantees that the running thread remains 'clean' in any thread-pooled environments.
- *
- * <h3>Usage</h3>
- *
- * This is typically considered a support class and is not often directly referenced. Most people prefer to use
- * the {@code Subject.}{@link Subject#associateWith(Callable) associateWith} method, which will automatically return
- * an instance of this class.
- * <p/>
- * An even more convenient alternative is to use a
- * {@link org.apache.shiro.concurrent.SubjectAwareExecutorService SubjectAwareExecutorService}, which
- * transparently uses instances of this class.
- *
- * @see Subject#associateWith(Callable)
- * @see org.apache.shiro.concurrent.SubjectAwareExecutorService SubjectAwareExecutorService
- * @since 1.0
- */
-public class SubjectCallable<V> implements Callable<V> {
-
- protected final ThreadState threadState;
- private final Callable<V> callable;
-
- public SubjectCallable(Subject subject, Callable<V> delegate) {
- this(new SubjectThreadState(subject), delegate);
- }
-
- protected SubjectCallable(ThreadState threadState, Callable<V> delegate) {
- if (threadState == null) {
- throw new IllegalArgumentException("ThreadState argument cannot be null.");
- }
- this.threadState = threadState;
- if (delegate == null) {
- throw new IllegalArgumentException("Callable delegate instance cannot be null.");
- }
- this.callable = delegate;
- }
-
- public V call() throws Exception {
- try {
- threadState.bind();
- return doCall(this.callable);
- } finally {
- threadState.restore();
- }
- }
-
- protected V doCall(Callable<V> target) throws Exception {
- return target.call();
- }
-}
+/*
+ * 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.subject.support;
+
+import org.apache.shiro.subject.Subject;
+import org.apache.shiro.util.ThreadState;
+
+import java.util.concurrent.Callable;
+
+/**
+ * A {@code SubjectCallable} associates a {@link Subject Subject} with a target/delegate
+ * {@link Callable Callable} to ensure proper {@code Subject} thread-state management when the {@code Callable} executes.
+ * This ensures that any calls to {@code SecurityUtils.}{@link org.apache.shiro.SecurityUtils#getSubject() getSubject()}
+ * during the target {@code Callable}'s execution still work correctly even if the {@code Callable} executes on a
+ * different thread than the one that created it. This allows {@code Subject} access during asynchronous operations.
+ * <p/>
+ * When instances of this class execute (typically via a {@link java.util.concurrent.ExecutorService ExecutorService}),
+ * the following occurs:
+ * <ol>
+ * <li>The specified Subject any of its associated thread state is first bound to the thread that executes the
+ * {@code Callable}.</li>
+ * <li>The delegate/target {@code Callable} is {@link java.util.concurrent.Callable#call() executed}</li>
+ * <li>The previous thread state that might have existed before the {@code Subject} was bound is fully restored</li>
+ * </ol>
+ * <p/>
+ * This behavior ensures that the thread that executes this {@code Callable}, which is often a different thread than
+ * the one that created the instance, retains a {@code Subject} to support {@code SecurityUtils.getSubject()}
+ * invocations. It also guarantees that the running thread remains 'clean' in any thread-pooled environments.
+ *
+ * <h3>Usage</h3>
+ *
+ * This is typically considered a support class and is not often directly referenced. Most people prefer to use
+ * the {@code Subject.}{@link Subject#associateWith(Callable) associateWith} method, which will automatically return
+ * an instance of this class.
+ * <p/>
+ * An even more convenient alternative is to use a
+ * {@link org.apache.shiro.concurrent.SubjectAwareExecutorService SubjectAwareExecutorService}, which
+ * transparently uses instances of this class.
+ *
+ * @see Subject#associateWith(Callable)
+ * @see org.apache.shiro.concurrent.SubjectAwareExecutorService SubjectAwareExecutorService
+ * @since 1.0
+ */
+public class SubjectCallable<V> implements Callable<V> {
+
+ protected final ThreadState threadState;
+ private final Callable<V> callable;
+
+ public SubjectCallable(Subject subject, Callable<V> delegate) {
+ this(new SubjectThreadState(subject), delegate);
+ }
+
+ protected SubjectCallable(ThreadState threadState, Callable<V> delegate) {
+ if (threadState == null) {
+ throw new IllegalArgumentException("ThreadState argument cannot be null.");
+ }
+ this.threadState = threadState;
+ if (delegate == null) {
+ throw new IllegalArgumentException("Callable delegate instance cannot be null.");
+ }
+ this.callable = delegate;
+ }
+
+ public V call() throws Exception {
+ try {
+ threadState.bind();
+ return doCall(this.callable);
+ } finally {
+ threadState.restore();
+ }
+ }
+
+ protected V doCall(Callable<V> target) throws Exception {
+ return target.call();
+ }
+}
Propchange: incubator/shiro/branches/shiro-root-1.0.x/core/src/main/java/org/apache/shiro/subject/support/SubjectCallable.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: incubator/shiro/branches/shiro-root-1.0.x/core/src/main/java/org/apache/shiro/subject/support/SubjectRunnable.java
URL: http://svn.apache.org/viewvc/incubator/shiro/branches/shiro-root-1.0.x/core/src/main/java/org/apache/shiro/subject/support/SubjectRunnable.java?rev=948527&r1=948526&r2=948527&view=diff
==============================================================================
--- incubator/shiro/branches/shiro-root-1.0.x/core/src/main/java/org/apache/shiro/subject/support/SubjectRunnable.java (original)
+++ incubator/shiro/branches/shiro-root-1.0.x/core/src/main/java/org/apache/shiro/subject/support/SubjectRunnable.java Wed May 26 18:34:28 2010
@@ -1,122 +1,122 @@
-/*
- * 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.subject.support;
-
-import org.apache.shiro.subject.Subject;
-import org.apache.shiro.util.ThreadState;
-
-/**
- * A {@code SubjectRunnable} ensures that a target/delegate {@link Runnable Runnable} will execute such that any
- * call to {@code SecurityUtils.}{@link org.apache.shiro.SecurityUtils#getSubject() getSubject()} during the
- * {@code Runnable}'s execution will return the associated {@code Subject} instance. The {@code SubjectRunnable}
- * instance can be run on any thread (the current thread or asynchronously on another thread) and the
- * {@code SecurityUtils.getSubject()} call will still work properly. This implementation also guarantees that Shiro's
- * thread state will be identical before and after execution to ensure threads remain clean in any thread-pooled
- * environment.
- * <p/>
- * When instances of this class {@link Runnable#run() run()}, the following occurs:
- * <ol>
- * <li>The Subject and any of its associated thread state is first bound to the thread that executes the
- * {@code Runnable}.</li>
- * <li>The delegate/target {@code Runnable} is {@link #doRun(Runnable) run}</li>
- * <li>Any previous thread state that might have existed before the {@code Subject} was bound is fully restored</li>
- * </ol>
- * <p/>
- *
- * <h3>Usage</h3>
- *
- * This is typically considered a support class and is not often directly referenced. Most people prefer to use
- * the {@code Subject.}{@link Subject#execute(Runnable) execute} or
- * {@code Subject.}{@link Subject#associateWith(Runnable) associateWith} methods, which transparently perform the
- * necessary association logic.
- * <p/>
- * An even more convenient alternative is to use a
- * {@link org.apache.shiro.concurrent.SubjectAwareExecutor SubjectAwareExecutor}, which transparently uses
- * instances of this class but does not require referencing Shiro's API at all.
- *
- * @see Subject#associateWith(Runnable)
- * @see org.apache.shiro.concurrent.SubjectAwareExecutor SubjectAwareExecutor
- * @since 1.0
- */
-public class SubjectRunnable implements Runnable {
-
- protected final ThreadState threadState;
- private final Runnable runnable;
-
- /**
- * Creates a new {@code SubjectRunnable} that, when executed, will execute the target {@code delegate}, but
- * guarantees that it will run associated with the specified {@code Subject}.
- *
- * @param subject the Subject to associate with the delegate's execution.
- * @param delegate the runnable to run.
- */
- public SubjectRunnable(Subject subject, Runnable delegate) {
- this(new SubjectThreadState(subject), delegate);
- }
-
- /**
- * Creates a new {@code SubjectRunnable} that, when executed, will perform thread state
- * {@link ThreadState#bind binding} and guaranteed {@link ThreadState#restore restoration} before and after the
- * {@link Runnable Runnable}'s execution, respectively.
- *
- * @param threadState the thread state to bind and unbind before and after the runnable's execution.
- * @param delegate the delegate {@code Runnable} to execute when this instance is {@link #run() run()}.
- * @throws IllegalArgumentException if either the {@code ThreadState} or {@link Runnable} arguments are {@code null}.
- */
- protected SubjectRunnable(ThreadState threadState, Runnable delegate) throws IllegalArgumentException {
- if (threadState == null) {
- throw new IllegalArgumentException("ThreadState argument cannot be null.");
- }
- this.threadState = threadState;
- if (delegate == null) {
- throw new IllegalArgumentException("Runnable argument cannot be null.");
- }
- this.runnable = delegate;
- }
-
- /**
- * {@link ThreadState#bind Bind}s the Subject thread state, executes the target {@code Runnable} and then guarantees
- * the previous thread state's {@link ThreadState#restore restoration}:
- * <pre>
- * try {
- * threadState.{@link ThreadState#bind bind()};
- * {@link #doRun doRun}(targetRunnable);
- * } finally {
- * threadState.{@link ThreadState#restore restore()}
- * }
- * </pre>
- */
- public void run() {
- try {
- threadState.bind();
- doRun(this.runnable);
- } finally {
- threadState.restore();
- }
- }
-
- /**
- * Simply calls the target {@link Runnable Runnable}'s {@link Runnable#run run()} method.
- *
- * @param runnable the target runnable to run.
- */
- protected void doRun(Runnable runnable) {
- runnable.run();
- }
-}
+/*
+ * 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.subject.support;
+
+import org.apache.shiro.subject.Subject;
+import org.apache.shiro.util.ThreadState;
+
+/**
+ * A {@code SubjectRunnable} ensures that a target/delegate {@link Runnable Runnable} will execute such that any
+ * call to {@code SecurityUtils.}{@link org.apache.shiro.SecurityUtils#getSubject() getSubject()} during the
+ * {@code Runnable}'s execution will return the associated {@code Subject} instance. The {@code SubjectRunnable}
+ * instance can be run on any thread (the current thread or asynchronously on another thread) and the
+ * {@code SecurityUtils.getSubject()} call will still work properly. This implementation also guarantees that Shiro's
+ * thread state will be identical before and after execution to ensure threads remain clean in any thread-pooled
+ * environment.
+ * <p/>
+ * When instances of this class {@link Runnable#run() run()}, the following occurs:
+ * <ol>
+ * <li>The Subject and any of its associated thread state is first bound to the thread that executes the
+ * {@code Runnable}.</li>
+ * <li>The delegate/target {@code Runnable} is {@link #doRun(Runnable) run}</li>
+ * <li>Any previous thread state that might have existed before the {@code Subject} was bound is fully restored</li>
+ * </ol>
+ * <p/>
+ *
+ * <h3>Usage</h3>
+ *
+ * This is typically considered a support class and is not often directly referenced. Most people prefer to use
+ * the {@code Subject.}{@link Subject#execute(Runnable) execute} or
+ * {@code Subject.}{@link Subject#associateWith(Runnable) associateWith} methods, which transparently perform the
+ * necessary association logic.
+ * <p/>
+ * An even more convenient alternative is to use a
+ * {@link org.apache.shiro.concurrent.SubjectAwareExecutor SubjectAwareExecutor}, which transparently uses
+ * instances of this class but does not require referencing Shiro's API at all.
+ *
+ * @see Subject#associateWith(Runnable)
+ * @see org.apache.shiro.concurrent.SubjectAwareExecutor SubjectAwareExecutor
+ * @since 1.0
+ */
+public class SubjectRunnable implements Runnable {
+
+ protected final ThreadState threadState;
+ private final Runnable runnable;
+
+ /**
+ * Creates a new {@code SubjectRunnable} that, when executed, will execute the target {@code delegate}, but
+ * guarantees that it will run associated with the specified {@code Subject}.
+ *
+ * @param subject the Subject to associate with the delegate's execution.
+ * @param delegate the runnable to run.
+ */
+ public SubjectRunnable(Subject subject, Runnable delegate) {
+ this(new SubjectThreadState(subject), delegate);
+ }
+
+ /**
+ * Creates a new {@code SubjectRunnable} that, when executed, will perform thread state
+ * {@link ThreadState#bind binding} and guaranteed {@link ThreadState#restore restoration} before and after the
+ * {@link Runnable Runnable}'s execution, respectively.
+ *
+ * @param threadState the thread state to bind and unbind before and after the runnable's execution.
+ * @param delegate the delegate {@code Runnable} to execute when this instance is {@link #run() run()}.
+ * @throws IllegalArgumentException if either the {@code ThreadState} or {@link Runnable} arguments are {@code null}.
+ */
+ protected SubjectRunnable(ThreadState threadState, Runnable delegate) throws IllegalArgumentException {
+ if (threadState == null) {
+ throw new IllegalArgumentException("ThreadState argument cannot be null.");
+ }
+ this.threadState = threadState;
+ if (delegate == null) {
+ throw new IllegalArgumentException("Runnable argument cannot be null.");
+ }
+ this.runnable = delegate;
+ }
+
+ /**
+ * {@link ThreadState#bind Bind}s the Subject thread state, executes the target {@code Runnable} and then guarantees
+ * the previous thread state's {@link ThreadState#restore restoration}:
+ * <pre>
+ * try {
+ * threadState.{@link ThreadState#bind bind()};
+ * {@link #doRun doRun}(targetRunnable);
+ * } finally {
+ * threadState.{@link ThreadState#restore restore()}
+ * }
+ * </pre>
+ */
+ public void run() {
+ try {
+ threadState.bind();
+ doRun(this.runnable);
+ } finally {
+ threadState.restore();
+ }
+ }
+
+ /**
+ * Simply calls the target {@link Runnable Runnable}'s {@link Runnable#run run()} method.
+ *
+ * @param runnable the target runnable to run.
+ */
+ protected void doRun(Runnable runnable) {
+ runnable.run();
+ }
+}
Propchange: incubator/shiro/branches/shiro-root-1.0.x/core/src/main/java/org/apache/shiro/subject/support/SubjectRunnable.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: incubator/shiro/branches/shiro-root-1.0.x/core/src/main/java/org/apache/shiro/subject/support/SubjectThreadState.java
URL: http://svn.apache.org/viewvc/incubator/shiro/branches/shiro-root-1.0.x/core/src/main/java/org/apache/shiro/subject/support/SubjectThreadState.java?rev=948527&r1=948526&r2=948527&view=diff
==============================================================================
--- incubator/shiro/branches/shiro-root-1.0.x/core/src/main/java/org/apache/shiro/subject/support/SubjectThreadState.java (original)
+++ incubator/shiro/branches/shiro-root-1.0.x/core/src/main/java/org/apache/shiro/subject/support/SubjectThreadState.java Wed May 26 18:34:28 2010
@@ -1,125 +1,125 @@
-/*
- * 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.subject.support;
-
-import org.apache.shiro.mgt.SecurityManager;
-import org.apache.shiro.subject.Subject;
-import org.apache.shiro.util.CollectionUtils;
-import org.apache.shiro.util.ThreadContext;
-import org.apache.shiro.util.ThreadState;
-
-import java.util.Map;
-
-/**
- * Manages thread-state for {@link Subject Subject} access (supporting
- * {@code SecurityUtils.}{@link org.apache.shiro.SecurityUtils#getSubject() getSubject()} calls)
- * during a thread's execution.
- * <p/>
- * The {@link #bind bind} method will bind a {@link Subject} and a
- * {@link org.apache.shiro.mgt.SecurityManager SecurityManager} to the {@link ThreadContext} so they can be retrieved
- * from the {@code ThreadContext} later by any
- * {@code SecurityUtils.}{@link org.apache.shiro.SecurityUtils#getSubject() getSubject()} calls that might occur during
- * the thread's execution.
- *
- * @since 1.0
- * @author Les Hazlewood
- */
-public class SubjectThreadState implements ThreadState {
-
- private Map<Object, Object> originalResources;
-
- private final Subject subject;
- private transient SecurityManager securityManager;
-
- /**
- * Creates a new {@code SubjectThreadState} that will bind and unbind the specified {@code Subject} to the
- * thread
- *
- * @param subject the {@code Subject} instance to bind and unbind from the {@link ThreadContext}.
- */
- public SubjectThreadState(Subject subject) {
- if (subject == null) {
- throw new IllegalArgumentException("Subject argument cannot be null.");
- }
- this.subject = subject;
-
- SecurityManager securityManager = null;
- if ( subject instanceof DelegatingSubject) {
- securityManager = ((DelegatingSubject)subject).getSecurityManager();
- }
- if ( securityManager == null) {
- securityManager = ThreadContext.getSecurityManager();
- }
- this.securityManager = securityManager;
- }
-
- /**
- * Returns the {@code Subject} instance managed by this {@code ThreadState} implementation.
- *
- * @return the {@code Subject} instance managed by this {@code ThreadState} implementation.
- */
- protected Subject getSubject() {
- return this.subject;
- }
-
- /**
- * Binds a {@link Subject} and {@link org.apache.shiro.mgt.SecurityManager SecurityManager} to the
- * {@link ThreadContext} so they can be retrieved later by any
- * {@code SecurityUtils.}{@link org.apache.shiro.SecurityUtils#getSubject() getSubject()} calls that might occur
- * during the thread's execution.
- * <p/>
- * Prior to binding, the {@code ThreadContext}'s existing {@link ThreadContext#getResources() resources} are
- * retained so they can be restored later via the {@link #restore restore} call.
- */
- public void bind() {
- SecurityManager securityManager = this.securityManager;
- if ( securityManager == null ) {
- //try just in case the constructor didn't find one at the time:
- securityManager = ThreadContext.getSecurityManager();
- }
- this.originalResources = ThreadContext.getResources();
- ThreadContext.remove();
-
- ThreadContext.bind(this.subject);
- if (securityManager != null) {
- ThreadContext.bind(securityManager);
- }
- }
-
- /**
- * {@link ThreadContext#remove Remove}s all thread-state that was bound by this instance. If any previous
- * thread-bound resources existed prior to the {@link #bind bind} call, they are restored back to the
- * {@code ThreadContext} to ensure the thread state is exactly as it was before binding.
- */
- public void restore() {
- ThreadContext.remove();
- if (!CollectionUtils.isEmpty(this.originalResources)) {
- ThreadContext.setResources(this.originalResources);
- }
- }
-
- /**
- * Completely {@link ThreadContext#remove removes} the {@code ThreadContext} state. Typically this method should
- * only be called in special cases - it is more 'correct' to {@link #restore restore} a thread to its previous
- * state than to clear it entirely.
- */
- public void clear() {
- ThreadContext.remove();
- }
-}
+/*
+ * 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.subject.support;
+
+import org.apache.shiro.mgt.SecurityManager;
+import org.apache.shiro.subject.Subject;
+import org.apache.shiro.util.CollectionUtils;
+import org.apache.shiro.util.ThreadContext;
+import org.apache.shiro.util.ThreadState;
+
+import java.util.Map;
+
+/**
+ * Manages thread-state for {@link Subject Subject} access (supporting
+ * {@code SecurityUtils.}{@link org.apache.shiro.SecurityUtils#getSubject() getSubject()} calls)
+ * during a thread's execution.
+ * <p/>
+ * The {@link #bind bind} method will bind a {@link Subject} and a
+ * {@link org.apache.shiro.mgt.SecurityManager SecurityManager} to the {@link ThreadContext} so they can be retrieved
+ * from the {@code ThreadContext} later by any
+ * {@code SecurityUtils.}{@link org.apache.shiro.SecurityUtils#getSubject() getSubject()} calls that might occur during
+ * the thread's execution.
+ *
+ * @since 1.0
+ * @author Les Hazlewood
+ */
+public class SubjectThreadState implements ThreadState {
+
+ private Map<Object, Object> originalResources;
+
+ private final Subject subject;
+ private transient SecurityManager securityManager;
+
+ /**
+ * Creates a new {@code SubjectThreadState} that will bind and unbind the specified {@code Subject} to the
+ * thread
+ *
+ * @param subject the {@code Subject} instance to bind and unbind from the {@link ThreadContext}.
+ */
+ public SubjectThreadState(Subject subject) {
+ if (subject == null) {
+ throw new IllegalArgumentException("Subject argument cannot be null.");
+ }
+ this.subject = subject;
+
+ SecurityManager securityManager = null;
+ if ( subject instanceof DelegatingSubject) {
+ securityManager = ((DelegatingSubject)subject).getSecurityManager();
+ }
+ if ( securityManager == null) {
+ securityManager = ThreadContext.getSecurityManager();
+ }
+ this.securityManager = securityManager;
+ }
+
+ /**
+ * Returns the {@code Subject} instance managed by this {@code ThreadState} implementation.
+ *
+ * @return the {@code Subject} instance managed by this {@code ThreadState} implementation.
+ */
+ protected Subject getSubject() {
+ return this.subject;
+ }
+
+ /**
+ * Binds a {@link Subject} and {@link org.apache.shiro.mgt.SecurityManager SecurityManager} to the
+ * {@link ThreadContext} so they can be retrieved later by any
+ * {@code SecurityUtils.}{@link org.apache.shiro.SecurityUtils#getSubject() getSubject()} calls that might occur
+ * during the thread's execution.
+ * <p/>
+ * Prior to binding, the {@code ThreadContext}'s existing {@link ThreadContext#getResources() resources} are
+ * retained so they can be restored later via the {@link #restore restore} call.
+ */
+ public void bind() {
+ SecurityManager securityManager = this.securityManager;
+ if ( securityManager == null ) {
+ //try just in case the constructor didn't find one at the time:
+ securityManager = ThreadContext.getSecurityManager();
+ }
+ this.originalResources = ThreadContext.getResources();
+ ThreadContext.remove();
+
+ ThreadContext.bind(this.subject);
+ if (securityManager != null) {
+ ThreadContext.bind(securityManager);
+ }
+ }
+
+ /**
+ * {@link ThreadContext#remove Remove}s all thread-state that was bound by this instance. If any previous
+ * thread-bound resources existed prior to the {@link #bind bind} call, they are restored back to the
+ * {@code ThreadContext} to ensure the thread state is exactly as it was before binding.
+ */
+ public void restore() {
+ ThreadContext.remove();
+ if (!CollectionUtils.isEmpty(this.originalResources)) {
+ ThreadContext.setResources(this.originalResources);
+ }
+ }
+
+ /**
+ * Completely {@link ThreadContext#remove removes} the {@code ThreadContext} state. Typically this method should
+ * only be called in special cases - it is more 'correct' to {@link #restore restore} a thread to its previous
+ * state than to clear it entirely.
+ */
+ public void clear() {
+ ThreadContext.remove();
+ }
+}
Propchange: incubator/shiro/branches/shiro-root-1.0.x/core/src/main/java/org/apache/shiro/subject/support/SubjectThreadState.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/shiro/branches/shiro-root-1.0.x/core/src/main/java/org/apache/shiro/subject/support/package-info.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/shiro/branches/shiro-root-1.0.x/core/src/main/java/org/apache/shiro/util/AbstractFactory.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/shiro/branches/shiro-root-1.0.x/core/src/main/java/org/apache/shiro/util/AntPathMatcher.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/shiro/branches/shiro-root-1.0.x/core/src/main/java/org/apache/shiro/util/ByteSource.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/shiro/branches/shiro-root-1.0.x/core/src/main/java/org/apache/shiro/util/CollectionUtils.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/shiro/branches/shiro-root-1.0.x/core/src/main/java/org/apache/shiro/util/Destroyable.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: incubator/shiro/branches/shiro-root-1.0.x/core/src/main/java/org/apache/shiro/util/Factory.java
URL: http://svn.apache.org/viewvc/incubator/shiro/branches/shiro-root-1.0.x/core/src/main/java/org/apache/shiro/util/Factory.java?rev=948527&r1=948526&r2=948527&view=diff
==============================================================================
--- incubator/shiro/branches/shiro-root-1.0.x/core/src/main/java/org/apache/shiro/util/Factory.java (original)
+++ incubator/shiro/branches/shiro-root-1.0.x/core/src/main/java/org/apache/shiro/util/Factory.java Wed May 26 18:34:28 2010
@@ -1,37 +1,37 @@
-/*
- * 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.util;
-
-/**
- * Generics-aware interface supporting the
- * <a href="http://en.wikipedia.org/wiki/Factory_method_pattern">Factory Method</a> design pattern.
- *
- * @param <T> The type of the instance returned by the Factory implementation.
- * @since 1.0
- */
-public interface Factory<T> {
-
- /**
- * Returns an instance of the required type. The implementation determines whether or not a new or cached
- * instance is created every time this method is called.
- *
- * @return an instance of the required type.
- */
- T getInstance();
-}
+/*
+ * 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.util;
+
+/**
+ * Generics-aware interface supporting the
+ * <a href="http://en.wikipedia.org/wiki/Factory_method_pattern">Factory Method</a> design pattern.
+ *
+ * @param <T> The type of the instance returned by the Factory implementation.
+ * @since 1.0
+ */
+public interface Factory<T> {
+
+ /**
+ * Returns an instance of the required type. The implementation determines whether or not a new or cached
+ * instance is created every time this method is called.
+ *
+ * @return an instance of the required type.
+ */
+ T getInstance();
+}
Propchange: incubator/shiro/branches/shiro-root-1.0.x/core/src/main/java/org/apache/shiro/util/Factory.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/shiro/branches/shiro-root-1.0.x/core/src/main/java/org/apache/shiro/util/Initializable.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/shiro/branches/shiro-root-1.0.x/core/src/main/java/org/apache/shiro/util/InstantiationException.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/shiro/branches/shiro-root-1.0.x/core/src/main/java/org/apache/shiro/util/JavaEnvironment.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: incubator/shiro/branches/shiro-root-1.0.x/core/src/main/java/org/apache/shiro/util/JdbcUtils.java
URL: http://svn.apache.org/viewvc/incubator/shiro/branches/shiro-root-1.0.x/core/src/main/java/org/apache/shiro/util/JdbcUtils.java?rev=948527&r1=948526&r2=948527&view=diff
==============================================================================
--- incubator/shiro/branches/shiro-root-1.0.x/core/src/main/java/org/apache/shiro/util/JdbcUtils.java (original)
+++ incubator/shiro/branches/shiro-root-1.0.x/core/src/main/java/org/apache/shiro/util/JdbcUtils.java Wed May 26 18:34:28 2010
@@ -1,116 +1,116 @@
-/*
- * 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.util;
-
-import java.sql.Connection;
-import java.sql.ResultSet;
-import java.sql.SQLException;
-import java.sql.Statement;
-
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-/**
- * A set of static helper methods for managing JDBC API objects.
- * <p/>
- * <em>Note:</em> Some parts of this class were copied from the Spring Framework and then modified.
- * They were copied here to prevent Spring dependencies in the Shiro core API. The original license conditions
- * (Apache 2.0) have been maintained.
- *
- * @author Jeremy Haile
- * @since 0.2
- */
-public class JdbcUtils {
-
- /** Private internal log instance. */
- private static final Logger log = LoggerFactory.getLogger(JdbcUtils.class);
-
- /**
- * Private constructor to prevent instantiation.
- */
- private JdbcUtils() {
- }
-
- /**
- * Close the given JDBC Connection and ignore any thrown exception.
- * This is useful for typical finally blocks in manual JDBC code.
- *
- * @param connection the JDBC Connection to close (may be <tt>null</tt>)
- */
- public static void closeConnection(Connection connection) {
- if (connection != null) {
- try {
- connection.close();
- } catch (SQLException ex) {
- if (log.isDebugEnabled()) {
- log.debug("Could not close JDBC Connection", ex);
- }
- } catch (Throwable ex) {
- if (log.isDebugEnabled()) {
- log.debug("Unexpected exception on closing JDBC Connection", ex);
- }
- }
- }
- }
-
- /**
- * Close the given JDBC Statement and ignore any thrown exception.
- * This is useful for typical finally blocks in manual JDBC code.
- *
- * @param statement the JDBC Statement to close (may be <tt>null</tt>)
- */
- public static void closeStatement(Statement statement) {
- if (statement != null) {
- try {
- statement.close();
- } catch (SQLException ex) {
- if (log.isDebugEnabled()) {
- log.debug("Could not close JDBC Statement", ex);
- }
- } catch (Throwable ex) {
- if (log.isDebugEnabled()) {
- log.debug("Unexpected exception on closing JDBC Statement", ex);
- }
- }
- }
- }
-
- /**
- * Close the given JDBC ResultSet and ignore any thrown exception.
- * This is useful for typical finally blocks in manual JDBC code.
- *
- * @param rs the JDBC ResultSet to close (may be <tt>null</tt>)
- */
- public static void closeResultSet(ResultSet rs) {
- if (rs != null) {
- try {
- rs.close();
- } catch (SQLException ex) {
- if (log.isDebugEnabled()) {
- log.debug("Could not close JDBC ResultSet", ex);
- }
- } catch (Throwable ex) {
- if (log.isDebugEnabled()) {
- log.debug("Unexpected exception on closing JDBC ResultSet", ex);
- }
- }
- }
- }
-
-}
+/*
+ * 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.util;
+
+import java.sql.Connection;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * A set of static helper methods for managing JDBC API objects.
+ * <p/>
+ * <em>Note:</em> Some parts of this class were copied from the Spring Framework and then modified.
+ * They were copied here to prevent Spring dependencies in the Shiro core API. The original license conditions
+ * (Apache 2.0) have been maintained.
+ *
+ * @author Jeremy Haile
+ * @since 0.2
+ */
+public class JdbcUtils {
+
+ /** Private internal log instance. */
+ private static final Logger log = LoggerFactory.getLogger(JdbcUtils.class);
+
+ /**
+ * Private constructor to prevent instantiation.
+ */
+ private JdbcUtils() {
+ }
+
+ /**
+ * Close the given JDBC Connection and ignore any thrown exception.
+ * This is useful for typical finally blocks in manual JDBC code.
+ *
+ * @param connection the JDBC Connection to close (may be <tt>null</tt>)
+ */
+ public static void closeConnection(Connection connection) {
+ if (connection != null) {
+ try {
+ connection.close();
+ } catch (SQLException ex) {
+ if (log.isDebugEnabled()) {
+ log.debug("Could not close JDBC Connection", ex);
+ }
+ } catch (Throwable ex) {
+ if (log.isDebugEnabled()) {
+ log.debug("Unexpected exception on closing JDBC Connection", ex);
+ }
+ }
+ }
+ }
+
+ /**
+ * Close the given JDBC Statement and ignore any thrown exception.
+ * This is useful for typical finally blocks in manual JDBC code.
+ *
+ * @param statement the JDBC Statement to close (may be <tt>null</tt>)
+ */
+ public static void closeStatement(Statement statement) {
+ if (statement != null) {
+ try {
+ statement.close();
+ } catch (SQLException ex) {
+ if (log.isDebugEnabled()) {
+ log.debug("Could not close JDBC Statement", ex);
+ }
+ } catch (Throwable ex) {
+ if (log.isDebugEnabled()) {
+ log.debug("Unexpected exception on closing JDBC Statement", ex);
+ }
+ }
+ }
+ }
+
+ /**
+ * Close the given JDBC ResultSet and ignore any thrown exception.
+ * This is useful for typical finally blocks in manual JDBC code.
+ *
+ * @param rs the JDBC ResultSet to close (may be <tt>null</tt>)
+ */
+ public static void closeResultSet(ResultSet rs) {
+ if (rs != null) {
+ try {
+ rs.close();
+ } catch (SQLException ex) {
+ if (log.isDebugEnabled()) {
+ log.debug("Could not close JDBC ResultSet", ex);
+ }
+ } catch (Throwable ex) {
+ if (log.isDebugEnabled()) {
+ log.debug("Unexpected exception on closing JDBC ResultSet", ex);
+ }
+ }
+ }
+ }
+
+}
Propchange: incubator/shiro/branches/shiro-root-1.0.x/core/src/main/java/org/apache/shiro/util/JdbcUtils.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: incubator/shiro/branches/shiro-root-1.0.x/core/src/main/java/org/apache/shiro/util/LifecycleUtils.java
URL: http://svn.apache.org/viewvc/incubator/shiro/branches/shiro-root-1.0.x/core/src/main/java/org/apache/shiro/util/LifecycleUtils.java?rev=948527&r1=948526&r2=948527&view=diff
==============================================================================
--- incubator/shiro/branches/shiro-root-1.0.x/core/src/main/java/org/apache/shiro/util/LifecycleUtils.java (original)
+++ incubator/shiro/branches/shiro-root-1.0.x/core/src/main/java/org/apache/shiro/util/LifecycleUtils.java Wed May 26 18:34:28 2010
@@ -1,101 +1,101 @@
-/*
- * 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.util;
-
-import org.apache.shiro.ShiroException;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import java.util.Collection;
-
-
-/**
- * Utility class to help call {@link org.apache.shiro.util.Initializable#init() Initializable.init()} and
- * {@link org.apache.shiro.util.Destroyable#destroy() Destroyable.destroy()} methods cleanly on any object.
- *
- * @author Les Hazlewood
- * @since 0.2
- */
-public abstract class LifecycleUtils {
-
- private static final Logger log = LoggerFactory.getLogger(LifecycleUtils.class);
-
- public static void init(Object o) throws ShiroException {
- if (o instanceof Initializable) {
- init((Initializable) o);
- }
- }
-
- public static void init(Initializable initializable) throws ShiroException {
- initializable.init();
- }
-
- /**
- * Calls {@link #init(Object) init} for each object in the collection. If the collection is {@code null} or empty,
- * this method returns quietly.
- *
- * @param c the collection containing objects to {@link #init init}.
- * @throws ShiroException if unable to initialize one or more instances.
- * @since 0.9
- */
- public static void init(Collection c) throws ShiroException {
- if (c == null || c.isEmpty()) {
- return;
- }
- for (Object o : c) {
- init(o);
- }
- }
-
- public static void destroy(Object o) {
- if (o instanceof Destroyable) {
- destroy((Destroyable) o);
- }
- }
-
- public static void destroy(Destroyable d) {
- if (d != null) {
- try {
- d.destroy();
- } catch (Throwable t) {
- if (log.isDebugEnabled()) {
- String msg = "Unable to cleanly destroy instance [" + d + "] of type [" + d.getClass().getName() + "].";
- log.debug(msg, t);
- }
- }
- }
- }
-
- /**
- * Calls {@link #destroy(Object) destroy} for each object in the collection.
- * If the collection is {@code null} or empty, this method returns quietly.
- *
- * @param c the collection of objects to destroy.
- * @since 0.9
- */
- public static void destroy(Collection c) {
- if (c == null || c.isEmpty()) {
- return;
- }
-
- for (Object o : c) {
- destroy(o);
- }
- }
-}
+/*
+ * 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.util;
+
+import org.apache.shiro.ShiroException;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.Collection;
+
+
+/**
+ * Utility class to help call {@link org.apache.shiro.util.Initializable#init() Initializable.init()} and
+ * {@link org.apache.shiro.util.Destroyable#destroy() Destroyable.destroy()} methods cleanly on any object.
+ *
+ * @author Les Hazlewood
+ * @since 0.2
+ */
+public abstract class LifecycleUtils {
+
+ private static final Logger log = LoggerFactory.getLogger(LifecycleUtils.class);
+
+ public static void init(Object o) throws ShiroException {
+ if (o instanceof Initializable) {
+ init((Initializable) o);
+ }
+ }
+
+ public static void init(Initializable initializable) throws ShiroException {
+ initializable.init();
+ }
+
+ /**
+ * Calls {@link #init(Object) init} for each object in the collection. If the collection is {@code null} or empty,
+ * this method returns quietly.
+ *
+ * @param c the collection containing objects to {@link #init init}.
+ * @throws ShiroException if unable to initialize one or more instances.
+ * @since 0.9
+ */
+ public static void init(Collection c) throws ShiroException {
+ if (c == null || c.isEmpty()) {
+ return;
+ }
+ for (Object o : c) {
+ init(o);
+ }
+ }
+
+ public static void destroy(Object o) {
+ if (o instanceof Destroyable) {
+ destroy((Destroyable) o);
+ }
+ }
+
+ public static void destroy(Destroyable d) {
+ if (d != null) {
+ try {
+ d.destroy();
+ } catch (Throwable t) {
+ if (log.isDebugEnabled()) {
+ String msg = "Unable to cleanly destroy instance [" + d + "] of type [" + d.getClass().getName() + "].";
+ log.debug(msg, t);
+ }
+ }
+ }
+ }
+
+ /**
+ * Calls {@link #destroy(Object) destroy} for each object in the collection.
+ * If the collection is {@code null} or empty, this method returns quietly.
+ *
+ * @param c the collection of objects to destroy.
+ * @since 0.9
+ */
+ public static void destroy(Collection c) {
+ if (c == null || c.isEmpty()) {
+ return;
+ }
+
+ for (Object o : c) {
+ destroy(o);
+ }
+ }
+}
Propchange: incubator/shiro/branches/shiro-root-1.0.x/core/src/main/java/org/apache/shiro/util/LifecycleUtils.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/shiro/branches/shiro-root-1.0.x/core/src/main/java/org/apache/shiro/util/MapContext.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/shiro/branches/shiro-root-1.0.x/core/src/main/java/org/apache/shiro/util/Nameable.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: incubator/shiro/branches/shiro-root-1.0.x/core/src/main/java/org/apache/shiro/util/PatternMatcher.java
URL: http://svn.apache.org/viewvc/incubator/shiro/branches/shiro-root-1.0.x/core/src/main/java/org/apache/shiro/util/PatternMatcher.java?rev=948527&r1=948526&r2=948527&view=diff
==============================================================================
--- incubator/shiro/branches/shiro-root-1.0.x/core/src/main/java/org/apache/shiro/util/PatternMatcher.java (original)
+++ incubator/shiro/branches/shiro-root-1.0.x/core/src/main/java/org/apache/shiro/util/PatternMatcher.java Wed May 26 18:34:28 2010
@@ -1,43 +1,43 @@
-/*
- * 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.util;
-
-/**
- * Interface for components that can match source strings against a specified pattern string.
- * <p/>
- * Different implementations can support different pattern types, for example, Ant style path expressions, or
- * regular expressions, or other types of text based patterns.
- *
- * @author Les Hazlewood
- * @see org.apache.shiro.util.AntPathMatcher AntPathMatcher
- * @since 0.9 RC2
- */
-public interface PatternMatcher {
-
- /**
- * Returns <code>true</code> if the given <code>source</code> matches the specified <code>pattern</code>,
- * <code>false</code> otherwise.
- *
- * @param pattern the pattern to match against
- * @param source the source to match
- * @return <code>true</code> if the given <code>source</code> matches the specified <code>pattern</code>,
- * <code>false</code> otherwise.
- */
- boolean matches(String pattern, String source);
-}
+/*
+ * 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.util;
+
+/**
+ * Interface for components that can match source strings against a specified pattern string.
+ * <p/>
+ * Different implementations can support different pattern types, for example, Ant style path expressions, or
+ * regular expressions, or other types of text based patterns.
+ *
+ * @author Les Hazlewood
+ * @see org.apache.shiro.util.AntPathMatcher AntPathMatcher
+ * @since 0.9 RC2
+ */
+public interface PatternMatcher {
+
+ /**
+ * Returns <code>true</code> if the given <code>source</code> matches the specified <code>pattern</code>,
+ * <code>false</code> otherwise.
+ *
+ * @param pattern the pattern to match against
+ * @param source the source to match
+ * @return <code>true</code> if the given <code>source</code> matches the specified <code>pattern</code>,
+ * <code>false</code> otherwise.
+ */
+ boolean matches(String pattern, String source);
+}
Propchange: incubator/shiro/branches/shiro-root-1.0.x/core/src/main/java/org/apache/shiro/util/PatternMatcher.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: incubator/shiro/branches/shiro-root-1.0.x/core/src/main/java/org/apache/shiro/util/RegExPatternMatcher.java
URL: http://svn.apache.org/viewvc/incubator/shiro/branches/shiro-root-1.0.x/core/src/main/java/org/apache/shiro/util/RegExPatternMatcher.java?rev=948527&r1=948526&r2=948527&view=diff
==============================================================================
--- incubator/shiro/branches/shiro-root-1.0.x/core/src/main/java/org/apache/shiro/util/RegExPatternMatcher.java (original)
+++ incubator/shiro/branches/shiro-root-1.0.x/core/src/main/java/org/apache/shiro/util/RegExPatternMatcher.java Wed May 26 18:34:28 2010
@@ -1,53 +1,53 @@
-/*
- * 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.util;
-
-import java.util.regex.Pattern;
-import java.util.regex.Matcher;
-
-/**
- * {@code PatternMatcher} implementation that uses standard {@link java.util.regex} objects.
- *
- * @see Pattern
- * @author Les Hazlewood
- * @since 1.0
- */
-public class RegExPatternMatcher implements PatternMatcher {
-
- /**
- * Simple implementation that merely uses the default pattern comparison logic provided by the
- * JDK.
- * <p/>This implementation essentially executes the following:
- * <pre>
- * Pattern p = Pattern.compile(pattern);
- * Matcher m = p.matcher(source);
- * return m.matches();</pre>
- * @param pattern the pattern to match against
- * @param source the source to match
- * @return {@code true} if the source matches the required pattern, {@code false} otherwise.
- */
- public boolean matches(String pattern, String source) {
- if (pattern == null) {
- throw new IllegalArgumentException("pattern argument cannot be null.");
- }
- Pattern p = Pattern.compile(pattern);
- Matcher m = p.matcher(source);
- return m.matches();
- }
-}
+/*
+ * 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.util;
+
+import java.util.regex.Pattern;
+import java.util.regex.Matcher;
+
+/**
+ * {@code PatternMatcher} implementation that uses standard {@link java.util.regex} objects.
+ *
+ * @see Pattern
+ * @author Les Hazlewood
+ * @since 1.0
+ */
+public class RegExPatternMatcher implements PatternMatcher {
+
+ /**
+ * Simple implementation that merely uses the default pattern comparison logic provided by the
+ * JDK.
+ * <p/>This implementation essentially executes the following:
+ * <pre>
+ * Pattern p = Pattern.compile(pattern);
+ * Matcher m = p.matcher(source);
+ * return m.matches();</pre>
+ * @param pattern the pattern to match against
+ * @param source the source to match
+ * @return {@code true} if the source matches the required pattern, {@code false} otherwise.
+ */
+ public boolean matches(String pattern, String source) {
+ if (pattern == null) {
+ throw new IllegalArgumentException("pattern argument cannot be null.");
+ }
+ Pattern p = Pattern.compile(pattern);
+ Matcher m = p.matcher(source);
+ return m.matches();
+ }
+}
Propchange: incubator/shiro/branches/shiro-root-1.0.x/core/src/main/java/org/apache/shiro/util/RegExPatternMatcher.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/shiro/branches/shiro-root-1.0.x/core/src/main/java/org/apache/shiro/util/SimpleByteSource.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/shiro/branches/shiro-root-1.0.x/core/src/main/java/org/apache/shiro/util/SoftHashMap.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/shiro/branches/shiro-root-1.0.x/core/src/main/java/org/apache/shiro/util/StringUtils.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: incubator/shiro/branches/shiro-root-1.0.x/core/src/main/java/org/apache/shiro/util/ThreadState.java
URL: http://svn.apache.org/viewvc/incubator/shiro/branches/shiro-root-1.0.x/core/src/main/java/org/apache/shiro/util/ThreadState.java?rev=948527&r1=948526&r2=948527&view=diff
==============================================================================
--- incubator/shiro/branches/shiro-root-1.0.x/core/src/main/java/org/apache/shiro/util/ThreadState.java (original)
+++ incubator/shiro/branches/shiro-root-1.0.x/core/src/main/java/org/apache/shiro/util/ThreadState.java Wed May 26 18:34:28 2010
@@ -1,84 +1,84 @@
-/*
- * 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.util;
-
-/**
- * A {@code ThreadState} instance manages any state that might need to be bound and/or restored during a thread's
- * execution.
- * <h3>Usage</h3>
- * Calling {@link #bind bind()} will place state on the currently executing thread to be accessed later during
- * the thread's execution.
- * <h4>WARNING</h4>
- * After the thread is finished executing, or if an exception occurs, any previous state <b>MUST</b> be
- * {@link #restore restored} to guarantee all threads stay clean in any thread-pooled environment. This should always
- * be done in a {@code try/finally} block:
- * <pre>
- * ThreadState state = //acquire or instantiate as necessary
- * try {
- * state.bind();
- * doSomething(); //execute any logic downstream logic that might need to access the state
- * } <b>finally {
- * state.restore();
- * }</b>
- * </pre>
- *
- * @since 1.0
- */
-public interface ThreadState {
-
- /**
- * Binds any state that should be made accessible during a thread's execution. This should typically always
- * be called in a {@code try/finally} block paired with the {@link #restore} call to guarantee that the thread
- * is cleanly restored back to its original state. For example:
- * <pre>
- * ThreadState state = //acquire or instantiate as necessary
- * <b>try {
- * state.bind();
- * doSomething(); //execute any logic downstream logic that might need to access the state
- * } </b> finally {
- * state.restore();
- * }
- * </pre>
- */
- void bind();
-
- /**
- * Restores a thread to its state before bind {@link #bind bind} was invoked. This should typically always be
- * called in a {@code finally} block to guarantee that the thread is cleanly restored back to its original state
- * before {@link #bind bind}'s bind was called. For example:
- * <pre>
- * ThreadState state = //acquire or instantiate as necessary
- * try {
- * state.bind();
- * doSomething(); //execute any logic downstream logic that might need to access the state
- * } <b>finally {
- * state.restore();
- * }</b>
- * </pre>
- */
- void restore();
-
- /**
- * Completely clears/removes the {@code ThreadContext} state. Typically this method should
- * only be called in special cases - it is more 'correct' to {@link #restore restore} a thread to its previous
- * state than to clear it entirely.
- */
- void clear();
-
-}
+/*
+ * 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.util;
+
+/**
+ * A {@code ThreadState} instance manages any state that might need to be bound and/or restored during a thread's
+ * execution.
+ * <h3>Usage</h3>
+ * Calling {@link #bind bind()} will place state on the currently executing thread to be accessed later during
+ * the thread's execution.
+ * <h4>WARNING</h4>
+ * After the thread is finished executing, or if an exception occurs, any previous state <b>MUST</b> be
+ * {@link #restore restored} to guarantee all threads stay clean in any thread-pooled environment. This should always
+ * be done in a {@code try/finally} block:
+ * <pre>
+ * ThreadState state = //acquire or instantiate as necessary
+ * try {
+ * state.bind();
+ * doSomething(); //execute any logic downstream logic that might need to access the state
+ * } <b>finally {
+ * state.restore();
+ * }</b>
+ * </pre>
+ *
+ * @since 1.0
+ */
+public interface ThreadState {
+
+ /**
+ * Binds any state that should be made accessible during a thread's execution. This should typically always
+ * be called in a {@code try/finally} block paired with the {@link #restore} call to guarantee that the thread
+ * is cleanly restored back to its original state. For example:
+ * <pre>
+ * ThreadState state = //acquire or instantiate as necessary
+ * <b>try {
+ * state.bind();
+ * doSomething(); //execute any logic downstream logic that might need to access the state
+ * } </b> finally {
+ * state.restore();
+ * }
+ * </pre>
+ */
+ void bind();
+
+ /**
+ * Restores a thread to its state before bind {@link #bind bind} was invoked. This should typically always be
+ * called in a {@code finally} block to guarantee that the thread is cleanly restored back to its original state
+ * before {@link #bind bind}'s bind was called. For example:
+ * <pre>
+ * ThreadState state = //acquire or instantiate as necessary
+ * try {
+ * state.bind();
+ * doSomething(); //execute any logic downstream logic that might need to access the state
+ * } <b>finally {
+ * state.restore();
+ * }</b>
+ * </pre>
+ */
+ void restore();
+
+ /**
+ * Completely clears/removes the {@code ThreadContext} state. Typically this method should
+ * only be called in special cases - it is more 'correct' to {@link #restore restore} a thread to its previous
+ * state than to clear it entirely.
+ */
+ void clear();
+
+}
Propchange: incubator/shiro/branches/shiro-root-1.0.x/core/src/main/java/org/apache/shiro/util/ThreadState.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/shiro/branches/shiro-root-1.0.x/core/src/main/java/org/apache/shiro/util/UnavailableConstructorException.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/shiro/branches/shiro-root-1.0.x/core/src/main/java/org/apache/shiro/util/package-info.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/shiro/branches/shiro-root-1.0.x/core/src/test/java/org/apache/shiro/AtUnitTestBase.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/shiro/branches/shiro-root-1.0.x/core/src/test/java/org/apache/shiro/ExceptionTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/shiro/branches/shiro-root-1.0.x/core/src/test/java/org/apache/shiro/authc/AbstractAuthenticatorTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/shiro/branches/shiro-root-1.0.x/core/src/test/java/org/apache/shiro/authc/ConcurrentAccessExceptionTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/shiro/branches/shiro-root-1.0.x/core/src/test/java/org/apache/shiro/authc/ExcessiveAttemptsExceptionTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/shiro/branches/shiro-root-1.0.x/core/src/test/java/org/apache/shiro/authc/ExpiredCredentialsExceptionTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/shiro/branches/shiro-root-1.0.x/core/src/test/java/org/apache/shiro/authc/IncorrectCredentialsExceptionTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/shiro/branches/shiro-root-1.0.x/core/src/test/java/org/apache/shiro/authc/LockedAccountExceptionTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: incubator/shiro/branches/shiro-root-1.0.x/core/src/test/java/org/apache/shiro/authc/SimpleAuthenticationInfoTest.java
URL: http://svn.apache.org/viewvc/incubator/shiro/branches/shiro-root-1.0.x/core/src/test/java/org/apache/shiro/authc/SimpleAuthenticationInfoTest.java?rev=948527&r1=948526&r2=948527&view=diff
==============================================================================
--- incubator/shiro/branches/shiro-root-1.0.x/core/src/test/java/org/apache/shiro/authc/SimpleAuthenticationInfoTest.java (original)
+++ incubator/shiro/branches/shiro-root-1.0.x/core/src/test/java/org/apache/shiro/authc/SimpleAuthenticationInfoTest.java Wed May 26 18:34:28 2010
@@ -1,93 +1,93 @@
-/*
- * 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.authc;
-
-import static org.junit.Assert.assertEquals;
-
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Set;
-
-import org.apache.shiro.subject.PrincipalCollection;
-import org.junit.Test;
-
-
-/**
- * @author Les Hazlewood
- * @author Kalle Korhonen
- * @since 0.9
- */
-public class SimpleAuthenticationInfoTest {
-
- @Test
- public void testMergeWithEmptyInstances() {
- SimpleAuthenticationInfo aggregate = new SimpleAuthenticationInfo();
- SimpleAuthenticationInfo local = new SimpleAuthenticationInfo();
- aggregate.merge(local);
- }
-
- /**
- * Verifies fix for JSEC-122
- */
- @Test
- public void testMergeWithAggregateNullCredentials() {
- SimpleAuthenticationInfo aggregate = new SimpleAuthenticationInfo();
- SimpleAuthenticationInfo local = new SimpleAuthenticationInfo("username", "password", "testRealm");
- aggregate.merge(local);
- }
-
- @SuppressWarnings("serial")
- @Test
- public void testMergeWithImmutablePrincipalCollection() {
- SimpleAuthenticationInfo aggregate = new SimpleAuthenticationInfo();
- // Make a quick test fixture that does *not* implement MutablePrincipalCollection
- PrincipalCollection principalCollection = new PrincipalCollection() {
- @SuppressWarnings("unchecked")
- public List asList() { return null;}
- @SuppressWarnings("unchecked")
- public Set asSet() {return null;}
- public <T> Collection<T> byType(Class<T> type) {return null;}
- @SuppressWarnings("unchecked")
- public Collection fromRealm(String realmName) {
- Collection<Object> principals = new HashSet<Object>();
- principals.add("testprincipal");
- return principals;
- }
- public Object getPrimaryPrincipal() {return null;}
- public Set<String> getRealmNames() {
- Set<String> realms = new HashSet<String>();
- realms.add("testrealm");
- return realms;
- }
- public boolean isEmpty() {return false;}
- public <T> T oneByType(Class<T> type) {return null;}
- @SuppressWarnings("unchecked")
- public Iterator iterator() {return null;}
-
- };
- aggregate.setPrincipals(principalCollection);
- SimpleAuthenticationInfo local = new SimpleAuthenticationInfo("username", "password", "testRealm");
- aggregate.merge(local);
- assertEquals(2, aggregate.getPrincipals().asList().size());
- }
-
-}
+/*
+ * 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.authc;
+
+import static org.junit.Assert.assertEquals;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Set;
+
+import org.apache.shiro.subject.PrincipalCollection;
+import org.junit.Test;
+
+
+/**
+ * @author Les Hazlewood
+ * @author Kalle Korhonen
+ * @since 0.9
+ */
+public class SimpleAuthenticationInfoTest {
+
+ @Test
+ public void testMergeWithEmptyInstances() {
+ SimpleAuthenticationInfo aggregate = new SimpleAuthenticationInfo();
+ SimpleAuthenticationInfo local = new SimpleAuthenticationInfo();
+ aggregate.merge(local);
+ }
+
+ /**
+ * Verifies fix for JSEC-122
+ */
+ @Test
+ public void testMergeWithAggregateNullCredentials() {
+ SimpleAuthenticationInfo aggregate = new SimpleAuthenticationInfo();
+ SimpleAuthenticationInfo local = new SimpleAuthenticationInfo("username", "password", "testRealm");
+ aggregate.merge(local);
+ }
+
+ @SuppressWarnings("serial")
+ @Test
+ public void testMergeWithImmutablePrincipalCollection() {
+ SimpleAuthenticationInfo aggregate = new SimpleAuthenticationInfo();
+ // Make a quick test fixture that does *not* implement MutablePrincipalCollection
+ PrincipalCollection principalCollection = new PrincipalCollection() {
+ @SuppressWarnings("unchecked")
+ public List asList() { return null;}
+ @SuppressWarnings("unchecked")
+ public Set asSet() {return null;}
+ public <T> Collection<T> byType(Class<T> type) {return null;}
+ @SuppressWarnings("unchecked")
+ public Collection fromRealm(String realmName) {
+ Collection<Object> principals = new HashSet<Object>();
+ principals.add("testprincipal");
+ return principals;
+ }
+ public Object getPrimaryPrincipal() {return null;}
+ public Set<String> getRealmNames() {
+ Set<String> realms = new HashSet<String>();
+ realms.add("testrealm");
+ return realms;
+ }
+ public boolean isEmpty() {return false;}
+ public <T> T oneByType(Class<T> type) {return null;}
+ @SuppressWarnings("unchecked")
+ public Iterator iterator() {return null;}
+
+ };
+ aggregate.setPrincipals(principalCollection);
+ SimpleAuthenticationInfo local = new SimpleAuthenticationInfo("username", "password", "testRealm");
+ aggregate.merge(local);
+ assertEquals(2, aggregate.getPrincipals().asList().size());
+ }
+
+}
Propchange: incubator/shiro/branches/shiro-root-1.0.x/core/src/test/java/org/apache/shiro/authc/SimpleAuthenticationInfoTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/shiro/branches/shiro-root-1.0.x/core/src/test/java/org/apache/shiro/authc/UnknownAccountExceptionTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/shiro/branches/shiro-root-1.0.x/core/src/test/java/org/apache/shiro/authc/credential/AllowAllCredentialsMatcherTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/shiro/branches/shiro-root-1.0.x/core/src/test/java/org/apache/shiro/authc/credential/HashedCredentialsMatcherTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/shiro/branches/shiro-root-1.0.x/core/src/test/java/org/apache/shiro/authc/credential/Md2CredentialsMatcherTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/shiro/branches/shiro-root-1.0.x/core/src/test/java/org/apache/shiro/authc/credential/Md5CredentialsMatcherTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/shiro/branches/shiro-root-1.0.x/core/src/test/java/org/apache/shiro/authc/credential/Sha1CredentialsMatcherTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/shiro/branches/shiro-root-1.0.x/core/src/test/java/org/apache/shiro/authc/credential/Sha256CredentialsMatcherTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/shiro/branches/shiro-root-1.0.x/core/src/test/java/org/apache/shiro/authc/credential/Sha384CredentialsMatcherTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/shiro/branches/shiro-root-1.0.x/core/src/test/java/org/apache/shiro/authc/credential/Sha512CredentialsMatcherTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/shiro/branches/shiro-root-1.0.x/core/src/test/java/org/apache/shiro/authc/pam/AllSuccessfulStrategyTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: incubator/shiro/branches/shiro-root-1.0.x/core/src/test/java/org/apache/shiro/authz/AuthorizationExceptionTest.java
URL: http://svn.apache.org/viewvc/incubator/shiro/branches/shiro-root-1.0.x/core/src/test/java/org/apache/shiro/authz/AuthorizationExceptionTest.java?rev=948527&r1=948526&r2=948527&view=diff
==============================================================================
--- incubator/shiro/branches/shiro-root-1.0.x/core/src/test/java/org/apache/shiro/authz/AuthorizationExceptionTest.java (original)
+++ incubator/shiro/branches/shiro-root-1.0.x/core/src/test/java/org/apache/shiro/authz/AuthorizationExceptionTest.java Wed May 26 18:34:28 2010
@@ -1,33 +1,33 @@
-/*
- * 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.authz;
-
-import org.apache.shiro.ExceptionTest;
-
-
-/**
- * @author Les Hazlewood
- * @since Jun 10, 2008 4:03:56 PM
- */
-public class AuthorizationExceptionTest extends ExceptionTest {
-
- protected Class getExceptionClass() {
- return AuthorizationException.class;
- }
-}
+/*
+ * 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.authz;
+
+import org.apache.shiro.ExceptionTest;
+
+
+/**
+ * @author Les Hazlewood
+ * @since Jun 10, 2008 4:03:56 PM
+ */
+public class AuthorizationExceptionTest extends ExceptionTest {
+
+ protected Class getExceptionClass() {
+ return AuthorizationException.class;
+ }
+}
Propchange: incubator/shiro/branches/shiro-root-1.0.x/core/src/test/java/org/apache/shiro/authz/AuthorizationExceptionTest.java
------------------------------------------------------------------------------
svn:eol-style = native