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:cherry.sqlman.tool.clause.SqlClauseControllerImpl.java

@Override
public ModelAndView create(SqlClauseForm form, BindingResult binding, Authentication auth, Locale locale,
        SitePreference sitePref, NativeWebRequest request) {

    if (hasErrors(form, binding)) {
        return withViewname(viewnameOfStart).build();
    }/*from  w ww.  j a v  a2 s.c o m*/

    int id = clauseService.create(form, auth.getName());
    return redirect(redirectOnCreate(id)).build();
}

From source file:cherry.sqlapp.controller.sqltool.search.SqltoolSearchControllerImpl.java

@Override
public ModelAndView execute(SqltoolSearchForm form, BindingResult binding, Authentication auth, Locale locale,
        SitePreference sitePref, HttpServletRequest request) {

    if (binding.hasErrors()) {
        ModelAndView mav = new ModelAndView(PathDef.VIEW_SQLTOOL_SEARCH_INIT);
        return mav;
    }//  w w  w . j a  v  a 2 s. com

    MetadataCondition cond = formUtil.createSqlCondition(form, auth.getName());
    long pageNo = form.getPageNo();
    long pageSz = (form.getPageSz() <= 0 ? defaultPageSize : form.getPageSz());

    PagedList<SqltoolMetadata> result = metadataService.search(cond, pageNo, pageSz);

    ModelAndView mav = new ModelAndView(PathDef.VIEW_SQLTOOL_SEARCH_INIT);
    mav.addObject(result);
    return mav;
}

From source file:com.cami.persistence.service.impl.RoleService.java

@Override
public Role updateUser(final Role role) {

    Authentication auth = SecurityContextHolder.getContext().getAuthentication();
    BCryptPasswordEncoder passwordEncoder = new BCryptPasswordEncoder();
    final Role userConnected = roleDao.retrieveAUser(auth.getName()); // get the current logged user
    final Role roleToUpdate = roleDao.findOne(role.getId());
    User userToUpdate;//from  w  w w .  j a  v  a2 s. c  om
    System.out.println("updating user with ID " + role.getId());
    System.out.println("in updateUser service method ...");

    if (!userConnected.getRole().equals("ROLE_ADMIN")) {
        System.out.println("userConected is not admin launching his update of password ...");
        userToUpdate = userDao.findByUsername(userConnected.getUser().getUsername());
        System.out.println("his username is " + userToUpdate.getUsername());
        System.out.println("encrypting his password ...");
        userToUpdate.setPassword(passwordEncoder.encode(role.getUser().getPassword()));
        System.out.println(" password encrypted  \n Saving new configuration ....");
        userToUpdate = userDao.save(userToUpdate);
        System.out.println("configuration saved");
        roleToUpdate.setUser(userToUpdate);
        System.out.println("updating cache ....");
        return roleDao.save(roleToUpdate);
    } else {
        userToUpdate = role.getUser();
        userToUpdate.setEnabled(role.getUser().isEnabled());
        userToUpdate.setNom(role.getUser().getNom());
        userToUpdate.setUsername(role.getUser().getUsername());
        userToUpdate.setPassword(passwordEncoder.encode(role.getUser().getPassword()));
        userToUpdate = userDao.save(userToUpdate);

        final String vraiRole = getTheRealRoleOf(role.getRole());
        roleToUpdate.setUser(userToUpdate);
        roleToUpdate.setRole(vraiRole);
        System.out.println("in update service user role= " + roleToUpdate.getRole());
        System.out.println("updating ... ");
        Role r = roleDao.save(roleToUpdate);
        System.out.println("update finished");
        System.out.println("userToUpdate's username is " + r.getUser().getUsername());
        System.out.println("\n \n \n \n in updateUser service method displaying user updated ");
        System.out.println("deleteAction of a user =" + role.getId() + " -Role=" + role.getRole() + " username="
                + role.getUser().getUsername() + " enabled=" + role.getUser().isEnabled());

        return r;
    }

}

From source file:org.mitre.uma.web.ClaimsAPI.java

