mirror of
https://github.com/apache/sqoop.git
synced 2025-05-10 04:50:29 +08:00
SQOOP-2483: Sqoop2: Findbugs: Fix singleton class problem in AuthenticationManager and AuthorizationManager
(Colin Ma via Jarek Jarcec Cecho)
This commit is contained in:
parent
bb7c350d55
commit
9ecd944dc5
@ -33,12 +33,6 @@ public class AuthenticationManager implements Reconfigurable {
|
|||||||
*/
|
*/
|
||||||
public static final String DEFAULT_AUTHENTICATION_HANDLER = "org.apache.sqoop.security.authentication.SimpleAuthenticationHandler";
|
public static final String DEFAULT_AUTHENTICATION_HANDLER = "org.apache.sqoop.security.authentication.SimpleAuthenticationHandler";
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Default authentication auto upgrade option value
|
|
||||||
*/
|
|
||||||
protected static boolean DEFAULT_AUTO_UPGRADE = false;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Private instance to singleton of this class.
|
* Private instance to singleton of this class.
|
||||||
*/
|
*/
|
||||||
@ -51,6 +45,11 @@ public class AuthenticationManager implements Reconfigurable {
|
|||||||
instance = new AuthenticationManager();
|
instance = new AuthenticationManager();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The private constructor for the singleton class,
|
||||||
|
*/
|
||||||
|
private AuthenticationManager(){}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return current instance.
|
* Return current instance.
|
||||||
*
|
*
|
||||||
@ -73,16 +72,16 @@ public static void setInstance(AuthenticationManager newInstance) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Private AuthenticiationHandler to singleton of this class.
|
* Private Authentication Handler to singleton of this class.
|
||||||
*/
|
*/
|
||||||
private static AuthenticationHandler authenticationHandler;
|
private AuthenticationHandler authenticationHandler;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return current authentication handler.
|
* Return current authentication handler.
|
||||||
*
|
*
|
||||||
* @return Current authentication handler
|
* @return Current authentication handler
|
||||||
*/
|
*/
|
||||||
public static AuthenticationHandler getAuthenticationHandler() {
|
public AuthenticationHandler getAuthenticationHandler() {
|
||||||
return authenticationHandler;
|
return authenticationHandler;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -18,7 +18,6 @@
|
|||||||
package org.apache.sqoop.security;
|
package org.apache.sqoop.security;
|
||||||
|
|
||||||
import org.apache.log4j.Logger;
|
import org.apache.log4j.Logger;
|
||||||
import org.apache.sqoop.common.MapContext;
|
|
||||||
import org.apache.sqoop.core.Reconfigurable;
|
import org.apache.sqoop.core.Reconfigurable;
|
||||||
import org.apache.sqoop.core.SqoopConfiguration;
|
import org.apache.sqoop.core.SqoopConfiguration;
|
||||||
|
|
||||||
@ -44,11 +43,6 @@ public class AuthorizationManager implements Reconfigurable {
|
|||||||
*/
|
*/
|
||||||
public static final String DEFAULT_SERVER_NAME = "SqoopServer1";
|
public static final String DEFAULT_SERVER_NAME = "SqoopServer1";
|
||||||
|
|
||||||
/**
|
|
||||||
* Default authorization auto upgrade option value
|
|
||||||
*/
|
|
||||||
protected static boolean DEFAULT_AUTO_UPGRADE = false;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Private instance to singleton of this class.
|
* Private instance to singleton of this class.
|
||||||
*/
|
*/
|
||||||
@ -61,6 +55,11 @@ public class AuthorizationManager implements Reconfigurable {
|
|||||||
instance = new AuthorizationManager();
|
instance = new AuthorizationManager();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The private constructor for the singleton class,
|
||||||
|
*/
|
||||||
|
private AuthorizationManager(){}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return current instance.
|
* Return current instance.
|
||||||
*
|
*
|
||||||
@ -83,16 +82,16 @@ public static void setInstance(AuthorizationManager newInstance) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Private AuthenticiationHandler to singleton of this class.
|
* Private Authorization Handler to singleton of this class.
|
||||||
*/
|
*/
|
||||||
private static AuthorizationHandler authorizationHandler;
|
private AuthorizationHandler authorizationHandler;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return current authorization handler.
|
* Return current authorization handler.
|
||||||
*
|
*
|
||||||
* @return Current authorization handler
|
* @return Current authorization handler
|
||||||
*/
|
*/
|
||||||
public static AuthorizationHandler getAuthorizationHandler() {
|
public AuthorizationHandler getAuthorizationHandler() {
|
||||||
return authorizationHandler;
|
return authorizationHandler;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -164,7 +164,7 @@ private static MPrivilege getPrivilege(MResource.TYPE resourceType,
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static void checkPrivilege(String doUserName, MPrivilege... privileges) {
|
private static void checkPrivilege(String doUserName, MPrivilege... privileges) {
|
||||||
AuthorizationHandler handler = AuthorizationManager.getAuthorizationHandler();
|
AuthorizationHandler handler = AuthorizationManager.getInstance().getAuthorizationHandler();
|
||||||
|
|
||||||
MPrincipal principal = new MPrincipal(doUserName, MPrincipal.TYPE.USER);
|
MPrincipal principal = new MPrincipal(doUserName, MPrincipal.TYPE.USER);
|
||||||
|
|
||||||
|
@ -133,7 +133,7 @@ public JsonBean handleEvent(RequestContext ctx) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private JsonBean getRoles(RequestContext ctx) {
|
private JsonBean getRoles(RequestContext ctx) {
|
||||||
AuthorizationHandler handler = AuthorizationManager.getAuthorizationHandler();
|
AuthorizationHandler handler = AuthorizationManager.getInstance().getAuthorizationHandler();
|
||||||
AuditLoggerManager manager = AuditLoggerManager.getInstance();
|
AuditLoggerManager manager = AuditLoggerManager.getInstance();
|
||||||
String principal_name = ctx.getParameterValue(PRINCIPAL_NAME_QUERY_PARAM);
|
String principal_name = ctx.getParameterValue(PRINCIPAL_NAME_QUERY_PARAM);
|
||||||
String principal_type = ctx.getParameterValue(PRINCIPAL_TYPE_QUERY_PARAM);
|
String principal_type = ctx.getParameterValue(PRINCIPAL_TYPE_QUERY_PARAM);
|
||||||
@ -153,7 +153,7 @@ private JsonBean getRoles(RequestContext ctx) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private JsonBean getPrincipal(RequestContext ctx) {
|
private JsonBean getPrincipal(RequestContext ctx) {
|
||||||
AuthorizationHandler handler = AuthorizationManager.getAuthorizationHandler();
|
AuthorizationHandler handler = AuthorizationManager.getInstance().getAuthorizationHandler();
|
||||||
AuditLoggerManager manager = AuditLoggerManager.getInstance();
|
AuditLoggerManager manager = AuditLoggerManager.getInstance();
|
||||||
String role_name = ctx.getParameterValue(ROLE_NAME_QUERY_PARAM);
|
String role_name = ctx.getParameterValue(ROLE_NAME_QUERY_PARAM);
|
||||||
|
|
||||||
@ -201,7 +201,7 @@ private void checkResourceExists(MResource resource) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private JsonBean getPrivilege(RequestContext ctx) {
|
private JsonBean getPrivilege(RequestContext ctx) {
|
||||||
AuthorizationHandler handler = AuthorizationManager.getAuthorizationHandler();
|
AuthorizationHandler handler = AuthorizationManager.getInstance().getAuthorizationHandler();
|
||||||
AuditLoggerManager manager = AuditLoggerManager.getInstance();
|
AuditLoggerManager manager = AuditLoggerManager.getInstance();
|
||||||
String principal_name = ctx.getParameterValue(PRINCIPAL_NAME_QUERY_PARAM);
|
String principal_name = ctx.getParameterValue(PRINCIPAL_NAME_QUERY_PARAM);
|
||||||
String principal_type = ctx.getParameterValue(PRINCIPAL_TYPE_QUERY_PARAM);
|
String principal_type = ctx.getParameterValue(PRINCIPAL_TYPE_QUERY_PARAM);
|
||||||
@ -225,7 +225,7 @@ private JsonBean getPrivilege(RequestContext ctx) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private JsonBean createRole(RequestContext ctx) {
|
private JsonBean createRole(RequestContext ctx) {
|
||||||
AuthorizationHandler handler = AuthorizationManager.getAuthorizationHandler();
|
AuthorizationHandler handler = AuthorizationManager.getInstance().getAuthorizationHandler();
|
||||||
AuditLoggerManager manager = AuditLoggerManager.getInstance();
|
AuditLoggerManager manager = AuditLoggerManager.getInstance();
|
||||||
|
|
||||||
RoleBean bean = new RoleBean();
|
RoleBean bean = new RoleBean();
|
||||||
@ -253,7 +253,7 @@ private JsonBean createRole(RequestContext ctx) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private JsonBean grantRevokeRole(RequestContext ctx, boolean isGrant) {
|
private JsonBean grantRevokeRole(RequestContext ctx, boolean isGrant) {
|
||||||
AuthorizationHandler handler = AuthorizationManager.getAuthorizationHandler();
|
AuthorizationHandler handler = AuthorizationManager.getInstance().getAuthorizationHandler();
|
||||||
AuditLoggerManager manager = AuditLoggerManager.getInstance();
|
AuditLoggerManager manager = AuditLoggerManager.getInstance();
|
||||||
|
|
||||||
RolesBean rolesBean = new RolesBean();
|
RolesBean rolesBean = new RolesBean();
|
||||||
@ -285,7 +285,7 @@ private JsonBean grantRevokeRole(RequestContext ctx, boolean isGrant) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private JsonBean grantRevokePrivilege(RequestContext ctx, boolean isGrant) {
|
private JsonBean grantRevokePrivilege(RequestContext ctx, boolean isGrant) {
|
||||||
AuthorizationHandler handler = AuthorizationManager.getAuthorizationHandler();
|
AuthorizationHandler handler = AuthorizationManager.getInstance().getAuthorizationHandler();
|
||||||
AuditLoggerManager manager = AuditLoggerManager.getInstance();
|
AuditLoggerManager manager = AuditLoggerManager.getInstance();
|
||||||
|
|
||||||
PrincipalsBean principalsBean = new PrincipalsBean();
|
PrincipalsBean principalsBean = new PrincipalsBean();
|
||||||
@ -330,7 +330,7 @@ private JsonBean grantRevokePrivilege(RequestContext ctx, boolean isGrant) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private JsonBean dropRole(RequestContext ctx) {
|
private JsonBean dropRole(RequestContext ctx) {
|
||||||
AuthorizationHandler handler = AuthorizationManager.getAuthorizationHandler();
|
AuthorizationHandler handler = AuthorizationManager.getInstance().getAuthorizationHandler();
|
||||||
AuditLoggerManager manager = AuditLoggerManager.getInstance();
|
AuditLoggerManager manager = AuditLoggerManager.getInstance();
|
||||||
|
|
||||||
String[] urlElements = ctx.getUrlElements();
|
String[] urlElements = ctx.getUrlElements();
|
||||||
|
@ -147,7 +147,7 @@ private JsonBean deleteJob(RequestContext ctx) {
|
|||||||
ctx.getRequest().getRemoteAddr(), "delete", "job", jobIdentifier);
|
ctx.getRequest().getRemoteAddr(), "delete", "job", jobIdentifier);
|
||||||
repository.deleteJob(jobId);
|
repository.deleteJob(jobId);
|
||||||
MResource resource = new MResource(String.valueOf(jobId), MResource.TYPE.JOB);
|
MResource resource = new MResource(String.valueOf(jobId), MResource.TYPE.JOB);
|
||||||
AuthorizationManager.getAuthorizationHandler().removeResource(resource);
|
AuthorizationManager.getInstance().getAuthorizationHandler().removeResource(resource);
|
||||||
return JsonBean.EMPTY_BEAN;
|
return JsonBean.EMPTY_BEAN;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -102,7 +102,7 @@ private JsonBean deleteLink(RequestContext ctx) {
|
|||||||
|
|
||||||
repository.deleteLink(linkId);
|
repository.deleteLink(linkId);
|
||||||
MResource resource = new MResource(String.valueOf(linkId), MResource.TYPE.LINK);
|
MResource resource = new MResource(String.valueOf(linkId), MResource.TYPE.LINK);
|
||||||
AuthorizationManager.getAuthorizationHandler().removeResource(resource);
|
AuthorizationManager.getInstance().getAuthorizationHandler().removeResource(resource);
|
||||||
return JsonBean.EMPTY_BEAN;
|
return JsonBean.EMPTY_BEAN;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -121,7 +121,7 @@ public Locale getAcceptLanguageHeader() {
|
|||||||
* @return Name of user sending the request
|
* @return Name of user sending the request
|
||||||
*/
|
*/
|
||||||
public String getUserName() {
|
public String getUserName() {
|
||||||
if (AuthenticationManager.getAuthenticationHandler().isSecurityEnabled()) {
|
if (AuthenticationManager.getInstance().getAuthenticationHandler().isSecurityEnabled()) {
|
||||||
return HttpUserGroupInformation.get().getShortUserName();
|
return HttpUserGroupInformation.get().getShortUserName();
|
||||||
} else {
|
} else {
|
||||||
return request.getParameter(PseudoAuthenticator.USER_NAME);
|
return request.getParameter(PseudoAuthenticator.USER_NAME);
|
||||||
|
Loading…
Reference in New Issue
Block a user