Skip to content

Commit

Permalink
Fix up sonar findbugs warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
cbeer committed Dec 14, 2013
1 parent cdf0540 commit 2d57816
Show file tree
Hide file tree
Showing 36 changed files with 169 additions and 264 deletions.
Expand Up @@ -42,7 +42,7 @@ public interface FedoraPolicyEnforcementPoint {
* @param allPrincipals
* @return
*/
public boolean hasModeShapePermission(Path absPath, String[] actions,
boolean hasModeShapePermission(Path absPath, String[] actions,
Set<Principal> allPrincipals, Principal userPrincipal);

/**
Expand All @@ -54,7 +54,7 @@ public boolean hasModeShapePermission(Path absPath, String[] actions,
* @param userPrincipal the user principal
* @return an iterator of permitted paths
*/
public Iterator<Path> filterPathsForReading(Iterator<Path> paths,
Iterator<Path> filterPathsForReading(Iterator<Path> paths,
Set<Principal> allPrincipals, Principal userPrincipal);

}
Expand Up @@ -36,5 +36,5 @@ public interface HTTPPrincipalFactory {
* @param request the request
* @return a set of security principals
*/
public Set<Principal> getGroupPrincipals(HttpServletRequest request);
Set<Principal> getGroupPrincipals(HttpServletRequest request);
}
Expand Up @@ -121,11 +121,12 @@ public ExecutionContext authenticate(final Credentials credentials,
final String repositoryName, final String workspaceName,
final ExecutionContext repositoryContext,
final Map<String, Object> sessionAttributes) {
logger.debug("in authenticate: " + credentials);
logger.debug("PEP: " + pep);
if (credentials == null || !(credentials instanceof ServletCredentials)) {
logger.debug("in authenticate: {}; PEP: {}", credentials, pep);

if (!(credentials instanceof ServletCredentials)) {
return null;
}

final ServletCredentials creds = (ServletCredentials) credentials;

// does this request have the fedoraAdmin role in the container?
Expand Down
Expand Up @@ -17,16 +17,15 @@

public interface Constants {

public static final String OAUTH_WORKSPACE = "oauth";
static final String OAUTH_WORKSPACE = "oauth";

// TODO get namespaced properties to work
public static final String CLIENT_PROPERTY = "oauth-client";
static final String CLIENT_PROPERTY = "oauth-client";

// TODO get namespaced properties to work
public static final String PRINCIPAL_PROPERTY = "oauth-principal";
static final String PRINCIPAL_PROPERTY = "oauth-principal";

// TODO get namespaced properties to work
public static final String SCOPES_PROPERTY = "oauth-scopes";
static final String SCOPES_PROPERTY = "oauth-scopes";

public static final Long EXPIRATION_TIMEOUT = 3600l;
}
Expand Up @@ -27,7 +27,7 @@ public interface TokenRequestValidations {
* @return
* @throws RepositoryException
*/
public boolean isValidAuthCode(final OAuthTokenRequest oauthRequest)
boolean isValidAuthCode(final OAuthTokenRequest oauthRequest)
throws RepositoryException;

/**
Expand All @@ -36,15 +36,15 @@ public boolean isValidAuthCode(final OAuthTokenRequest oauthRequest)
* @return
* @throws RepositoryException
*/
public boolean isValidClient(final OAuthTokenRequest oauthRequest);
boolean isValidClient(final OAuthTokenRequest oauthRequest);

/**
* Checks the validity of the secret given with the given request
* @param oauthRequest
* @return
* @throws RepositoryException
*/
public boolean isValidSecret(final OAuthTokenRequest oauthRequest);
boolean isValidSecret(final OAuthTokenRequest oauthRequest);

/**
* Checks the validity of the authN credentials
Expand All @@ -53,6 +53,6 @@ public boolean isValidAuthCode(final OAuthTokenRequest oauthRequest)
* @return
* @throws RepositoryException
*/
public boolean isValidCredentials(final OAuthTokenRequest oauthRequest);
boolean isValidCredentials(final OAuthTokenRequest oauthRequest);

}
Expand Up @@ -47,6 +47,7 @@
import javax.ws.rs.core.Context;
import javax.ws.rs.core.Response;

import com.google.common.collect.Iterables;
import org.apache.oltu.oauth2.as.issuer.MD5Generator;
import org.apache.oltu.oauth2.as.issuer.OAuthIssuerImpl;
import org.apache.oltu.oauth2.as.request.OAuthAuthzRequest;
Expand Down Expand Up @@ -82,7 +83,7 @@ public class AuthzEndpoint extends AbstractResource {
public Response getAuthorization(@Context final HttpServletRequest request)
throws URISyntaxException, OAuthSystemException, RepositoryException {

OAuthAuthzRequest oauthRequest = null;
final OAuthAuthzRequest oauthRequest;

final OAuthIssuerImpl oauthIssuerImpl =
new OAuthIssuerImpl(new MD5Generator());
Expand Down Expand Up @@ -118,13 +119,6 @@ public Response getAuthorization(@Context final HttpServletRequest request)
builder.setParam("client_secret", "YOUR_SECRET");
}

/** as far as I can tell from spec and a number of docs,
* "token" is not a valid response type for the authCode
* endpoint
*/
// } else if (responseType.equals(TOKEN.toString())) {
// builder.setAccessToken(oauthIssuerImpl.accessToken());
// builder.setExpiresIn(EXPIRATION_TIMEOUT);
} else {
String errorDesc =
"Invalid response_type parameter value \"" +
Expand Down Expand Up @@ -189,8 +183,7 @@ private void saveAuthCode(final String authCode, final Set<String> scopes,
jcrTools.findOrCreateNode(session, "/authorization-codes/" +
authCode);
codeNode.setProperty(CLIENT_PROPERTY, client);
codeNode.setProperty(Constants.SCOPES_PROPERTY, scopes
.toArray(new String[0]));
codeNode.setProperty(Constants.SCOPES_PROPERTY, Iterables.toArray(scopes, String.class));
session.save();
} finally {
session.logout();
Expand Down
Expand Up @@ -16,8 +16,6 @@

package org.fcrepo.auth.roles.basic;



import java.security.Principal;
import java.util.Set;

Expand Down Expand Up @@ -53,7 +51,7 @@ public boolean rolesHaveModeShapePermission(final String absPath,
return true;
}
if (roles.contains("writer")) {
if (absPath.toString().contains(AUTHZ_DETECTION)) {
if (absPath.contains(AUTHZ_DETECTION)) {
log.debug("Denying writer role permission to perform an action on an ACL node.");
return false;
} else {
Expand Down
Expand Up @@ -133,9 +133,9 @@ public Iterator<Path> filterPathsForReading(final Iterator<Path> paths,
public boolean hasModeShapePermission(final Path absPath,
final String[] actions, final Set<Principal> allPrincipals,
final Principal userPrincipal) {
final boolean newNode = false;
Set<String> roles = null;
JcrSession session = null;
final Set<String> roles;
final JcrSession session;

try {
session = (JcrSession)sessionFactory.getInternalSession();
final Map<String, List<String>> acl =
Expand All @@ -148,28 +148,26 @@ public boolean hasModeShapePermission(final Path absPath,
}

if (log.isDebugEnabled()) {
final StringBuilder msg = new StringBuilder();
msg.append(roles.toString()).append("\t").append(
Arrays.toString(actions)).append("\t").append(
newNode ? "NEW" : "OLD").append("\t").append(
(absPath == null ? absPath : absPath.toString()));
log.debug(msg.toString());
log.debug("{}\t{}\t{}", roles, actions, absPath);
if (actions.length > 1) { // have yet to see more than one
log.debug("FOUND MULTIPLE ACTIONS: {}", Arrays
.toString(actions));
}
}

if (actions.length == 1 && "remove_child_nodes".equals(actions[0])) {
// in roles-based ACLs, the permission to remove children is
// conferred by earlier check for "remove_node" on the child node
// itself.
return true;
}

if (!rolesHaveModeShapePermission(absPath.toString(), actions,
allPrincipals,
userPrincipal, roles)) {
return false;
}

if (actions.length == 1 && "remove".equals(actions[0])) {
// you must be able to delete all the children
// TODO make recursive/ACL-query-based check configurable
Expand Down
Expand Up @@ -16,6 +16,7 @@

package org.fcrepo.auth.roles.common;

import static com.sun.jersey.api.Responses.notFound;
import static javax.ws.rs.core.MediaType.APPLICATION_JSON;

import java.util.List;
Expand Down Expand Up @@ -89,14 +90,14 @@ private AccessRolesProvider getAccessRolesProvider() {
*
* @param pathList
* @return JSON representation of assignment map
* @throws Exception
* @throws RepositoryException
*/
@GET
@Produces(APPLICATION_JSON)
@Timed
public Response get(@PathParam("path")
final List<PathSegment> pathList, @QueryParam("effective")
final String effective) throws Exception {
final String effective) throws RepositoryException {
final String path = toPath(pathList);
log.debug("Get access roles for: {}", path);
log.debug("effective: {}", effective);
Expand All @@ -113,7 +114,7 @@ public Response get(@PathParam("path")
response = Response.ok(data);
}
} catch (final PathNotFoundException e) {
response = Response.status(404).entity(e.getMessage());
response = notFound().entity(e.getMessage());
} catch (final AccessDeniedException e) {
response = Response.status(Status.FORBIDDEN);
} finally {
Expand All @@ -128,14 +129,14 @@ public Response get(@PathParam("path")
* @param pathList
* @param data
* @return
* @throws Exception
* @throws RepositoryException
*/
@POST
@Consumes(APPLICATION_JSON)
@Timed
public Response post(@PathParam("path")
final List<PathSegment> pathList, final Map<String, Set<String>> data)
throws Exception {
throws RepositoryException {
final String path = toPath(pathList);
log.debug("POST Received request param: {}", request);
Response.ResponseBuilder response;
Expand Down Expand Up @@ -172,16 +173,16 @@ private void validatePOST(final Map<String, Set<String>> data)
throw new IllegalArgumentException(
"Posted access roles must include role assignments");
}
for (final String key : data.keySet()) {
if (key == null || data.get(key) == null || data.get(key).isEmpty()) {
for (final Map.Entry<String, Set<String>> entry : data.entrySet()) {
if (entry.getKey() == null || entry.getValue() == null || entry.getValue().isEmpty()) {
throw new IllegalArgumentException(
"Assignments must include principal name and one or more roles");
}
if (key.trim().length() == 0) {
if (entry.getKey().trim().length() == 0) {
throw new IllegalArgumentException(
"Principal names cannot be an empty strings or whitespace.");
}
for (final String r : data.get(key)) {
for (final String r : entry.getValue()) {
if (r.trim().length() == 0) {
throw new IllegalArgumentException(
"Role names cannot be an empty strings or whitespace.");
Expand Down
Expand Up @@ -38,6 +38,8 @@
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

import static com.google.common.collect.Iterables.toArray;

/**
* Provides the effective access roles for authorization.
*
Expand Down Expand Up @@ -175,13 +177,12 @@ public void postRoles(final Node node, final Map<String, Set<String>> data)
}
}

for (final String key : data.keySet()) {
for (final Map.Entry<String, Set<String>> entry : data.entrySet()) {
final Node assign =
acl.addNode(JcrName.assignment.getQualified(),
JcrName.Assignment.getQualified());
assign.setProperty(JcrName.principal.getQualified(), key);
assign.setProperty(JcrName.role.getQualified(), data.get(key)
.toArray(new String[] {}));
assign.setProperty(JcrName.principal.getQualified(), entry.getKey());
assign.setProperty(JcrName.role.getQualified(), toArray(entry.getValue(), String.class));
}
}

Expand Down
Expand Up @@ -38,7 +38,7 @@ public class JcrPropertiesGenerator implements DCGenerator {
private static final Logger LOGGER =
getLogger(JcrPropertiesGenerator.class);

public static final String[] SALIENT_DC_PROPERTY_NAMESPACES =
protected static final String[] SALIENT_DC_PROPERTY_NAMESPACES =
new String[] {"dc:*"};

@Override
Expand Down

0 comments on commit 2d57816

Please sign in to comment.