From: <luc...@us...> - 2010-07-29 16:18:57
|
Revision: 2830 http://openutils.svn.sourceforge.net/openutils/?rev=2830&view=rev Author: lucaboati Date: 2010-07-29 16:18:47 +0000 (Thu, 29 Jul 2010) Log Message: ----------- first commit for magnolia OpenId integration Added Paths: ----------- trunk/openutils-mgnlopenid/ trunk/openutils-mgnlopenid/pom.xml trunk/openutils-mgnlopenid/src/ trunk/openutils-mgnlopenid/src/main/ trunk/openutils-mgnlopenid/src/main/assembly/ trunk/openutils-mgnlopenid/src/main/assembly/assembly-bundle.xml trunk/openutils-mgnlopenid/src/main/etc/ trunk/openutils-mgnlopenid/src/main/etc/header.txt trunk/openutils-mgnlopenid/src/main/java/ trunk/openutils-mgnlopenid/src/main/java/net/ trunk/openutils-mgnlopenid/src/main/java/net/sourceforge/ trunk/openutils-mgnlopenid/src/main/java/net/sourceforge/openutils/ trunk/openutils-mgnlopenid/src/main/java/net/sourceforge/openutils/mgnlopenid/ trunk/openutils-mgnlopenid/src/main/java/net/sourceforge/openutils/mgnlopenid/OpenIdAuthenticationModule.java trunk/openutils-mgnlopenid/src/main/java/net/sourceforge/openutils/mgnlopenid/OpenIdCallBackHandler.java trunk/openutils-mgnlopenid/src/main/java/net/sourceforge/openutils/mgnlopenid/OpenIdLoginHandler.java trunk/openutils-mgnlopenid/src/main/java/net/sourceforge/openutils/mgnlopenid/OpenIdMagnoliaUser.java trunk/openutils-mgnlopenid/src/main/java/net/sourceforge/openutils/mgnlopenid/OpenIdMgnlUserManager.java trunk/openutils-mgnlopenid/src/main/java/net/sourceforge/openutils/mgnlopenid/lifecycle/ trunk/openutils-mgnlopenid/src/main/java/net/sourceforge/openutils/mgnlopenid/lifecycle/OpenIdModule.java trunk/openutils-mgnlopenid/src/main/java/net/sourceforge/openutils/mgnlopenid/pages/ trunk/openutils-mgnlopenid/src/main/java/net/sourceforge/openutils/mgnlopenid/pages/FormRedirection.java trunk/openutils-mgnlopenid/src/main/java/net/sourceforge/openutils/mgnlopenid/pages/Login.java trunk/openutils-mgnlopenid/src/main/java/net/sourceforge/openutils/mgnlopenid/setup/ trunk/openutils-mgnlopenid/src/main/java/net/sourceforge/openutils/mgnlopenid/setup/OpenIdModuleVersionHandler.java trunk/openutils-mgnlopenid/src/main/java/net/sourceforge/openutils/mgnlopenid/tags/ trunk/openutils-mgnlopenid/src/main/java/net/sourceforge/openutils/mgnlopenid/tags/el/ trunk/openutils-mgnlopenid/src/main/java/net/sourceforge/openutils/mgnlopenid/tags/el/OpenIdEl.java trunk/openutils-mgnlopenid/src/main/resources/ trunk/openutils-mgnlopenid/src/main/resources/META-INF/ trunk/openutils-mgnlopenid/src/main/resources/META-INF/magnolia/ trunk/openutils-mgnlopenid/src/main/resources/META-INF/magnolia/openid.xml trunk/openutils-mgnlopenid/src/main/resources/META-INF/openid.tld trunk/openutils-mgnlopenid/src/main/resources/mgnl-bootstrap/ trunk/openutils-mgnlopenid/src/main/resources/mgnl-bootstrap/openid/ trunk/openutils-mgnlopenid/src/main/resources/mgnl-bootstrap/openid/config.modules.openid.pages.formredirection.xml trunk/openutils-mgnlopenid/src/main/resources/mgnl-bootstrap/openid/config.modules.openid.pages.login.xml trunk/openutils-mgnlopenid/src/main/resources/mgnl-bootstrap/openid/config.server.filters.login.loginHandlers.openid.xml trunk/openutils-mgnlopenid/src/main/resources/mgnl-bootstrap/openid/config.server.filters.uriSecurity.bypasses.formredirectionOpenId.xml trunk/openutils-mgnlopenid/src/main/resources/mgnl-bootstrap/openid/config.server.filters.uriSecurity.bypasses.loginOpenId.xml trunk/openutils-mgnlopenid/src/main/resources/mgnl-bootstrap/openid/config.server.security.userManagers.openid.xml trunk/openutils-mgnlopenid/src/main/resources/mgnl-bootstrap/openid-nooverwrite/ trunk/openutils-mgnlopenid/src/main/resources/mgnl-bootstrap/openid-nooverwrite/userroles.openid-user.xml trunk/openutils-mgnlopenid/src/main/resources/mgnl-bootstrap-samples/ trunk/openutils-mgnlopenid/src/main/resources/mgnl-bootstrap-samples/openid/ trunk/openutils-mgnlopenid/src/main/resources/mgnl-bootstrap-samples/openid/config.server.filters.uriSecurity.clientCallback.patterns.openid.xml trunk/openutils-mgnlopenid/src/main/resources/net/ trunk/openutils-mgnlopenid/src/main/resources/net/sourceforge/ trunk/openutils-mgnlopenid/src/main/resources/net/sourceforge/openutils/ trunk/openutils-mgnlopenid/src/main/resources/net/sourceforge/openutils/mgnlopenid/ trunk/openutils-mgnlopenid/src/main/resources/net/sourceforge/openutils/mgnlopenid/pages/ trunk/openutils-mgnlopenid/src/main/resources/net/sourceforge/openutils/mgnlopenid/pages/FormRedirection.html trunk/openutils-mgnlopenid/src/main/resources/net/sourceforge/openutils/mgnlopenid/pages/Login.html trunk/openutils-mgnlopenid/src/site/ Added: trunk/openutils-mgnlopenid/pom.xml =================================================================== --- trunk/openutils-mgnlopenid/pom.xml (rev 0) +++ trunk/openutils-mgnlopenid/pom.xml 2010-07-29 16:18:47 UTC (rev 2830) @@ -0,0 +1,83 @@ +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> + <parent> + <groupId>net.sourceforge.openutils</groupId> + <artifactId>openutils-parent</artifactId> + <version>1.5</version> + </parent> + <modelVersion>4.0.0</modelVersion> + <packaging>jar</packaging> + <artifactId>openutils-mgnlopenid</artifactId> + <name>Magnolia OpenId Module</name> + <description>Magnolia OpenId Module: a module for Magnolia CMS for OpenId login integration.</description> + <version>0.1-SNAPSHOT</version> + <inceptionYear>2010</inceptionYear> + <licenses> + <license> + <name>GPLv3</name> + <url>http://www.gnu.org/licenses/gpl-3.0.txt</url> + </license> + </licenses> + <url>http://www.openmindlab.com/lab/products/openid.html</url> + <build> + <resources> + <resource> + <filtering>false</filtering> + <directory>src/main/resources</directory> + <includes> + <include>**/*</include> + </includes> + </resource> + <resource> + <filtering>true</filtering> + <directory>src/main/resources</directory> + <includes> + <include>META-INF/magnolia/*</include> + </includes> + </resource> + </resources> + </build> + <dependencies> + <dependency> + <groupId>info.magnolia</groupId> + <artifactId>magnolia-jaas</artifactId> + <version>${magnolia.version}</version> + </dependency> + <dependency> + <groupId>net.sourceforge.openutils</groupId> + <artifactId>openutils-mgnltasks</artifactId> + <version>4.1.2</version> + </dependency> + <dependency> + <groupId>org.openid4java</groupId> + <artifactId>openid4java-consumer</artifactId> + <!--artifactId>openid4java-server</artifactId--> + <!--artifactId>openid4java-infocard</artifactId--> + <!--artifactId>openid4java-xri</artifactId--> + <!--artifactId>openid4java</artifactId--> + <version>0.9.5</version> + <exclusions> + <exclusion> + <groupId>commons-logging</groupId> + <artifactId>commons-logging</artifactId> + </exclusion> + </exclusions> + </dependency> + </dependencies> + <repositories> + <repository> + <id>repository.magnolia.info</id> + <name>magnolia repository</name> + <url>http://svn.magnolia.info/maven/m2</url> + <releases> + <enabled>true</enabled> + </releases> + <snapshots> + <enabled>false</enabled> + </snapshots> + </repository> + </repositories> + <properties> + <magnolia.version>4.3.5</magnolia.version> + </properties> +</project> Added: trunk/openutils-mgnlopenid/src/main/assembly/assembly-bundle.xml =================================================================== --- trunk/openutils-mgnlopenid/src/main/assembly/assembly-bundle.xml (rev 0) +++ trunk/openutils-mgnlopenid/src/main/assembly/assembly-bundle.xml 2010-07-29 16:18:47 UTC (rev 2830) @@ -0,0 +1,34 @@ +<assembly> + <id>bundle</id> + <formats> + <format>zip</format> + </formats> + <includeBaseDirectory>false</includeBaseDirectory> + <fileSets> + <fileSet> + <filtered>true</filtered> + <outputDirectory>/</outputDirectory> + <lineEnding>crlf</lineEnding> + <directory>${basedir}/src/main/bundle</directory> + <includes> + <include>*</include> + </includes> + </fileSet> + <fileSet> + <directory>.</directory> + <outputDirectory>/sources/</outputDirectory> + <includes> + <include>src/**/*</include> + <include>pom.xml</include> + </includes> + </fileSet> + </fileSets> + <dependencySets> + <dependencySet> + <outputDirectory>bin</outputDirectory> + <includes> + <include>net.sourceforge.openutils:*</include> + </includes> + </dependencySet> + </dependencySets> +</assembly> \ No newline at end of file Added: trunk/openutils-mgnlopenid/src/main/etc/header.txt =================================================================== --- trunk/openutils-mgnlopenid/src/main/etc/header.txt (rev 0) +++ trunk/openutils-mgnlopenid/src/main/etc/header.txt 2010-07-29 16:18:47 UTC (rev 2830) @@ -0,0 +1,16 @@ + +${name} (${url}) +Copyright(C) ${year}, Openmind S.r.l. http://www.openmindonline.it + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program 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 General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see <http://www.gnu.org/licenses/>. \ No newline at end of file Added: trunk/openutils-mgnlopenid/src/main/java/net/sourceforge/openutils/mgnlopenid/OpenIdAuthenticationModule.java =================================================================== --- trunk/openutils-mgnlopenid/src/main/java/net/sourceforge/openutils/mgnlopenid/OpenIdAuthenticationModule.java (rev 0) +++ trunk/openutils-mgnlopenid/src/main/java/net/sourceforge/openutils/mgnlopenid/OpenIdAuthenticationModule.java 2010-07-29 16:18:47 UTC (rev 2830) @@ -0,0 +1,365 @@ +/** + * + * Magnolia OpenId Module (http://www.openmindlab.com/lab/products/openid.html) + * Copyright(C) 2010-2010, Openmind S.r.l. http://www.openmindonline.it + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +package net.sourceforge.openutils.mgnlopenid; + +import info.magnolia.cms.security.User; +import info.magnolia.cms.security.UserManager; +import info.magnolia.cms.security.auth.Entity; +import info.magnolia.cms.security.auth.GroupList; +import info.magnolia.cms.security.auth.RoleList; +import info.magnolia.cms.security.auth.callback.RealmCallback; +import info.magnolia.cms.security.auth.callback.UserCallback; +import info.magnolia.cms.util.BooleanUtil; +import info.magnolia.jaas.principal.EntityImpl; +import info.magnolia.jaas.principal.GroupListImpl; +import info.magnolia.jaas.principal.RoleListImpl; +import info.magnolia.jaas.sp.AbstractLoginModule; +import info.magnolia.jaas.sp.UserAwareLoginModule; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import javax.security.auth.Subject; +import javax.security.auth.callback.Callback; +import javax.security.auth.callback.CallbackHandler; +import javax.security.auth.callback.TextInputCallback; +import javax.security.auth.callback.UnsupportedCallbackException; +import javax.security.auth.login.LoginException; +import javax.security.auth.spi.LoginModule; + +import org.apache.commons.lang.ArrayUtils; +import org.apache.commons.lang.StringUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + + +/** + * This class implements a JAAS <code>LoginModule</code> that defers authentication to OpenId. See the <a + * href="http://java.sun.com/j2se/1.4.2/docs/guide/security/jaas/JAASRefGuide.html"> JAAS documentation</a> for details + * about configuration and architecture. + * <p> + * The calling application's <code>CallbackHandler</code> MUST return the <strong>authorization request</strong> for + * a <code>TextInputCallback</code> whose prompt is "auth". + * <p> + * Sample jaas.config configuration: + * </p> + * + * <pre> + * magnolia { + * net.sourceforge.openutils.mgnlopenid.OpenIdAuthenticationModule requisite + * realm=openid + * default_role=openid-user + * roles_attribute=roles + * groups_attribute=groups; + * info.magnolia.jaas.sp.jcr.JCRAuthenticationModule + * requisite + * skip_on_previous_success=true; + * info.magnolia.jaas.sp.jcr.JCRAuthorizationModule required; + * }; + * + * + * </pre> + * + * @author Luca Boati + */ +public class OpenIdAuthenticationModule extends AbstractLoginModule implements LoginModule, UserAwareLoginModule +{ + + protected Subject subject; + + protected CallbackHandler callbackHandler; + + protected User user; + + private String identifier; + + private String email; + + private String nickname; + + private boolean skipOnPreviousSuccess; + + private String defaultGroup; + + private String defaultRole; + + private String rolesAttribute = "roles"; + + private String groupsAttribute = "groups"; + + protected Logger log = LoggerFactory.getLogger(getClass()); + + /** + * @param subject + * @param callbackHandler + * @param sharedState + * @param options can contain + */ + @Override + public void initialize(Subject subject, CallbackHandler callbackHandler, Map sharedState, Map options) + { + super.initialize(subject, callbackHandler, sharedState, options); + this.subject = subject; + this.callbackHandler = callbackHandler; + this.defaultGroup = (String) options.get("default_group"); + this.defaultRole = (String) options.get("default_role"); + + if (options.get("roles_attribute") != null) + { + rolesAttribute = (String) options.get("roles_attribute"); + } + + if (options.get("groups_attribute") != null) + { + groupsAttribute = (String) options.get("groups_attribute"); + } + + // private on AbstractLoginModule + this.skipOnPreviousSuccess = BooleanUtil + .toBoolean((String) options.get(OPTION_SKIP_ON_PREVIOUS_SUCCESS), false); + } + + @Override + public boolean login() throws LoginException + { + if (skipOnPreviousSuccess && this.getSharedStatus() == STATUS_SUCCEEDED) + { + return true; + } + + if (this.callbackHandler == null) + { + throw new LoginException("Error: no CallbackHandler available"); + } + + List<Callback> callbacksList = new ArrayList<Callback>(); + + TextInputCallback identifierCallback = new TextInputCallback("identifier"); + TextInputCallback emailCallback = new TextInputCallback("email"); + TextInputCallback nicknameCallback = new TextInputCallback("nickname"); + RealmCallback realmCallback = null; + + callbacksList.add(identifierCallback); + callbacksList.add(emailCallback); + callbacksList.add(nicknameCallback); + + // if the realm is not defined in the jaas configuration + // we ask use a callback to get the value + if (this.useRealmCallback) + { + realmCallback = new RealmCallback(); + callbacksList.add(realmCallback); + } + + this.success = false; + + Callback[] callbacks = callbacksList.toArray(new Callback[callbacksList.size()]); + + try + { + this.callbackHandler.handle(callbacks); + + // FIXME we do that only to be compatible to the old way jaas modules were written + if (this instanceof UserAwareLoginModule) + { + User user = ((UserAwareLoginModule) this).getUser(); + if (user != null) + { + this.callbackHandler.handle(new Callback[]{new UserCallback(user) }); + } + } + } + catch (IOException e) + { + if (log.isDebugEnabled()) + { + log.debug("Exception caught", e); + } + throw new LoginException(e.toString()); + } + catch (UnsupportedCallbackException e) + { + if (log.isDebugEnabled()) + { + log.debug(e.getMessage(), e); + } + throw new LoginException(e.getCallback().toString() + " not available"); + } + + // this.name = ((NameCallback) callbacks[0]).getName(); + // this.pswd = ((PasswordCallback) callbacks[1]).getPassword(); + if (this.useRealmCallback) + { + this.realm = StringUtils.defaultIfEmpty(realmCallback.getRealm(), this.realm); + } + + this.identifier = identifierCallback.getText(); + this.email = emailCallback.getText(); + this.nickname = nicknameCallback.getText(); + + if (StringUtils.isNotBlank(this.email) && StringUtils.isNotBlank(this.identifier)) + { + + setEntity(); + user = new OpenIdMagnoliaUser(subject); + + this.success = true; + this.setSharedStatus(STATUS_SUCCEEDED); + } + + return this.success; + } + + /** + * {@inheritDoc} + */ + @Override + public void validateUser() throws LoginException + { + + } + + @Override + public boolean commit() throws LoginException + { + if (!this.success) + { + return false; + } + this.setACL(); + return true; + } + + /** + * {@inheritDoc} + */ + public User getUser() + { + return user; + } + + @Override + public boolean release() + { + return false; + } + + /** + * {@inheritDoc} + */ + @Override + public void setACL() + { + // delegate to the Authorization module + } + + /** + * {@inheritDoc} + */ + @SuppressWarnings("unchecked") + @Override + public void setEntity() + { + EntityImpl entity = new EntityImpl(); + Map<String, String> attributes = new HashMap<String, String>(); + + String name = "openid"; + if (StringUtils.isNotBlank(this.identifier)) + { + name = this.identifier; + } + entity.addProperty(Entity.NAME, name); + + if (this.email != null) + { + entity.addProperty(Entity.EMAIL, this.email); + } + + entity.addProperty(Entity.LANGUAGE, "en"); + + this.subject.getPrincipals().add(entity); + + String[] roles = StringUtils.split(attributes.get(rolesAttribute)); + String[] groups = StringUtils.split(attributes.get(groupsAttribute)); + + if (roles == null) + { + roles = new String[0]; + } + if (groups == null) + { + groups = new String[0]; + } + + if (defaultGroup != null) + { + groups = (String[]) ArrayUtils.add(groups, defaultGroup); + } + + if (defaultRole != null) + { + roles = (String[]) ArrayUtils.add(roles, defaultRole); + } + + addGroups(groups); + addRoles(roles); + + } + + /** + * Set the list of groups, info.magnolia.jaas.principal.GroupList. + * @param groups array of group names + */ + protected void addGroups(String[] groups) + { + GroupList groupList = new GroupListImpl(); + + for (int j = 0; j < groups.length; j++) + { + String group = groups[j]; + groupList.add(group); + addGroupName(group); + } + + this.subject.getPrincipals().add(groupList); + } + + /** + * Set the list of roles, info.magnolia.jaas.principal.RoleList. + * @param roles array of role names + */ + protected void addRoles(String[] roles) + { + RoleList roleList = new RoleListImpl(); + + for (int j = 0; j < roles.length; j++) + { + String role = roles[j]; + roleList.add(role); + addRoleName(role); + } + + this.subject.getPrincipals().add(roleList); + } + +} \ No newline at end of file Added: trunk/openutils-mgnlopenid/src/main/java/net/sourceforge/openutils/mgnlopenid/OpenIdCallBackHandler.java =================================================================== --- trunk/openutils-mgnlopenid/src/main/java/net/sourceforge/openutils/mgnlopenid/OpenIdCallBackHandler.java (rev 0) +++ trunk/openutils-mgnlopenid/src/main/java/net/sourceforge/openutils/mgnlopenid/OpenIdCallBackHandler.java 2010-07-29 16:18:47 UTC (rev 2830) @@ -0,0 +1,118 @@ +/** + * + * Magnolia OpenId Module (http://www.openmindlab.com/lab/products/openid.html) + * Copyright(C) 2010-2010, Openmind S.r.l. http://www.openmindonline.it + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +package net.sourceforge.openutils.mgnlopenid; + +import info.magnolia.cms.security.auth.callback.RealmCallback; + +import java.io.IOException; + +import javax.security.auth.callback.Callback; +import javax.security.auth.callback.CallbackHandler; +import javax.security.auth.callback.TextInputCallback; +import javax.security.auth.callback.UnsupportedCallbackException; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + + +/** + * @author Luca Boati + * @version $Id: $ + */ +public class OpenIdCallBackHandler implements CallbackHandler +{ + + /** + * Logger. + */ + private Logger log = LoggerFactory.getLogger(OpenIdCallBackHandler.class); + + private String realm; + + private String identifier; + + private String email; + + private String nickname; + + public OpenIdCallBackHandler(String realm, String identifier, String email, String nickname) + { + this.realm = realm; + this.identifier = identifier; + this.email = email; + this.nickname = nickname; + } + + public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException + { + for (int i = 0; i < callbacks.length; i++) + { + if (callbacks[i] instanceof TextInputCallback) + { + TextInputCallback text = (TextInputCallback) callbacks[i]; + if ("identifier".equals(text.getPrompt())) + { + log.info(getIdentifier()); + text.setText(getIdentifier()); + } + if ("email".equals(text.getPrompt())) + { + log.info(getEmail()); + text.setText(getEmail()); + } + if ("nickname".equals(text.getPrompt())) + { + log.info(getNickname()); + text.setText(getNickname()); + } + } + else if (callbacks[i] instanceof RealmCallback) + { + log.info(this.realm); + ((RealmCallback) callbacks[i]).setRealm(this.realm); + } + else + { + throw (new UnsupportedCallbackException(callbacks[i], "Callback class not supported")); + } + } + } + + public String getRealm() + { + return realm; + } + + public String getEmail() + { + return email; + } + + public String getNickname() + { + return nickname; + } + + public String getIdentifier() + { + return identifier; + } + +} \ No newline at end of file Added: trunk/openutils-mgnlopenid/src/main/java/net/sourceforge/openutils/mgnlopenid/OpenIdLoginHandler.java =================================================================== --- trunk/openutils-mgnlopenid/src/main/java/net/sourceforge/openutils/mgnlopenid/OpenIdLoginHandler.java (rev 0) +++ trunk/openutils-mgnlopenid/src/main/java/net/sourceforge/openutils/mgnlopenid/OpenIdLoginHandler.java 2010-07-29 16:18:47 UTC (rev 2830) @@ -0,0 +1,509 @@ +/** + * + * Magnolia OpenId Module (http://www.openmindlab.com/lab/products/openid.html) + * Copyright(C) 2010-2010, Openmind S.r.l. http://www.openmindonline.it + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +package net.sourceforge.openutils.mgnlopenid; + +import info.magnolia.cms.security.SecuritySupport; +import info.magnolia.cms.security.User; +import info.magnolia.cms.security.auth.login.LoginHandler; +import info.magnolia.cms.security.auth.login.LoginHandlerBase; +import info.magnolia.cms.security.auth.login.LoginResult; +import info.magnolia.context.MgnlContext; + +import java.io.IOException; +import java.util.Iterator; +import java.util.List; + +import javax.security.auth.Subject; +import javax.security.auth.login.LoginContext; +import javax.security.auth.login.LoginException; +import javax.servlet.RequestDispatcher; +import javax.servlet.ServletException; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.apache.commons.lang.StringUtils; +import org.openid4java.OpenIDException; +import org.openid4java.consumer.ConsumerException; +import org.openid4java.consumer.ConsumerManager; +import org.openid4java.consumer.InMemoryConsumerAssociationStore; +import org.openid4java.consumer.InMemoryNonceVerifier; +import org.openid4java.consumer.VerificationResult; +import org.openid4java.discovery.DiscoveryInformation; +import org.openid4java.discovery.Identifier; +import org.openid4java.message.AuthRequest; +import org.openid4java.message.AuthSuccess; +import org.openid4java.message.MessageExtension; +import org.openid4java.message.ParameterList; +import org.openid4java.message.ax.AxMessage; +import org.openid4java.message.ax.FetchRequest; +import org.openid4java.message.ax.FetchResponse; +import org.openid4java.message.sreg.SRegMessage; +import org.openid4java.message.sreg.SRegResponse; +import org.openid4java.util.HttpClientFactory; +import org.openid4java.util.ProxyProperties; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + + +/** + * OpenId Consumer (Relying Party) implementation. + */ +public class OpenIdLoginHandler extends LoginHandlerBase implements LoginHandler +{ + + /** + * Logger. + */ + private Logger log = LoggerFactory.getLogger(OpenIdLoginHandler.class); + + /** + * The JAAS chain/module to use. + */ + private String jaasChain = "magnolia"; + + private String realm; + + private ConsumerManager manager; + + private String proxyName; + + private Integer proxyPort; + + private String userSuppliedString = "mgnlUserOpenID"; + + private String openidMode = "openid.mode"; + + private String bpMgnlOpenId = "bpMgnlOpenId"; + + // configure the return_to URL where your application will receive + // the authentication responses from the OpenID provider + private String returnToUrl; + + private String formRedirectionUrl; + + public OpenIdLoginHandler() throws ConsumerException + { + // instantiate a ConsumerManager object + manager = new ConsumerManager(); + manager.setAssociations(new InMemoryConsumerAssociationStore()); + manager.setNonceVerifier(new InMemoryNonceVerifier(5000)); + + } + + public LoginResult handle(HttpServletRequest request, HttpServletResponse response) + { + + final String userSuppliedString = request.getParameter(this.userSuppliedString); + final String openidMode = request.getParameter(this.openidMode); + final String bpMgnlOpenId = request.getParameter(this.bpMgnlOpenId); + if (StringUtils.isNotEmpty(userSuppliedString) && StringUtils.isEmpty(bpMgnlOpenId)) + { + String authResult = null; + try + { + authResult = authRequest(userSuppliedString, request, response); + } + catch (IOException e) + { + log.error("Error on auth request ", e); + } + if (StringUtils.isNotBlank(authResult)) + { + return LoginResult.getCurrentLoginResult(); + } + } + if (StringUtils.isNotEmpty(openidMode)) + { + Identifier identifier = verifyResponse(request); + String email = (String) request.getAttribute("email"); + String nickname = (String) request.getAttribute("nickname"); + if (identifier == null || StringUtils.isEmpty(email)) + { + LoginException loginException = new LoginException("null identifier or email"); + return new LoginResult(LoginResult.STATUS_FAILED, loginException); + } + else + { + Subject subject; + try + { + OpenIdCallBackHandler callbackHandler = new OpenIdCallBackHandler(this.realm, identifier + .getIdentifier(), email, nickname); + LoginContext loginContext = new LoginContext( + StringUtils.defaultString(getJaasChain(), "magnolia"), + callbackHandler); + + loginContext.login(); + subject = loginContext.getSubject(); + User user = SecuritySupport.Factory.getInstance().getUserManager().getUser(subject); + if (user != null) + { + user.setSubject(subject); + } + else + { + log + .error("Unable to obtain a user from userManager, maybe the external user manager is not configured for the " + + this.realm + + " realm?"); + } + return new LoginResult(LoginResult.STATUS_SUCCEEDED, user); + } + catch (LoginException e) + { + log.info("Can't login due to:", e); + return new LoginResult(LoginResult.STATUS_FAILED, e); + } + } + } + + return LoginResult.NOT_HANDLED; + } + + public String authRequest(String userSuppliedString, HttpServletRequest httpReq, HttpServletResponse httpResp) + throws IOException + { + try + { + // --- Forward proxy setup (only if needed) --- + ProxyProperties proxyProps = new ProxyProperties(); + if (StringUtils.isNotBlank(proxyName) && proxyPort != null) + { + proxyProps.setProxyHostName(proxyName); + proxyProps.setProxyPort(proxyPort); + HttpClientFactory.setProxyProperties(proxyProps); + } + + // perform discovery on the user-supplied identifier + List discoveries = manager.discover(userSuppliedString); + + // attempt to associate with the OpenID provider + // and retrieve one service endpoint for authentication + DiscoveryInformation discovered = manager.associate(discoveries); + returnToUrl = httpReq.getRequestURL().toString() + "?"; + // store the discovery information in the user's session + httpReq.getSession().setAttribute("openid-disc", discovered); + + // obtain a AuthRequest message to be sent to the OpenID provider + AuthRequest authReq = manager.authenticate(discovered, returnToUrl); + + // Attribute Exchange example: fetching the 'email' attribute + FetchRequest fetch = FetchRequest.createFetchRequest(); + fetch.addAttribute("email", + // attribute alias + "http://schema.openid.net/contact/email", // type URI + true); // required + + fetch.addAttribute("nickname", "http://schema.openid.net/namePerson/friendly", true); + fetch.addAttribute("fullname", "http://schema.openid.net/contact/fullname", true); + fetch.addAttribute("dob", "http://schema.openid.net/contact/dob", true); + fetch.addAttribute("gender", "http://schema.openid.net/contact/gender", true); + fetch.addAttribute("postcode", "http://schema.openid.net/contact/postcode", true); + fetch.addAttribute("country", "http://schema.openid.net/contact/country", true); + fetch.addAttribute("language", "http://schema.openid.net/contact/language", true); + fetch.addAttribute("timezone", "http://schema.openid.net/contact/timezone", true); + + // attach the extension to the authentication request + authReq.addExtension(fetch); + + if (!discovered.isVersion2()) + { + // Option 1: GET HTTP-redirect to the OpenID Provider endpoint + // The only method supported in OpenID 1.x + // redirect-URL usually limited ~2048 bytes + httpResp.addHeader("Content-Encoding", "gzip"); + httpResp.sendRedirect(authReq.getDestinationUrl(true)); + return null; + } + else + { + // Option 2: HTML FORM Redirection (Allows payloads >2048 bytes) + + RequestDispatcher dispatcher = MgnlContext.getWebContext().getServletContext().getRequestDispatcher( + this.formRedirectionUrl + "?" + this.bpMgnlOpenId + "=true"); + httpReq.setAttribute("authReq", authReq); + dispatcher.forward(httpReq, httpResp); + } + } + catch (OpenIDException e) + { + log.error("Error on authentication ", e); + } + catch (ServletException e) + { + log.error("Error on authentication ", e); + } + + return null; + } + + // --- processing the authentication response --- + public Identifier verifyResponse(HttpServletRequest httpReq) + { + try + { + // extract the parameters from the authentication response + // (which comes in as a HTTP request from the OpenID provider) + ParameterList response = new ParameterList(httpReq.getParameterMap()); + + // retrieve the previously stored discovery information + DiscoveryInformation discovered = (DiscoveryInformation) httpReq.getSession().getAttribute("openid-disc"); + + // extract the receiving URL from the HTTP request + StringBuffer receivingURL = httpReq.getRequestURL(); + String queryString = httpReq.getQueryString(); + if (queryString != null && queryString.length() > 0) + receivingURL.append("?").append(httpReq.getQueryString()); + + // verify the response; ConsumerManager needs to be the same + // (static) instance used to place the authentication request + VerificationResult verification = manager.verify(receivingURL.toString(), response, discovered); + + // examine the verification result and extract the verified identifier + Identifier verified = verification.getVerifiedId(); + if (verified != null) + { + AuthSuccess authSuccess = (AuthSuccess) verification.getAuthResponse(); + + if (authSuccess.hasExtension(SRegMessage.OPENID_NS_SREG)) + { + MessageExtension ext = authSuccess.getExtension(SRegMessage.OPENID_NS_SREG); + if (ext instanceof SRegResponse) + { + SRegResponse sregResp = (SRegResponse) ext; + for (Iterator iter = sregResp.getAttributeNames().iterator(); iter.hasNext();) + { + String name = (String) iter.next(); + String value = sregResp.getParameterValue(name); + httpReq.setAttribute(name, value); + } + } + } + if (authSuccess.hasExtension(AxMessage.OPENID_NS_AX)) + { + FetchResponse fetchResp = (FetchResponse) authSuccess.getExtension(AxMessage.OPENID_NS_AX); + + // List emails = fetchResp.getAttributeValues("email"); + // String email = (String) emails.get(0); + + List aliases = fetchResp.getAttributeAliases(); + for (Iterator iter = aliases.iterator(); iter.hasNext();) + { + String alias = (String) iter.next(); + List values = fetchResp.getAttributeValues(alias); + if (values.size() > 0) + { + log.debug(alias + " : " + values.get(0)); + httpReq.setAttribute(alias, values.get(0)); + } + } + } + + return verified; // success + } + } + catch (OpenIDException e) + { + // present error to the user + } + + return null; + } + + /** + * Returns the manager. + * @return the manager + */ + public ConsumerManager getManager() + { + return manager; + } + + /** + * Sets the manager. + * @param manager the manager to set + */ + public void setManager(ConsumerManager manager) + { + this.manager = manager; + } + + /** + * Returns the returnToUrl. + * @return the returnToUrl + */ + public String getReturnToUrl() + { + return returnToUrl; + } + + /** + * Sets the returnToUrl. + * @param returnToUrl the returnToUrl to set + */ + public void setReturnToUrl(String returnToUrl) + { + this.returnToUrl = returnToUrl; + } + + /** + * Returns the proxyName. + * @return the proxyName + */ + public String getProxyName() + { + return proxyName; + } + + /** + * Sets the proxyName. + * @param proxyName the proxyName to set + */ + public void setProxyName(String proxyName) + { + this.proxyName = proxyName; + } + + /** + * Returns the proxyPort. + * @return the proxyPort + */ + public Integer getProxyPort() + { + return proxyPort; + } + + /** + * Sets the proxyPort. + * @param proxyPort the proxyPort to set + */ + public void setProxyPort(Integer proxyPort) + { + this.proxyPort = proxyPort; + } + + /** + * Returns the userSuppliedString. + * @return the userSuppliedString + */ + public String getUserSuppliedString() + { + return userSuppliedString; + } + + /** + * Sets the userSuppliedString. + * @param userSuppliedString the userSuppliedString to set + */ + public void setUserSuppliedString(String userSuppliedString) + { + this.userSuppliedString = userSuppliedString; + } + + /** + * Returns the openidMode. + * @return the openidMode + */ + public String getOpenidMode() + { + return openidMode; + } + + /** + * Sets the openidMode. + * @param openidMode the openidMode to set + */ + public void setOpenidMode(String openidMode) + { + this.openidMode = openidMode; + } + + /** + * Returns the bpMgnlOpenId. + * @return the bpMgnlOpenId + */ + public String getBpMgnlOpenId() + { + return bpMgnlOpenId; + } + + /** + * Sets the bpMgnlOpenId. + * @param bpMgnlOpenId the bpMgnlOpenId to set + */ + public void setBpMgnlOpenId(String bpMgnlOpenId) + { + this.bpMgnlOpenId = bpMgnlOpenId; + } + + /** + * Returns the formRedirectionUrl. + * @return the formRedirectionUrl + */ + public String getFormRedirectionUrl() + { + return formRedirectionUrl; + } + + /** + * Sets the formRedirectionUrl. + * @param formRedirectionUrl the formRedirectionUrl to set + */ + public void setFormRedirectionUrl(String formRedirectionUrl) + { + this.formRedirectionUrl = formRedirectionUrl; + } + + /** + * Returns the jaasChain. + * @return the jaasChain + */ + public String getJaasChain() + { + return jaasChain; + } + + /** + * Sets the jaasChain. + * @param jaasChain the jaasChain to set + */ + public void setJaasChain(String jaasChain) + { + this.jaasChain = jaasChain; + } + + /** + * Returns the realm. + * @return the realm + */ + public String getRealm() + { + return realm; + } + + /** + * Sets the realm. + * @param realm the realm to set + */ + public void setRealm(String realm) + { + this.realm = realm; + } +} \ No newline at end of file Added: trunk/openutils-mgnlopenid/src/main/java/net/sourceforge/openutils/mgnlopenid/OpenIdMagnoliaUser.java =================================================================== --- trunk/openutils-mgnlopenid/src/main/java/net/sourceforge/openutils/mgnlopenid/OpenIdMagnoliaUser.java (rev 0) +++ trunk/openutils-mgnlopenid/src/main/java/net/sourceforge/openutils/mgnlopenid/OpenIdMagnoliaUser.java 2010-07-29 16:18:47 UTC (rev 2830) @@ -0,0 +1,108 @@ +/** + * + * Magnolia OpenId Module (http://www.openmindlab.com/lab/products/openid.html) + * Copyright(C) 2010-2010, Openmind S.r.l. http://www.openmindonline.it + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +package net.sourceforge.openutils.mgnlopenid; + +import info.magnolia.cms.security.ExternalUser; + +import javax.security.auth.Subject; + + +/** + * @author Luca Boati + */ +public class OpenIdMagnoliaUser extends ExternalUser +{ + + /** + * Stable serialVersionUID. + */ + private static final long serialVersionUID = 42L; + + /** + * @param subject + */ + protected OpenIdMagnoliaUser(Subject subject) + { + super(subject); + } + + /** + * {@inheritDoc} + */ + @Override + public void addGroup(String groupName) throws UnsupportedOperationException + { + // Do nothing + } + + /** + * {@inheritDoc} + */ + @Override + public void addRole(String roleName) throws UnsupportedOperationException + { + // Do nothing + } + + /** + * {@inheritDoc} + */ + @Override + public void removeGroup(String groupName) throws UnsupportedOperationException + { + // Do nothind + } + + /** + * {@inheritDoc} + */ + @Override + public void removeRole(String roleName) throws UnsupportedOperationException + { + // Do nothing + } + + /** + * {@inheritDoc} + */ + @Override + public void setEnabled(boolean enabled) + { + // Do nothing + } + + /** + * {@inheritDoc} + */ + @Override + public void setProperty(String propertyName, String value) + { + // Do nothing + } + + /** + * {@inheritDoc} + */ + @Override + public String getProperty(String propertyName) + { + return null; + } +} Added: trunk/openutils-mgnlopenid/src/main/java/net/sourceforge/openutils/mgnlopenid/OpenIdMgnlUserManager.java =================================================================== --- trunk/openutils-mgnlopenid/src/main/java/net/sourceforge/openutils/mgnlopenid/OpenIdMgnlUserManager.java (rev 0) +++ trunk/openutils-mgnlopenid/src/main/java/net/sourceforge/openutils/mgnlopenid/OpenIdMgnlUserManager.java 2010-07-29 16:18:47 UTC (rev 2830) @@ -0,0 +1,66 @@ +/** + * + * Magnolia OpenId Module (http://www.openmindlab.com/lab/products/openid.html) + * Copyright(C) 2010-2010, Openmind S.r.l. http://www.openmindonline.it + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +package net.sourceforge.openutils.mgnlopenid; + +import info.magnolia.cms.security.ExternalUserManager; +import info.magnolia.cms.security.User; + +import javax.security.auth.Subject; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + + +/** + * @author Luca Boati + */ +public class OpenIdMgnlUserManager extends ExternalUserManager +{ + + /** + * Logger. + */ + private Logger log = LoggerFactory.getLogger(OpenIdMgnlUserManager.class); + + /** + * {@inheritDoc} + */ + @Override + public User getUser(String name) throws UnsupportedOperationException + { + return null; + } + + /** + * {@inheritDoc} + */ + @Override + public User getUser(Subject subject) throws UnsupportedOperationException + { + // this could be the case if no one is logged in yet + if (subject == null) + { + log.debug("subject not set."); + return null; + } + return new OpenIdMagnoliaUser(subject); + } + +} \ No newline at end of file Added: trunk/openutils-mgnlopenid/src/main/java/net/sourceforge/openutils/mgnlopenid/lifecycle/OpenIdModule.java =================================================================== --- trunk/openutils-mgnlopenid/src/main/java/net/sourceforge/openutils/mgnlopenid/lifecycle/OpenIdModule.java (rev 0) +++ trunk/openutils-mgnlopenid/src/main/java/net/sourceforge/openutils/mgnlopenid/lifecycle/OpenIdModule.java 2010-07-29 16:18:47 UTC (rev 2830) @@ -0,0 +1,78 @@ +/** + * + * Magnolia OpenId Module (http://www.openmindlab.com/lab/products/openid.html) + * Copyright(C) 2010-2010, Openmind S.r.l. http://www.openmindonline.it + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +package net.sourceforge.openutils.mgnlopenid.lifecycle; + +import info.magnolia.module.ModuleLifecycle; +import info.magnolia.module.ModuleLifecycleContext; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + + +/** + * OpenId module lifecycle manager + * @author Luca Boati + */ +public class OpenIdModule implements ModuleLifecycle +{ + + /** + * Media module name. + */ + public static final String NAME = "openid"; + + private Logger log = LoggerFactory.getLogger(OpenIdModule.class); + + private String version; + + /** + * Constructor + */ + public OpenIdModule() + { + } + + /** + * {@inheritDoc} + */ + public void start(ModuleLifecycleContext ctx) + { + log.info("Starting module openid"); + version = ctx.getCurrentModuleDefinition().getVersion().toString(); + } + + /** + * {@inheritDoc} + */ + public void stop(ModuleLifecycleContext ctx) + { + log.info("Stopping module openid"); + } + + /** + * Returns the version. + * @return the version + */ + public String getVersion() + { + return version; + } + +} Added: trunk/openutils-mgnlopenid/src/main/java/net/sourceforge/openutils/mgnlopenid/pages/FormRedirection.java =================================================================== --- trunk/openutils-mgnlopenid/src/main/java/net/sourceforge/openutils/mgnlopenid/pages/FormRedirection.java (rev 0) +++ trunk/openutils-mgnlopenid/src/main/java/net/sourceforge/openutils/mgnlopenid/pages/FormRedirection.java 2010-07-29 16:18:47 UTC (rev 2830) @@ -0,0 +1,146 @@ +/** + * + * Magnolia OpenId Module (http://www.openmindlab.com/lab/products/openid.html) + * Copyright(C) 2010-2010, Openmind S.r.l. http://www.openmindonline.it + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +package net.sourceforge.openutils.mgnlopenid.pages; + +import info.magnolia.cms.i18n.Messages; +import info.magnolia.module.admininterface.TemplatedMVCHandler; + +import java.util.Date; +import java.util.Set; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import net.sourceforge.openutils.mgnlopenid.tags.el.OpenIdEl; + +import org.openid4java.message.AuthRequest; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + + +/** + * Page that contains form redirection + * @author Luca Boati + */ +public class FormRedirection extends TemplatedMVCHandler +{ + + /** + * Logger. + */ + private Logger log = LoggerFactory.getLogger(FormRedirection.class); + + private String cacheKiller; + + private AuthRequest authReq; + + private Set parameters; + + /** + * @param name command name + * @param request + * @param response + */ + public FormRedirection(String name, HttpServletRequest request, HttpServletResponse response) + { + super(name, request, response); + cacheKiller = String.valueOf(new Date().getTime()); + authReq = (AuthRequest) request.getAttribute("authReq"); + parameters = authReq.getParameterMap().entrySet(); + } + + /** + * {@inheritDoc} + */ + @Override + public void init() + { + super.init(); + } + + /** + * Returns the cacheKiller. + * @return the cacheKiller + */ + public String getCacheKiller() + { + return cacheKiller; + } + + /** + * Sets the cacheKiller. + * @param cacheKiller the cacheKiller to set + */ + public void setCacheKiller(String cacheKiller) + { + this.cacheKiller = cacheKiller; + } + + /** + * {@inheritDoc} + */ + @Override + public Messages getMsgs() + { + return super.getMsgs(); + } + + public String getMessage(String key, String arg) + { + return super.getMsgs().get(key, new String[]{arg }); + } + + /** + * Returns the installed media module version. + * @return version as string. + */ + public String getModuleVersion() + { + return OpenIdEl.module().getVersion(); + } + + /** + * Returns the authReq. + * @return the authReq + */ + public AuthRequest getAuthReq() + { + return authReq; + } + + /** + * Returns the parameters. + * @return the parameters + */ + public Set getParameters() + { + return parameters; + } + + /** + * Sets the parameters. + * @param parameters the parameters to set + */ + public void setParameters(Set parameters) + { + this.parameters = parameters; + } + +} Added: trunk/openutils-mgnlopenid/src/main/java/net/sourceforge/openutils/mgnlopenid/pages/Login.java =================================================================== --- trunk/openutils-mgnlopenid/src/main/java/net/sourceforge/openutils/mgnlopenid/pages/Login.java (rev 0) +++ trunk/openutils-mgnlopenid/src/main/java/net/sourceforge/openutils/mgnlopenid/pages/Login.java 2010-07-29 16:18:47 UTC (rev 2830) @@ -0,0 +1,111 @@ +/** + * + * Magnolia OpenId Module (http://www.openmindlab.com/lab/products/openid.html) + * Copyright(C) 2010-2010, Openmind S.r.l. http://www.openmindonline.it + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +package net.sourceforge.openutils.mgnlopenid.pages; + +import info.magnolia.cms.i18n.Messages; +import info.magnolia.module.admininterface.TemplatedMVCHandler; + +import java.util.Date; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import net.sourceforge.openutils.mgnlopenid.tags.el.OpenIdEl; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + + +/** + * Page that contains login form + * @author Luca Boati + */ +public class Login extends TemplatedMVCHandler +{ + + /** + * Logger. + */ + private Logger log = LoggerFactory.getLogger(Login.class); + + private String cacheKiller; + + /** + * @param name command name + * @param request + * @param response + */ + public Login(String name, HttpServletRequest request, HttpServletResponse response) + { + super(name, request, response); + cacheKiller = String.valueOf(new Date().getTime()); + } + + /** + * {@inheritDoc} + */ + @Override + public void init() + { + super.init(); + } + + /** + * Returns the cacheKiller. + * @return the cacheKiller + */ + public String getCacheKiller() + { + return cacheKiller; + } + + /** + * Sets the cacheKiller. + * @param cacheKiller the cacheKiller to set + */ + public void setCacheKiller(String cacheKiller) + { + this.cacheKiller = cacheKiller; + } + + /** + * {@inheritDoc} + */ + @Override + public Messages getMsgs() + { + return super.getMsgs(); + } + + public String getMessage(String key, String arg) + { + return super.getMsgs().get(key, new String[]{arg }); + } + + /** + * Returns the installed media module version. + * @return version as string. + */ + public String getModuleVersion() + { + return OpenIdEl.module().getVersion(); + } + +} Added: trunk/openutils-mgnlopenid/src/main/java/net/sourceforge/openutils/mgnlopenid/setup/OpenIdModuleVersionHandler.java =================================================================== --- trunk/openutils-mgnlopenid/src/main/java/net/sourceforge/openutils/mgnlopenid/setup/OpenIdModuleVersionHandler.java (rev 0) +++ trunk/openutils-mgnlopenid/src/main/java/net/sourceforge/openutils/mgnlopenid/setup/OpenIdModuleVersionHandler.java 2010-07-29 16:18:47 UTC (rev 2830) @@ -0,0 +1,102 @@ +/** + * + * Magnolia OpenId Module (http://www.openmindlab.com/lab/products/openid.html) + * Copyright(C) 2010-2010, Openmind S.r.l. http://www.openmindonline.it + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +package net.sourceforge.openutils.mgnlopenid.setup; + +import info.magnolia.cms.core.SystemProperty; +import info.magnolia.module.InstallContext; +import info.magnolia.module.ModuleRegistry; +import info.magnolia.module.delta.BootstrapSingleResource; +import info.magnolia.module.delta.Task; +import it.openutils.mgnltasks.SamplesExtractionTask; +import it.openutils.mgnltasks.SetNodeOrderTask; +import it.openutils.mgnltasks.SimpleModuleVersionHandler; + +import java.util.ArrayList; +import java.util.List; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + + +/** + * Module version handler for media module + * @author manuel + * @ver... [truncated message content] |