@GET // @RolesAllowed("user") public DrawView show() { KeycloakSecurityContext session = (KeycloakSecurityContext) request.getAttribute(KeycloakSecurityContext.class.getName()); DrawBean bean = new DrawBean(); DrawView view = new DrawView(bean); bean.setIdToken(session.getIdToken()); return view; }
jsonNode = JsonSerialization.mapper.valueToTree(securityContext.getToken()); } else if (source.startsWith("id_token[")) { jsonNode = JsonSerialization.mapper.valueToTree(securityContext.getIdToken()); } else { throw new RuntimeException("Invalid placeholder [" + placeHolder + "]");
@POST @Path("/draw") @RolesAllowed("user") public DrawView draw(@FormParam("date") String dateAsString) { KeycloakSecurityContext session = (KeycloakSecurityContext) request.getAttribute(KeycloakSecurityContext.class.getName()); DrawBean bean = new DrawBean(); LocalDate date = LocalDate.parse(dateAsString); bean.setDraw(DrawingService.drawNumbers(date)); DrawView view = new DrawView(bean); bean.setIdToken(session.getIdToken()); return view; }
/** * Create a successful result. * * @param authentication valid credentials */ public AuthResults(Authentication authentication) { Object username = null; Object details = null; if (authentication.getDetails() instanceof SimpleKeycloakAccount) { details = (SimpleKeycloakAccount) authentication.getDetails(); assert ((SimpleKeycloakAccount) details).getPrincipal() instanceof KeycloakPrincipal; final KeycloakPrincipal principal = (KeycloakPrincipal) ((SimpleKeycloakAccount) details).getPrincipal(); username = principal.getName(); if (principal.getKeycloakSecurityContext().getIdToken() != null) { username = principal.getKeycloakSecurityContext().getIdToken().getPreferredUsername(); } } else { username = authentication.getPrincipal(); details = authentication.getDetails(); } this.authentication = new UsernamePasswordAuthenticationToken( username, authentication.getCredentials(), authentication.getAuthorities()); ((UsernamePasswordAuthenticationToken) this.authentication).setDetails(details); this.challenge = null; }