Example usage for org.springframework.security.core Authentication getName

List of usage examples for org.springframework.security.core Authentication getName

Introduction

In this page you can find the example usage for org.springframework.security.core Authentication getName.

Prototype

public String getName();

Source Link

Document

Returns the name of this principal.

Usage

From source file:reconf.server.services.security.SecurityAccessDecisionManager.java

private boolean isAuthorized(Authentication auth, String productId) {
    if (ApplicationSecurity.isRoot(auth)) {
        return true;
    }//  w ww.j a  v  a  2s .c  om
    if (!products.exists(productId)) {
        return true;
    }
    return userProducts.exists(new UserProductKey(auth.getName(), productId));
}

From source file:com.exxonmobile.ace.hybris.storefront.security.AcceleratorAuthenticationProvider.java

@Override
public Authentication authenticate(Authentication authentication) throws AuthenticationException {
    final String username = (authentication.getPrincipal() == null) ? "NONE_PROVIDED"
            : authentication.getName();
    if (getBruteForceAttackCounter().isAttack(username)) {
        try {//from   w w w  .  j  a v a 2  s. c  o  m
            UserModel userModel = getUserService().getUserForUID(StringUtils.lowerCase(username));
            userModel.setLoginDisabled(true);
            getModelService().save(userModel);
            bruteForceAttackCounter.resetUserCounter(userModel.getUid());
        } catch (UnknownIdentifierException e) {
            LOG.warn("Brute force attack attempt for non existing user name " + username);
        } finally {
            throw new BadCredentialsException(
                    messages.getMessage("CoreAuthenticationProvider.badCredentials", "Bad credentials"));
        }
    }

    // check if the user of the cart matches the current user and if the
    // user is not anonymous. If otherwise, remove delete the session cart as it might
    // be stolen / from another user
    String sessionCartUserId = getCartService().getSessionCart().getUser().getUid();

    if (!username.equals(sessionCartUserId)
            && !sessionCartUserId.equals(userService.getAnonymousUser().getUid())) {
        getCartService().setSessionCart(null);
    }
    return super.authenticate(authentication);
}

From source file:org.openinfinity.sso.identityprovisioning.bpmn.ProcessEngineBridgeImpl.java

@Log(level = LogLevel.INFO)
@AuditTrail/*from  w ww  .j  av  a  2  s . c  o m*/
public void claimTask(String taskId) {
    SecurityContext securityContext = SecurityContextHolder.getContext();
    Authentication authentication = securityContext.getAuthentication();
    IdentityService identityService = processEngine.getIdentityService();
    identityService.setAuthenticatedUserId(authentication.getName());
    TaskService taskService = processEngine.getTaskService();
    taskService.claim(taskId, authentication.getName());
}

From source file:org.openinfinity.sso.identityprovisioning.bpmn.ProcessEngineBridgeImpl.java

@Log(level = LogLevel.INFO)
@AuditTrail/*  w  w  w .j  a va 2 s . com*/
public void completeTask(String taskId, Map<String, Object> variables) {
    SecurityContext securityContext = SecurityContextHolder.getContext();
    Authentication authentication = securityContext.getAuthentication();
    IdentityService identityService = processEngine.getIdentityService();
    identityService.setAuthenticatedUserId(authentication.getName());
    TaskService taskService = processEngine.getTaskService();
    taskService.complete(taskId, variables);
}

From source file:org.openinfinity.sso.identityprovisioning.bpmn.ProcessEngineBridgeImpl.java

public Collection<org.openinfinity.sso.identityprovisioning.bpmn.Task> queryForTasksByRole(String role) {
    SecurityContext securityContext = SecurityContextHolder.getContext();
    Authentication authentication = securityContext.getAuthentication();
    IdentityService identityService = processEngine.getIdentityService();
    identityService.setAuthenticatedUserId(authentication.getName());
    TaskService taskService = processEngine.getTaskService();
    List<Task> tasks = taskService.createTaskQuery().taskCandidateGroup(role).list();
    Collection<org.openinfinity.sso.identityprovisioning.bpmn.Task> simpleTasks = mapTasks(tasks);
    return Collections.unmodifiableCollection(simpleTasks);
}

From source file:org.openinfinity.sso.identityprovisioning.bpmn.ProcessEngineBridgeImpl.java

@Log(level = LogLevel.INFO)
@AuditTrail//from w ww  . j  av  a2 s .  c  om
public String startProcess(String processDefinitionKey, Map<String, Object> variables) {
    SecurityContext securityContext = SecurityContextHolder.getContext();
    Authentication authentication = securityContext.getAuthentication();
    IdentityService identityService = processEngine.getIdentityService();
    identityService.setAuthenticatedUserId(authentication.getName());
    RuntimeService runtimeService = processEngine.getRuntimeService();
    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey(processDefinitionKey, variables);
    return processInstance.getId();
}

From source file:org.openinfinity.sso.identityprovisioning.bpmn.ProcessEngineBridgeImpl.java

