You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@clerezza.apache.org by it...@apache.org on 2010/11/17 13:47:11 UTC
svn commit: r1036010 - in
/incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.platform.security/src/main/java/org/apache/clerezza/platform/security/auth:
AuthenticatingFilter.java LoginListener.java
Author: ito
Date: Wed Nov 17 12:47:11 2010
New Revision: 1036010
URL: http://svn.apache.org/viewvc?rev=1036010&view=rev
Log:
CLEREZZA-359: LoginListener Interface created
Added:
incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.platform.security/src/main/java/org/apache/clerezza/platform/security/auth/LoginListener.java
Modified:
incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.platform.security/src/main/java/org/apache/clerezza/platform/security/auth/AuthenticatingFilter.java
Modified: incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.platform.security/src/main/java/org/apache/clerezza/platform/security/auth/AuthenticatingFilter.java
URL: http://svn.apache.org/viewvc/incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.platform.security/src/main/java/org/apache/clerezza/platform/security/auth/AuthenticatingFilter.java?rev=1036010&r1=1036009&r2=1036010&view=diff
==============================================================================
--- incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.platform.security/src/main/java/org/apache/clerezza/platform/security/auth/AuthenticatingFilter.java (original)
+++ incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.platform.security/src/main/java/org/apache/clerezza/platform/security/auth/AuthenticatingFilter.java Wed Nov 17 12:47:11 2010
@@ -20,9 +20,14 @@ package org.apache.clerezza.platform.sec
import java.security.PrivilegedActionException;
import java.security.PrivilegedExceptionAction;
+import java.util.ArrayList;
+import java.util.Collections;
import java.util.Comparator;
+import java.util.HashSet;
import java.util.Iterator;
+import java.util.List;
+import java.util.Set;
import java.util.SortedSet;
import java.util.TreeSet;
import javax.security.auth.Subject;
@@ -31,6 +36,7 @@ import org.apache.felix.scr.annotations.
import org.apache.felix.scr.annotations.Reference;
import org.apache.felix.scr.annotations.ReferenceCardinality;
import org.apache.felix.scr.annotations.ReferencePolicy;
+import org.apache.felix.scr.annotations.References;
import org.apache.felix.scr.annotations.Service;
import org.slf4j.Logger;
@@ -48,15 +54,22 @@ import org.wymiwyg.wrhapi.filter.Filter;
*/
@Component
@Service(Filter.class)
-@Reference(name="weightedAuthenticationMethod",
- cardinality=ReferenceCardinality.MANDATORY_MULTIPLE,
- policy=ReferencePolicy.DYNAMIC,
- referenceInterface=WeightedAuthenticationMethod.class)
+@References({
+ @Reference(name="weightedAuthenticationMethod",
+ cardinality=ReferenceCardinality.MANDATORY_MULTIPLE,
+ policy=ReferencePolicy.DYNAMIC,
+ referenceInterface=WeightedAuthenticationMethod.class),
+ @Reference(name="loginListener",
+ cardinality=ReferenceCardinality.OPTIONAL_MULTIPLE,
+ policy=ReferencePolicy.DYNAMIC,
+ referenceInterface=LoginListener.class)
+ })
public class AuthenticatingFilter implements Filter {
private final Logger logger = LoggerFactory.getLogger(AuthenticatingFilter.class);
private SortedSet<WeightedAuthenticationMethod> methodList =
new TreeSet<WeightedAuthenticationMethod>(new WeightedAuthMethodComparator());
+ private final Set<LoginListener> loginListenerSet = Collections.synchronizedSet(new HashSet<LoginListener>());
public static final Subject ANONYMOUS_SUBJECT = UserUtil.createSubject("anonymous");
@Override
@@ -85,6 +98,14 @@ public class AuthenticatingFilter implem
subject = ANONYMOUS_SUBJECT;
} else {
subject = UserUtil.createSubject(userName);
+ Set<LoginListener> tempLoginListenerSet = null;
+ synchronized(loginListenerSet) {
+ tempLoginListenerSet = new HashSet<LoginListener>(loginListenerSet);
+ }
+ for (Iterator<LoginListener> it = tempLoginListenerSet.iterator(); it.hasNext();) {
+ LoginListener listener = it.next();
+ listener.userLoggedIn(userName, authenticationMethod.getClass());
+ }
}
try {
Subject.doAsPrivileged(subject, new PrivilegedExceptionAction() {
@@ -123,13 +144,31 @@ public class AuthenticatingFilter implem
/**
* Unregister a <code>WeightedAuthenticationMethod</code>
*
- * @param method the method to be deregistered
+ * @param method the method to be unregistered
*/
protected void unbindWeightedAuthenticationMethod(WeightedAuthenticationMethod method) {
methodList.remove(method);
}
/**
+ * Registers a <code>LoginListener</code>
+ *
+ * @param listener the listener to be registered
+ */
+ protected void bindLoginListener(LoginListener listener) {
+ loginListenerSet.add(listener);
+ }
+
+ /**
+ * Unregisters a <code>LoginListener</code>
+ *
+ * @param listener the listener to be unregistered
+ */
+ protected void unbindLoginListener(LoginListener listener) {
+ loginListenerSet.remove(listener);
+ }
+
+ /**
* Compares the WeightedAuthenticationMethods, descending for weight and ascending by name
*/
static class WeightedAuthMethodComparator
Added: incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.platform.security/src/main/java/org/apache/clerezza/platform/security/auth/LoginListener.java
URL: http://svn.apache.org/viewvc/incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.platform.security/src/main/java/org/apache/clerezza/platform/security/auth/LoginListener.java?rev=1036010&view=auto
==============================================================================
--- incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.platform.security/src/main/java/org/apache/clerezza/platform/security/auth/LoginListener.java (added)
+++ incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.platform.security/src/main/java/org/apache/clerezza/platform/security/auth/LoginListener.java Wed Nov 17 12:47:11 2010
@@ -0,0 +1,36 @@
+/*
+ * 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.clerezza.platform.security.auth;
+
+/**
+ * A Service interface whose implementations will be notified when a user has
+ * successfully logged in.
+ *
+ * @author tio
+ */
+public interface LoginListener {
+
+ /**
+ * Notifies when a user is logged in successfully.
+ *
+ * @param userName of the user who has successfully logged in
+ * @param clazz the AuthenticationMethod used
+ */
+ public void userLoggedIn(String userName, Class<? extends AuthenticationMethod> clazz);
+}