Example usage for org.springframework.security.oauth2.provider OAuth2Authentication getName

List of usage examples for org.springframework.security.oauth2.provider OAuth2Authentication getName

Introduction

In this page you can find the example usage for org.springframework.security.oauth2.provider OAuth2Authentication getName.

Prototype

public String getName() 

Source Link

Usage

From source file:org.trustedanalytics.user.current.AuthDetailsFinder.java

@Override
public String findUserName(Authentication authentication) {
    if (authentication == null) {
        throw new IllegalArgumentException("Authentication argument must not be null");
    }//from w  w  w .j av  a2 s  .c om
    OAuth2Authentication oauth2 = (OAuth2Authentication) authentication;
    return oauth2.getName();
}

From source file:com.epam.reportportal.auth.SsoEndpoint.java

@RequestMapping(value = { "/sso/me/apitoken" }, method = RequestMethod.POST)
public OAuth2AccessToken createApiToken(OAuth2Authentication user) {
    tokenServicesFacade.revokeUserTokens(user.getName(), ReportPortalClient.api);
    return tokenServicesFacade.createToken(ReportPortalClient.api, user.getName(),
            user.getUserAuthentication());
}

From source file:org.trustedanalytics.servicecatalog.service.rest.ServiceInstancesControllerHelpers.java

public String findUserName(Authentication authentication) {
    if (authentication == null) {
        throw new IllegalArgumentException("Authentication argument must not be null");
    }/*from   w w w. j  a v a 2 s  .  com*/
    OAuth2Authentication oauth2 = (OAuth2Authentication) authentication;
    return oauth2.getName();
}

From source file:com.ar.dev.tierra.api.controller.DetalleNotaCreditoController.java

@RequestMapping(value = "/add", method = RequestMethod.POST)
public ResponseEntity<?> add(@RequestBody DetalleNotaCredito detalleNotaCredito,
        OAuth2Authentication authentication) {
    Usuarios user = facadeService.getUsuariosDAO().findUsuarioByUsername(authentication.getName());
    detalleNotaCredito.setFechaCreacion(new Date());
    detalleNotaCredito.setUsuarioCreacion(user.getIdUsuario());
    facadeService.getDetalleNotaCreditoDAO().add(detalleNotaCredito);
    JsonResponse msg = new JsonResponse("Success", "Detalle agregado con exito");
    return new ResponseEntity<>(msg, HttpStatus.OK);
}

From source file:com.ar.dev.tierra.api.controller.DetalleNotaCreditoController.java

@RequestMapping(value = "/update", method = RequestMethod.POST)
public ResponseEntity<?> update(@RequestBody DetalleNotaCredito detalleNotaCredito,
        OAuth2Authentication authentication) {
    Usuarios user = facadeService.getUsuariosDAO().findUsuarioByUsername(authentication.getName());
    detalleNotaCredito.setFechaModificacion(new Date());
    detalleNotaCredito.setUsuarioModificacion(user.getIdUsuario());
    facadeService.getDetalleNotaCreditoDAO().update(detalleNotaCredito);
    JsonResponse msg = new JsonResponse("Success", "Detalle modificado con exito");
    return new ResponseEntity<>(msg, HttpStatus.OK);
}

From source file:com.climate.oada.security.oauth.TokenServicesImpl.java

@Override
public OAuth2AccessToken createAccessToken(OAuth2Authentication authentication) throws AuthenticationException {
    LOG.debug("Generating OAuth Token for principal: " + authentication.getName());
    DefaultOAuth2AccessToken result = null;
    String randomUUID = UUID.randomUUID().toString();
    MessageDigest md = null;/*w  w w.  j  a va 2 s  . c  o  m*/
    try {
        byte[] emailBytes = authentication.getName().getBytes("UTF-8");
        md = MessageDigest.getInstance("MD5");
        String emailDigest = new String(Base64.encodeBase64(md.digest(emailBytes)));
        String token = randomUUID + emailDigest;
        result = new DefaultOAuth2AccessToken(token);
        int validitySeconds = getAccessTokenValiditySeconds(authentication.getAuthorizationRequest());
        if (validitySeconds > 0) {
            result.setExpiration(new Date(System.currentTimeMillis() + (validitySeconds * SEC_TO_MSEC)));
        }
        result.setTokenType("Bearer");
        tokenStore.storeAccessToken(result, authentication);
    } catch (Exception e) {
        LOG.error("Unable to generate OAuth token: " + e.getMessage());
    }
    return result;
}

From source file:com.ar.dev.tierra.api.controller.CategoriaController.java

@RequestMapping(value = "/update", method = RequestMethod.POST)
public ResponseEntity<?> update(OAuth2Authentication authentication, @RequestBody Categoria categoria) {
    Usuarios user = facadeService.getUsuariosDAO().findUsuarioByUsername(authentication.getName());
    categoria.setUsuarioModificacion(user.getIdUsuario());
    categoria.setFechaModificacion(new Date());
    facadeService.getCategoriaDAO().update(categoria);
    JsonResponse msg = new JsonResponse("Success", "Categoria modificada con exito");
    return new ResponseEntity<>(msg, HttpStatus.OK);
}

From source file:com.ar.dev.tierra.api.controller.CategoriaController.java

@RequestMapping(value = "/add", method = RequestMethod.POST)
public ResponseEntity<?> add(OAuth2Authentication authentication, @RequestBody Categoria categoria) {
    Usuarios user = facadeService.getUsuariosDAO().findUsuarioByUsername(authentication.getName());
    categoria.setUsuarioCreacion(user.getIdUsuario());
    categoria.setFechaCreacion(new Date());
    categoria.setEstado(true);/*w  ww.j  a  v a  2 s  .  c  o m*/
    facadeService.getCategoriaDAO().add(categoria);
    JsonResponse msg = new JsonResponse("Success", "Categoria agregada con exito");
    return new ResponseEntity<>(msg, HttpStatus.OK);
}

From source file:com.ar.dev.tierra.api.controller.CategoriaController.java

@PreAuthorize("hasAnyAuthority('ROLE_ADMIN, ROLE_REPOSITOR')")
@RequestMapping(value = "/delete", method = RequestMethod.POST)
public ResponseEntity<?> delete(OAuth2Authentication authentication, @RequestBody Categoria categoria) {
    Usuarios user = facadeService.getUsuariosDAO().findUsuarioByUsername(authentication.getName());
    categoria.setEstado(false);/*from ww w. ja  v  a2  s  .  c o m*/
    categoria.setUsuarioModificacion(user.getIdUsuario());
    categoria.setFechaModificacion(new Date());
    facadeService.getCategoriaDAO().update(categoria);
    JsonResponse msg = new JsonResponse("Success", "Categoria eliminada con exito");
    return new ResponseEntity<>(msg, HttpStatus.OK);
}

From source file:com.ar.dev.tierra.api.controller.EntidadBancariaController.java

@RequestMapping(value = "/add", method = RequestMethod.POST)
public ResponseEntity<?> add(OAuth2Authentication authentication, @RequestBody EntidadBancaria bancaria) {
    Usuarios user = facadeService.getUsuariosDAO().findUsuarioByUsername(authentication.getName());
    bancaria.setUsuarioCreacion(user.getIdUsuario());
    bancaria.setFechaCreaciion(new Date());
    facadeService.getEntidadBancariaDAO().add(bancaria);
    JsonResponse msg = new JsonResponse("Success", "Entidad agregada con exito");
    return new ResponseEntity<>(msg, HttpStatus.OK);
}