@RequestMapping(value = "/{rsid}", method = RequestMethod.PUT, consumes = MimeTypeUtils.APPLICATION_JSON_VALUE, produces = MimeTypeUtils.APPLICATION_JSON_VALUE)
public String setClaimsForResourceSet(@PathVariable(value = "rsid") Long rsid, @RequestBody String jsonString,
        Model m, Authentication auth) {

    ResourceSet rs = resourceSetService.getById(rsid);

    if (rs == null) {
        m.addAttribute(HttpCodeView.CODE, HttpStatus.NOT_FOUND);
        return HttpCodeView.VIEWNAME;
    }//from w w w .j av a  2  s  . c om

    if (!rs.getOwner().equals(auth.getName())) {
        // authenticated user didn't match the owner of the resource set
        m.addAttribute(HttpCodeView.CODE, HttpStatus.FORBIDDEN);
        return HttpCodeView.VIEWNAME;
    }

    @SuppressWarnings("serial")
    Set<Claim> claims = (new Gson()).fromJson(jsonString, new TypeToken<Set<Claim>>() {
    }.getType());

    rs.setClaimsRequired(claims);

    resourceSetService.update(rs, rs);

    m.addAttribute(JsonEntityView.ENTITY, rs.getClaimsRequired());

    return JsonEntityView.VIEWNAME;
}

From source file:com.companyname.services.PlatUserAuthenticationCache.java

public void add(Authentication authentication) {
    Assert.notNull(authentication, "cannot cache a null authentication");
    init();//w w w  .  j a  v a 2  s . c o m
    String key = getHashKey(authentication);

    if (!cache.containsKey(key)) {
        cache.put(key, authentication);
        logger.info("authentication request is cached for user " + authentication.getName());
    } else {
        logger.info("authentication request was already cached for user " + authentication.getName());
    }
}

From source file:com.companyname.services.PlatUserAuthenticationCache.java

public void remove(Authentication authentication) {
    Assert.notNull(authentication, "cann't remove a null authentication");
    init();//from ww w  . j  ava2s.  c  o m
    String key = getHashKey(authentication);

    if (cache.containsKey(key)) {
        cache.remove(key);
        logger.info("authentication request is removed from cache for user " + authentication.getName());
    } else {
        logger.info(
                "authentication request is not in the cache to remove for user " + authentication.getName());
    }
}

From source file:com.kdubb.socialshowcaseboot.config.SocialConfig.java

@Override
public UserIdSource getUserIdSource() {
    return new UserIdSource() {
        @Override//  w w  w  .  j a v a2 s  .co m
        public String getUserId() {
            Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
            if (authentication == null) {
                throw new IllegalStateException("Unable to get a ConnectionRepository: no user signed in");
            }
            return authentication.getName();
        }
    };
}

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

/**
 * Kommentin poistaminen sen ID:n perusteella Asetetaan lippu "deleted" true
 * -arvoon jotta kommentti ei ny. Tllin vltetn Data violation
 * exceptionit jne./*w w  w  . j av a  2  s.c  om*/
 *
 * @param a Autentikointi
 * @param commentId Kommentin id
 * @return Nkym
 */
@Transactional
@RequestMapping(value = "/comment", method = RequestMethod.POST)
public String deleteComment(Authentication a, @RequestParam Long commentId) {
    Comment c = commentRepo.findOne(commentId);
    //Aseta pois nkyvilt
    c.setVisible(false);
    commentRepo.save(c);
    LOG.log(Level.INFO, "Paakayttaja ''{0}'' poisti kayttajan ''{1}'' kommentin viestin sisallolla \"{2}\"",
            new Object[] { a.getName(), c.getUser().getUsername(), c.getBody() });
    return "redirect:/";
}

From source file:org.cloudfoundry.identity.uaa.login.DefaultAutologinCodeStore.java

@Override
public String storeUser(Authentication user) {
    flush();//from   www .j  a  v a  2 s.c  om
    String code = generator.generate();
    TokenExpiry expiry = new TokenExpiry(code, user, new Date(System.currentTimeMillis() + validityPeriod));
    this.expiryQueue.put(expiry);
    codes.put(code, expiry);
    logger.info("Stored user [" + user.getName() + "] with code: " + code);
    return code;
}