Skip to content

Commit 0770c90

Browse files
authored
Merge pull request #1525 from tulinkry/auth-stacks
using authorization stacks instead of a list
2 parents 24716fd + 18c99e4 commit 0770c90

17 files changed

+2094
-1032
lines changed

plugins/src/main/java/HttpBasicAuthorizationPlugin.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public class HttpBasicAuthorizationPlugin implements IAuthorizationPlugin {
6060
}
6161

6262
@Override
63-
public void load() {
63+
public void load(Map<String, Object> parameters) {
6464
}
6565

6666
@Override

plugins/src/main/java/SampleAuthorizationPlugin.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,29 +17,30 @@
1717
* CDDL HEADER END
1818
*/
1919

20-
/*
21-
* Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
20+
/*
21+
* Copyright (c) 2016, 2017, Oracle and/or its affiliates. All rights reserved.
2222
*/
23+
import java.util.Map;
2324
import javax.servlet.http.HttpServletRequest;
2425
import org.opensolaris.opengrok.authorization.IAuthorizationPlugin;
2526
import org.opensolaris.opengrok.configuration.Group;
2627
import org.opensolaris.opengrok.configuration.Project;
28+
2729
/**
2830
* Sample authorization plugin.
29-
*
31+
*
3032
* Always just bypass all authorization requests.
3133
*/
3234
public class SampleAuthorizationPlugin implements IAuthorizationPlugin {
3335

3436
@Override
35-
public void load() {
37+
public void load(Map<String, Object> parameters) {
3638
}
3739

3840
@Override
3941
public void unload() {
4042
}
4143

42-
4344
@Override
4445
public boolean isAllowed(HttpServletRequest request, Project project) {
4546
return true;
@@ -50,4 +51,3 @@ public boolean isAllowed(HttpServletRequest request, Group group) {
5051
return true;
5152
}
5253
}
53-
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
/*
2+
* CDDL HEADER START
3+
*
4+
* The contents of this file are subject to the terms of the
5+
* Common Development and Distribution License (the "License").
6+
* You may not use this file except in compliance with the License.
7+
*
8+
* See LICENSE.txt included in this distribution for the specific
9+
* language governing permissions and limitations under the License.
10+
*
11+
* When distributing Covered Code, include this CDDL HEADER in each
12+
* file and include the License file at LICENSE.txt.
13+
* If applicable, add the following below this CDDL HEADER, with the
14+
* fields enclosed by brackets "[]" replaced with your own identifying
15+
* information: Portions Copyright [yyyy] [name of copyright owner]
16+
*
17+
* CDDL HEADER END
18+
*/
19+
20+
/*
21+
* Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
22+
*/
23+
package org.opensolaris.opengrok.authorization;
24+
25+
import java.util.Arrays;
26+
import java.util.stream.Collectors;
27+
28+
/**
29+
* Enum for avaliable authorization roles.
30+
*
31+
* @author Krystof Tulinger
32+
*/
33+
public enum AuthControlFlag {
34+
/**
35+
* Failure of such a plugin will ultimately lead to the authorization
36+
* framework returning failure but only after the remaining plugins have
37+
* been invoked.
38+
*
39+
*/
40+
REQUIRED("required"),
41+
/**
42+
* Like required, however, in the case that such a plugin returns a failure,
43+
* control is directly returned to the application. The return value is that
44+
* associated with the first required or requisite plugin to fail.
45+
*
46+
*/
47+
REQUISITE("requisite"),
48+
/**
49+
* If such a plugin succeeds and no prior required plugin has failed the
50+
* authorization framework returns success to the application immediately
51+
* without calling any further plugins in the stack. A failure of a
52+
* sufficient plugin is ignored and processing of the plugin list continues
53+
* unaffected.
54+
*/
55+
SUFFICIENT("sufficient");
56+
57+
private final String flag;
58+
59+
private AuthControlFlag(String flag) {
60+
this.flag = flag;
61+
}
62+
63+
@Override
64+
public String toString() {
65+
return this.flag;
66+
}
67+
68+
public boolean isRequired() {
69+
return REQUIRED.equals(this);
70+
}
71+
72+
public boolean isRequisite() {
73+
return REQUISITE.equals(this);
74+
}
75+
76+
public boolean isSufficient() {
77+
return SUFFICIENT.equals(this);
78+
}
79+
80+
/**
81+
* Get the enum value for the string parameter.
82+
*
83+
* @param flag parameter describing the desired enum value
84+
* @return the flag representing the parameter value
85+
*
86+
* @throws IllegalArgumentException when there is no such value in the enum
87+
*/
88+
public static AuthControlFlag get(String flag) throws IllegalArgumentException {
89+
try {
90+
return AuthControlFlag.valueOf(flag.toUpperCase());
91+
} catch (IllegalArgumentException ex) {
92+
// flag does not exist -> add some more info about which flags do exist
93+
throw new IllegalArgumentException(
94+
String.format("No control flag \"%s\", available flags are [%s]. %s",
95+
flag,
96+
Arrays.asList(AuthControlFlag.values())
97+
.stream()
98+
.map(AuthControlFlag::toString)
99+
.collect(Collectors.joining(", ")),
100+
ex.getLocalizedMessage()), ex);
101+
}
102+
}
103+
}

src/org/opensolaris/opengrok/authorization/AuthorizationCheck.java

Lines changed: 0 additions & 155 deletions
This file was deleted.

0 commit comments

Comments
 (0)