[jboss-cvs] Picketbox SVN: r39 - in trunk/picketbox/src/main/java/org/picketbox: plugins and 1 other directory.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Thu Feb 18 17:39:53 EST 2010
Author: anil.saldhana at jboss.com
Date: 2010-02-18 17:39:53 -0500 (Thu, 18 Feb 2010)
New Revision: 39
Added:
trunk/picketbox/src/main/java/org/picketbox/exceptions/PicketBoxProcessingException.java
Modified:
trunk/picketbox/src/main/java/org/picketbox/plugins/PicketBoxProcessor.java
Log:
javadoc and exceptions
Added: trunk/picketbox/src/main/java/org/picketbox/exceptions/PicketBoxProcessingException.java
===================================================================
--- trunk/picketbox/src/main/java/org/picketbox/exceptions/PicketBoxProcessingException.java (rev 0)
+++ trunk/picketbox/src/main/java/org/picketbox/exceptions/PicketBoxProcessingException.java 2010-02-18 22:39:53 UTC (rev 39)
@@ -0,0 +1,54 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.picketbox.exceptions;
+
+import java.security.GeneralSecurityException;
+
+/**
+ * Exception indicating a processing exception
+ * @author Anil.Saldhana at redhat.com
+ * @since Feb 18, 2010
+ */
+public class PicketBoxProcessingException extends GeneralSecurityException
+{
+ private static final long serialVersionUID = 1L;
+
+ public PicketBoxProcessingException()
+ {
+ super();
+ }
+
+ public PicketBoxProcessingException(String arg0, Throwable arg1)
+ {
+ super(arg0, arg1);
+ }
+
+ public PicketBoxProcessingException(String arg0)
+ {
+ super(arg0);
+ }
+
+ public PicketBoxProcessingException(Throwable arg0)
+ {
+ super(arg0);
+ }
+}
\ No newline at end of file
Modified: trunk/picketbox/src/main/java/org/picketbox/plugins/PicketBoxProcessor.java
===================================================================
--- trunk/picketbox/src/main/java/org/picketbox/plugins/PicketBoxProcessor.java 2010-02-18 22:30:59 UTC (rev 38)
+++ trunk/picketbox/src/main/java/org/picketbox/plugins/PicketBoxProcessor.java 2010-02-18 22:39:53 UTC (rev 39)
@@ -22,10 +22,12 @@
package org.picketbox.plugins;
import java.security.Principal;
+import java.security.PrivilegedActionException;
import javax.security.auth.Subject;
import javax.security.auth.login.LoginException;
+import org.jboss.logging.Logger;
import org.jboss.security.AuthenticationManager;
import org.jboss.security.AuthorizationManager;
import org.jboss.security.SecurityConstants;
@@ -36,6 +38,7 @@
import org.jboss.security.callbacks.SecurityContextCallbackHandler;
import org.jboss.security.identity.RoleGroup;
import org.picketbox.config.PicketBoxConfiguration;
+import org.picketbox.exceptions.PicketBoxProcessingException;
import org.picketbox.factories.SecurityFactory;
/**
@@ -44,6 +47,8 @@
*/
public class PicketBoxProcessor
{
+ private static Logger log = Logger.getLogger(PicketBoxProcessor.class);
+
Principal principal = null;
Object credential = null;
@@ -51,42 +56,92 @@
{
}
+ /**
+ * Set the username/credential
+ * @param username
+ * @param credential
+ */
public void setSecurityInfo(String username, Object credential)
{
this.principal = new SimplePrincipal(username);
this.credential = credential;
}
- public Principal getCallerPrincipal() throws Exception
+ /**
+ * Get the authenticated principal
+ * @return
+ * @throws PicketBoxProcessingException
+ */
+ public Principal getCallerPrincipal() throws PicketBoxProcessingException
{
Principal principal = null;
- SecurityContext securityContext = SecurityActions.getSecurityContext();
+ SecurityContext securityContext = null;
+ try
+ {
+ securityContext = SecurityActions.getSecurityContext();
+ }
+ catch (PrivilegedActionException pae)
+ {
+ throw new PicketBoxProcessingException(pae.getCause());
+ }
if(securityContext != null)
principal = securityContext.getUtil().getUserPrincipal();
return principal;
}
- public RoleGroup getCallerRoles() throws Exception
+ /**
+ * Get the caller roles
+ * @return
+ * @throws PicketBoxProcessingException
+ */
+ public RoleGroup getCallerRoles() throws PicketBoxProcessingException
{
RoleGroup roleGroup = null;
- SecurityContext securityContext = SecurityActions.getSecurityContext();
+ SecurityContext securityContext = null;
+ try
+ {
+ securityContext = SecurityActions.getSecurityContext();
+ }
+ catch (PrivilegedActionException pae)
+ {
+ throw new PicketBoxProcessingException(pae.getCause());
+ }
if(securityContext != null)
roleGroup = securityContext.getUtil().getRoles();
return roleGroup;
}
- public Subject getCallerSubject() throws Exception
+ /**
+ * Get the caller subject
+ * @return
+ * @throws PicketBoxProcessingException
+ */
+ public Subject getCallerSubject() throws PicketBoxProcessingException
{
Subject subject = new Subject();
- SecurityContext securityContext = SecurityActions.getSecurityContext();
+ SecurityContext securityContext = null;
+ try
+ {
+ securityContext = SecurityActions.getSecurityContext();
+ }
+ catch (PrivilegedActionException pae)
+ {
+ throw new PicketBoxProcessingException(pae.getCause());
+ }
if(securityContext != null)
subject = securityContext.getUtil().getSubject();
return subject;
}
- public void process(Object pojo) throws Exception
+ /**
+ * Process the POJO for security annotations
+ * @param pojo
+ * @throws PicketBoxProcessingException
+ * @throws LoginException
+ */
+ public void process(Object pojo) throws LoginException, PicketBoxProcessingException
{
String securityDomain = SecurityConstants.DEFAULT_APPLICATION_POLICY;
@@ -125,6 +180,12 @@
if(roles == null)
throw new RuntimeException("Roles from subject is null");
}
+ catch(PrivilegedActionException pae)
+ {
+ if(log.isTraceEnabled())
+ log.trace("Exception in processing:",pae);
+ throw new PicketBoxProcessingException(pae.getCause());
+ }
finally
{
SecurityFactory.release();
More information about the jboss-cvs-commits
mailing list