@Override public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.getWriter().write("This is a public servlet \n"); String webName = null; if (request.getUserPrincipal() != null) { webName = request.getUserPrincipal().getName(); } response.getWriter().write("web username: " + webName + "\n"); boolean webHasRole = request.isUserInRole("architect"); response.getWriter().write("web user has role \"architect\": " + webHasRole + "\n"); }
/** Returns true if {@code toVerify} was signed by {@code signingCert}'s public key. */ private boolean verifySignature(X509Certificate toVerify, X509Certificate signingCert) { if (!toVerify.getIssuerDN().equals(signingCert.getSubjectDN())) return false; try { toVerify.verify(signingCert.getPublicKey()); return true; } catch (GeneralSecurityException verifyFailed) { return false; } }
private SigModel(X509Certificate cert) { this.subject=cert.getSubjectDN().toString(); this.issuer=cert.getIssuerDN().toString(); this.validDates= FORMAT.format(cert.getNotBefore())+" to "+ FORMAT.format(cert.getNotAfter()); } }
@GET @Timed @Produces(APPLICATION_JSON_WITH_CHARSET) @RolesAllowed({"admin", "$dynamic"}) public Object list(@Context GraphManager manager, @Context SecurityContext sc) { Set<String> graphs = manager.graphs(); String role = sc.getUserPrincipal().getName(); if (role.equals("admin")) { return ImmutableMap.of("graphs", graphs); } else { // Filter by user role String graph = role; if (graphs.contains(graph)) { return ImmutableMap.of("graphs", ImmutableList.of(graph)); } else { return ImmutableMap.of("graphs", ImmutableList.of()); } } }
spaceAvailable.set(false); if (logger.isDebugEnabled()) { logger.debug("Received request from " + request.getRemoteHost() + " but no space available; Indicating Service Unavailable"); response.sendError(HttpServletResponse.SC_SERVICE_UNAVAILABLE); return; } else { response.setHeader("Content-Type", MediaType.TEXT_PLAIN); final boolean contentGzipped = Boolean.parseBoolean(request.getHeader(GZIPPED_HEADER)); final X509Certificate[] certs = (X509Certificate[]) request.getAttribute("javax.servlet.request.X509Certificate"); foundSubject = DEFAULT_FOUND_SUBJECT; if (certs != null && certs.length > 0) { for (final X509Certificate cert : certs) { foundSubject = cert.getSubjectDN().getName(); if (authorizedPattern.matcher(foundSubject).matches()) { break; } else { logger.warn("Rejecting transfer attempt from " + foundSubject + " because the DN is not authorized, host=" + request.getRemoteHost()); response.sendError(HttpServletResponse.SC_FORBIDDEN, "not allowed based on dn"); return;
@Override public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.getWriter().write("This is a public servlet \n"); String webName = null; boolean isCustomPrincipal = false; if (request.getUserPrincipal() != null) { Principal principal = request.getUserPrincipal(); isCustomPrincipal = principal instanceof MyPrincipal; webName = principal.getName(); } boolean webHasRole = request.isUserInRole("architect"); response.getWriter().write("isCustomPrincipal: " + isCustomPrincipal + "\n"); response.getWriter().write("web username: " + webName + "\n"); response.getWriter().write("web user has role \"architect\": " + webHasRole + "\n"); HttpSession session = request.getSession(false); if (session != null) { response.getWriter().write("Session ID: " + session.getId()); } else { response.getWriter().write("No session"); } }
@Override public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.getWriter().write("This is a public servlet \n"); if (request.getUserPrincipal() != null) { webName = request.getUserPrincipal().getName(); response.getWriter().write("before web username: " + webName + "\n"); boolean webHasRole = request.isUserInRole("architect"); response.getWriter().write("before web user has role \"architect\": " + webHasRole + "\n"); if (request.getUserPrincipal() != null) { webName = request.getUserPrincipal().getName();
public boolean logout(final HttpServletRequest request, final HttpServletResponse response) throws AuthenticatorException { final HttpSession session = request.getSession(); final Principal p = (Principal) session.getAttribute(LOGGED_IN_KEY); LOGGER.debug("Logging out [{}] from CAS.", p.getName()); session.setAttribute(LOGGED_OUT_KEY, p); session.setAttribute(LOGGED_IN_KEY, null); session.setAttribute(AbstractCasFilter.CONST_CAS_ASSERTION, null); return true; } }
@Override protected void doDelete(final HttpServletRequest request, final HttpServletResponse response) throws ServletException, IOException { final X509Certificate[] certs = (X509Certificate[]) request.getAttribute("javax.servlet.request.X509Certificate"); String foundSubject = DEFAULT_FOUND_SUBJECT; if (certs != null && certs.length > 0) { for (final X509Certificate cert : certs) { foundSubject = cert.getSubjectDN().getName(); if (authorizedPattern.matcher(foundSubject).matches()) { break; } else { logger.warn(processor + " rejecting transfer attempt from " + foundSubject + " because the DN is not authorized"); response.sendError(HttpServletResponse.SC_FORBIDDEN, "not allowed based on dn"); return; final String uri = request.getRequestURI(); final int slashIndex = uri.lastIndexOf("/"); int questionIndex = uri.indexOf("?"); session.commit(); response.setStatus(HttpServletResponse.SC_OK); response.flushBuffer(); } catch (final Throwable t) {
protected String getUserName(HttpServletRequest request) { Principal principal = request.getUserPrincipal(); String username = (principal == null) ? request.getSession().getId() : principal.getName(); return username; }
AwsProxyRequest req = (AwsProxyRequest)servletRequest.getAttribute(API_GATEWAY_EVENT_PROPERTY); AwsProxyRequestContext gatewayContext = req.getRequestContext(); logLineBuilder.append(servletRequest.getRemoteAddr()); logLineBuilder.append(" "); if (ctx != null && ctx.getUserPrincipal().getName() != null) { logLineBuilder.append(ctx.getUserPrincipal().getName()); logLineBuilder.append(" "); logLineBuilder.append(servletRequest.getMethod().toUpperCase(Locale.ENGLISH)); logLineBuilder.append(" "); logLineBuilder.append(servletRequest.getRequestURI()); logLineBuilder.append(servletResponse.getStatus()); logLineBuilder.append(" ");
if (request.getUserPrincipal() != null) { webName = request.getUserPrincipal().getName(); request.logout(); HttpSession session = request.getSession(false); if (session != null) { session.invalidate(); if (request.getUserPrincipal() != null) { webNameAfterLogout = request.getUserPrincipal().getName(); response.getWriter().write("web username: " + webName + "\n" + "EJB username: " + ejbName + "\n"); response.getWriter().write("web username after logout: " + webNameAfterLogout + "\n" + "EJB username after logout: " + ejbNameAfterLogout + "\n");
@GET @Path( "/{username}" ) public Response getUser( @PathParam( "username" ) String username, @Context HttpServletRequest req ) { Principal principal = req.getUserPrincipal(); if ( principal == null || !principal.getName().equals( username ) ) { return output.notFound(); } LoginContext loginContext = getLoginContextFromUserPrincipal( principal ); UserManager userManager = userManagerSupplier.getUserManager( loginContext.subject(), false ); try { User user = userManager.getUser( username ); return output.ok( new AuthorizationRepresentation( user ) ); } catch ( InvalidArgumentsException e ) { return output.notFound(); } }
public void handle(HttpServletRequest request, HttpServletResponse response, FilterChain chain) throws IOException, ServletException { if (request != null) { LOG.info("Access from: {} url: {} principal: {}", request.getRemoteAddr(), request.getRequestURL(), (request.getUserPrincipal() == null ? "" : request.getUserPrincipal().getName())); } chain.doFilter(request, response); }
public TUGIAssumingTransportFactory(TTransportFactory wrapped, Subject subject) { this.wrapped = wrapped; this.subject = subject; Set<Principal> principals = (Set<Principal>) subject.getPrincipals(); if (principals.size() > 0) { LOG.info("Service principal:" + ((Principal) (principals.toArray()[0])).getName()); } }
@Override public String greet(String name) { try { System.out.println("context path (HttpServletRequest): " + httpServletRequest.getContextPath()); System.out.println("session id: " + httpSession.getId()); System.out.println("context path (ServletContext): " + servletContext.getContextPath()); System.out.println("user transaction status: " + ut.getStatus()); System.out.println("security principal: " + principal.getName()); } catch (SystemException ex) { Logger.getLogger(SimpleGreeting.class.getName()).log(Level.SEVERE, null, ex); } return "Hello " + name; }
/** * This is called to determine if the Principal is already in the HttpSession in a Seraph ready manner. * * @param httpServletRequest the request in play * @param principal the principal to put in the session * @return true if the principal is already in the session */ protected boolean isPrincipalAlreadyInSessionContext(final HttpServletRequest httpServletRequest, final Principal principal) { Principal currentPrincipal = (Principal) httpServletRequest.getSession().getAttribute(LOGGED_IN_KEY); return currentPrincipal != null && currentPrincipal.getName() != null && principal != null && currentPrincipal.getName().equals(principal.getName()); }
protected String getDistinguishedName(final X509Certificate[] certs) { if (certs != null && certs.length > 0 && certs[0] != null) { return certs[0].getSubjectDN().getName(); } else { return null; } }
Principal principal = securityContext.getUserPrincipal(); String username = principal.getName();
@POST @Produces(APPLICATION_JSON) public SupportResponse submit(@PathParam("jobId") JobId jobId) throws IOException, UserNotFoundException { return supportService.uploadSupportRequest(context.getUserPrincipal().getName(), jobId); }