Skip to content

Commit

Permalink
Bug 459781 - Customizable authentication & authorization: fixed testing
Browse files Browse the repository at this point in the history
mock
  • Loading branch information
edgarmueller committed Feb 12, 2015
1 parent 556b186 commit 76431c1
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 18 deletions.
Original file line number Diff line number Diff line change
@@ -1,32 +1,36 @@
/*******************************************************************************
* Copyright (c) 2011-2015 EclipseSource Muenchen GmbH and others.
* Copyright (c) 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 - initial API and implementation
* Edgar Mueller - initial API and implementation
******************************************************************************/
package org.eclipse.emf.emfstore.internal.server.accesscontrol;

import org.eclipse.emf.emfstore.common.extensionpoint.ESExtensionPoint;
import org.eclipse.emf.emfstore.common.extensionpoint.ESExtensionPointException;
import org.eclipse.emf.emfstore.internal.common.model.util.ModelUtil;
import org.eclipse.emf.emfstore.internal.server.ServerConfiguration;
import org.eclipse.emf.emfstore.internal.server.impl.api.ESOrgUnitProviderImpl;
import org.eclipse.emf.emfstore.internal.server.model.ServerSpace;
import org.eclipse.emf.emfstore.server.auth.ESAuthenticationControlType;
import org.eclipse.emf.emfstore.server.auth.ESAuthorizationService;
import org.eclipse.emf.emfstore.server.auth.ESOrgUnitResolver;
import org.eclipse.emf.emfstore.server.model.ESOrgUnitProvider;

/**
* @author Edgar
* Access control class holding references to the customizable access control related services.
*
* @author emueller
*
*/
public class AccessControl {

private static final String ACCESSCONTROL_EXTENSION_ID = "org.eclipse.emf.emfstore.server.accessControl";
private static final String ACCESSCONTROL_EXTENSION_ID = "org.eclipse.emf.emfstore.server.accessControl"; //$NON-NLS-1$

private final ESOrgUnitProvider orgUnitProvider;

Expand All @@ -39,14 +43,46 @@ public class AccessControl {

private final ServerSpace serverSpace;

private ESAuthenticationControlType authenticationControlType;

public AccessControl(ServerSpace serverSpace) {
this.serverSpace = serverSpace;
sessions = new Sessions();

orgUnitProvider = initOrgUnitProviderService();
orgUnitResolver = initOrgUnitResolverService();
authorizationService = initAuthorizationService();
loginService = new LoginService(sessions, orgUnitProvider,
loginService = initLoginService();
}

public AccessControl(
ESAuthenticationControlType authenticationControlType,
ServerSpace serverSpace) {

this.authenticationControlType = authenticationControlType;
this.serverSpace = serverSpace;
sessions = new Sessions();

orgUnitProvider = initOrgUnitProviderService();
orgUnitResolver = initOrgUnitResolverService();
authorizationService = initAuthorizationService();
loginService = initLoginService();
}

/**
* @return
*/
private LoginService initLoginService() {

if (authenticationControlType == null) {
final String[] splittedProperty = ServerConfiguration
.getSplittedProperty(ServerConfiguration.AUTHENTICATION_POLICY);
authenticationControlType = ESAuthenticationControlType.valueOf(splittedProperty[0]);
}
return new LoginService(
authenticationControlType,
sessions,
orgUnitProvider,
getOrgUnitResolverServive());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
import org.eclipse.emf.emfstore.common.extensionpoint.ESExtensionPoint;
import org.eclipse.emf.emfstore.common.extensionpoint.ESExtensionPointException;
import org.eclipse.emf.emfstore.internal.common.model.util.ModelUtil;
import org.eclipse.emf.emfstore.internal.server.ServerConfiguration;
import org.eclipse.emf.emfstore.internal.server.accesscontrol.authentication.ESUserVerifierFactory;
import org.eclipse.emf.emfstore.internal.server.core.MonitorProvider;
import org.eclipse.emf.emfstore.internal.server.exceptions.AccessControlException;
Expand Down Expand Up @@ -44,6 +43,7 @@ public class LoginService {
private final Sessions sessions;
private final ESOrgUnitResolver orgUnitResolver;
private final ESOrgUnitProvider orgUnitProvider;
private final ESAuthenticationControlType authenticationControlType;

/**
* Constructor.
Expand All @@ -57,10 +57,13 @@ public class LoginService {
* @param orgUnitResolver
* an {@link ESOrgUnitResolver} for resolving any roles and groups on a given organizational unit
*/
public LoginService(Sessions sessions,
public LoginService(
ESAuthenticationControlType authenticationControlType,
Sessions sessions,
ESOrgUnitProvider orgUnitProvider,
ESOrgUnitResolver orgUnitResolver) {

this.authenticationControlType = authenticationControlType;
this.sessions = sessions;
this.orgUnitProvider = orgUnitProvider;
this.orgUnitResolver = orgUnitResolver;
Expand All @@ -74,10 +77,9 @@ private ESUserVerifier initUserVerifierService() {
return new ESExtensionPoint(USER_VERIFIER_EXTENSION_ID, true).getClass(
"providerClass", ESUserVerifier.class); //$NON-NLS-1$
}
final String[] splittedProperty = ServerConfiguration
.getSplittedProperty(ServerConfiguration.AUTHENTICATION_POLICY);

return ESUserVerifierFactory.getInstance().createUserVerifier(
ESAuthenticationControlType.valueOf(splittedProperty[0]),
authenticationControlType,
orgUnitProvider);
} catch (final ESExtensionPointException e) {
final String message = "Custom Access Control could not be initialized";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,9 @@ public ESAuthenticationInformation verifyUser(String username, String password,
ESClientVersionInfo clientVersionInfo) throws AccessControlException {

checkClientVersion(clientVersionInfo);
password = preparePassword(password);
final String preparedPassword = preparePassword(password);

if (verifySuperUser(username, password) || verifyPassword(username, password)) {
if (verifySuperUser(username, preparedPassword) || verifyPassword(username, preparedPassword)) {
final AuthenticationInformation createAuthenticationInfo = createAuthenticationInfo();
createAuthenticationInfo.setResolvedACUser(findUser(username));
return createAuthenticationInfo.toAPI();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
import org.eclipse.emf.emfstore.internal.server.model.accesscontrol.roles.RolesFactory;
import org.eclipse.emf.emfstore.internal.server.model.dao.ACDAOFacade;
import org.eclipse.emf.emfstore.internal.server.model.impl.api.ESSessionIdImpl;
import org.eclipse.emf.emfstore.server.auth.ESAuthenticationControlType;
import org.eclipse.emf.emfstore.server.exceptions.ESException;
import org.osgi.framework.FrameworkUtil;

Expand Down Expand Up @@ -161,12 +162,9 @@ public static ServerMock startMockServer(Map<String, String> properties) throws

ServerConfiguration.setProperties(initProperties(properties));
setSuperUser(daoFacadeMock);
final AccessControl accessControl = new AccessControl(serverSpace);

// accessControl.setAuthenticationControl(ESUserVerifierFactory.INSTANCE
// .createAuthenticationControl(ESAuthenticationControlType.model, orgUnitProviderImpl));

// AdminConnectionManagerMock adminConnectionManagerMock = new AdminConnectionManagerMock(accessControl);
final AccessControl accessControl = new AccessControl(
ESAuthenticationControlType.model,
serverSpace);

final EMFStore emfStore = EMFStoreImpl.createInterface(serverSpace, accessControl);
ESWorkspaceProviderImpl.getInstance().setConnectionManager(
Expand Down

0 comments on commit 76431c1

Please sign in to comment.