use of org.openkilda.saml.model.SamlConfig 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.openkilda.saml.model.SamlConfig in project open-kilda by telstra.
the class UrlMetadataProvider method getMetadataURI.
@Override
public String getMetadataURI() {
SamlService samlService = ApplicationContextProvider.getContext().getBean(SamlService.class);
SamlConfig samlConfig = samlService.getById(getMetaDataEntityId());
return samlConfig.getUrl();
}
use of org.openkilda.saml.model.SamlConfig in project open-kilda by telstra.
the class SamlService method getAll.
/**
* Gets all the providers.
*
* @return the providers
*/
public List<SamlConfig> getAll() {
List<SamlConfigEntity> samlConfigEntityList = samlRepository.findAll();
List<SamlConfig> samlConfigList = new ArrayList<>();
for (SamlConfigEntity samlConfigEntity : samlConfigEntityList) {
SamlConfig samlConfig = SamlConversionUtil.toSamlConfig(samlConfigEntity);
samlConfigList.add(samlConfig);
}
return samlConfigList;
}
use of org.openkilda.saml.model.SamlConfig 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.openkilda.saml.model.SamlConfig in project open-kilda by telstra.
the class SamlService method getAllActiveIdp.
/**
* Gets all the active providers.
*
* @return the active providers
*/
public List<SamlConfig> getAllActiveIdp() {
List<SamlConfigEntity> samlConfigEntityList = samlRepository.findAllByStatus(true);
List<SamlConfig> samlConfigList = new ArrayList<>();
for (SamlConfigEntity samlConfigEntity : samlConfigEntityList) {
SamlConfig samlConfig = SamlConversionUtil.toSamlConfig(samlConfigEntity);
samlConfigList.add(samlConfig);
}
return samlConfigList;
}
Aggregations