List of usage examples for java.security Principal getName
public String getName();
From source file:mx.gob.cfe.documentos.web.UsuarioController.java
@RequestMapping("/ver/{id}") public String ver(@PathVariable Long id, Model model, Principal principal) { String name = principal.getName(); Usuario usuario = instance.obtinePorUsername(name); if (!usuario.isAdministrador()) { return "usuario/noAutorizado"; }/*ww w . ja v a 2s .com*/ model.addAttribute("usuario", instance.obtiene(id)); return "usuario/ver"; }
From source file:mx.gob.cfe.documentos.web.UsuarioController.java
@RequestMapping("/eliminar/{id}") public String elimina(@PathVariable Long id, Model model, RedirectAttributes redirectAttributes, Principal principal) { String name = principal.getName(); Usuario usuario = instance.obtinePorUsername(name); if (!usuario.isAdministrador()) { return "usuario/noAutorizado"; }/*from www .j a v a 2 s.c o m*/ String nombre = instance.elimina(id); redirectAttributes.addFlashAttribute("mensaje", "Se elimino el usuario" + nombre); return "redirect:/usuario"; }
From source file:com.github.iexel.fontus.web.mvc.GlobalControllerAdviceMvc.java
@ModelAttribute public void loginModel(Model model, Locale locale, Principal principal) { if (principal != null) { model.addAttribute("userName", principal.getName()); }/* w w w.j a va2 s .com*/ // model.addAttribute("springMvcLocale", locale.getLanguage()); model.addAttribute("userLocale", locale); }
From source file:mx.gob.cfe.documentos.web.UsuarioController.java
@RequestMapping public String lista(Model model, Principal principal) { String name = principal.getName(); Usuario usuario = instance.obtinePorUsername(name); if (!usuario.isAdministrador()) { return "usuario/noAutorizado"; }// w w w .j av a 2s . com model.addAttribute("usuarios", instance.lista()); List lista = instance.lista(); log.error("lista{}", lista); return "usuario/lista"; }
From source file:edu.zipcloud.cloudstreetmarket.api.controllers.SessionController.java
@RequestMapping(value = "/{username}", method = GET) @ApiOperation(value = "Get the session Id of the current authenticated user") @PreAuthorize("isAuthenticated()") public String get(@ApiParam(value = "Username: johnd") @PathVariable(value = "username") String username, HttpServletRequest request, Principal principal) { if (principal == null || !principal.getName().equals(username)) { throw new AccessDeniedException("You must be authenticated as " + username + "!"); }//from www.j a v a 2 s.c om HttpSession session = request.getSession(false); if (session != null) { return session.getId(); } return ""; }
From source file:it.greenvulcano.gvesb.identity.impl.HTTPIdentityInfo.java
@Override public String getName() { Principal p = request.getUserPrincipal(); return (p != null ? p.getName() : "NONE"); }
From source file:oauth2.controllers.ChangePasswordController.java
@ModelAttribute(FORM_ATTRIBUTE_NAME) public Object backingBean(Principal principal) { return new ChangePasswordForm(principal.getName()); }
From source file:runtheshow.resource.webservice.ArtisteService.java
@RequestMapping(value = "/current", method = RequestMethod.GET) @ResponseBody//from ww w. ja v a 2s . co m public ProfileArtiste getUserById(Principal user) { return artisteMetier.getArtisteByUserName(userMetier.getUserByName(user.getName())); }
From source file:mx.gob.cfe.documentos.web.UsuarioController.java
@RequestMapping("/crea") public String crea(@Valid Usuario usuario, RedirectAttributes redirectAttributes, BindingResult bindingResult, Model model, Principal principal) { String name = principal.getName(); Usuario usuarioSession = instance.obtinePorUsername(name); if (!usuarioSession.isAdministrador()) { return "usuario/noAutorizado"; }//from www . j a v a 2 s . c o m if (bindingResult.hasErrors()) { return "usuario/nuevo"; } Set rolesUser = new HashSet(); rolesUser.add(rolDao.obtiene("ROLE_USER")); usuario.setRoles(rolesUser); usuario.setFechaAlta(new Date()); instance.crea(usuario); redirectAttributes.addFlashAttribute("mensaje", "El usuario" + usuario.getNombre() + "ha sido creado"); return "redirect:/usuario/ver/" + usuario.getId(); }
From source file:org.keycloak.adapters.springsecurity.userdetails.authentication.DirectAccessGrantUserDetailsAuthenticationProvider.java
/** * Returns the username from the given {@link KeycloakAuthenticationToken}. By default, this method * resolves the username from the token's {@link KeycloakPrincipal}'s name. This value can be controlled * via <code>keycloak.json</code>'s * <a href="http://docs.jboss.org/keycloak/docs/1.2.0.CR1/userguide/html/ch08.html#adapter-config"><code>principal-attribute</code></a>. * For more fine-grained username resolution, override this method. * * @param token the {@link KeycloakAuthenticationToken} from which to extract the username * * @return the username to use when loading a user from the this provider's {@link UserDetailsService}. * * @see UserDetailsService#loadUserByUsername * @see OidcKeycloakAccount#getPrincipal */// w w w . j a v a 2 s . co m protected String resolveUsername(KeycloakAuthenticationToken token) { Assert.notNull(token, "KeycloakAuthenticationToken required"); Assert.notNull(token.getAccount(), "KeycloakAuthenticationToken.getAccount() cannot be return null"); OidcKeycloakAccount account = token.getAccount(); Principal principal = account.getPrincipal(); return principal.getName(); }