2 * Copyright (c) 2016 Brocade Communications Systems, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
9 package org.opendaylight.aaa.shiro.filters;
11 import org.apache.shiro.authc.AuthenticationException;
12 import org.apache.shiro.authc.AuthenticationInfo;
13 import org.apache.shiro.authc.AuthenticationToken;
14 import org.apache.shiro.subject.PrincipalCollection;
15 import org.slf4j.Logger;
16 import org.slf4j.LoggerFactory;
19 * Follows the event-listener pattern; the <code>Authenticator</code> notifies this class about
20 * authentication attempts. <code>AuthenticationListener</code> logs successful and unsuccessful
21 * authentication attempts appropriately. Log messages are emitted at the <code>DEBUG</code> log
22 * level. To enable the messages out of the box, use the following command from karaf:
23 * <code>log:set DEBUG org.opendaylight.aaa.shiro.authc.AuthenicationListener</code>
25 * @author Ryan Goulding (ryandgoulding@gmail.com)
27 public class AuthenticationListener implements org.apache.shiro.authc.AuthenticationListener {
29 private static final Logger LOG = LoggerFactory.getLogger(AuthenticationListener.class);
32 public void onSuccess(final AuthenticationToken authenticationToken, final AuthenticationInfo authenticationInfo) {
33 if (LOG.isDebugEnabled()) {
34 final String successMessage = AuthenticationTokenUtils.generateSuccessfulAuthenticationMessage(authenticationToken);
35 LOG.debug(successMessage);
40 public void onFailure(final AuthenticationToken authenticationToken, final AuthenticationException e) {
41 if (LOG.isDebugEnabled()) {
42 final String failureMessage = AuthenticationTokenUtils.generateUnsuccessfulAuthenticationMessage(authenticationToken);
43 LOG.debug(failureMessage);
48 public void onLogout(final PrincipalCollection principalCollection) {
49 // Do nothing; AAA is aimed at RESTCONF, which stateless by definition.
50 // Including this output would very quickly pollute the log.