Skip to content

using authorization stacks instead of a list #1525

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Apr 28, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion plugins/src/main/java/HttpBasicAuthorizationPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public class HttpBasicAuthorizationPlugin implements IAuthorizationPlugin {
}

@Override
public void load() {
public void load(Map<String, Object> parameters) {
}

@Override
Expand Down
12 changes: 6 additions & 6 deletions plugins/src/main/java/SampleAuthorizationPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,29 +17,30 @@
* CDDL HEADER END
*/

/*
* Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
/*
* Copyright (c) 2016, 2017, Oracle and/or its affiliates. All rights reserved.
*/
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import org.opensolaris.opengrok.authorization.IAuthorizationPlugin;
import org.opensolaris.opengrok.configuration.Group;
import org.opensolaris.opengrok.configuration.Project;

/**
* Sample authorization plugin.
*
*
* Always just bypass all authorization requests.
*/
public class SampleAuthorizationPlugin implements IAuthorizationPlugin {

@Override
public void load() {
public void load(Map<String, Object> parameters) {
}

@Override
public void unload() {
}


@Override
public boolean isAllowed(HttpServletRequest request, Project project) {
return true;
Expand All @@ -50,4 +51,3 @@ public boolean isAllowed(HttpServletRequest request, Group group) {
return true;
}
}

103 changes: 103 additions & 0 deletions src/org/opensolaris/opengrok/authorization/AuthControlFlag.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
/*
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file is refactored from the AuthorizationCheck.java class

* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* See LICENSE.txt included in this distribution for the specific
* language governing permissions and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at LICENSE.txt.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/

/*
* Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
*/
package org.opensolaris.opengrok.authorization;

import java.util.Arrays;
import java.util.stream.Collectors;

/**
* Enum for avaliable authorization roles.
*
* @author Krystof Tulinger
*/
public enum AuthControlFlag {
/**
* Failure of such a plugin will ultimately lead to the authorization
* framework returning failure but only after the remaining plugins have
* been invoked.
*
*/
REQUIRED("required"),
/**
* Like required, however, in the case that such a plugin returns a failure,
* control is directly returned to the application. The return value is that
* associated with the first required or requisite plugin to fail.
*
*/
REQUISITE("requisite"),
/**
* If such a plugin succeeds and no prior required plugin has failed the
* authorization framework returns success to the application immediately
* without calling any further plugins in the stack. A failure of a
* sufficient plugin is ignored and processing of the plugin list continues
* unaffected.
*/
SUFFICIENT("sufficient");

private final String flag;

private AuthControlFlag(String flag) {
this.flag = flag;
}

@Override
public String toString() {
return this.flag;
}

public boolean isRequired() {
return REQUIRED.equals(this);
}

public boolean isRequisite() {
return REQUISITE.equals(this);
}

public boolean isSufficient() {
return SUFFICIENT.equals(this);
}

/**
* Get the enum value for the string parameter.
*
* @param flag parameter describing the desired enum value
* @return the flag representing the parameter value
*
* @throws IllegalArgumentException when there is no such value in the enum
*/
public static AuthControlFlag get(String flag) throws IllegalArgumentException {
try {
return AuthControlFlag.valueOf(flag.toUpperCase());
} catch (IllegalArgumentException ex) {
// flag does not exist -> add some more info about which flags do exist
throw new IllegalArgumentException(
String.format("No control flag \"%s\", available flags are [%s]. %s",
flag,
Arrays.asList(AuthControlFlag.values())
.stream()
.map(AuthControlFlag::toString)
.collect(Collectors.joining(", ")),
ex.getLocalizedMessage()), ex);
}
}
}
155 changes: 0 additions & 155 deletions src/org/opensolaris/opengrok/authorization/AuthorizationCheck.java

This file was deleted.

Loading