Example usage for org.springframework.security.core.context SecurityContextHolder getContext

List of usage examples for org.springframework.security.core.context SecurityContextHolder getContext

Introduction

In this page you can find the example usage for org.springframework.security.core.context SecurityContextHolder getContext.

Prototype

public static SecurityContext getContext() 

Source Link

Document

Obtain the current SecurityContext.

Usage

From source file:com.kirayim.homesec.service.impl.CameraManagerImpl.java

@Override
public Camera save(Camera object) {

    // New object
    if (object.getCameraId() == null) {
        object.setCreationTime(new Date());

        User user = (User) SecurityContextHolder.getContext().getAuthentication().getPrincipal();

        object.setOwner(user);//ww w . j a  v  a2 s  .co  m
    }

    return super.save(object); //To change body of generated methods, choose Tools | Templates.
}

From source file:org.jtalks.common.security.SecurityContextFacade.java

/**
 * @return {@code SecurityContext} from {@code SecurityContextHolder}
 */
public SecurityContext getContext() {
    return SecurityContextHolder.getContext();
}

From source file:BusinessLayer.service.CloseacService.java

public Double closeAccount(String password) {
    CustomSecurityUser currentUser = (CustomSecurityUser) SecurityContextHolder.getContext().getAuthentication()
            .getPrincipal();//ww w.j av  a 2 s .c  o m
    System.out.println(currentUser.getId());

    Utilisateur utilisateur = userDAO.getUser(currentUser.getId());

    if (!utilisateur.getEnabled()) {
        throw new DisabledUserProfileException();
    }

    if (!(utilisateur.getPass().equals(password))) {
        throw new WrongPasswordException();
    }

    utilisateur.setEnabled(Boolean.FALSE);

    userDAO.saveUser(utilisateur);

    List useraccounts = accountDAO.getUserAccounts(currentUser.getId());

    Double somme = 0.0;
    for (Object account : useraccounts) {
        somme += ((Compte) account).getSolde();
    }

    return somme;

}

From source file:security.data.SecurityEvaluationContextExtension.java

@Override
public SecurityExpressionRoot getRootObject() {
    Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
    return new SecurityExpressionRoot(authentication) {
    };/* w  w  w .  j  a  v a2  s .  co  m*/
}

From source file:nl.surfnet.coin.selfservice.util.SpringSecurity.java

/**
 * @return/*from w w  w .  ja v  a  2  s .  c o  m*/
 */
public static boolean isFullyAuthenticated() {
    final Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
    return authentication != null && authentication.isAuthenticated()
            && authentication.getPrincipal() instanceof CoinUser;
}

From source file:com.mycompany.projetsportmanager.spring.rest.controllers.SecurityController.java

@RequestMapping(method = RequestMethod.GET, produces = "application/json; charset=utf-8")
public UserProfilesAccessKey securitiesGet(HttpServletRequest request) {
    final SecurityContext securityContext = SecurityContextHolder.getContext();
    if (securityContext != null
            && securityContext.getAuthentication().getPrincipal() instanceof AuthenticatedUserDTO) {
        return ((AuthenticatedUserDTO) securityContext.getAuthentication().getPrincipal())
                .getUserProfilesAccessKey();
    }/*from   w  ww  .j  av a 2s  .  c o  m*/
    return new UserProfilesAccessKey();
}

From source file:web.Controller.AddUserController.java

protected Object formBackingObject(HttpServletRequest request) {
    CustomSecurityUser currentUser = (CustomSecurityUser) SecurityContextHolder.getContext().getAuthentication()
            .getPrincipal();/*from w  w w. j  a va 2 s  .c o  m*/
    System.out.println(currentUser.getId());
    return new CommandAddUser();
}

From source file:com.minlia.cloud.framework.common.security.SpringSecurityUtil.java

public static User authenticate(final String key, final String uuid) {
    final SpringSecurityPrincipal principal = new SpringSecurityPrincipal(randomAlphabetic(6),
            randomAlphabetic(6), true, Lists.<GrantedAuthority>newArrayList(), uuid);
    SecurityContextHolder.getContext().setAuthentication(
            new RunAsUserToken(key, principal, null, Lists.<GrantedAuthority>newArrayList(), null));

    return principal;
}

From source file:org.kamranzafar.xmpp.template.rest.XmppPrebindResource.java

@RequestMapping(method = RequestMethod.GET)
@ResponseBody
public XmppUser prebind() {
    return (XmppUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
}

From source file:com.trenako.security.SpringSecurityService.java

private SecurityContext getSecContext() {
    return SecurityContextHolder.getContext();
}