use of org.apache.ranger.view.VXResponse in project ranger by apache.
the class UserREST method changePassword.
/**
* @param userId
* @param changePassword
* @return
*/
@POST
@Path("{userId}/passwordchange")
@Produces({ "application/xml", "application/json" })
public VXResponse changePassword(@PathParam("userId") Long userId, VXPasswordChange changePassword) {
if (changePassword == null || stringUtil.isEmpty(changePassword.getLoginId())) {
logger.warn("SECURITY:changePassword(): Invalid loginId provided. loginId was empty or null");
throw restErrorUtil.createRESTException("serverMsg.userRestUser", MessageEnums.DATA_NOT_FOUND, null, null, "");
}
logger.info("changePassword:" + changePassword.getLoginId());
XXPortalUser gjUser = daoManager.getXXPortalUser().findByLoginId(changePassword.getLoginId());
if (gjUser == null) {
logger.warn("SECURITY:changePassword(): Invalid loginId provided: loginId=" + changePassword.getLoginId());
throw restErrorUtil.createRESTException("serverMsg.userRestUser", MessageEnums.DATA_NOT_FOUND, null, null, changePassword.getLoginId());
}
userManager.checkAccessForUpdate(gjUser);
changePassword.setId(gjUser.getId());
VXResponse ret = userManager.changePassword(changePassword);
return ret;
}
use of org.apache.ranger.view.VXResponse in project ranger by apache.
the class CustomLogoutSuccessHandler method onLogoutSuccess.
@Override
public void onLogoutSuccess(HttpServletRequest request, HttpServletResponse response, Authentication authentication) throws IOException, ServletException {
request.getServletContext().removeAttribute(request.getRequestedSessionId());
response.setContentType("application/json;charset=UTF-8");
response.setHeader("Cache-Control", "no-cache");
response.setHeader("X-Frame-Options", "DENY");
String jsonStr = "";
try {
VXResponse vXResponse = new VXResponse();
vXResponse.setStatusCode(HttpServletResponse.SC_OK);
vXResponse.setMsgDesc("Logout Successful");
jsonStr = jsonUtil.writeObjectAsString(vXResponse);
response.setStatus(HttpServletResponse.SC_OK);
response.getWriter().write(jsonStr);
if (logger.isDebugEnabled()) {
logger.debug("Log-out Successfully done. Returning Json : " + jsonStr);
}
} catch (IOException e) {
logger.info("Error while writing JSON in HttpServletResponse");
}
}
use of org.apache.ranger.view.VXResponse in project ranger by apache.
the class RangerAuthFailureHandler method onAuthenticationFailure.
/*
* (non-Javadoc)
*
* @see org.springframework.security.web.authentication.
* ExceptionMappingAuthenticationFailureHandler
* #onAuthenticationFailure(javax.servlet.http.HttpServletRequest,
* javax.servlet.http.HttpServletResponse,
* org.springframework.security.core.AuthenticationException)
*/
@Override
public void onAuthenticationFailure(HttpServletRequest request, HttpServletResponse response, AuthenticationException exception) throws IOException, ServletException {
String ajaxRequestHeader = request.getHeader("X-Requested-With");
if (logger.isDebugEnabled()) {
logger.debug("commence() X-Requested-With=" + ajaxRequestHeader);
}
response.setContentType("application/json;charset=UTF-8");
response.setHeader("Cache-Control", "no-cache");
response.setHeader("X-Frame-Options", "DENY");
String jsonResp = "";
try {
String msg = exception.getMessage();
VXResponse vXResponse = new VXResponse();
if (msg != null && !msg.isEmpty()) {
if (CLIUtil.getMessage("AbstractUserDetailsAuthenticationProvider.badCredentials", request).equalsIgnoreCase(msg)) {
vXResponse.setStatusCode(HttpServletResponse.SC_UNAUTHORIZED);
vXResponse.setMsgDesc("The username or password you entered is incorrect...");
logger.info("Error Message : " + msg);
} else if (msg.contains("Could not get JDBC Connection; nested exception is java.sql.SQLException: Connections could not be acquired from the underlying database!")) {
vXResponse.setStatusCode(HttpServletResponse.SC_UNAUTHORIZED);
vXResponse.setMsgDesc("Unable to connect to DB...");
} else if (msg.contains("Communications link failure")) {
vXResponse.setStatusCode(HttpServletResponse.SC_UNAUTHORIZED);
vXResponse.setMsgDesc("Unable to connect to DB...");
} else if (CLIUtil.getMessage("AbstractUserDetailsAuthenticationProvider.disabled", request).equalsIgnoreCase(msg)) {
vXResponse.setStatusCode(HttpServletResponse.SC_UNAUTHORIZED);
vXResponse.setMsgDesc("The username or password you entered is disable...");
}
}
jsonResp = jsonUtil.writeObjectAsString(vXResponse);
response.getWriter().write(jsonResp);
response.setStatus(HttpServletResponse.SC_UNAUTHORIZED);
} catch (IOException e) {
logger.info("Error while writing JSON in HttpServletResponse");
}
if (ajaxRequestHeader != null && "XMLHttpRequest".equalsIgnoreCase(ajaxRequestHeader)) {
// response);
if (logger.isDebugEnabled()) {
logger.debug("Sending login failed response : " + jsonResp);
}
}
// else {
// super.onAuthenticationFailure(request, response, exception);
// }
}
use of org.apache.ranger.view.VXResponse in project ranger by apache.
the class UserService method validateForCreate.
@Override
protected void validateForCreate(VXPortalUser userProfile) {
List<VXMessage> messageList = new ArrayList<VXMessage>();
if (stringUtil.isEmpty(userProfile.getEmailAddress())) {
logger.info("Empty Email Address." + userProfile);
messageList.add(MessageEnums.NO_INPUT_DATA.getMessage(null, "emailAddress"));
}
if (stringUtil.isEmpty(userProfile.getFirstName())) {
logger.info("Empty firstName." + userProfile);
messageList.add(MessageEnums.NO_INPUT_DATA.getMessage(null, "firstName"));
}
if (stringUtil.isEmpty(userProfile.getLastName())) {
logger.info("Empty lastName." + userProfile);
messageList.add(MessageEnums.NO_INPUT_DATA.getMessage(null, "lastName"));
}
// firstName
if (!stringUtil.isValidName(userProfile.getFirstName())) {
logger.info("Invalid first name." + userProfile);
messageList.add(MessageEnums.INVALID_INPUT_DATA.getMessage(null, "firstName"));
}
userProfile.setFirstName(stringUtil.toCamelCaseAllWords(userProfile.getFirstName()));
// lastName
if (!stringUtil.isValidName(userProfile.getLastName())) {
logger.info("Invalid last name." + userProfile);
messageList.add(MessageEnums.INVALID_INPUT_DATA.getMessage(null, "lastName"));
}
userProfile.setLastName(stringUtil.toCamelCaseAllWords(userProfile.getLastName()));
if (!stringUtil.validateEmail(userProfile.getEmailAddress())) {
logger.info("Invalid email address." + userProfile);
messageList.add(MessageEnums.INVALID_INPUT_DATA.getMessage(null, "emailAddress"));
}
// Normalize email. Make it lower case
userProfile.setEmailAddress(stringUtil.normalizeEmail(userProfile.getEmailAddress()));
// loginId
userProfile.setLoginId(userProfile.getEmailAddress());
// password
if (!stringUtil.validatePassword(userProfile.getPassword(), new String[] { userProfile.getFirstName(), userProfile.getLastName() })) {
logger.info("Invalid password." + userProfile);
messageList.add(MessageEnums.INVALID_INPUT_DATA.getMessage(null, "password"));
}
// firstName
if (!stringUtil.validateString(StringUtil.VALIDATION_NAME, userProfile.getFirstName())) {
logger.info("Invalid first name." + userProfile);
messageList.add(MessageEnums.INVALID_INPUT_DATA.getMessage(null, "firstName"));
}
// lastName
if (!stringUtil.validateString(StringUtil.VALIDATION_NAME, userProfile.getLastName())) {
logger.info("Invalid last name." + userProfile);
messageList.add(MessageEnums.INVALID_INPUT_DATA.getMessage(null, "lastName"));
}
// create the public screen name
userProfile.setPublicScreenName(userProfile.getFirstName() + " " + userProfile.getLastName());
if (!messageList.isEmpty()) {
VXResponse gjResponse = new VXResponse();
gjResponse.setStatusCode(VXResponse.STATUS_ERROR);
gjResponse.setMsgDesc("Validation failure");
gjResponse.setMessageList(messageList);
logger.info("Validation Error in createUser() userProfile=" + userProfile + ", error=" + gjResponse);
throw restErrorUtil.createRESTException(gjResponse);
}
}
use of org.apache.ranger.view.VXResponse in project ranger by apache.
the class XResourceService method searchXResources.
@Override
public VXResourceList searchXResources(SearchCriteria searchCriteria) {
VXResourceList returnList;
UserSessionBase currentUserSession = ContextUtil.getCurrentUserSession();
// If user is system admin
if (currentUserSession.isUserAdmin()) {
returnList = super.searchXResources(searchCriteria);
} else {
// need to be optimize
returnList = new VXResourceList();
int startIndex = searchCriteria.getStartIndex();
int pageSize = searchCriteria.getMaxRows();
searchCriteria.setStartIndex(0);
searchCriteria.setMaxRows(Integer.MAX_VALUE);
List<XXResource> resultList = (List<XXResource>) searchResources(searchCriteria, searchFields, sortFields, returnList);
List<XXResource> adminPermResourceList = new ArrayList<XXResource>();
for (XXResource xXResource : resultList) {
VXResponse vXResponse = xaBizUtil.hasPermission(populateViewBean(xXResource), AppConstants.XA_PERM_TYPE_ADMIN);
if (vXResponse.getStatusCode() == VXResponse.STATUS_SUCCESS) {
adminPermResourceList.add(xXResource);
}
}
if (!adminPermResourceList.isEmpty()) {
populatePageList(adminPermResourceList, startIndex, pageSize, returnList);
}
}
if (returnList != null && returnList.getResultSize() > 0) {
for (VXResource vXResource : returnList.getVXResources()) {
populateAuditList(vXResource);
}
}
return returnList;
}
Aggregations