Refine search
import javax.servlet.http.HttpServletRequest; @GET @Path("/yourservice") @Produces("text/xml") public void activate(@Context HttpServletRequest requestContext,@Context SecurityContext context){ String yourIP = requestContext.getRemoteAddr(); //If security is enabled Principal principal = context.getUserPrincipal(); String userName = principal.getName(); }
/** * Get the user name from the security context, i.e. the user making the HTTP request. * With simple/pseudo security mode this should return the * value of user.name query param, in kerberos mode it's the kinit'ed user. */ private String getRequestingUser() { if (theSecurityContext == null) { return null; } String userName = null; if (theSecurityContext.getUserPrincipal() == null) { userName = Main.UserNameHandler.getUserName(request); } else { userName = theSecurityContext.getUserPrincipal().getName(); } if(userName == null) { return null; } //map hue/foo.bar@something.com->hue since user group checks // and config files are in terms of short name return UserGroupInformation.createRemoteUser(userName).getShortUserName(); }
public static Map<String, Object> toMapModel(SecurityContext sc, Map<String, Object> model) { model.put("clusterName", config.getString(DrillOnYarnConfig.APP_NAME)); boolean useAuth = AMSecurityManagerImpl.isEnabled(); final boolean isUserLoggedIn = (useAuth) ? AuthDynamicFeature.isUserLoggedIn(sc) : false; model.put("showLogin", useAuth && !isUserLoggedIn); model.put("showLogout", isUserLoggedIn); model.put("docsLink", config.getString(DrillOnYarnConfig.HTTP_DOCS_LINK)); String userName = isUserLoggedIn ? sc.getUserPrincipal().getName() : DrillUserPrincipal.ANONYMOUS_USER; model.put("loggedInUserName", userName); return model; } }
@Override public String getRemoteUser() { return securityContext.getUserPrincipal().getName(); }
public String getDefaultPrivateSelector() { if (userPrincipalAsPrivateSelector) { SecurityContext securityContext = ResteasyContext.getContextData(SecurityContext.class); if (securityContext != null) { return securityContext.getUserPrincipal().getName(); } } return null; }
@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()); } } }
if (ctx != null && ctx.getUserPrincipal().getName() != null) { logLineBuilder.append(ctx.getUserPrincipal().getName()); logLineBuilder.append(" ");
@Context public void setSecurityContext(SecurityContext context) { if (context != null && context.getUserPrincipal() != null) { username = context.getUserPrincipal().getName(); } }
@Context public void setSecurityContext(SecurityContext context) { if (context != null && context.getUserPrincipal() != null) { username = context.getUserPrincipal().getName(); } }
public static String getUser() { SecurityContext sc = SecurityContextUtil.getSC(); if ((sc != null) && (sc.getUserPrincipal() != null)) { return sc.getUserPrincipal().getName(); } return null; }
public static final String getUser() { SecurityContext sc = SecurityContextUtil.getSC(); if ((sc != null) && (sc.getUserPrincipal() != null)) { return sc.getUserPrincipal().getName(); } return null; }
@POST @Produces(APPLICATION_JSON) public SupportResponse submit(@PathParam("jobId") JobId jobId) throws IOException, UserNotFoundException { return supportService.uploadSupportRequest(context.getUserPrincipal().getName(), jobId); }
@PUT @Consumes(APPLICATION_JSON) @Produces(APPLICATION_JSON) @RolesAllowed(Roles.ADMIN) @Path("/{oAuthProviderName}") @ApiOperation(value = "Update OAuth provider", httpMethod = HttpMethod.PUT) public Response update(@PathParam("oAuthProviderName") String oAuthProviderName, PatchData patch, @Context SecurityContext securityContext) { service.updateOAuthProvider(oAuthProviderName, patch, securityContext.getUserPrincipal().getName()); return status(Response.Status.OK).build(); }
@DELETE @Produces(APPLICATION_JSON) @RolesAllowed(Roles.ADMIN) @Path("/{oAuthProviderName}") @ApiOperation(value = "Remove OAuth provider", httpMethod = HttpMethod.DELETE) public Response remove(@PathParam("oAuthProviderName") String oAuthProviderName, @Context SecurityContext securityContext) { service.removeOAuthProvider(oAuthProviderName, securityContext.getUserPrincipal().getName()); return status(Response.Status.OK).build(); } }
@POST @Consumes(APPLICATION_JSON) @Produces(APPLICATION_JSON) @RolesAllowed(Roles.ADMIN) @ApiOperation(value = "Create OAuth provider", httpMethod = HttpMethod.POST) public Response create(OAuthProvider oAuthProvider, @Context SecurityContext securityContext) { service.createOAuthProvider(oAuthProvider, securityContext.getUserPrincipal().getName()); return status(Response.Status.CREATED).build(); }
@GET @Path("/folder/{path: .*}") @Produces(MediaType.APPLICATION_JSON) public Folder getFolder(@PathParam("path") String path, @QueryParam("includeContents") @DefaultValue("true") boolean includeContents) throws NamespaceException, IOException, SourceFolderNotFoundException, PhysicalDatasetNotFoundException, SourceNotFoundException { sourceService.checkSourceExists(sourceName); SourceFolderPath folderPath = SourceFolderPath.fromURLPath(sourceName, path); return sourceService.getFolder(sourceName, folderPath, includeContents, securityContext.getUserPrincipal().getName()); }
private void checkUser(UserName userName, String action) throws DACUnauthorizedException { if (!securityContext.isUserInRole("admin") && !securityContext.getUserPrincipal().getName().equals(userName.getName())) { throw new DACUnauthorizedException(format("User %s is not allowed to %s user %s", securityContext.getUserPrincipal().getName(), action, userName.getName())); } }
@POST @Path("/{id}/cancel") public void cancelJob(@PathParam("id") String id) throws JobException { final String username = securityContext.getUserPrincipal().getName(); try { jobs.cancel(username, new JobId(id), String.format("Query cancelled by user '%s'", username)); } catch (JobNotFoundException e) { throw new NotFoundException(String.format("Could not find a job with id [%s]", id)); } } }
@PUT @Consumes(APPLICATION_JSON) @Produces(APPLICATION_JSON) @Path("/{topicName}") @RolesAllowed({Roles.TOPIC_OWNER, Roles.ADMIN}) @ApiOperation(value = "Update topic", httpMethod = HttpMethod.PUT) public Response update(@PathParam("topicName") String qualifiedTopicName, PatchData patch, @Context SecurityContext securityContext) { String updatedBy = securityContext.getUserPrincipal().getName(); topicService.updateTopicWithSchema(TopicName.fromQualifiedName(qualifiedTopicName), patch, updatedBy); return status(Response.Status.OK).build(); }
@Override public void filter(ContainerRequestContext requestContext, ContainerResponseContext responseContext) throws IOException { String absolutePath = uriInfo.getAbsolutePath().toString(); int status = responseContext.getStatus(); Principal principal = securityContext.getUserPrincipal(); String principalName = principal.getName(); }