Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
yzhou2001 committed Mar 25, 2016
2 parents 99b1b72 + e156625 commit 8975c60
Show file tree
Hide file tree
Showing 113 changed files with 4,356 additions and 828 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -214,8 +214,7 @@ synchronized private PrintWriter getLogFileStream() throws Throwable {
currentTime.getTime());
Configuration conf = createConfiguration();

String fullPath = parentFolder
+ org.apache.hadoop.fs.Path.SEPARATOR + fileName;
String fullPath = parentFolder + Path.SEPARATOR + fileName;
String defaultPath = fullPath;
URI uri = URI.create(fullPath);
FileSystem fileSystem = FileSystem.get(uri, conf);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.ranger.audit.destination.AuditDestination;
import org.apache.ranger.audit.model.AuditEventBase;
import org.apache.ranger.audit.model.AuthzAuditEvent;
import org.apache.ranger.audit.provider.MiscUtil;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
package org.apache.ranger.audit.provider;

import java.util.Collection;
import java.util.Properties;

import org.apache.ranger.audit.model.AuditEventBase;
import org.apache.ranger.audit.model.AuthzAuditEvent;
Expand All @@ -27,11 +26,6 @@ public abstract class BufferedAuditProvider extends BaseAuditHandler {
private LogBuffer<AuditEventBase> mBuffer = null;
private LogDestination<AuditEventBase> mDestination = null;

@Override
public void init(Properties props) {
super.init(props);
}

@Override
public boolean log(AuditEventBase event) {
if (event instanceof AuthzAuditEvent) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@ private Writer createWriter(OutputStream os ) {
}

boolean isCurrentFilename(String filename) {
return mBufferFilename != null && filename != null && filename.equals(mBufferFilename);
return filename != null && filename.equals(mBufferFilename);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -438,7 +438,7 @@ public static UserGroupInformation createUGIFromSubject(Subject subject)
if (subject != null) {
logger.info("SUBJECT.PRINCIPALS.size()="
+ subject.getPrincipals().size());
java.util.Set<Principal> principals = subject.getPrincipals();
Set<Principal> principals = subject.getPrincipals();
for (Principal principal : principals) {
logger.info("SUBJECT.PRINCIPAL.NAME=" + principal.getName());
}
Expand Down Expand Up @@ -534,7 +534,7 @@ static public Set<String> getGroupsForRequestUser(String userName) {
.createRemoteUser(userName);
String groups[] = ugi.getGroupNames();
if (groups != null && groups.length > 0) {
java.util.Set<String> groupsSet = new java.util.HashSet<String>();
Set<String> groupsSet = new java.util.HashSet<String>();
for (int i = 0; i < groups.length; i++) {
groupsSet.add(groups[i]);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ private void openFile() {

long startTime = MiscUtil.getRolloverStartTime(mNextRolloverTime, (mRolloverIntervalSeconds * 1000L));

mHdfsFilename = MiscUtil.replaceTokens(mDirectory + org.apache.hadoop.fs.Path.SEPARATOR + mFile, startTime);
mHdfsFilename = MiscUtil.replaceTokens(mDirectory + Path.SEPARATOR + mFile, startTime);

FSDataOutputStream ostream = null;
FileSystem fileSystem = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ protected void login() {
String msgDesc = "Unable to find login username for hadoop environment, ["
+ serviceName + "]";
HadoopException hdpException = new HadoopException(msgDesc);
hdpException.generateResponseDataMap(false, msgDesc, msgDesc + errMsg,
hdpException.generateResponseDataMap(false, msgDesc + errMsg, msgDesc + errMsg,
null, null);

throw hdpException;
Expand Down Expand Up @@ -110,14 +110,14 @@ protected void login() {
+ serviceName + "]";

HadoopException hdpException = new HadoopException(msgDesc, ioe);
hdpException.generateResponseDataMap(false, getMessage(ioe),
hdpException.generateResponseDataMap(false, getMessage(ioe) + errMsg,
msgDesc + errMsg, null, null);
throw hdpException;
} catch (SecurityException se) {
String msgDesc = "Unable to login to Hadoop environment ["
+ serviceName + "]";
HadoopException hdpException = new HadoopException(msgDesc, se);
hdpException.generateResponseDataMap(false, getMessage(se),
hdpException.generateResponseDataMap(false, getMessage(se) + errMsg,
msgDesc + errMsg, null, null);
throw hdpException;
} finally {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,11 @@

package org.apache.ranger.plugin.client;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import org.apache.commons.lang.StringUtils;

public class HadoopException extends RuntimeException {

Expand Down Expand Up @@ -57,4 +61,25 @@ public void generateResponseDataMap(boolean connectivityStatus,
responseData.put("fieldName", fieldName);
}

public String getMessage(Throwable excp) {
List<String> errList = new ArrayList<String>();
while (excp != null) {
if (!errList.contains(excp.getMessage() + ". \n")) {
if (excp.getMessage() != null && !(excp.getMessage().equalsIgnoreCase(""))) {
errList.add(excp.getMessage() + ". \n");
}
}
excp = excp.getCause();
}
return StringUtils.join(errList, "");
}

public HashMap<String,Object> getResponseData() {
return responseData;
}

public void setReponseData(HashMap<String,Object> responseData) {
this.responseData = responseData;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public final class RangerScriptExecutionContext {
this.accessRequest = accessRequest;
}

public final String getResource() {
public String getResource() {
String ret = null;
Object val = getRequestContext().get(RangerAccessRequestUtil.KEY_CONTEXT_RESOURCE);

Expand All @@ -58,11 +58,11 @@ public final String getResource() {
return ret;
}

public final Map<String, Object> getRequestContext() {
public Map<String, Object> getRequestContext() {
return accessRequest.getContext();
}

public final String getRequestContextAttribute(String attributeName) {
public String getRequestContextAttribute(String attributeName) {
String ret = null;

if (StringUtils.isNotBlank(attributeName)) {
Expand All @@ -76,27 +76,27 @@ public final String getRequestContextAttribute(String attributeName) {
return ret;
}

public final boolean isAccessTypeAny() { return accessRequest.isAccessTypeAny(); }
public boolean isAccessTypeAny() { return accessRequest.isAccessTypeAny(); }

public final boolean isAccessTypeDelegatedAdmin() { return accessRequest.isAccessTypeDelegatedAdmin(); }
public boolean isAccessTypeDelegatedAdmin() { return accessRequest.isAccessTypeDelegatedAdmin(); }

public final String getUser() { return accessRequest.getUser(); }
public String getUser() { return accessRequest.getUser(); }

public final Set<String> getUserGroups() { return accessRequest.getUserGroups(); }
public Set<String> getUserGroups() { return accessRequest.getUserGroups(); }

public final Date getAccessTime() { return accessRequest.getAccessTime(); }
public Date getAccessTime() { return accessRequest.getAccessTime(); }

public final String getClientIPAddress() { return accessRequest.getClientIPAddress(); }
public String getClientIPAddress() { return accessRequest.getClientIPAddress(); }

public final String getClientType() { return accessRequest.getClientType(); }
public String getClientType() { return accessRequest.getClientType(); }

public final String getAction() { return accessRequest.getAction(); }
public String getAction() { return accessRequest.getAction(); }

public final String getRequestData() { return accessRequest.getRequestData(); }
public String getRequestData() { return accessRequest.getRequestData(); }

public final String getSessionId() { return accessRequest.getSessionId(); }
public String getSessionId() { return accessRequest.getSessionId(); }

public final RangerTag getCurrentTag() {
public RangerTag getCurrentTag() {
RangerTag ret = null;
Object val = getRequestContext().get(RangerAccessRequestUtil.KEY_CONTEXT_TAG_OBJECT);

Expand All @@ -110,12 +110,12 @@ public final RangerTag getCurrentTag() {
return ret;
}

public final String getCurrentTagType() {
public String getCurrentTagType() {
RangerTag tagObject = getCurrentTag();
return (tagObject != null) ? tagObject.getType() : null;
}

public final Set<String> getAllTagTypes() {
public Set<String> getAllTagTypes() {
Set<String> allTagTypes = null;
List<RangerTag> tagObjectList = getAllTags();

Expand All @@ -132,7 +132,7 @@ public final Set<String> getAllTagTypes() {
return allTagTypes;
}

public final Map<String, String> getTagAttributes(final String tagType) {
public Map<String, String> getTagAttributes(final String tagType) {
Map<String, String> ret = null;

if (StringUtils.isNotBlank(tagType)) {
Expand All @@ -153,7 +153,7 @@ public final Map<String, String> getTagAttributes(final String tagType) {
return ret;
}

public final Set<String> getAttributeNames(final String tagType) {
public Set<String> getAttributeNames(final String tagType) {
Set<String> ret = null;
Map<String, String> attributes = getTagAttributes(tagType);

Expand All @@ -164,7 +164,7 @@ public final Set<String> getAttributeNames(final String tagType) {
return ret;
}

public final String getAttributeValue(final String tagType, final String attributeName) {
public String getAttributeValue(final String tagType, final String attributeName) {
String ret = null;

if (StringUtils.isNotBlank(tagType) || StringUtils.isNotBlank(attributeName)) {
Expand All @@ -177,7 +177,7 @@ public final String getAttributeValue(final String tagType, final String attribu
return ret;
}

public final String getAttributeValue(final String attributeName) {
public String getAttributeValue(final String attributeName) {
String ret = null;

if (StringUtils.isNotBlank(attributeName)) {
Expand All @@ -194,18 +194,18 @@ public final String getAttributeValue(final String attributeName) {
return ret;
}

public final boolean getResult() {
public boolean getResult() {
return result;

}

public final void setResult(final boolean result) {
public void setResult(final boolean result) {
this.result = result;
}

// Utilities - TODO

public final Date getAsDate(String value) {
public Date getAsDate(String value) {
Date ret = null;

if (StringUtils.isNotBlank(value)) {
Expand All @@ -225,13 +225,13 @@ public final Date getAsDate(String value) {
return ret;
}

public final Date getTagAttributeAsDate(String tagType, String attributeName) {
public Date getTagAttributeAsDate(String tagType, String attributeName) {
String attrValue = getAttributeValue(tagType, attributeName);

return getAsDate(attrValue);
}

public final boolean isAccessedAfter(String tagType, String attributeName) {
public boolean isAccessedAfter(String tagType, String attributeName) {
boolean ret = false;
Date accessDate = getAccessTime();
Date expiryDate = getTagAttributeAsDate(tagType, attributeName);
Expand All @@ -243,7 +243,7 @@ public final boolean isAccessedAfter(String tagType, String attributeName) {
return ret;
}

public final boolean isAccessedAfter(String attributeName) {
public boolean isAccessedAfter(String attributeName) {
boolean ret = false;
Date accessDate = getAccessTime();
Date expiryDate = getAsDate(getAttributeValue(attributeName));
Expand All @@ -255,7 +255,7 @@ public final boolean isAccessedAfter(String attributeName) {
return ret;
}

public final boolean isAccessedBefore(String tagType, String attributeName) {
public boolean isAccessedBefore(String tagType, String attributeName) {
boolean ret = true;
Date accessDate = getAccessTime();
Date expiryDate = getTagAttributeAsDate(tagType, attributeName);
Expand All @@ -267,7 +267,7 @@ public final boolean isAccessedBefore(String tagType, String attributeName) {
return ret;
}

public final boolean isAccessedBefore(String attributeName) {
public boolean isAccessedBefore(String attributeName) {
boolean ret = true;
Date accessDate = getAccessTime();
Date expiryDate = getAsDate(getAttributeValue(attributeName));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,9 @@ public enum ValidationErrorCode {
POLICY_VALIDATION_ERR_POLICY_ITEM_ACCESS_TYPE_DENY(3023, "Currently deny access types are not supported. Access type is set to deny."),
POLICY_VALIDATION_ERR_INVALID_RESOURCE_NO_COMPATIBLE_HIERARCHY_SINGLE(3024, "Invalid resources specified. {0} policy can specify values for the following resources: {1}"),
POLICY_VALIDATION_ERR_INVALID_RESOURCE_MISSING_MANDATORY_SINGLE(3025, "Invalid resources specified. {0} policy must specify values for the following resources: {1}"),
POLICY_VALIDATION_ERR_MISSING_RESOURCE_LIST(3026, "Resource list was empty or contains null. At least one resource must be specified"),
POLICY_VALIDATION_ERR_POLICY_UPDATE_MOVE_SERVICE_NOT_ALLOWED(3027, "attempt to move policy id={0} from service={1} to service={2} is not allowed"),
POLICY_VALIDATION_ERR_POLICY_TYPE_CHANGE_NOT_ALLOWED(3028, "attempt to change type of policy id={0} from type={1} to type={2} is not allowed"),
;


Expand Down
Loading

0 comments on commit 8975c60

Please sign in to comment.