Fix packaging for shiro bundle
[aaa.git] / aaa-shiro / impl / src / main / java / org / opendaylight / aaa / shiro / filters / AuthenticationListener.java
1 /*
2  * Copyright (c) 2016 - 2017 Brocade Communications Systems, Inc. and others.  All rights reserved.
3  *
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
7  */
8
9 package org.opendaylight.aaa.shiro.filters;
10
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;
17
18 /**
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>
24  */
25 public class AuthenticationListener implements org.apache.shiro.authc.AuthenticationListener {
26
27     private static final Logger LOG = LoggerFactory.getLogger(AuthenticationListener.class);
28
29     @Override
30     public void onSuccess(final AuthenticationToken authenticationToken, final AuthenticationInfo authenticationInfo) {
31         if (LOG.isDebugEnabled()) {
32             LOG.debug(AuthenticationTokenUtils.generateSuccessfulAuthenticationMessage(authenticationToken));
33         }
34     }
35
36     @Override
37     public void onFailure(final AuthenticationToken authenticationToken, final AuthenticationException e) {
38         if (LOG.isDebugEnabled()) {
39             LOG.debug(AuthenticationTokenUtils.generateUnsuccessfulAuthenticationMessage(authenticationToken));
40         }
41     }
42
43     @Override
44     public void onLogout(final PrincipalCollection principalCollection) {
45         // Do nothing;  AAA is aimed at RESTCONF, which stateless by definition.
46         // Including this output would very quickly pollute the log.
47     }
48 }