@Log(level = LogLevel.INFO)
@AuditTrail/*  w ww .jav  a2s.co  m*/
public Collection<org.openinfinity.sso.identityprovisioning.bpmn.Task> queryForAllUserTasks() {
    SecurityContext securityContext = SecurityContextHolder.getContext();
    Authentication authentication = securityContext.getAuthentication();
    IdentityService identityService = processEngine.getIdentityService();
    identityService.setAuthenticatedUserId(authentication.getName());
    TaskService taskService = processEngine.getTaskService();
    List<Task> tasks = taskService.createTaskQuery().list();
    Collection<org.openinfinity.sso.identityprovisioning.bpmn.Task> simpleTasks = mapTasks(tasks);
    return Collections.unmodifiableCollection(simpleTasks);
}

From source file:org.openinfinity.sso.identityprovisioning.bpmn.ProcessEngineBridgeImpl.java

@Log(level = LogLevel.INFO)
@AuditTrail/*  w w  w  . ja va2 s.co m*/
public Collection<org.openinfinity.sso.identityprovisioning.bpmn.Task> queryForUserTasks() {
    SecurityContext securityContext = SecurityContextHolder.getContext();
    Authentication authentication = securityContext.getAuthentication();
    IdentityService identityService = processEngine.getIdentityService();
    identityService.setAuthenticatedUserId(authentication.getName());
    TaskService taskService = processEngine.getTaskService();
    List<Task> tasks = taskService.createTaskQuery().taskCandidateUser(authentication.getName()).list();
    Collection<org.openinfinity.sso.identityprovisioning.bpmn.Task> simpleTasks = mapTasks(tasks);
    return Collections.unmodifiableCollection(simpleTasks);
}

From source file:org.openinfinity.sso.identityprovisioning.bpmn.ProcessEngineBridgeImpl.java

public Collection<org.openinfinity.sso.identityprovisioning.bpmn.Task> queryForTasksByUserRoles() {
    SecurityContext securityContext = SecurityContextHolder.getContext();
    Authentication authentication = securityContext.getAuthentication();
    IdentityService identityService = processEngine.getIdentityService();
    identityService.setAuthenticatedUserId(authentication.getName());
    TaskService taskService = processEngine.getTaskService();
    Collection<? extends GrantedAuthority> grantedAuthorities = authentication.getAuthorities();
    List<String> candidateGroups = new ArrayList<String>();
    for (GrantedAuthority grantedAuthority : grantedAuthorities) {
        if (grantedAuthority.getAuthority() != null)
            candidateGroups.add(grantedAuthority.getAuthority());
    }//from ww w  .  j  a  v a2s .  c  om
    List<Task> tasks = taskService.createTaskQuery().taskCandidateGroupIn(candidateGroups).list();
    Collection<org.openinfinity.sso.identityprovisioning.bpmn.Task> simpleTasks = mapTasks(tasks);
    return Collections.unmodifiableCollection(simpleTasks);
}

From source file:com.alehuo.wepas2016projekti.controller.UploadController.java

/**
 * Kuvan latauksen ksittely//w w w .  ja  v a  2s.c o  m
 * @param a Autentikointi
 * @param m Malli
 * @param formData Lomakkeen data
 * @param bs BindingResult
 * @param l Locale
 * @return
 */
@RequestMapping(method = RequestMethod.POST)
public String processUpload(Authentication a, Model m, @Valid @ModelAttribute ImageUploadFormData formData,
        BindingResult bs, Locale l) {
    //Hae autentikointi
    UserAccount u = userService.getUserByUsername(a.getName());
    m.addAttribute("user", u);
    if (bs.hasErrors()) {
        LOG.log(Level.WARNING,
                "Kayttaja ''{0}'' yritti ladata kuvaa, mutta syotteita ei validoitu. Onko otsikko tyhja?",
                a.getName());
        return "upload";
    }
    MultipartFile file = formData.getFile();
    String description = formData.getDescription();

    //Tiedostomuodon tarkistus
    if (!(file.getContentType().equals("image/jpg") || file.getContentType().equals("image/png")
            || file.getContentType().equals("image/jpeg") || file.getContentType().equals("image/bmp")
            || file.getContentType().equals("image/gif"))) {
        if (l.toString().equals("fi")) {
            bs.rejectValue("file", "error.file", "Tiedostomuotoa ei sallita.");
        } else {
            bs.rejectValue("file", "error.file", "File type not permitted.");
        }

        if (bs.hasErrors()) {
            LOG.log(Level.WARNING,
                    "Kayttaja ''{0}'' yritti ladata kuvaa, mutta tiedostomuotoa ''{1}'' ei sallita.",
                    new Object[] { a.getName(), file.getContentType() });
            return "upload";
        }
    } else {
        //Tallenna kuva
        Image i;
        try {
            i = imageService.addImage(u, file.getBytes(), file.getContentType(), description);
            LOG.log(Level.INFO, "Kayttaja ''{0}'' latasi uuden kuvan palveluun. Kuvan tunniste: ''{1}''",
                    new Object[] { a.getName(), i.getUuid() });
        } catch (IOException ex) {
            LOG.log(Level.SEVERE, null, ex);
            LOG.log(Level.SEVERE,
                    "Kayttaja ''{0}'' yritti ladata kuvaa palveluun, mutta tapahtui palvelinvirhe.",
                    a.getName());
            if (l.toString().equals("fi")) {
                bs.rejectValue("file", "error.file", "Kuvan lhetys eponnistui.");
            } else {
                bs.rejectValue("file", "error.file", "Image upload failed.");
            }

            return "upload";
        }

    }

    return "redirect:/";
}