48 changed files with 636 additions and 997 deletions
@ -0,0 +1,37 @@
@@ -0,0 +1,37 @@
|
||||
/* Copyright 2004, 2005 Acegi Technology Pty Limited |
||||
* |
||||
* Licensed 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 net.sf.acegisecurity.event.authentication; |
||||
|
||||
import net.sf.acegisecurity.Authentication; |
||||
import net.sf.acegisecurity.AuthenticationException; |
||||
|
||||
|
||||
/** |
||||
* Application event which indicates authentication failure due to the user |
||||
* attempting to login to too many concurrent sessions. |
||||
* |
||||
* @author Ben Alex |
||||
* @version $Id$ |
||||
*/ |
||||
public class AuthenticationFailureConcurrentLoginEvent |
||||
extends AbstractAuthenticationFailureEvent { |
||||
//~ Constructors ===========================================================
|
||||
|
||||
public AuthenticationFailureConcurrentLoginEvent( |
||||
Authentication authentication, AuthenticationException exception) { |
||||
super(authentication, exception); |
||||
} |
||||
} |
||||
@ -0,0 +1,38 @@
@@ -0,0 +1,38 @@
|
||||
/* Copyright 2004, 2005 Acegi Technology Pty Limited |
||||
* |
||||
* Licensed 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 net.sf.acegisecurity.event.authentication; |
||||
|
||||
import net.sf.acegisecurity.Authentication; |
||||
import net.sf.acegisecurity.AuthenticationException; |
||||
|
||||
|
||||
/** |
||||
* Application event which indicates authentication failure due to there being |
||||
* no registered <code>AuthenticationProvider</code> that can process the |
||||
* request. |
||||
* |
||||
* @author Ben Alex |
||||
* @version $Id$ |
||||
*/ |
||||
public class AuthenticationFailureProviderNotFoundEvent |
||||
extends AbstractAuthenticationFailureEvent { |
||||
//~ Constructors ===========================================================
|
||||
|
||||
public AuthenticationFailureProviderNotFoundEvent( |
||||
Authentication authentication, AuthenticationException exception) { |
||||
super(authentication, exception); |
||||
} |
||||
} |
||||
@ -0,0 +1,37 @@
@@ -0,0 +1,37 @@
|
||||
/* Copyright 2004, 2005 Acegi Technology Pty Limited |
||||
* |
||||
* Licensed 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 net.sf.acegisecurity.event.authentication; |
||||
|
||||
import net.sf.acegisecurity.Authentication; |
||||
import net.sf.acegisecurity.AuthenticationException; |
||||
|
||||
|
||||
/** |
||||
* Application event which indicates authentication failure due to the CAS |
||||
* user's ticket being generated by an untrusted proxy. |
||||
* |
||||
* @author Ben Alex |
||||
* @version $Id$ |
||||
*/ |
||||
public class AuthenticationFailureProxyUntrustedEvent |
||||
extends AbstractAuthenticationFailureEvent { |
||||
//~ Constructors ===========================================================
|
||||
|
||||
public AuthenticationFailureProxyUntrustedEvent( |
||||
Authentication authentication, AuthenticationException exception) { |
||||
super(authentication, exception); |
||||
} |
||||
} |
||||
@ -0,0 +1,37 @@
@@ -0,0 +1,37 @@
|
||||
/* Copyright 2004, 2005 Acegi Technology Pty Limited |
||||
* |
||||
* Licensed 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 net.sf.acegisecurity.event.authentication; |
||||
|
||||
import net.sf.acegisecurity.Authentication; |
||||
import net.sf.acegisecurity.AuthenticationException; |
||||
|
||||
|
||||
/** |
||||
* Application event which indicates authentication failure due to there being |
||||
* a problem internal to the <code>AuthenticationManager</code>. |
||||
* |
||||
* @author Ben Alex |
||||
* @version $Id$ |
||||
*/ |
||||
public class AuthenticationFailureServiceExceptionEvent |
||||
extends AbstractAuthenticationFailureEvent { |
||||
//~ Constructors ===========================================================
|
||||
|
||||
public AuthenticationFailureServiceExceptionEvent( |
||||
Authentication authentication, AuthenticationException exception) { |
||||
super(authentication, exception); |
||||
} |
||||
} |
||||
@ -0,0 +1,65 @@
@@ -0,0 +1,65 @@
|
||||
/* Copyright 2004, 2005 Acegi Technology Pty Limited |
||||
* |
||||
* Licensed 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 net.sf.acegisecurity.event.authentication; |
||||
|
||||
import org.apache.commons.logging.Log; |
||||
import org.apache.commons.logging.LogFactory; |
||||
|
||||
import org.springframework.context.ApplicationEvent; |
||||
import org.springframework.context.ApplicationListener; |
||||
|
||||
import org.springframework.util.ClassUtils; |
||||
|
||||
|
||||
/** |
||||
* Outputs authentication-related application events to Commons Logging. |
||||
* |
||||
* <P> |
||||
* All authentication failures are logged at the warning level, whilst |
||||
* authentication successes are logged at the information level. |
||||
* </p> |
||||
* |
||||
* @author Ben Alex |
||||
* @version $Id$ |
||||
*/ |
||||
public class LoggerListener implements ApplicationListener { |
||||
//~ Static fields/initializers =============================================
|
||||
|
||||
private static final Log logger = LogFactory.getLog(LoggerListener.class); |
||||
|
||||
//~ Methods ================================================================
|
||||
|
||||
public void onApplicationEvent(ApplicationEvent event) { |
||||
if (event instanceof AbstractAuthenticationEvent) { |
||||
AbstractAuthenticationEvent authEvent = (AbstractAuthenticationEvent) event; |
||||
|
||||
if (logger.isWarnEnabled()) { |
||||
String message = "Authentication event " |
||||
+ ClassUtils.getShortName(authEvent.getClass()) + ": " |
||||
+ authEvent.getAuthentication().getName() + "; details: " |
||||
+ authEvent.getAuthentication().getDetails(); |
||||
|
||||
if (event instanceof AbstractAuthenticationFailureEvent) { |
||||
message = message + "; exception: " |
||||
+ ((AbstractAuthenticationFailureEvent) event).getException() |
||||
.getMessage(); |
||||
} |
||||
|
||||
logger.warn(message); |
||||
} |
||||
} |
||||
} |
||||
} |
||||
@ -0,0 +1,5 @@
@@ -0,0 +1,5 @@
|
||||
<html> |
||||
<body> |
||||
Provides support objects for security event interception (ie authorization). |
||||
</body> |
||||
</html> |
||||
@ -1,79 +0,0 @@
@@ -1,79 +0,0 @@
|
||||
/* Copyright 2004 Acegi Technology Pty Limited |
||||
* |
||||
* Licensed 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 net.sf.acegisecurity.intercept.event; |
||||
|
||||
import net.sf.acegisecurity.Authentication; |
||||
import net.sf.acegisecurity.AuthenticationException; |
||||
import net.sf.acegisecurity.ConfigAttributeDefinition; |
||||
|
||||
|
||||
/** |
||||
* Indicates a secure object invocation failed because the principal could not |
||||
* be authenticated. |
||||
* |
||||
* @author Ben Alex |
||||
* @version $Id$ |
||||
*/ |
||||
public class AuthenticationFailureEvent extends SecurityInterceptionEvent { |
||||
//~ Instance fields ========================================================
|
||||
|
||||
private Authentication authentication; |
||||
private AuthenticationException authenticationException; |
||||
private ConfigAttributeDefinition configAttributeDefinition; |
||||
|
||||
//~ Constructors ===========================================================
|
||||
|
||||
/** |
||||
* Construct the event. |
||||
* |
||||
* @param secureObject the secure object |
||||
* @param configAttribs that apply to the secure object |
||||
* @param authentication that was found on the <code>ContextHolder</code> |
||||
* @param authenticationException that was returned by the |
||||
* <code>AuthenticationManager</code> |
||||
* |
||||
* @throws IllegalArgumentException DOCUMENT ME! |
||||
*/ |
||||
public AuthenticationFailureEvent(Object secureObject, |
||||
ConfigAttributeDefinition configAttribs, Authentication authentication, |
||||
AuthenticationException authenticationException) { |
||||
super(secureObject); |
||||
|
||||
if ((configAttribs == null) || (authentication == null) |
||||
|| (authenticationException == null)) { |
||||
throw new IllegalArgumentException( |
||||
"All parameters are required and cannot be null"); |
||||
} |
||||
|
||||
this.configAttributeDefinition = configAttribs; |
||||
this.authentication = authentication; |
||||
this.authenticationException = authenticationException; |
||||
} |
||||
|
||||
//~ Methods ================================================================
|
||||
|
||||
public Authentication getAuthentication() { |
||||
return authentication; |
||||
} |
||||
|
||||
public AuthenticationException getAuthenticationException() { |
||||
return authenticationException; |
||||
} |
||||
|
||||
public ConfigAttributeDefinition getConfigAttributeDefinition() { |
||||
return configAttributeDefinition; |
||||
} |
||||
} |
||||
@ -1,5 +0,0 @@
@@ -1,5 +0,0 @@
|
||||
<html> |
||||
<body> |
||||
Provides support objects for security event interception. |
||||
</body> |
||||
</html> |
||||
@ -1,40 +0,0 @@
@@ -1,40 +0,0 @@
|
||||
/* Copyright 2004, 2005 Acegi Technology Pty Limited |
||||
* |
||||
* Licensed 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 net.sf.acegisecurity.providers.dao.event; |
||||
|
||||
import net.sf.acegisecurity.Authentication; |
||||
import net.sf.acegisecurity.UserDetails; |
||||
|
||||
|
||||
/** |
||||
* Application event which indicates authentication failure due to nonexistent |
||||
* username. <code>AuthenticationFailureUsernameNotFoundEvent.getUser()</code> |
||||
* returns an instance of <code>User</code>, where the username is filled by |
||||
* the <code>String</code> provided at login attempt. The other properties are |
||||
* set to non-<code>null</code> values without any meaning. |
||||
* |
||||
* @author Karel Miarka |
||||
*/ |
||||
public class AuthenticationFailureUsernameNotFoundEvent |
||||
extends AuthenticationFailureEvent { |
||||
//~ Constructors ===========================================================
|
||||
|
||||
// ~ Constructors ===========================================================
|
||||
public AuthenticationFailureUsernameNotFoundEvent( |
||||
Authentication authentication, UserDetails user) { |
||||
super(authentication, user); |
||||
} |
||||
} |
||||
@ -1,43 +0,0 @@
@@ -1,43 +0,0 @@
|
||||
/* Copyright 2004, 2005 Acegi Technology Pty Limited |
||||
* |
||||
* Licensed 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 net.sf.acegisecurity.providers.dao.event; |
||||
|
||||
import net.sf.acegisecurity.Authentication; |
||||
import net.sf.acegisecurity.UserDetails; |
||||
|
||||
|
||||
/** |
||||
* Application event which indicates authentication failure due to invalid |
||||
* username or password. |
||||
* |
||||
* <P> |
||||
* <code>AuthenticationFailureUsernameOrPasswordEvent.getUser()</code> returns |
||||
* an instance of <code>User</code>, where the username is filled by the |
||||
* <code>String</code> provided at login attempt. The other properties are set |
||||
* to non-<code>null</code> values without any meaning. |
||||
* </p> |
||||
* |
||||
* @author Karel Miarka |
||||
*/ |
||||
public class AuthenticationFailureUsernameOrPasswordEvent |
||||
extends AuthenticationFailureEvent { |
||||
//~ Constructors ===========================================================
|
||||
|
||||
public AuthenticationFailureUsernameOrPasswordEvent( |
||||
Authentication authentication, UserDetails user) { |
||||
super(authentication, user); |
||||
} |
||||
} |
||||
@ -1,131 +0,0 @@
@@ -1,131 +0,0 @@
|
||||
/* Copyright 2004, 2005 Acegi Technology Pty Limited |
||||
* |
||||
* Licensed 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 net.sf.acegisecurity.providers.dao.event; |
||||
|
||||
import org.apache.commons.logging.Log; |
||||
import org.apache.commons.logging.LogFactory; |
||||
|
||||
import org.springframework.context.ApplicationEvent; |
||||
import org.springframework.context.ApplicationListener; |
||||
|
||||
|
||||
/** |
||||
* Outputs authentication-related application events to Commons Logging. |
||||
* |
||||
* <P> |
||||
* All authentication failures are logged at the warning level, whilst |
||||
* authentication successes are logged at the information level. |
||||
* </p> |
||||
* |
||||
* @author Ben Alex |
||||
* @version $Id$ |
||||
*/ |
||||
public class LoggerListener implements ApplicationListener { |
||||
//~ Static fields/initializers =============================================
|
||||
|
||||
private static final Log logger = LogFactory.getLog(LoggerListener.class); |
||||
|
||||
//~ Methods ================================================================
|
||||
|
||||
public void onApplicationEvent(ApplicationEvent event) { |
||||
if (event instanceof AuthenticationFailurePasswordEvent) { |
||||
AuthenticationFailurePasswordEvent authEvent = (AuthenticationFailurePasswordEvent) event; |
||||
|
||||
if (logger.isWarnEnabled()) { |
||||
logger.warn( |
||||
"Authentication failed due to incorrect password for user: " |
||||
+ authEvent.getUser().getUsername() + "; details: " |
||||
+ authEvent.getAuthentication().getDetails()); |
||||
} |
||||
} |
||||
|
||||
if (event instanceof AuthenticationFailureDisabledEvent) { |
||||
AuthenticationFailureDisabledEvent authEvent = (AuthenticationFailureDisabledEvent) event; |
||||
|
||||
if (logger.isWarnEnabled()) { |
||||
logger.warn( |
||||
"Authentication failed due to account being disabled for user: " |
||||
+ authEvent.getUser().getUsername() + "; details: " |
||||
+ authEvent.getAuthentication().getDetails()); |
||||
} |
||||
} |
||||
|
||||
if (event instanceof AuthenticationFailureAccountLockedEvent) { |
||||
AuthenticationFailureAccountLockedEvent authEvent = (AuthenticationFailureAccountLockedEvent) event; |
||||
|
||||
if (logger.isWarnEnabled()) { |
||||
logger.warn( |
||||
"Authentication failed due to account being locked for user: " |
||||
+ authEvent.getUser().getUsername() + "; details: " |
||||
+ authEvent.getAuthentication().getDetails()); |
||||
} |
||||
} |
||||
|
||||
if (event instanceof AuthenticationFailureCredentialsExpiredEvent) { |
||||
AuthenticationFailureCredentialsExpiredEvent authEvent = (AuthenticationFailureCredentialsExpiredEvent) event; |
||||
|
||||
if (logger.isWarnEnabled()) { |
||||
logger.warn( |
||||
"Authentication failed due to account credentials have been expired for user: " |
||||
+ authEvent.getUser().getUsername() + "; details: " |
||||
+ authEvent.getAuthentication().getDetails()); |
||||
} |
||||
} |
||||
|
||||
if (event instanceof AuthenticationFailureAccountExpiredEvent) { |
||||
AuthenticationFailureAccountExpiredEvent authEvent = (AuthenticationFailureAccountExpiredEvent) event; |
||||
|
||||
if (logger.isWarnEnabled()) { |
||||
logger.warn( |
||||
"Authentication failed due to account having expired for user: " |
||||
+ authEvent.getUser().getUsername() + "; details: " |
||||
+ authEvent.getAuthentication().getDetails()); |
||||
} |
||||
} |
||||
|
||||
if (event instanceof AuthenticationFailureUsernameNotFoundEvent) { |
||||
AuthenticationFailureUsernameNotFoundEvent authEvent = (AuthenticationFailureUsernameNotFoundEvent) event; |
||||
|
||||
if (logger.isWarnEnabled()) { |
||||
logger.warn( |
||||
"Authentication failed due to nonexistent username: " |
||||
+ authEvent.getUser().getUsername() + "; details: " |
||||
+ authEvent.getAuthentication().getDetails()); |
||||
} |
||||
} |
||||
|
||||
if (event instanceof AuthenticationFailureUsernameOrPasswordEvent) { |
||||
AuthenticationFailureUsernameOrPasswordEvent authEvent = (AuthenticationFailureUsernameOrPasswordEvent) event; |
||||
|
||||
if (logger.isWarnEnabled()) { |
||||
logger.warn( |
||||
"Authentication failed due to invalid username or password: " |
||||
+ authEvent.getUser().getUsername() + "; details: " |
||||
+ authEvent.getAuthentication().getDetails()); |
||||
} |
||||
} |
||||
|
||||
if (event instanceof AuthenticationSuccessEvent) { |
||||
AuthenticationSuccessEvent authEvent = (AuthenticationSuccessEvent) event; |
||||
|
||||
if (logger.isInfoEnabled()) { |
||||
logger.info("Authentication success for user: " |
||||
+ authEvent.getUser().getUsername() + "; details: " |
||||
+ authEvent.getAuthentication().getDetails()); |
||||
} |
||||
} |
||||
} |
||||
} |
||||
@ -0,0 +1,57 @@
@@ -0,0 +1,57 @@
|
||||
/* Copyright 2004, 2005 Acegi Technology Pty Limited |
||||
* |
||||
* Licensed 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 net.sf.acegisecurity.event.authentication; |
||||
|
||||
import junit.framework.TestCase; |
||||
|
||||
import net.sf.acegisecurity.Authentication; |
||||
import net.sf.acegisecurity.LockedException; |
||||
import net.sf.acegisecurity.providers.UsernamePasswordAuthenticationToken; |
||||
|
||||
|
||||
/** |
||||
* Tests {@link LoggerListener}. |
||||
* |
||||
* @author Ben Alex |
||||
* @version $Id$ |
||||
*/ |
||||
public class LoggerListenerTests extends TestCase { |
||||
//~ Methods ================================================================
|
||||
|
||||
public final void setUp() throws Exception { |
||||
super.setUp(); |
||||
} |
||||
|
||||
public static void main(String[] args) { |
||||
junit.textui.TestRunner.run(LoggerListenerTests.class); |
||||
} |
||||
|
||||
public void testLogsEvents() { |
||||
AuthenticationFailureDisabledEvent event = new AuthenticationFailureDisabledEvent(getAuthentication(), |
||||
new LockedException("TEST")); |
||||
LoggerListener listener = new LoggerListener(); |
||||
listener.onApplicationEvent(event); |
||||
assertTrue(true); |
||||
} |
||||
|
||||
private Authentication getAuthentication() { |
||||
UsernamePasswordAuthenticationToken authentication = new UsernamePasswordAuthenticationToken("Principal", |
||||
"Credentials"); |
||||
authentication.setDetails("127.0.0.1"); |
||||
|
||||
return authentication; |
||||
} |
||||
} |
||||
@ -1,88 +0,0 @@
@@ -1,88 +0,0 @@
|
||||
/* Copyright 2004 Acegi Technology Pty Limited |
||||
* |
||||
* Licensed 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 net.sf.acegisecurity.intercept.event; |
||||
|
||||
import junit.framework.TestCase; |
||||
|
||||
import net.sf.acegisecurity.BadCredentialsException; |
||||
import net.sf.acegisecurity.ConfigAttributeDefinition; |
||||
import net.sf.acegisecurity.MockMethodInvocation; |
||||
import net.sf.acegisecurity.providers.UsernamePasswordAuthenticationToken; |
||||
|
||||
|
||||
/** |
||||
* Tests {@link AuthenticationFailureEvent}. |
||||
* |
||||
* @author Ben Alex |
||||
* @version $Id$ |
||||
*/ |
||||
public class AuthenticationFailureEventTests extends TestCase { |
||||
//~ Constructors ===========================================================
|
||||
|
||||
public AuthenticationFailureEventTests() { |
||||
super(); |
||||
} |
||||
|
||||
public AuthenticationFailureEventTests(String arg0) { |
||||
super(arg0); |
||||
} |
||||
|
||||
//~ Methods ================================================================
|
||||
|
||||
public static void main(String[] args) { |
||||
junit.textui.TestRunner.run(AuthenticationFailureEventTests.class); |
||||
} |
||||
|
||||
public void testRejectsNulls() { |
||||
try { |
||||
AuthenticationFailureEvent event = new AuthenticationFailureEvent(null, |
||||
new ConfigAttributeDefinition(), |
||||
new UsernamePasswordAuthenticationToken("foo", "bar"), |
||||
new BadCredentialsException("error")); |
||||
fail("Should have thrown IllegalArgumentException"); |
||||
} catch (IllegalArgumentException expected) { |
||||
assertTrue(true); |
||||
} |
||||
|
||||
try { |
||||
AuthenticationFailureEvent event = new AuthenticationFailureEvent(new MockMethodInvocation(), |
||||
null, |
||||
new UsernamePasswordAuthenticationToken("foo", "bar"), |
||||
new BadCredentialsException("error")); |
||||
fail("Should have thrown IllegalArgumentException"); |
||||
} catch (IllegalArgumentException expected) { |
||||
assertTrue(true); |
||||
} |
||||
|
||||
try { |
||||
AuthenticationFailureEvent event = new AuthenticationFailureEvent(new MockMethodInvocation(), |
||||
new ConfigAttributeDefinition(), null, |
||||
new BadCredentialsException("error")); |
||||
fail("Should have thrown IllegalArgumentException"); |
||||
} catch (IllegalArgumentException expected) { |
||||
assertTrue(true); |
||||
} |
||||
|
||||
try { |
||||
AuthenticationFailureEvent event = new AuthenticationFailureEvent(new MockMethodInvocation(), |
||||
new ConfigAttributeDefinition(), |
||||
new UsernamePasswordAuthenticationToken("foo", "bar"), null); |
||||
fail("Should have thrown IllegalArgumentException"); |
||||
} catch (IllegalArgumentException expected) { |
||||
assertTrue(true); |
||||
} |
||||
} |
||||
} |
||||
@ -1,98 +0,0 @@
@@ -1,98 +0,0 @@
|
||||
/* Copyright 2004, 2005 Acegi Technology Pty Limited |
||||
* |
||||
* Licensed 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 net.sf.acegisecurity.providers.dao.event; |
||||
|
||||
import junit.framework.TestCase; |
||||
|
||||
import net.sf.acegisecurity.Authentication; |
||||
import net.sf.acegisecurity.GrantedAuthority; |
||||
import net.sf.acegisecurity.GrantedAuthorityImpl; |
||||
import net.sf.acegisecurity.providers.UsernamePasswordAuthenticationToken; |
||||
import net.sf.acegisecurity.providers.dao.User; |
||||
|
||||
|
||||
/** |
||||
* Tests {@link LoggerListener}. |
||||
* |
||||
* @author Ben Alex |
||||
* @version $Id$ |
||||
*/ |
||||
public class LoggerListenerTests extends TestCase { |
||||
//~ Methods ================================================================
|
||||
|
||||
public final void setUp() throws Exception { |
||||
super.setUp(); |
||||
} |
||||
|
||||
public static void main(String[] args) { |
||||
junit.textui.TestRunner.run(LoggerListenerTests.class); |
||||
} |
||||
|
||||
public void testLogsDisabledEvents() { |
||||
AuthenticationFailureDisabledEvent event = new AuthenticationFailureDisabledEvent(getAuthentication(), |
||||
getUser()); |
||||
LoggerListener listener = new LoggerListener(); |
||||
listener.onApplicationEvent(event); |
||||
assertTrue(true); |
||||
} |
||||
|
||||
public void testLogsPasswordEvents() { |
||||
AuthenticationFailurePasswordEvent event = new AuthenticationFailurePasswordEvent(getAuthentication(), |
||||
getUser()); |
||||
LoggerListener listener = new LoggerListener(); |
||||
listener.onApplicationEvent(event); |
||||
assertTrue(true); |
||||
} |
||||
|
||||
public void testLogsSuccessEvents() { |
||||
AuthenticationSuccessEvent event = new AuthenticationSuccessEvent(getAuthentication(), |
||||
getUser()); |
||||
LoggerListener listener = new LoggerListener(); |
||||
listener.onApplicationEvent(event); |
||||
assertTrue(true); |
||||
} |
||||
|
||||
public void testLogsUsernameNotFoundEvents() { |
||||
AuthenticationFailureUsernameNotFoundEvent event = new AuthenticationFailureUsernameNotFoundEvent(getAuthentication(), |
||||
getUser()); |
||||
LoggerListener listener = new LoggerListener(); |
||||
listener.onApplicationEvent(event); |
||||
assertTrue(true); |
||||
} |
||||
|
||||
public void testLogsUsernameOfPasswordEvent() { |
||||
AuthenticationFailureUsernameOrPasswordEvent event = new AuthenticationFailureUsernameOrPasswordEvent(getAuthentication(), |
||||
getUser()); |
||||
LoggerListener listener = new LoggerListener(); |
||||
listener.onApplicationEvent(event); |
||||
assertTrue(true); |
||||
} |
||||
|
||||
private Authentication getAuthentication() { |
||||
UsernamePasswordAuthenticationToken authentication = new UsernamePasswordAuthenticationToken("Principal", |
||||
"Credentials"); |
||||
authentication.setDetails("127.0.0.1"); |
||||
|
||||
return authentication; |
||||
} |
||||
|
||||
private User getUser() { |
||||
User user = new User("foo", "bar", true, true, true, true, |
||||
new GrantedAuthority[] {new GrantedAuthorityImpl("ROLE_FOOBAR")}); |
||||
|
||||
return user; |
||||
} |
||||
} |
||||
Loading…
Reference in new issue