Search in sources :

Example 1 with SamlConfig

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;
}
Also used : RoleEntity(org.usermanagement.dao.entity.RoleEntity) SAMLCredential(org.springframework.security.saml.SAMLCredential) NameID(org.opensaml.saml2.core.NameID) Authentication(org.springframework.security.core.Authentication) ModelAndView(org.springframework.web.servlet.ModelAndView) UserInfo(org.usermanagement.model.UserInfo) AnonymousAuthenticationToken(org.springframework.security.authentication.AnonymousAuthenticationToken) SamlConfig(org.openkilda.saml.model.SamlConfig) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 2 with SamlConfig

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();
}
Also used : SamlService(org.openkilda.saml.service.SamlService) SamlConfig(org.openkilda.saml.model.SamlConfig)

Example 3 with SamlConfig

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;
}
Also used : ArrayList(java.util.ArrayList) SamlConfigEntity(org.openkilda.saml.dao.entity.SamlConfigEntity) SamlConfig(org.openkilda.saml.model.SamlConfig)

Example 4 with SamlConfig

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;
}
Also used : RoleEntity(org.usermanagement.dao.entity.RoleEntity) SamlConfig(org.openkilda.saml.model.SamlConfig) HashSet(java.util.HashSet)

Example 5 with 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;
}
Also used : ArrayList(java.util.ArrayList) SamlConfigEntity(org.openkilda.saml.dao.entity.SamlConfigEntity) SamlConfig(org.openkilda.saml.model.SamlConfig)

Aggregations

SamlConfig (org.openkilda.saml.model.SamlConfig)7 SamlConfigEntity (org.openkilda.saml.dao.entity.SamlConfigEntity)3 ArrayList (java.util.ArrayList)2 SamlService (org.openkilda.saml.service.SamlService)2 MetadataProviderException (org.opensaml.saml2.metadata.provider.MetadataProviderException)2 RoleEntity (org.usermanagement.dao.entity.RoleEntity)2 Blob (java.sql.Blob)1 HashSet (java.util.HashSet)1 NameID (org.opensaml.saml2.core.NameID)1 AnonymousAuthenticationToken (org.springframework.security.authentication.AnonymousAuthenticationToken)1 Authentication (org.springframework.security.core.Authentication)1 SAMLCredential (org.springframework.security.saml.SAMLCredential)1 Transactional (org.springframework.transaction.annotation.Transactional)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1 ModelAndView (org.springframework.web.servlet.ModelAndView)1 UserInfo (org.usermanagement.model.UserInfo)1