use of org.usermanagement.model.UserInfo in project open-kilda by telstra.
the class BaseController method validateAndRedirect.
/**
* Validate request.
* <ul>
* <li>If user is logged in and role is user then redirected to Home.</li>
* <li>If user is logged in and role is not user then redirected to view
* passed as an argument.</li>
* <li>If user is not logged in then redirected to login page.</li>
* </ul>
*
* @param request HttpServletRequest to check user log in status.
* @param viewName on which user has to redirect if logged in and not of type user.
* @return ModelAndView information containing view name on which user is going to be redirected.
*/
public ModelAndView validateAndRedirect(final HttpServletRequest request, final String viewName) {
ModelAndView modelAndView;
if (isUserLoggedIn()) {
UserInfo userInfo = getLoggedInUser(request);
LOGGER.info("Logged in user. view name: " + viewName + ", User name: " + userInfo.getName());
modelAndView = new ModelAndView(IConstants.View.REDIRECT_HOME);
} else {
LOGGER.warn("User is not logged in, redirected to login page. Requested view name: " + viewName);
modelAndView = new ModelAndView("login");
modelAndView.addObject("idps", samlService.getAllActiveIdp());
}
return modelAndView;
}
use of org.usermanagement.model.UserInfo in project open-kilda by telstra.
the class RequestInterceptor method preHandle.
@Override
public boolean preHandle(final HttpServletRequest request, final HttpServletResponse response, final Object handler) throws AccessDeniedException {
String correlationId = request.getParameter(CORRELATION_ID);
correlationId = correlationId == null ? UUID.randomUUID().toString() : correlationId;
HttpSession session = request.getSession();
UserInfo userInfo = null;
if (IConstants.SessionTimeout.TIME_IN_MINUTE == null) {
IConstants.SessionTimeout.TIME_IN_MINUTE = Integer.valueOf(applicationSettingService.getApplicationSettings().get(ApplicationSetting.SESSION_TIMEOUT.name()));
}
session.setMaxInactiveInterval(IConstants.SessionTimeout.TIME_IN_MINUTE * 60);
userInfo = (UserInfo) session.getAttribute(IConstants.SESSION_OBJECT);
if (userInfo != null) {
validateUser(userInfo);
if (handler instanceof HandlerMethod) {
HandlerMethod handlerMethod = (HandlerMethod) handler;
Permissions permissions = handlerMethod.getMethod().getAnnotation(Permissions.class);
if (permissions != null) {
validateAndPopulatePermisssion(userInfo, permissions);
}
}
updateRequestContext(correlationId, request, userInfo);
} else {
RequestContext requestContext = serverContext.getRequestContext();
requestContext.setCorrelationId(correlationId);
}
return true;
}
use of org.usermanagement.model.UserInfo in project open-kilda by telstra.
the class FlowService method getFlowById.
/**
* Flow by flow id.
*
* @param flowId
* the flow id
* @return the flow by id
* @throws AccessDeniedException the access denied exception
*/
public FlowInfo getFlowById(String flowId, boolean controller) throws AccessDeniedException {
FlowInfo flowInfo = new FlowInfo();
FlowV2 flow = null;
try {
flow = flowsIntegrationService.getFlowById(flowId);
} catch (InvalidResponseException ex) {
LOGGER.error("Error occurred while retrieving flows from controller", ex);
if (controller) {
throw new InvalidResponseException(ex.getCode(), ex.getResponse());
}
}
Map<String, String> csNames = switchIntegrationService.getSwitchNames();
if (flow != null) {
flowInfo = flowConverter.toFlowV2Info(flow, csNames);
}
UserInfo userInfo = userService.getLoggedInUserInfo();
try {
if (!controller && userInfo.getPermissions().contains(IConstants.Permission.FW_FLOW_INVENTORY)) {
if (storeService.getLinkStoreConfig().getUrls().size() > 0) {
InventoryFlow inventoryFlow = flowStoreService.getFlowById(flowId);
if (flow == null && inventoryFlow.getId() == null) {
throw new RequestValidationException("Can not get flow: Flow " + flowId + " not found");
} else if (flow != null && inventoryFlow.getId() != null) {
flowInfo.setState(inventoryFlow.getState());
FlowDiscrepancy discrepancy = new FlowDiscrepancy();
discrepancy.setControllerDiscrepancy(false);
if (flowInfo.getMaximumBandwidth() != (inventoryFlow.getMaximumBandwidth() == null ? 0 : inventoryFlow.getMaximumBandwidth())) {
discrepancy.setBandwidth(true);
FlowBandwidth flowBandwidth = new FlowBandwidth();
flowBandwidth.setControllerBandwidth(flow.getMaximumBandwidth());
flowBandwidth.setInventoryBandwidth(inventoryFlow.getMaximumBandwidth());
discrepancy.setBandwidthValue(flowBandwidth);
}
if (("UP".equalsIgnoreCase(flowInfo.getStatus()) && !"ACTIVE".equalsIgnoreCase(inventoryFlow.getState())) || ("DOWN".equalsIgnoreCase(flowInfo.getStatus()) && "ACTIVE".equalsIgnoreCase(inventoryFlow.getState()))) {
discrepancy.setStatus(true);
FlowState flowState = new FlowState();
flowState.setControllerState(flow.getStatus());
flowState.setInventoryState(inventoryFlow.getState());
discrepancy.setStatusValue(flowState);
}
flowInfo.setInventoryFlow(true);
flowInfo.setDiscrepancy(discrepancy);
} else if (inventoryFlow.getId() == null && flow != null) {
FlowDiscrepancy discrepancy = new FlowDiscrepancy();
discrepancy.setInventoryDiscrepancy(true);
discrepancy.setControllerDiscrepancy(false);
discrepancy.setStatus(true);
discrepancy.setBandwidth(true);
FlowBandwidth flowBandwidth = new FlowBandwidth();
flowBandwidth.setControllerBandwidth(flow.getMaximumBandwidth());
flowBandwidth.setInventoryBandwidth(0);
discrepancy.setBandwidthValue(flowBandwidth);
FlowState flowState = new FlowState();
flowState.setControllerState(flow.getStatus());
flowState.setInventoryState(null);
discrepancy.setStatusValue(flowState);
flowInfo.setDiscrepancy(discrepancy);
} else {
flowConverter.toFlowInfo(flowInfo, inventoryFlow, csNames);
}
}
}
if (flow == null) {
throw new RequestValidationException("Can not get flow: Flow " + flowId + " not found");
}
} catch (Exception ex) {
LOGGER.error("Error occurred while retrieving flows from store", ex);
throw new RequestValidationException(ex.getMessage());
}
return flowInfo;
}
use of org.usermanagement.model.UserInfo in project open-kilda by telstra.
the class UserConversionUtil method toUserInfo.
/**
* To user info.
*
* @param userEntity the user entity
* @return the user info
*/
public static UserInfo toUserInfo(final UserEntity userEntity) {
UserInfo userInfo = null;
if (userEntity != null) {
userInfo = new UserInfo();
userInfo.setName(userEntity.getName());
userInfo.setEmail(userEntity.getEmail().toLowerCase());
userInfo.setUsername(userEntity.getUsername().toLowerCase());
userInfo.setIs2FaEnabled(userEntity.getIs2FaEnabled());
userInfo.setStatus(userEntity.getStatusEntity().getStatus());
userInfo.setUserId(userEntity.getUserId());
Set<String> roles = new HashSet<>();
if (!ValidatorUtil.isNull(userEntity.getRoles())) {
for (RoleEntity roleEntity : userEntity.getRoles()) {
roles.add(roleEntity.getName());
}
userInfo.setRoles(roles);
}
}
return userInfo;
}
use of org.usermanagement.model.UserInfo in project open-kilda by telstra.
the class RoleConversionUtil method toRole.
/**
* To role.
*
* @param roleEntity the role entity
* @param withPermissions the with permissions
* @param withUsers the with users
* @return the role
*/
public static Role toRole(final RoleEntity roleEntity, final boolean withPermissions, final boolean withUsers) {
Role role = new Role();
role.setName(roleEntity.getName());
role.setRoleId(roleEntity.getRoleId());
role.setStatus(roleEntity.getStatusEntity().getStatus());
role.setDescription(roleEntity.getDescription());
if (withPermissions) {
List<Permission> permissionList = new ArrayList<Permission>();
if (!ValidatorUtil.isNull(roleEntity.getPermissions())) {
for (PermissionEntity permissionEntity : roleEntity.getPermissions()) {
permissionList.add(PermissionConversionUtil.toPermission(permissionEntity, null));
}
role.setPermissions(permissionList);
}
}
if (withUsers) {
List<UserInfo> userInfoList = new ArrayList<>();
for (UserEntity userEntity : roleEntity.getUsers()) {
if (userEntity.getUserId() != 1) {
UserInfo userInfo = new UserInfo();
userInfo.setUserId(userEntity.getUserId());
userInfo.setName(userEntity.getName());
userInfoList.add(userInfo);
}
}
role.setUserInfo(userInfoList);
}
return role;
}
Aggregations