Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 431a1d1a549d141b65e7a1e01a2d18f7fd9cc01a (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
/*******************************************************************************
 * Copyright (c) 2008, 2016 IBM Corporation and others.
 *
 * This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License 2.0
 * which accompanies this distribution, and is available at
 * https://www.eclipse.org/legal/epl-2.0/
 *
 * SPDX-License-Identifier: EPL-2.0
 * 
 * Contributors:
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/
package org.eclipse.osgi.internal.permadmin;

import java.util.ArrayList;
import java.util.List;
import org.osgi.service.condpermadmin.ConditionalPermissionInfo;
import org.osgi.service.condpermadmin.ConditionalPermissionUpdate;

public class SecurityTableUpdate implements ConditionalPermissionUpdate {

	private final SecurityAdmin securityAdmin;
	private final List<ConditionalPermissionInfo> rows;
	private final long timeStamp;

	public SecurityTableUpdate(SecurityAdmin securityAdmin, SecurityRow[] rows, long timeStamp) {
		this.securityAdmin = securityAdmin;
		this.timeStamp = timeStamp;
		// must make a snap shot of the security rows.
		this.rows = new ArrayList<>(rows.length);
		for (int i = 0; i < rows.length; i++)
			// Use SecurityRowSnapShot to prevent modification before commit 
			// and to throw exceptions from delete
			this.rows.add(new SecurityRowSnapShot(rows[i].getName(), rows[i].internalGetConditionInfos(), rows[i].internalGetPermissionInfos(), rows[i].getAccessDecision()));
	}

	public boolean commit() {
		return securityAdmin.commit(rows, timeStamp);
	}

	public List<ConditionalPermissionInfo> getConditionalPermissionInfos() {
		// it is fine to return the internal list; it is a snap shot and we allow clients to modify it.
		return rows;
	}

}

Back to the top