[jboss-cvs] JBossAS SVN: r62988 - projects/security/security-jboss-sx/trunk/src/main/org/jboss/security/plugins.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Fri May 11 10:31:21 EDT 2007
Author: anil.saldhana at jboss.com
Date: 2007-05-11 10:31:21 -0400 (Fri, 11 May 2007)
New Revision: 62988
Added:
projects/security/security-jboss-sx/trunk/src/main/org/jboss/security/plugins/JBossAuthenticationManager.java
Log:
default implementation of the AuthenticationManager interface. This needs caching to be implemented.
Added: projects/security/security-jboss-sx/trunk/src/main/org/jboss/security/plugins/JBossAuthenticationManager.java
===================================================================
--- projects/security/security-jboss-sx/trunk/src/main/org/jboss/security/plugins/JBossAuthenticationManager.java (rev 0)
+++ projects/security/security-jboss-sx/trunk/src/main/org/jboss/security/plugins/JBossAuthenticationManager.java 2007-05-11 14:31:21 UTC (rev 62988)
@@ -0,0 +1,110 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2007, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt 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.jboss.security.plugins;
+
+import java.security.Principal;
+import java.util.Map;
+
+import javax.security.auth.Subject;
+import javax.security.auth.callback.CallbackHandler;
+import javax.security.auth.login.LoginContext;
+import javax.security.auth.login.LoginException;
+
+import org.jboss.security.AuthenticationManager;
+import org.jboss.security.SecurityConstants;
+
+//$Id$
+
+/**
+ * Default Implementation of the AuthenticationManager Interface
+ * @author Anil.Saldhana at redhat.com
+ * @since May 10, 2007
+ * @version $Revision$
+ */
+public class JBossAuthenticationManager implements AuthenticationManager
+{
+ protected String securityDomain = SecurityConstants.DEFAULT_APPLICATION_POLICY;
+
+ protected CallbackHandler callbackHandler = null;
+
+ private ThreadLocal<Subject> subjectLocal = new ThreadLocal<Subject>();
+
+ public JBossAuthenticationManager(String sdomain, CallbackHandler cbh)
+ {
+ this.securityDomain = sdomain;
+ this.callbackHandler = cbh;
+ }
+
+ /**
+ * @see AuthenticationManager#getActiveSubject()
+ */
+ public Subject getActiveSubject()
+ {
+ return subjectLocal.get();
+ }
+
+ /**
+ * @see AuthenticationManager#getSecurityDomain()
+ */
+ public String getSecurityDomain()
+ {
+ return securityDomain;
+ }
+
+ /**
+ * @see AuthenticationManager#getTargetPrincipal(Principal, Map)
+ */
+ public Principal getTargetPrincipal(Principal principal, Map<String,Object> map)
+ {
+ throw new RuntimeException("Unimplemented");
+ }
+
+ /**
+ * @see AuthenticationManager#isValid(Principal, Object)
+ */
+ public boolean isValid(Principal principal, Object credential)
+ {
+ return isValid(principal, credential, new Subject());
+ }
+
+ /**
+ * @see AuthenticationManager#isValid(Principal, Object, Subject)
+ */
+ public boolean isValid(Principal principal, Object credential, Subject subject)
+ {
+ if(subject == null)
+ throw new IllegalArgumentException("Subject is null");
+ LoginContext lc = null;
+
+ try
+ {
+ lc = new LoginContext(securityDomain, subject, callbackHandler);
+ lc.login();
+ subjectLocal.set(lc.getSubject());
+ }
+ catch (LoginException e)
+ {
+ throw new RuntimeException(e);
+ }
+ return true;
+ }
+}
More information about the jboss-cvs-commits
mailing list