From picketlink-commits at lists.jboss.org Mon Apr 11 10:23:40 2011 Content-Type: multipart/mixed; boundary="===============5631384116817752030==" MIME-Version: 1.0 From: picketlink-commits at lists.jboss.org To: picketlink-commits at lists.jboss.org Subject: [picketlink-commits] Picketlink SVN: r870 - federation/trunk/picketlink-bindings/src/main/java/org/picketlink/identity/federation/bindings/tomcat. Date: Mon, 11 Apr 2011 10:23:40 -0400 Message-ID: <201104111423.p3BENeaL003021@svn01.web.mwc.hst.phx2.redhat.com> --===============5631384116817752030== Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Author: anil.saldhana(a)jboss.com Date: 2011-04-11 10:23:40 -0400 (Mon, 11 Apr 2011) New Revision: 870 Added: federation/trunk/picketlink-bindings/src/main/java/org/picketlink/identi= ty/federation/bindings/tomcat/PicketLinkAuthenticator.java Log: PLFED-169: a tomcat authenticator that delegates to the realm Added: federation/trunk/picketlink-bindings/src/main/java/org/picketlink/id= entity/federation/bindings/tomcat/PicketLinkAuthenticator.java =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- federation/trunk/picketlink-bindings/src/main/java/org/picketlink/ident= ity/federation/bindings/tomcat/PicketLinkAuthenticator.java = (rev 0) +++ federation/trunk/picketlink-bindings/src/main/java/org/picketlink/ident= ity/federation/bindings/tomcat/PicketLinkAuthenticator.java 2011-04-11 14:2= 3:40 UTC (rev 870) @@ -0,0 +1,113 @@ +/* + * 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.picketlink.identity.federation.bindings.tomcat; + +import java.io.IOException; +import java.security.Principal; + +import org.apache.catalina.Realm; +import org.apache.catalina.authenticator.AuthenticatorBase; +import org.apache.catalina.connector.Request; +import org.apache.catalina.connector.Response; +import org.apache.catalina.deploy.LoginConfig; +import org.apache.log4j.Logger; + +/** + * An authenticator that delegates actual authentication to a realm, and i= n turn to a security + * manager, by presenting a "conventional" identity. The security manager = must accept the + * conventional identity and generate the real identity for the authentica= ted principal. + * = + * @author Ovidiu Feodorov + * @author Anil.Saldhana(a)redhat.com + * @since Apr 11, 2011 + */ +public class PicketLinkAuthenticator extends AuthenticatorBase +{ + protected static Logger log =3D Logger.getLogger(PicketLinkAuthenticato= r.class); + + protected boolean trace =3D log.isTraceEnabled(); + + /** + * The {@link Realm} requires an user name + */ + protected String userName =3D "custom-authenticator-user"; + + /** + * The {@link Realm} requires a password + */ + protected String password =3D "custom-authenticator-password"; + + /** + * This is the auth method used in the register method + */ + protected String authMethod =3D "SECURITY_DOMAIN"; + + public PicketLinkAuthenticator() + { + if (trace) + { + log.trace("PicketLinkAuthenticator Created"); + } + } + + /** + * Set the user name via WEB-INF/context.xml (JBoss AS) + * @param defaultUserName + */ + public void setUserName(String defaultUserName) + { + this.userName =3D defaultUserName; + } + + /** + * Set the password via WEB-INF/context.xml (JBoss AS) + * @param defaultPassword + */ + public void setPassword(String defaultPassword) + { + this.password =3D defaultPassword; + } + + /** + * Set the auth method via WEB-INF/context.xml (JBoss AS) + * @param authMethod + */ + public void setAuthMethod(String authMethod) + { + this.authMethod =3D authMethod; + } + + @Override + protected boolean authenticate(Request request, Response response, Logi= nConfig loginConfig) throws IOException + { + Realm realm =3D context.getRealm(); + + Principal principal =3D realm.authenticate(this.userName, this.passw= ord); + + if (principal !=3D null) + { + register(request, response, principal, this.authMethod, null, nul= l); + } + + return true; + } +} \ No newline at end of file --===============5631384116817752030==--