com.atlassian.sal.api.user.UserProfile Java Examples
The following examples show how to use
com.atlassian.sal.api.user.UserProfile.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: CommitBlockerHook.java From pr-harmony with GNU General Public License v3.0 | 6 votes |
@Override public boolean onReceive(Repository repository, Collection<RefChange> collection, HookResponse hookResponse) { Config config = configDao.getConfigForRepo(repository.getProject().getKey(), repository.getSlug()); UserProfile user = userManager.getRemoteUser(); for(RefChange ch : collection) { String branch = regexUtils.formatBranchName(ch.getRef().getId()); Set<String> excluded = newHashSet(concat(config.getExcludedUsers(), userUtils.dereferenceGroups(config.getExcludedGroups()))); if(regexUtils.match(config.getBlockedCommits(), branch) && !excluded.contains(user.getUsername())) { hookResponse.err().write("\n" + "******************************\n" + "* !! Commit Rejected !! *\n" + "******************************\n\n" + "Direct commits are not allowed\n" + "to branch [" + branch + "].\n\n" ); return false; } } return true; }
Example #2
Source File: ConfigServlet.java From pr-harmony with GNU General Public License v3.0 | 5 votes |
@Override public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { UserProfile user = userManager.getRemoteUser(); if(user == null) { response.sendRedirect(loginUriProvider.getLoginUri(getUri(request)).toASCIIString()); } else { handleRequest(request.getRequestURI(), user.getUsername(), response); } }
Example #3
Source File: AdminConfigResource.java From stash-token-auth with GNU General Public License v3.0 | 5 votes |
@GET @Produces(MediaType.APPLICATION_JSON) public Response get(@Context HttpServletRequest request) { UserProfile user = userManager.getRemoteUser(); if (user == null || !userManager.isSystemAdmin(user.getUserKey())) { return Response.status(Response.Status.UNAUTHORIZED).build(); } return Response.ok(adminDao.getAdminConfig()).build(); }
Example #4
Source File: AdminConfigResource.java From stash-token-auth with GNU General Public License v3.0 | 5 votes |
@PUT @Consumes(MediaType.APPLICATION_JSON) public Response put(final AdminConfig config, @Context HttpServletRequest request) { final UserProfile user = userManager.getRemoteUser(); if (user == null || !userManager.isSystemAdmin(user.getUserKey())) { return Response.status(Status.UNAUTHORIZED).build(); } transactionTemplate.execute(new TransactionCallback<Object>() { @Override public Object doInTransaction() { AdminConfig current = adminDao.getAdminConfig(); //if the server secret changes, we need to invalidate all tokens if (!Objects.equals(current.getKey(), config.getKey())) { log.warn("Server secret was changed, removing all current tokens"); for (UserConfig uc : userDao.getAllUserConfigs()) { uc.setToken(null); userDao.setUserConfig(uc.getUsername(), uc); } } adminDao.setAdminConfig(config); return null; } }); return Response.noContent().build(); }
Example #5
Source File: AdminConfigServlet.java From stash-token-auth with GNU General Public License v3.0 | 5 votes |
@Override public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { UserProfile user = userManager.getRemoteUser(); if (user == null || !userManager.isSystemAdmin(user.getUserKey())) { utils.redirectToLogin(request, response); return; } response.setContentType("text/html;charset=utf-8"); renderer.render("admin.html", response.getWriter()); }
Example #6
Source File: UserConfigResource.java From stash-token-auth with GNU General Public License v3.0 | 5 votes |
@GET @Path("/") @Produces(MediaType.APPLICATION_JSON) public Response getConfig(@Context HttpServletRequest request) { UserProfile user = userManager.getRemoteUser(); String username = user.getUsername(); UserConfig config = userDao.getUserConfig(username); if (config.getToken() == null) { config.setToken(generateEncryptedToken(username)); userDao.setUserConfig(username, config); } return Response.ok(config).build(); }
Example #7
Source File: UserConfigResource.java From stash-token-auth with GNU General Public License v3.0 | 5 votes |
@GET @Path("/regenerate-token") @Produces(MediaType.APPLICATION_JSON) public Response regenerateToken(@Context HttpServletRequest request) { UserProfile user = userManager.getRemoteUser(); String username = user.getUsername(); userDao.setUserConfig(username, new UserConfig(generateEncryptedToken(username))); return Response.ok().build(); }
Example #8
Source File: UserConfigServlet.java From stash-token-auth with GNU General Public License v3.0 | 5 votes |
@Override public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { UserProfile user = userManager.getRemoteUser(); if (user == null) { utils.redirectToLogin(request, response); return; } response.setContentType("text/html;charset=utf-8"); renderer.render("user.html", response.getWriter()); }
Example #9
Source File: BaseResource.java From kitchen-duty-plugin-for-atlassian-jira with MIT License | 5 votes |
protected Boolean isUserLoggedIn() { UserProfile user = userManager.getRemoteUser(); if (user != null) { return true; } else { return false; } }
Example #10
Source File: BaseResource.java From kitchen-duty-plugin-for-atlassian-jira with MIT License | 4 votes |
public Boolean isUserNotAdmin() { UserProfile user = userManager.getRemoteUser();; return (user == null || !userManager.isAdmin(user.getUserKey())); }