本文整理汇总了Java中com.atlassian.confluence.user.AuthenticatedUserThreadLocal类的典型用法代码示例。如果您正苦于以下问题:Java AuthenticatedUserThreadLocal类的具体用法?Java AuthenticatedUserThreadLocal怎么用?Java AuthenticatedUserThreadLocal使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
AuthenticatedUserThreadLocal类属于com.atlassian.confluence.user包,在下文中一共展示了AuthenticatedUserThreadLocal类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getProfile
import com.atlassian.confluence.user.AuthenticatedUserThreadLocal; //导入依赖的package包/类
@GET
@Path("/{username}")
@AnonymousAllowed
@Produces({"application/json"})
public Response getProfile(@PathParam("username") String username) {
final Response response;
final ConfluenceUser user = _userAccessor.getUserByName(username);
final ConfluenceUser currentUser = AuthenticatedUserThreadLocal.get();
final Locale locale = currentUser != null ? _localeManager.getLocale(currentUser) : null;
if (user == null || !_userHelper.isProfileViewPermitted()) {
response = getNotFoundResponse();
} else {
final UserDto original = _userDtoFactory.getUserDto(user);
final ExtendedUserDto dto = new ExtendedUserDto(original, createGroupsFor(currentUser, user, locale));
response = ok(dto).build();
}
return response;
}
示例2: getRemoteUser
import com.atlassian.confluence.user.AuthenticatedUserThreadLocal; //导入依赖的package包/类
public User getRemoteUser()
{
HttpServletRequest request = ServletActionContext.getRequest();
if (request != null)
{
String remoteUserName = request.getRemoteUser();
if (remoteUserName != null)
{
return getUserAccessor().getUser(remoteUserName);
}
}
return AuthenticatedUserThreadLocal.getUser();
}
示例3: newFriendlyDateFormatter
import com.atlassian.confluence.user.AuthenticatedUserThreadLocal; //导入依赖的package包/类
protected FriendlyDateFormatter newFriendlyDateFormatter() {
// Get current user's timezone, or default one
User authUser = AuthenticatedUserThreadLocal.getUser();
TimeZone timeZone;
if (authUser == null) {
// anonymous
timeZone = TimeZone.getDefault();
} else {
ConfluenceUserPreferences prefs = userAccessor
.getConfluenceUserPreferences(authUser);
timeZone = prefs.getTimeZone();
}
// Build date formatter
DateFormatter dateFormatter = new DateFormatter(timeZone,
formatSettingsManager, localeManager);
// Build "friendly" date formatter
FriendlyDateFormatter friendlyDateFormatter = new FriendlyDateFormatter(
new Date(), dateFormatter);
return friendlyDateFormatter;
}
示例4: newNumberFormatter
import com.atlassian.confluence.user.AuthenticatedUserThreadLocal; //导入依赖的package包/类
protected NumberFormat newNumberFormatter() {
// Get current user's timezone, or default one
User authUser = AuthenticatedUserThreadLocal.getUser();
NumberFormat result = null;
if (authUser != null) {
ConfluenceUserPreferences prefs = userAccessor
.getConfluenceUserPreferences(authUser);
if (prefs != null && prefs.getLocale() != null) {
result = NumberFormat.getNumberInstance(prefs.getLocale());
}
}
if (result == null) {
// anonymous
result = NumberFormat.getNumberInstance();
}
return result;
}
示例5: saveItemWithAttachments
import com.atlassian.confluence.user.AuthenticatedUserThreadLocal; //导入依赖的package包/类
/**
* This is the rest API call to save a new Item.
*
* @param message
* @param threadID
* @return a new item with the given parameters
*/
@POST
@Consumes({MediaType.APPLICATION_FORM_URLENCODED, MediaType.APPLICATION_JSON})
@Path("items/withAttachments")
public Response saveItemWithAttachments(@QueryParam(value = "message") String message,
@QueryParam(value = "threadID") int threadID, @QueryParam(value = "attachments") String attachments) {
Date date = Calendar.getInstance().getTime();
String safeMessage = sanitizer.sanitizeInput(message);
checkEmptyInput(safeMessage);
String userKey = AuthenticatedUserThreadLocal.get().getKey().getStringValue();
if (attachments.isEmpty()) {
return getResponseItemAdd(threadID, date, safeMessage, userKey);
} else {
List<SerializableAttachment> safeAttachments = sanitizer.parseAttachmentJson(attachments);
return Response.ok(
SerializablePost.build(itemRepository.add(safeMessage, date, threadID, userKey, safeAttachments))
).build();
}
}
示例6: saveThread
import com.atlassian.confluence.user.AuthenticatedUserThreadLocal; //导入依赖的package包/类
/**
* This is the rest API call to save a new thread.
*
* @param title
* @param description
* @param sticky
* @return a new thread with the given parameters
*/
@POST
@Consumes({MediaType.APPLICATION_FORM_URLENCODED})
@Path("threads")
public Response saveThread(@FormParam(value = "title") String title,
@FormParam(value = "description") String description,
@FormParam(value = "sticky") boolean sticky,
@FormParam(value = "forumID") int forumID) {
System.out.println("forumID: " + forumID);
String safeTitle = sanitizer.sanitizeInput(title);
String safeDescription = sanitizer.sanitizeInput(description);
checkEmptyInput(safeTitle);
checkEmptyInput(safeDescription);
Date date = Calendar.getInstance().getTime();
String userKey = AuthenticatedUserThreadLocal.get().getKey().getStringValue();
return Response.ok(
SerializableThread.build(threadRepo.add(safeTitle, safeDescription,
sticky, date, forumID, userKey))
).build();
}
示例7: setUp
import com.atlassian.confluence.user.AuthenticatedUserThreadLocal; //导入依赖的package包/类
@Before
public void setUp() throws Exception {
assertNotNull(entityManager);
ao = new TestActiveObjects(entityManager);
forumAO = ao.create(ForumAO.class, new DBParam("TITLE", "ForumTitle"));
forumAO.setDescription("ForumDescription");
forumAO.save();
forumID = forumAO.getID();
userManagementRepository = new UserManagementRepositoryImplement(ao);
roleManagementRepository = new RoleManagementRepositoryImplement(ao);
permissionManagementRepository = new PermissionManagementRepositoryImplement(ao);
forumRepository = new ForumRepositoryImplement(ao);
rightsManagement = new RightsManagementImplement(userManagementRepository, roleManagementRepository, permissionManagementRepository, forumRepository);
threadRepository = new ThreadRepositoryImplement(ao, rightsManagement);
itemRepository = new ItemRepositoryImplement(ao, rightsManagement);
mockAdminUser = MockConfluenceUserFactory.mockUser();
mockParticipantUser = MockConfluenceUserFactory.mockUser();
userKeyAdmin = mockAdminUser.getKey().getStringValue();
userKeyParticipant = mockParticipantUser.getKey().getStringValue();
rightsManagement.initPermissions();
rightsManagement.initAdmin(userKeyAdmin, forumID);
rightsManagement.addUser(userKeyAdmin, userKeyParticipant, "Admin",
forumID);
AuthenticatedUserThreadLocal.set(mockAdminUser);
AuthenticatedUserThreadLocal.set(mockParticipantUser);
}
示例8: setUp
import com.atlassian.confluence.user.AuthenticatedUserThreadLocal; //导入依赖的package包/类
@Before
public void setUp() throws Exception {
assertNotNull(entityManager);
ao = new TestActiveObjects(entityManager);
forumAO = ao.create(ForumAO.class, new DBParam("TITLE", "ForumTitle"));
forumAO.setDescription("ForumDescription");
forumAO.save();
forumID = forumAO.getID();
userManagementRepository = new UserManagementRepositoryImplement(ao);
roleManagementRepository = new RoleManagementRepositoryImplement(ao);
permissionManagementRepository = new PermissionManagementRepositoryImplement(ao);
forumRepository = new ForumRepositoryImplement(ao);
rightsManagement = new RightsManagementImplement(userManagementRepository, roleManagementRepository, permissionManagementRepository, forumRepository);
threadRepository = new ThreadRepositoryImplement(ao, rightsManagement);
itemRepository = new ItemRepositoryImplement(ao, rightsManagement);
itemRestService = new ItemRestService(itemRepository, sanitizer);
mockAdminUser = MockConfluenceUserFactory.mockUser();
userKeyAdmin = mockAdminUser.getKey().getStringValue();
rightsManagement.initPermissions();
rightsManagement.initAdmin(userKeyAdmin, forumID);
AuthenticatedUserThreadLocal.set(mockAdminUser);
thread = threadRepository.add(threadTitle, threadDescription,
threadSticky, date, forumID, userKeyAdmin);
item = itemRepository.add(itemMessage, date, thread.getID(),
userKeyAdmin);
}
示例9: setUp
import com.atlassian.confluence.user.AuthenticatedUserThreadLocal; //导入依赖的package包/类
@Before
public void setUp() throws Exception {
assertNotNull(entityManager);
ao = new TestActiveObjects(entityManager);
forumAO = ao.create(ForumAO.class, new DBParam("TITLE", "ForumTitle"));
forumAO.setDescription("ForumDescription");
forumAO.save();
forumID = forumAO.getID();
userManagementRepository = new UserManagementRepositoryImplement(ao);
roleManagementRepository = new RoleManagementRepositoryImplement(ao);
permissionManagementRepository = new PermissionManagementRepositoryImplement(ao);
forumRepository = new ForumRepositoryImplement(ao);
rightsManagement = new RightsManagementImplement(userManagementRepository, roleManagementRepository, permissionManagementRepository, forumRepository);
threadRepository = new ThreadRepositoryImplement(ao, rightsManagement);
threadRestService = new ThreadRestService(threadRepository, sanitizer);
mockAdminUser = MockConfluenceUserFactory.mockUser();
userKeyAdmin = mockAdminUser.getKey().getStringValue();
rightsManagement.initPermissions();
rightsManagement.initAdmin(userKeyAdmin, forumID);
AuthenticatedUserThreadLocal.set(mockAdminUser);
thread = threadRepository.add(threadTitle, threadDescription,
threadSticky, threadDate, forumID, userKeyAdmin);
}
示例10: getTemplateNameFor
import com.atlassian.confluence.user.AuthenticatedUserThreadLocal; //导入依赖的package包/类
@Nonnull
protected String getTemplateNameFor(@Nonnull Map<String, Object> context, @Nullable User user) {
final ConfluenceUser currentUser = AuthenticatedUserThreadLocal.get();
final String variant;
if ((user == null || !user.equals(currentUser)) && !_permissionManager.hasPermission(currentUser, VIEW, TARGET_PEOPLE_DIRECTORY)) {
variant = ".accessDenied";
} else {
final Object username = context.get("username");
if (username == null || username.toString().isEmpty()) {
variant = ".missingUsername";
} else if (context.get("user") == null) {
variant = ".unknownUser";
} else {
variant = "";
}
}
return TEMPLATE_NAME_PREFIX + variant + TEMPLATE_NAME_SUFFIX;
}
示例11: onSpaceRemoveEvent
import com.atlassian.confluence.user.AuthenticatedUserThreadLocal; //导入依赖的package包/类
@EventListener
public void onSpaceRemoveEvent(SpaceRemoveEvent spaceRemoveEvent) {
String username = AuthenticatedUserThreadLocal.getUsername();
if (username == null) {
username = "";
}
metricCollector.spaceDeleteCounter(username);
}
示例12: onSpaceCreateEvent
import com.atlassian.confluence.user.AuthenticatedUserThreadLocal; //导入依赖的package包/类
@EventListener
public void onSpaceCreateEvent(SpaceCreateEvent spaceCreateEvent) {
String username = AuthenticatedUserThreadLocal.getUsername();
if (username == null) {
username = "";
}
metricCollector.spaceCreateCounter(username);
}
示例13: doesCurrentUserHaveToken
import com.atlassian.confluence.user.AuthenticatedUserThreadLocal; //导入依赖的package包/类
@GET
@Path("ask")
public boolean doesCurrentUserHaveToken() {
String userKey = AuthenticatedUserThreadLocal.get().getKey().getStringValue();
return ao.executeInTransaction(() ->
ao.find(BundleAccessToken.class, Query.select().where("USER_KEY = ?", userKey)).length == 1);
}
示例14: shouldDisplay
import com.atlassian.confluence.user.AuthenticatedUserThreadLocal; //导入依赖的package包/类
public boolean shouldDisplay(Map<String, Object> context)
{
Attachment attachment = (Attachment) context.get("attachment");
if (attachment == null)
{
return false;
}
if (!isXExtension(attachment.getFileExtension()))
{
return false;
}
if (attachment.getFileSize() > DocumentManager.GetMaxFileSize())
{
return false;
}
ConfluenceUser user = AuthenticatedUserThreadLocal.get();
boolean accessEdit = AttachmentUtil.checkAccess(attachment, user, true);
boolean accessView = AttachmentUtil.checkAccess(attachment, user, false);
if (!forEdit && (!accessView || accessEdit))
{
return false;
}
if (forEdit && !accessEdit)
{
return false;
}
return true;
}
示例15: saveAttachment
import com.atlassian.confluence.user.AuthenticatedUserThreadLocal; //导入依赖的package包/类
public static void saveAttachment(Long attachmentId, InputStream attachmentData, int size, ConfluenceUser user)
throws IOException, IllegalArgumentException
{
AttachmentManager attachmentManager = (AttachmentManager) ContainerManager.getComponent("attachmentManager");
Attachment attachment = attachmentManager.getAttachment(attachmentId);
Attachment oldAttachment = attachment.copy();
attachment.setFileSize(size);
AuthenticatedUserThreadLocal.set(user);
attachmentManager.saveAttachment(attachment, oldAttachment, attachmentData);
}