/*******************************************************************************
 * Copyright (c) 2010-2013 ITER Organization.
 * 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
 ******************************************************************************/
package org.csstudio.iter.authorizationprovider;

import java.util.HashSet;
import java.util.Set;

import javax.security.auth.Subject;

import org.csstudio.security.authorization.AuthorizationProvider;
import org.csstudio.security.authorization.Authorizations;

/**
 * AuthorizationProvider based on LDAP group membership but settings default
 * authorization to non-LDAPusers.
 * 
 */
@SuppressWarnings("nls")
public class ITERAuthorizationProvider extends
		org.csstudio.security.authorization.LDAPGroupAuthorizationProvider
		implements AuthorizationProvider {

	@Override
	public Authorizations getAuthorizations(Subject user) throws Exception {
		Authorizations authorizations = super.getAuthorizations(user);
		String[] defaultAuthList = Preferences.getDefaultAuthorization();
		if (defaultAuthList == null || defaultAuthList.length == 0) {
			return authorizations;
		}
		Set<String> authList = new HashSet<>(authorizations.getAuthorizations());

		for (String auth : defaultAuthList) {
			authList.add(auth);
		}

		return new Authorizations(authList);
	}
}

@@ -544,16 +544,48 @@
 til.Set;
+%0Aimport java.util.logging.Level;
 %0A%0Aimport
@@ -1167,38 +1167,413 @@
 s = 
-super.getAuthorizations(user);
+null;%0A%09%09try %7B%0A%09%09%09authorizations = super.getAuthorizations(user);%0A%09%09%7D catch (Exception e) %7B%0A%09%09%09// Handle LDAP connection error.%0A%09%09%09Activator.getLogger().log(Level.WARNING,%0A%09%09%09%09%09%22Unable to retrieve authorizations from LDAP server : %22 + e.getMessage());%0A%09%09%7D%0A%09%09if (authorizations == null%0A%09%09%09%09%7C%7C authorizations.getAuthorizations() == null) %7B%0A%09%09%09authorizations = new Authorizations(new HashSet%3CString%3E(0));%0A%09%09%7D%0A
 %0A%09%09S
@@ -1731,16 +1731,17 @@
 ns;%0A%09%09%7D%0A
+%0A
 %09%09Set%3CSt
@@ -1808,17 +1808,16 @@
 ons());%0A
-%0A
 %09%09for (S

Update ITER Authorization provider to apply default authorization even if LDAP is not reachable.