use of org.usermanagement.dao.entity.RoleEntity in project open-kilda by telstra.
the class SamlController method samlAuthenticate.
/**
* Saml Authenticate.
*
* @param request the request
* @return the model and view
*/
@RequestMapping(value = "/authenticate")
public ModelAndView samlAuthenticate(final HttpServletRequest request, RedirectAttributes redir) {
ModelAndView modelAndView = null;
String error = null;
Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
if (null != authentication) {
boolean isValid = (authentication.isAuthenticated() && !(authentication instanceof AnonymousAuthenticationToken));
if (isValid) {
SAMLCredential saml = (SAMLCredential) authentication.getCredentials();
SamlConfig samlConfig = samlService.getConfigByEntityId(saml.getRemoteEntityID());
NameID nameId = (NameID) authentication.getPrincipal();
String username = nameId.getValue();
UserInfo userInfo = userService.getUserInfoByUsername(username);
if (userInfo != null && userInfo.getStatus().equalsIgnoreCase(Status.ACTIVE.name())) {
userService.populateUserInfo(userInfo, username);
request.getSession().setAttribute(IConstants.SESSION_OBJECT, userInfo);
userService.updateLoginDetail(username);
modelAndView = new ModelAndView(IConstants.View.REDIRECT_HOME);
} else if (userInfo != null && userInfo.getStatus().equalsIgnoreCase(Status.INACTIVE.name())) {
error = messageUtil.getAttributeUserInactive();
request.getSession(false);
modelAndView = new ModelAndView(IConstants.View.REDIRECT_LOGIN);
} else if (userInfo == null && samlConfig.isUserCreation()) {
Set<RoleEntity> roleEntities = roleService.getRoleByIds(samlConfig.getRoles());
userService.createSamlUser(nameId.getValue(), roleEntities);
UserInfo userInfo1 = getLoggedInUser(request);
userService.populateUserInfo(userInfo1, username);
userService.updateLoginDetail(username);
modelAndView = new ModelAndView(IConstants.View.REDIRECT_HOME);
} else {
error = messageUtil.getAttributeUserDoesNotExist();
LOGGER.warn("User is not logged in, redirected to login page. Requested view name: ");
request.getSession(false);
modelAndView = new ModelAndView(IConstants.View.REDIRECT_LOGIN);
}
}
} else {
error = messageUtil.getAttributeAuthenticationFailure();
LOGGER.warn("User is not logged in, redirected to login page. Requested view name: ");
modelAndView = new ModelAndView(IConstants.View.LOGIN);
}
if (error != null) {
redir.addFlashAttribute("error", error);
}
return modelAndView;
}
use of org.usermanagement.dao.entity.RoleEntity in project open-kilda by telstra.
the class SamlService method create.
/**
* Creates the provider.
*
* @param file the metadata file
* @param url the metadata url
* @param name the provider name
* @param entityId the entityId
* @param status the provider status
* @param attribute the attribute
* @param userCreation the userCreation
* @param roleIds the role Ids
* @return the SamlConfig
*/
public SamlConfig create(MultipartFile file, String name, String url, String entityId, boolean status, boolean userCreation, List<Long> roleIds, String attribute) {
samlValidator.validateCreateProvider(file, name, entityId, url, userCreation, roleIds);
Set<RoleEntity> roleEntities = roleService.getRolesById(roleIds);
SamlConfigEntity samlConfigEntity = SamlConversionUtil.toSamlConfigEntity(file, name, url, entityId, status, attribute, userCreation, roleEntities);
samlRepository.save(samlConfigEntity);
try {
metadataManager.loadProviderMetadata(samlConfigEntity.getUuid(), samlConfigEntity.getType().name());
} catch (MetadataProviderException e) {
LOGGER.error("Error occurred while loading provider" + e);
}
return SamlConversionUtil.toSamlConfig(samlConfigEntity);
}
use of org.usermanagement.dao.entity.RoleEntity in project open-kilda by telstra.
the class SamlService method update.
/**
* Updates the provider.
*
* @param uuid the uuid
* @param file the metadata file
* @param name the provider name
* @param url the metadata url
* @param entityId the entityId
* @param status the provider status
* @param attribute the attribute
* @param userCreation the userCreation
* @param roleIds the role Ids
* @return the SamlConfig
*/
public SamlConfig update(String uuid, MultipartFile file, String name, String url, String entityId, boolean status, String attribute, boolean userCreation, List<Long> roleIds) {
SamlConfigEntity samlConfigEntity = samlValidator.validateUpdateProvider(uuid, file, name, entityId, url, userCreation, roleIds);
Set<RoleEntity> roleEntities = roleService.getRolesById(roleIds);
boolean requireManagerUpdate = SamlConversionUtil.toUpdateSamlConfigEntity(samlConfigEntity, roleEntities, file, name, url, entityId, status, userCreation, attribute);
samlRepository.save(samlConfigEntity);
if (requireManagerUpdate) {
metadataManager.updateProviderToMetadataManager(samlConfigEntity.getUuid(), samlConfigEntity.getType().name());
}
return SamlConversionUtil.toSamlConfig(samlConfigEntity);
}
use of org.usermanagement.dao.entity.RoleEntity in project open-kilda by telstra.
the class SamlConversionUtil method toSamlConfig.
/**
* To saml config.
*
* @param samlConfigEntity the saml config entity
* @return the saml config
*/
public static SamlConfig toSamlConfig(SamlConfigEntity samlConfigEntity) {
SamlConfig samlConfig = new SamlConfig();
samlConfig.setName(samlConfigEntity.getName());
samlConfig.setUrl(samlConfigEntity.getUrl());
samlConfig.setEntityId(samlConfigEntity.getEntityId());
samlConfig.setUuid(samlConfigEntity.getUuid());
samlConfig.setUserCreation(samlConfigEntity.isUserCreation());
samlConfig.setStatus(samlConfigEntity.isStatus());
samlConfig.setType(samlConfigEntity.getType());
samlConfig.setAttribute(samlConfigEntity.getAttribute());
Set<Long> roles = new HashSet<>();
if (samlConfigEntity.getRoles() != null) {
for (RoleEntity roleEntity : samlConfigEntity.getRoles()) {
roles.add(roleEntity.getRoleId());
}
samlConfig.setRoles(roles);
}
return samlConfig;
}
use of org.usermanagement.dao.entity.RoleEntity in project open-kilda by telstra.
the class RoleService method assignRoleByPermissionId.
/**
* Assign role by permission id.
*
* @param permissionId the permission id
* @param request the request
* @return the permission
*/
@Transactional(propagation = Propagation.REQUIRED, readOnly = false)
public Permission assignRoleByPermissionId(final Long permissionId, final Permission request) {
PermissionEntity permissionEntity = permissionRepository.findByPermissionId(permissionId);
if (ValidatorUtil.isNull(permissionEntity)) {
LOGGER.warn("Permission with permissionId '" + permissionId + "' not found. Error: " + messageUtil.getAttributeInvalid("permissionId", permissionId + ""));
throw new RequestValidationException(messageUtil.getAttributeInvalid("permissionId", permissionId + ""));
}
permissionEntity.getRoles().clear();
if (request.getRoles() != null) {
for (Role role : request.getRoles()) {
RoleEntity roleEntity = roleRepository.findByRoleId(role.getRoleId());
permissionEntity.getRoles().add(roleEntity);
}
}
permissionRepository.save(permissionEntity);
activityLogger.log(ActivityType.ASSIGN_ROLES_TO_PERMISSION, permissionEntity.getName());
LOGGER.info("Roles assigned with permission successfully (permissionId: " + permissionId + ")");
return RoleConversionUtil.toPermissionByRole(permissionEntity.getRoles(), permissionEntity);
}
Aggregations