From e1f70fc668fdfbe8302a422a61f0ceff0070e222 Mon Sep 17 00:00:00 2001 From: Edgar Mueller Date: Thu, 12 Feb 2015 15:34:33 +0100 Subject: [PATCH] Bug 459781 - Customizable authentication & authorization: Removed warnings & added javadoc --- .../build.properties | 53 ++++++++--------- .../authentication/ACUserContainer.java | 2 +- .../authentication/ESUserVerifierFactory.java | 33 ++++++----- .../authentication/Messages.java | 30 ++++++++++ .../authentication/messages.properties | 1 + .../verifiers/EMFModelUserVerifier.java | 12 +++- .../verifiers/LDAPUserVerifier.java | 12 ++-- .../SimplePropertyFileUserVerifier.java | 57 +++++-------------- 8 files changed, 107 insertions(+), 93 deletions(-) create mode 100644 bundles/org.eclipse.emf.emfstore.server/src/org/eclipse/emf/emfstore/internal/server/accesscontrol/authentication/Messages.java create mode 100644 bundles/org.eclipse.emf.emfstore.server/src/org/eclipse/emf/emfstore/internal/server/accesscontrol/authentication/messages.properties diff --git a/bundles/org.eclipse.emf.emfstore.server/build.properties b/bundles/org.eclipse.emf.emfstore.server/build.properties index 89e5cddae..6ed938876 100644 --- a/bundles/org.eclipse.emf.emfstore.server/build.properties +++ b/bundles/org.eclipse.emf.emfstore.server/build.properties @@ -1,26 +1,27 @@ -bin.includes = .,\ - META-INF/,\ - plugin.xml,\ - schema/,\ - lib/org.apache.ws.commons.util_1.0.1.v20100518-1140.jar,\ - lib/xmlrpc-client-3.1.3.jar,\ - lib/xmlrpc-common-3.1.3.jar,\ - lib/xmlrpc-server-3.1.3.jar,\ - src/org/eclipse/emf/emfstore/internal/server/es.properties,\ - src/org/eclipse/emf/emfstore/internal/server/emfstoreServer.keystore,\ - about.ini,\ - about.html,\ - about.mappings,\ - about.properties,\ - modeling32.png,\ - src/org/eclipse/emf/emfstore/internal/server/core/messages.properties,\ - src/org/eclipse/emf/emfstore/internal/server/messages.properties,\ - src/org/eclipse/emf/emfstore/internal/server/conflictDetection/messages.properties,\ - src/org/eclipse/emf/emfstore/internal/server/accesscontrol/messages.properties,\ - src/org/eclipse/emf/emfstore/internal/server/accesscontrol/authentication/verifiers/messages.properties,\ - src/org/eclipse/emf/emfstore/internal/server/startup/messages.properties,\ - src/org/eclipse/emf/emfstore/internal/server/connection/xmlrpc/messages.properties -source.. = src/ -output.. = bin/ -src.includes = about.html - +bin.includes = .,\ + META-INF/,\ + plugin.xml,\ + schema/,\ + lib/org.apache.ws.commons.util_1.0.1.v20100518-1140.jar,\ + lib/xmlrpc-client-3.1.3.jar,\ + lib/xmlrpc-common-3.1.3.jar,\ + lib/xmlrpc-server-3.1.3.jar,\ + src/org/eclipse/emf/emfstore/internal/server/es.properties,\ + src/org/eclipse/emf/emfstore/internal/server/emfstoreServer.keystore,\ + about.ini,\ + about.html,\ + about.mappings,\ + about.properties,\ + modeling32.png,\ + src/org/eclipse/emf/emfstore/internal/server/core/messages.properties,\ + src/org/eclipse/emf/emfstore/internal/server/messages.properties,\ + src/org/eclipse/emf/emfstore/internal/server/conflictDetection/messages.properties,\ + src/org/eclipse/emf/emfstore/internal/server/accesscontrol/messages.properties,\ + src/org/eclipse/emf/emfstore/internal/server/accesscontrol/authentication/verifiers/messages.properties,\ + src/org/eclipse/emf/emfstore/internal/server/startup/messages.properties,\ + src/org/eclipse/emf/emfstore/internal/server/connection/xmlrpc/messages.properties,\ + src/org/eclipse/emf/emfstore/internal/server/accesscontrol/authentication/messages.properties +source.. = src/ +output.. = bin/ +src.includes = about.html + diff --git a/bundles/org.eclipse.emf.emfstore.server/src/org/eclipse/emf/emfstore/internal/server/accesscontrol/authentication/ACUserContainer.java b/bundles/org.eclipse.emf.emfstore.server/src/org/eclipse/emf/emfstore/internal/server/accesscontrol/authentication/ACUserContainer.java index 4d9430b8c..5f2007ac4 100644 --- a/bundles/org.eclipse.emf.emfstore.server/src/org/eclipse/emf/emfstore/internal/server/accesscontrol/authentication/ACUserContainer.java +++ b/bundles/org.eclipse.emf.emfstore.server/src/org/eclipse/emf/emfstore/internal/server/accesscontrol/authentication/ACUserContainer.java @@ -75,7 +75,7 @@ private void checkLastActive() throws AccessControlException { * Integer.parseInt(property) */) { // OW: delete from map - throw new SessionTimedOutException("Usersession timed out."); + throw new SessionTimedOutException(Messages.ACUserContainer_Session_Timed_Out); } } diff --git a/bundles/org.eclipse.emf.emfstore.server/src/org/eclipse/emf/emfstore/internal/server/accesscontrol/authentication/ESUserVerifierFactory.java b/bundles/org.eclipse.emf.emfstore.server/src/org/eclipse/emf/emfstore/internal/server/accesscontrol/authentication/ESUserVerifierFactory.java index 7e1180dda..d8705b0ea 100644 --- a/bundles/org.eclipse.emf.emfstore.server/src/org/eclipse/emf/emfstore/internal/server/accesscontrol/authentication/ESUserVerifierFactory.java +++ b/bundles/org.eclipse.emf.emfstore.server/src/org/eclipse/emf/emfstore/internal/server/accesscontrol/authentication/ESUserVerifierFactory.java @@ -48,15 +48,18 @@ public static ESUserVerifierFactory getInstance() { } /** + * Creates an {@link ESUserVerifier} based on the given {@link ESAuthenticationControlType}. * - * {@inheritDoc} - * - * @see org.eclipse.emf.emfstore.internal.server.accesscontrol.authentication.ESUserVerifierFactory#createUserVerifier(org.eclipse.emf.emfstore.server.auth.ESAuthenticationControlType, - * org.eclipse.emf.emfstore.server.auth.ESUserProvider) + * @param authenticationControlType + * the requested type of {@link ESUserVerifier} + * @param orgUnitProvider + * provides access to users and groups if necessary + * @return the requested {@link ESUserVerifier} + * @throws FatalESException in case no fitting {@link ESUserVerifier} can be found or the initialization fails */ public ESUserVerifier createUserVerifier( ESAuthenticationControlType authenticationControlType, ESOrgUnitProvider orgUnitProvider) - throws FatalESException { + throws FatalESException { if (authenticationControlType.equals(ESAuthenticationControlType.ldap)) { final UserVerifierChain chain = new UserVerifierChain(orgUnitProvider); @@ -64,20 +67,20 @@ public ESUserVerifier createUserVerifier( int count = 1; while (count != -1) { - final String ldapUrl = properties.getProperty(ServerConfiguration.AUTHENTICATION_LDAP_PREFIX + "." + final String ldapUrl = properties.getProperty(ServerConfiguration.AUTHENTICATION_LDAP_PREFIX + "." //$NON-NLS-1$ + count - + "." + ServerConfiguration.AUTHENTICATION_LDAP_URL); - final String ldapBase = properties.getProperty(ServerConfiguration.AUTHENTICATION_LDAP_PREFIX + "." + + "." + ServerConfiguration.AUTHENTICATION_LDAP_URL); //$NON-NLS-1$ + final String ldapBase = properties.getProperty(ServerConfiguration.AUTHENTICATION_LDAP_PREFIX + "." //$NON-NLS-1$ + count - + "." + ServerConfiguration.AUTHENTICATION_LDAP_BASE); - final String searchDn = properties.getProperty(ServerConfiguration.AUTHENTICATION_LDAP_PREFIX + "." + + "." + ServerConfiguration.AUTHENTICATION_LDAP_BASE); //$NON-NLS-1$ + final String searchDn = properties.getProperty(ServerConfiguration.AUTHENTICATION_LDAP_PREFIX + "." //$NON-NLS-1$ + count - + "." + ServerConfiguration.AUTHENTICATION_LDAP_SEARCHDN); - final String authUser = properties.getProperty(ServerConfiguration.AUTHENTICATION_LDAP_PREFIX + "." + + "." + ServerConfiguration.AUTHENTICATION_LDAP_SEARCHDN); //$NON-NLS-1$ + final String authUser = properties.getProperty(ServerConfiguration.AUTHENTICATION_LDAP_PREFIX + "." //$NON-NLS-1$ + count - + "." + ServerConfiguration.AUTHENTICATION_LDAP_AUTHUSER); - final String authPassword = properties.getProperty(ServerConfiguration.AUTHENTICATION_LDAP_PREFIX + "." - + count + "." + ServerConfiguration.AUTHENTICATION_LDAP_AUTHPASS); + + "." + ServerConfiguration.AUTHENTICATION_LDAP_AUTHUSER); //$NON-NLS-1$ + final String authPassword = properties.getProperty(ServerConfiguration.AUTHENTICATION_LDAP_PREFIX + "." //$NON-NLS-1$ + + count + "." + ServerConfiguration.AUTHENTICATION_LDAP_AUTHPASS); //$NON-NLS-1$ if (ldapUrl != null && ldapBase != null && searchDn != null) { final LDAPUserVerifier ldapVerifier = new LDAPUserVerifier(orgUnitProvider, diff --git a/bundles/org.eclipse.emf.emfstore.server/src/org/eclipse/emf/emfstore/internal/server/accesscontrol/authentication/Messages.java b/bundles/org.eclipse.emf.emfstore.server/src/org/eclipse/emf/emfstore/internal/server/accesscontrol/authentication/Messages.java new file mode 100644 index 000000000..816de0ae6 --- /dev/null +++ b/bundles/org.eclipse.emf.emfstore.server/src/org/eclipse/emf/emfstore/internal/server/accesscontrol/authentication/Messages.java @@ -0,0 +1,30 @@ +/******************************************************************************* + * Copyright (c) 2011-2015 EclipseSource Muenchen GmbH and others. + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Edgar Mueller - initial API and implementation + ******************************************************************************/ +package org.eclipse.emf.emfstore.internal.server.accesscontrol.authentication; + +import org.eclipse.osgi.util.NLS; + +/** + * @author emueller + * @generated + */ +public class Messages extends NLS { + private static final String BUNDLE_NAME = "org.eclipse.emf.emfstore.internal.server.accesscontrol.authentication.messages"; //$NON-NLS-1$ + public static String ACUserContainer_Session_Timed_Out; + static { + // initialize resource bundle + NLS.initializeMessages(BUNDLE_NAME, Messages.class); + } + + private Messages() { + } +} diff --git a/bundles/org.eclipse.emf.emfstore.server/src/org/eclipse/emf/emfstore/internal/server/accesscontrol/authentication/messages.properties b/bundles/org.eclipse.emf.emfstore.server/src/org/eclipse/emf/emfstore/internal/server/accesscontrol/authentication/messages.properties new file mode 100644 index 000000000..300a7b668 --- /dev/null +++ b/bundles/org.eclipse.emf.emfstore.server/src/org/eclipse/emf/emfstore/internal/server/accesscontrol/authentication/messages.properties @@ -0,0 +1 @@ +ACUserContainer_Session_Timed_Out=Usersession timed out. diff --git a/bundles/org.eclipse.emf.emfstore.server/src/org/eclipse/emf/emfstore/internal/server/accesscontrol/authentication/verifiers/EMFModelUserVerifier.java b/bundles/org.eclipse.emf.emfstore.server/src/org/eclipse/emf/emfstore/internal/server/accesscontrol/authentication/verifiers/EMFModelUserVerifier.java index e5fbe9764..a9aec57fb 100644 --- a/bundles/org.eclipse.emf.emfstore.server/src/org/eclipse/emf/emfstore/internal/server/accesscontrol/authentication/verifiers/EMFModelUserVerifier.java +++ b/bundles/org.eclipse.emf.emfstore.server/src/org/eclipse/emf/emfstore/internal/server/accesscontrol/authentication/verifiers/EMFModelUserVerifier.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2011-2013 EclipseSource Muenchen GmbH and others. + * Copyright (c) 2011-2015 EclipseSource Muenchen GmbH and others. * * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 @@ -22,8 +22,14 @@ */ public class EMFModelUserVerifier extends UserVerifier { - public EMFModelUserVerifier(ESOrgUnitProvider userProvider) { - super(userProvider); + /** + * Constructor. + * + * @param orgUnitProvider + * provides access to users and groups + */ + public EMFModelUserVerifier(ESOrgUnitProvider orgUnitProvider) { + super(orgUnitProvider); } /** diff --git a/bundles/org.eclipse.emf.emfstore.server/src/org/eclipse/emf/emfstore/internal/server/accesscontrol/authentication/verifiers/LDAPUserVerifier.java b/bundles/org.eclipse.emf.emfstore.server/src/org/eclipse/emf/emfstore/internal/server/accesscontrol/authentication/verifiers/LDAPUserVerifier.java index f5dcb8a94..db21a989e 100644 --- a/bundles/org.eclipse.emf.emfstore.server/src/org/eclipse/emf/emfstore/internal/server/accesscontrol/authentication/verifiers/LDAPUserVerifier.java +++ b/bundles/org.eclipse.emf.emfstore.server/src/org/eclipse/emf/emfstore/internal/server/accesscontrol/authentication/verifiers/LDAPUserVerifier.java @@ -25,8 +25,6 @@ import org.eclipse.emf.emfstore.internal.common.model.util.ModelUtil; import org.eclipse.emf.emfstore.internal.server.connection.ServerKeyStoreManager; import org.eclipse.emf.emfstore.internal.server.exceptions.AccessControlException; -import org.eclipse.emf.emfstore.server.auth.ESUserVerifier; -import org.eclipse.emf.emfstore.server.model.ESClientVersionInfo; import org.eclipse.emf.emfstore.server.model.ESOrgUnitProvider; /** @@ -48,7 +46,10 @@ public class LDAPUserVerifier extends UserVerifier { /** * Default constructor. * - * @param ldapUrl url, if url starts with ldaps:// SSL is used. + * @param orgUnitProvider + * provides access to users and groups + * @param ldapUrl + * URL, if URLstarts with ldaps:// SSL is used. * @param ldapBase base * @param searchDn dn * @param authUser user to allow access to server @@ -72,8 +73,8 @@ public LDAPUserVerifier(ESOrgUnitProvider orgUnitProvider, /** * This method must be implemented by subclasses in order to verify a pair of username and password. - * When using authentication you should use {@link ESUserVerifier#logIn(String, String, ESClientVersionInfo)} in - * order to gain a session id. + * When using authentication you should use {@link org.eclipse.emf.emfstore.server.auth.ESUserVerifier + * ESUserVerifier#verifyUser(String, String, ESClientVersionInfo)} in order to gain a session id. * * @param username * the user name as entered by the client; may differ from the user name of the {@code resolvedUser} @@ -83,7 +84,6 @@ public LDAPUserVerifier(ESOrgUnitProvider orgUnitProvider, * @throws AccessControlException * if an exception occurs during the verification process */ - // TODO: introduce common interface verifying passwords @Override public boolean verifyPassword(String username, String password) throws AccessControlException { DirContext dirContext = null; diff --git a/bundles/org.eclipse.emf.emfstore.server/src/org/eclipse/emf/emfstore/internal/server/accesscontrol/authentication/verifiers/SimplePropertyFileUserVerifier.java b/bundles/org.eclipse.emf.emfstore.server/src/org/eclipse/emf/emfstore/internal/server/accesscontrol/authentication/verifiers/SimplePropertyFileUserVerifier.java index 1fcf68341..144acddbf 100644 --- a/bundles/org.eclipse.emf.emfstore.server/src/org/eclipse/emf/emfstore/internal/server/accesscontrol/authentication/verifiers/SimplePropertyFileUserVerifier.java +++ b/bundles/org.eclipse.emf.emfstore.server/src/org/eclipse/emf/emfstore/internal/server/accesscontrol/authentication/verifiers/SimplePropertyFileUserVerifier.java @@ -19,12 +19,9 @@ import java.util.Properties; import org.eclipse.emf.emfstore.internal.common.model.util.ModelUtil; -import org.eclipse.emf.emfstore.internal.server.accesscontrol.authentication.verifiers.SimplePropertyFileUserVerifier.Hash; import org.eclipse.emf.emfstore.internal.server.exceptions.AccessControlException; import org.eclipse.emf.emfstore.internal.server.exceptions.FatalESException; import org.eclipse.emf.emfstore.server.model.ESOrgUnitProvider; -import org.eclipse.emf.emfstore.server.model.ESSessionId; -import org.eclipse.emf.emfstore.server.model.ESUser; /** * This verifier can be used to store user and passwords in a property file. Entries in the property file look should @@ -55,32 +52,38 @@ public enum Hash { /** * Default constructor. No hash will be used for passwords * - * @see #SimplePropertyFileUserVerifier(String, Hash) - * @param filePath path to password file + * @param orgUnitProvider + * provides access to users and groups + * @param propertyFilePath + * path to file * @throws FatalESException in case of failure */ - public SimplePropertyFileUserVerifier(ESOrgUnitProvider orgUnitProvider, String filePath) throws FatalESException { - this(orgUnitProvider, filePath, Hash.NONE); + public SimplePropertyFileUserVerifier(ESOrgUnitProvider orgUnitProvider, String propertyFilePath) throws FatalESException { + this(orgUnitProvider, propertyFilePath, Hash.NONE); } /** * Constructor with ability to select hash algorithm for password. * - * @param filePath path to file - * @param hash selected hash + * @param orgUnitProvider + * provides access to users and groups + * @param propertyFilePath + * path to file + * @param hash + * selected hash * @throws FatalESException if hash is null */ - public SimplePropertyFileUserVerifier(ESOrgUnitProvider orgUnitProvider, String filePath, Hash hash) + public SimplePropertyFileUserVerifier(ESOrgUnitProvider orgUnitProvider, String propertyFilePath, Hash hash) throws FatalESException { super(orgUnitProvider); - this.filePath = filePath; + filePath = propertyFilePath; if (hash == null) { throw new FatalESException(Messages.SimplePropertyFileVerifier_HashMayNotBeNull); } this.hash = hash; passwordFile = new Properties(); - loadPasswordFile(filePath); + loadPasswordFile(propertyFilePath); } private void loadPasswordFile(String filePath) { @@ -148,34 +151,4 @@ private String hashPassword(String password) { return null; } - - /** - * {@inheritDoc} - * - * @see org.eclipse.emf.emfstore.server.auth.ESUserVerifier#resolve(org.eclipse.emf.emfstore.server.model.ESSessionId) - */ - public ESUser resolve(ESSessionId api) { - // TODO Auto-generated method stub - return null; - } - - /** - * {@inheritDoc} - * - * @see org.eclipse.emf.emfstore.server.auth.ESUserVerifier#isValid(org.eclipse.emf.emfstore.server.model.ESSessionId) - */ - public boolean isValid(ESSessionId sessionId) { - // TODO Auto-generated method stub - return false; - } - - /** - * {@inheritDoc} - * - * @see org.eclipse.emf.emfstore.server.auth.ESUserVerifier#getUser(org.eclipse.emf.emfstore.server.model.ESSessionId) - */ - public ESUser getUser(ESSessionId sessionId) { - // TODO Auto-generated method stub - return null; - } }