9 changed files with 581 additions and 8 deletions
@ -0,0 +1,72 @@
@@ -0,0 +1,72 @@
|
||||
/* 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.AuthenticationCredentialsNotFoundException; |
||||
import net.sf.acegisecurity.ConfigAttributeDefinition; |
||||
|
||||
|
||||
/** |
||||
* Indicates a secure object invocation failed because the |
||||
* <code>Authentication</code> could not be obtained from the |
||||
* <code>ContextHolder</code>. |
||||
* |
||||
* @author Ben Alex |
||||
* @version $Id$ |
||||
*/ |
||||
public class AuthenticationCredentialsNotFoundEvent |
||||
extends SecurityInterceptionEvent { |
||||
//~ Instance fields ========================================================
|
||||
|
||||
private AuthenticationCredentialsNotFoundException credentialsNotFoundException; |
||||
private ConfigAttributeDefinition configAttributeDefinition; |
||||
|
||||
//~ Constructors ===========================================================
|
||||
|
||||
/** |
||||
* Construct the event. |
||||
* |
||||
* @param secureObject the secure object |
||||
* @param configAttribs that apply to the secure object |
||||
* @param credentialsNotFoundException exception returned to the caller |
||||
* (contains reason) |
||||
* |
||||
* @throws IllegalArgumentException DOCUMENT ME! |
||||
*/ |
||||
public AuthenticationCredentialsNotFoundEvent(Object secureObject, |
||||
ConfigAttributeDefinition configAttribs, |
||||
AuthenticationCredentialsNotFoundException credentialsNotFoundException) { |
||||
super(secureObject); |
||||
|
||||
if ((configAttribs == null) || (credentialsNotFoundException == null)) { |
||||
throw new IllegalArgumentException( |
||||
"All parameters are required and cannot be null"); |
||||
} |
||||
|
||||
this.configAttributeDefinition = configAttribs; |
||||
this.credentialsNotFoundException = credentialsNotFoundException; |
||||
} |
||||
|
||||
//~ Methods ================================================================
|
||||
|
||||
public ConfigAttributeDefinition getConfigAttributeDefinition() { |
||||
return configAttributeDefinition; |
||||
} |
||||
|
||||
public AuthenticationCredentialsNotFoundException getCredentialsNotFoundException() { |
||||
return credentialsNotFoundException; |
||||
} |
||||
} |
||||
@ -0,0 +1,79 @@
@@ -0,0 +1,79 @@
|
||||
/* 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; |
||||
} |
||||
} |
||||
@ -0,0 +1,79 @@
@@ -0,0 +1,79 @@
|
||||
/* 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.AccessDeniedException; |
||||
import net.sf.acegisecurity.Authentication; |
||||
import net.sf.acegisecurity.ConfigAttributeDefinition; |
||||
|
||||
|
||||
/** |
||||
* Indicates a secure object invocation failed because the principal could not |
||||
* be authorized for the request. |
||||
* |
||||
* @author Ben Alex |
||||
* @version $Id$ |
||||
*/ |
||||
public class AuthorizationFailureEvent extends SecurityInterceptionEvent { |
||||
//~ Instance fields ========================================================
|
||||
|
||||
private AccessDeniedException accessDeniedException; |
||||
private Authentication authentication; |
||||
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 accessDeniedException that was returned by the |
||||
* <code>AccessDecisionManager</code> |
||||
* |
||||
* @throws IllegalArgumentException DOCUMENT ME! |
||||
*/ |
||||
public AuthorizationFailureEvent(Object secureObject, |
||||
ConfigAttributeDefinition configAttribs, Authentication authentication, |
||||
AccessDeniedException accessDeniedException) { |
||||
super(secureObject); |
||||
|
||||
if ((configAttribs == null) || (authentication == null) |
||||
|| (accessDeniedException == null)) { |
||||
throw new IllegalArgumentException( |
||||
"All parameters are required and cannot be null"); |
||||
} |
||||
|
||||
this.configAttributeDefinition = configAttribs; |
||||
this.authentication = authentication; |
||||
this.accessDeniedException = accessDeniedException; |
||||
} |
||||
|
||||
//~ Methods ================================================================
|
||||
|
||||
public AccessDeniedException getAccessDeniedException() { |
||||
return accessDeniedException; |
||||
} |
||||
|
||||
public Authentication getAuthentication() { |
||||
return authentication; |
||||
} |
||||
|
||||
public ConfigAttributeDefinition getConfigAttributeDefinition() { |
||||
return configAttributeDefinition; |
||||
} |
||||
} |
||||
@ -0,0 +1,71 @@
@@ -0,0 +1,71 @@
|
||||
/* 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.ConfigAttributeDefinition; |
||||
|
||||
|
||||
/** |
||||
* Event indicating a secure object was invoked successfully. |
||||
* |
||||
* <P> |
||||
* Published just before the secure object attempts to proceed. |
||||
* </p> |
||||
* |
||||
* @author Ben Alex |
||||
* @version $Id$ |
||||
*/ |
||||
public class AuthorizedEvent extends SecurityInterceptionEvent { |
||||
//~ Instance fields ========================================================
|
||||
|
||||
private Authentication authentication; |
||||
private ConfigAttributeDefinition configAttributeDefinition; |
||||
|
||||
//~ Constructors ===========================================================
|
||||
|
||||
/** |
||||
* Construct the event. |
||||
* |
||||
* @param secureObject the secure object |
||||
* @param configAttribs that apply to the secure object |
||||
* @param authentication that successfully called the secure object |
||||
* |
||||
* @throws IllegalArgumentException DOCUMENT ME! |
||||
*/ |
||||
public AuthorizedEvent(Object secureObject, |
||||
ConfigAttributeDefinition configAttribs, Authentication authentication) { |
||||
super(secureObject); |
||||
|
||||
if ((configAttribs == null) || (authentication == null)) { |
||||
throw new IllegalArgumentException( |
||||
"All parameters are required and cannot be null"); |
||||
} |
||||
|
||||
this.configAttributeDefinition = configAttribs; |
||||
this.authentication = authentication; |
||||
} |
||||
|
||||
//~ Methods ================================================================
|
||||
|
||||
public Authentication getAuthentication() { |
||||
return authentication; |
||||
} |
||||
|
||||
public ConfigAttributeDefinition getConfigAttributeDefinition() { |
||||
return configAttributeDefinition; |
||||
} |
||||
} |
||||
@ -0,0 +1,104 @@
@@ -0,0 +1,104 @@
|
||||
/* 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 org.apache.commons.logging.Log; |
||||
import org.apache.commons.logging.LogFactory; |
||||
|
||||
import org.springframework.context.ApplicationEvent; |
||||
import org.springframework.context.ApplicationListener; |
||||
|
||||
|
||||
/** |
||||
* Outputs interceptor-related application events to Commons Logging. |
||||
* |
||||
* <P> |
||||
* All failures are logged at the warning level, with success events logged at |
||||
* the information level, and public invocation events logged at the debug |
||||
* 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 AuthenticationCredentialsNotFoundEvent) { |
||||
AuthenticationCredentialsNotFoundEvent authEvent = (AuthenticationCredentialsNotFoundEvent) event; |
||||
|
||||
if (logger.isWarnEnabled()) { |
||||
logger.warn("Security interception failed due to: " |
||||
+ authEvent.getCredentialsNotFoundException() |
||||
+ "; secure object: " + authEvent.getSource() |
||||
+ "; configuration attributes: " |
||||
+ authEvent.getConfigAttributeDefinition()); |
||||
} |
||||
} |
||||
|
||||
if (event instanceof AuthenticationFailureEvent) { |
||||
AuthenticationFailureEvent authEvent = (AuthenticationFailureEvent) event; |
||||
|
||||
if (logger.isWarnEnabled()) { |
||||
logger.warn("Security authentication failed due to: " |
||||
+ authEvent.getAuthenticationException() |
||||
+ "; for authentication request: " |
||||
+ authEvent.getAuthentication() + "; secure object: " |
||||
+ authEvent.getSource() + "; configuration attributes: " |
||||
+ authEvent.getConfigAttributeDefinition()); |
||||
} |
||||
} |
||||
|
||||
if (event instanceof AuthorizationFailureEvent) { |
||||
AuthorizationFailureEvent authEvent = (AuthorizationFailureEvent) event; |
||||
|
||||
if (logger.isWarnEnabled()) { |
||||
logger.warn("Security authorization failed due to: " |
||||
+ authEvent.getAccessDeniedException() |
||||
+ "; authenticated principal: " |
||||
+ authEvent.getAuthentication() + "; secure object: " |
||||
+ authEvent.getSource() + "; configuration attributes: " |
||||
+ authEvent.getConfigAttributeDefinition()); |
||||
} |
||||
} |
||||
|
||||
if (event instanceof AuthorizedEvent) { |
||||
AuthorizedEvent authEvent = (AuthorizedEvent) event; |
||||
|
||||
if (logger.isInfoEnabled()) { |
||||
logger.info("Security authorized for authenticated principal: " |
||||
+ authEvent.getAuthentication() + "; secure object: " |
||||
+ authEvent.getSource() + "; configuration attributes: " |
||||
+ authEvent.getConfigAttributeDefinition()); |
||||
} |
||||
} |
||||
|
||||
if (event instanceof PublicInvocationEvent) { |
||||
PublicInvocationEvent authEvent = (PublicInvocationEvent) event; |
||||
|
||||
if (logger.isInfoEnabled()) { |
||||
logger.info( |
||||
"Security interception not required for public secure object: " |
||||
+ authEvent.getSource()); |
||||
} |
||||
} |
||||
} |
||||
} |
||||
@ -0,0 +1,46 @@
@@ -0,0 +1,46 @@
|
||||
/* 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; |
||||
|
||||
/** |
||||
* Event that is generated whenever a public secure object is invoked. |
||||
* |
||||
* <P> |
||||
* A public secure object is a secure object that has no |
||||
* <code>ConfigAttributeDefinition</code> defined. A public secure object will |
||||
* not cause the <code>ContextHolder</code> to be inspected or authenticated, |
||||
* and no authorization will take place. |
||||
* </p> |
||||
* |
||||
* <P> |
||||
* Published just before the secure object attempts to proceed. |
||||
* </p> |
||||
* |
||||
* @author Ben Alex |
||||
* @version $Id$ |
||||
*/ |
||||
public class PublicInvocationEvent extends SecurityInterceptionEvent { |
||||
//~ Constructors ===========================================================
|
||||
|
||||
/** |
||||
* Construct the event, passing in the public secure object. |
||||
* |
||||
* @param secureObject the public secure object |
||||
*/ |
||||
public PublicInvocationEvent(Object secureObject) { |
||||
super(secureObject); |
||||
} |
||||
} |
||||
@ -0,0 +1,38 @@
@@ -0,0 +1,38 @@
|
||||
/* 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 org.springframework.context.ApplicationEvent; |
||||
|
||||
|
||||
/** |
||||
* Abstract superclass for all security interception related events. |
||||
* |
||||
* @author Ben Alex |
||||
* @version $Id$ |
||||
*/ |
||||
public abstract class SecurityInterceptionEvent extends ApplicationEvent { |
||||
//~ Constructors ===========================================================
|
||||
|
||||
/** |
||||
* Construct the event, passing in the secure object being intercepted. |
||||
* |
||||
* @param secureObject the secure object |
||||
*/ |
||||
public SecurityInterceptionEvent(Object secureObject) { |
||||
super(secureObject); |
||||
} |
||||
} |
||||
Loading…
Reference in new issue