Changeset 6940
- Timestamp:
- 12/16/08 13:48:44 (20 months ago)
- Location:
- head/ambra/webapp/src
- Files:
-
- 1 added
- 25 modified
-
main/java/org/topazproject/ambra/action/BaseSessionAwareActionSupport.java (added)
-
main/java/org/topazproject/ambra/action/FeedbackAction.java (modified) (1 diff)
-
main/java/org/topazproject/ambra/admin/action/ViewRatingAction.java (modified) (2 diffs)
-
main/java/org/topazproject/ambra/annotation/action/CreateAnnotationAction.java (modified) (4 diffs)
-
main/java/org/topazproject/ambra/annotation/action/CreateFlagAction.java (modified) (3 diffs)
-
main/java/org/topazproject/ambra/annotation/action/CreateReplyAction.java (modified) (3 diffs)
-
main/java/org/topazproject/ambra/annotation/service/AnnotationService.java (modified) (10 diffs)
-
main/java/org/topazproject/ambra/annotation/service/ReplyService.java (modified) (4 diffs)
-
main/java/org/topazproject/ambra/article/action/EmailArticleAction.java (modified) (1 diff)
-
main/java/org/topazproject/ambra/rating/action/AbstractRatingAction.java (modified) (2 diffs)
-
main/java/org/topazproject/ambra/rating/action/GetAverageRatingsAction.java (modified) (2 diffs)
-
main/java/org/topazproject/ambra/rating/action/RateAction.java (modified) (2 diffs)
-
main/java/org/topazproject/ambra/rating/service/RatingsService.java (modified) (2 diffs)
-
main/java/org/topazproject/ambra/search/action/SearchAction.java (modified) (3 diffs)
-
main/java/org/topazproject/ambra/search/service/SearchService.java (modified) (2 diffs)
-
main/java/org/topazproject/ambra/user/action/AdminUserAlertsAction.java (modified) (1 diff)
-
main/java/org/topazproject/ambra/user/action/MemberUserAlertsAction.java (modified) (1 diff)
-
main/java/org/topazproject/ambra/user/action/MemberUserProfileAction.java (modified) (3 diffs)
-
main/java/org/topazproject/ambra/user/action/UserActionSupport.java (modified) (3 diffs)
-
main/java/org/topazproject/ambra/user/action/UserAlertsAction.java (modified) (4 diffs)
-
main/java/org/topazproject/ambra/user/action/UserProfileAction.java (modified) (3 diffs)
-
main/java/org/topazproject/ambra/user/AmbraUser.java (modified) (4 diffs)
-
main/java/org/topazproject/ambra/web/UserContext.java (modified) (1 diff)
-
test/java/org/topazproject/ambra/annotation/action/AnnotationActionsTest.java (modified) (3 diffs)
-
test/java/org/topazproject/ambra/user/action/UserActionsTest.java (modified) (4 diffs)
-
test/java/org/topazproject/ambra/user/action/UserAlertsTest.java (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
head/ambra/webapp/src/main/java/org/topazproject/ambra/action/FeedbackAction.java
r6880 r6940 59 59 60 60 private void setUserDetailsFromSession() { 61 final AmbraUser ambraUser = AmbraUser.getCurrentUser();61 final AmbraUser ambraUser = getCurrentUser(); 62 62 if (null != ambraUser) { 63 63 name = ambraUser.getDisplayName(); -
head/ambra/webapp/src/main/java/org/topazproject/ambra/admin/action/ViewRatingAction.java
r6588 r6940 21 21 22 22 import org.springframework.transaction.annotation.Transactional; 23 import org.topazproject.ambra.action.Base ActionSupport;23 import org.topazproject.ambra.action.BaseSessionAwareActionSupport; 24 24 import org.topazproject.ambra.models.Rating; 25 25 import org.topazproject.ambra.rating.service.RatingsService; 26 26 27 27 @SuppressWarnings("serial") 28 public class ViewRatingAction extends Base ActionSupport {28 public class ViewRatingAction extends BaseSessionAwareActionSupport { 29 29 private String ratingId; 30 30 private Rating rating; … … 34 34 @Transactional(readOnly = true) 35 35 public String execute() throws Exception { 36 rating = getRatingsService().getRating(ratingId );36 rating = getRatingsService().getRating(ratingId, getCurrentUser()); 37 37 return SUCCESS; 38 38 } -
head/ambra/webapp/src/main/java/org/topazproject/ambra/annotation/action/CreateAnnotationAction.java
r6607 r6940 27 27 import org.springframework.transaction.annotation.Transactional; 28 28 import org.springframework.transaction.interceptor.TransactionAspectSupport; 29 import org.topazproject.ambra.action.Base ActionSupport;29 import org.topazproject.ambra.action.BaseSessionAwareActionSupport; 30 30 import org.topazproject.ambra.annotation.Context; 31 31 import org.topazproject.ambra.annotation.ContextFormatter; 32 32 import org.topazproject.ambra.annotation.service.AnnotationService; 33 33 import org.topazproject.ambra.util.ProfanityCheckingService; 34 import org.topazproject.ambra.user.AmbraUser; 34 35 35 36 import com.opensymphony.xwork2.validator.annotations.RequiredStringValidator; … … 39 40 */ 40 41 @SuppressWarnings("serial") 41 public class CreateAnnotationAction extends Base ActionSupport {42 public class CreateAnnotationAction extends BaseSessionAwareActionSupport { 42 43 private String target; 43 44 private String commentTitle; … … 73 74 if (profaneWordsInBody.isEmpty() && profaneWordsInTitle.isEmpty()) { 74 75 final String scontext = ContextFormatter.asXPointer(new Context(startPath, startOffset, endPath, endOffset, target)); 75 annotationId = annotationService.createComment(target, scontext, supercedes, commentTitle, mimeType, comment, isPublic );76 annotationId = annotationService.createComment(target, scontext, supercedes, commentTitle, mimeType, comment, isPublic, getCurrentUser()); 76 77 if (log.isDebugEnabled()) { 77 78 log.debug("CreateAnnotationAction called and annotation created with id: " + annotationId); … … 79 80 if ("correction".equals(noteType)) { 80 81 annotationService.createFlag(annotationId, "Create Correction", 81 "Note created and flagged as a correction", mimeType );82 "Note created and flagged as a correction", mimeType, getCurrentUser()); 82 83 } 83 84 } else { -
head/ambra/webapp/src/main/java/org/topazproject/ambra/annotation/action/CreateFlagAction.java
r6607 r6940 24 24 import org.springframework.transaction.annotation.Transactional; 25 25 import org.springframework.transaction.interceptor.TransactionAspectSupport; 26 import org.topazproject.ambra.action.Base ActionSupport;26 import org.topazproject.ambra.action.BaseSessionAwareActionSupport; 27 27 import org.topazproject.ambra.annotation.service.AnnotationService; 28 28 … … 33 33 */ 34 34 @SuppressWarnings("serial") 35 public class CreateFlagAction extends Base ActionSupport {35 public class CreateFlagAction extends BaseSessionAwareActionSupport { 36 36 private String target; 37 37 private String comment; … … 47 47 public String execute() throws Exception { 48 48 try { 49 annotationId = annotationService.createFlag(target, reasonCode, comment, mimeType );49 annotationId = annotationService.createFlag(target, reasonCode, comment, mimeType, getCurrentUser()); 50 50 } catch (final Exception e) { 51 51 log.error("Could not create flag for target: " + target, e); -
head/ambra/webapp/src/main/java/org/topazproject/ambra/annotation/action/CreateReplyAction.java
r6603 r6940 26 26 import org.springframework.transaction.annotation.Transactional; 27 27 import org.springframework.transaction.interceptor.TransactionAspectSupport; 28 import org.topazproject.ambra.action.Base ActionSupport;28 import org.topazproject.ambra.action.BaseSessionAwareActionSupport; 29 29 import org.topazproject.ambra.annotation.service.ReplyService; 30 30 import org.topazproject.ambra.util.ProfanityCheckingService; 31 import org.topazproject.ambra.user.AmbraUser; 31 32 32 33 import com.opensymphony.xwork2.validator.annotations.RequiredStringValidator; … … 36 37 */ 37 38 @SuppressWarnings("serial") 38 public class CreateReplyAction extends Base ActionSupport {39 public class CreateReplyAction extends BaseSessionAwareActionSupport { 39 40 private String replyId; 40 41 private String root; … … 57 58 58 59 if (profaneWordsInBody.isEmpty() && profaneWordsInTitle.isEmpty()) { 59 replyId = replyService.createReply(root, inReplyTo, commentTitle, mimeType, comment );60 replyId = replyService.createReply(root, inReplyTo, commentTitle, mimeType, comment, getCurrentUser()); 60 61 } else { 61 62 addProfaneMessages(profaneWordsInBody, "comment", "comment"); -
head/ambra/webapp/src/main/java/org/topazproject/ambra/annotation/service/AnnotationService.java
r6882 r6940 94 94 * @param isPublic to set up public permissions 95 95 * 96 * @param user 96 97 * @return a the new annotation id 97 98 * … … 99 100 */ 100 101 private String createAnnotation(Class<? extends ArticleAnnotation> annotationClass, 101 final String mimeType, final String target,102 final String context, final String olderAnnotation,103 final String title, final String body, boolean isPublic)102 final String mimeType, final String target, 103 final String context, final String olderAnnotation, 104 final String title, final String body, boolean isPublic, AmbraUser user) 104 105 throws Exception { 105 106 … … 114 115 throw new UnsupportedOperationException("supersedes is not supported"); 115 116 116 String user = AmbraUser.getCurrentUser().getUserId();117 AnnotationBlob blob= new AnnotationBlob(contentType);117 String userId = user.getUserId(); 118 AnnotationBlob blob = new AnnotationBlob(contentType); 118 119 final ArticleAnnotation annotation = annotationClass.newInstance(); 119 120 … … 122 123 annotation.setContext(context); 123 124 annotation.setTitle(title); 124 annotation.setCreator(user );125 annotation.setCreator(userId); 125 126 annotation.setBody(blob); 126 127 annotation.setCreated(new Date()); … … 132 133 if (log.isDebugEnabled()) 133 134 log.debug("created annotaion " + newId + " for " + target + " with body in blob " 134 + blob.getId());135 + blob.getId()); 135 136 136 137 permissionsService.propagatePermissions(newId, new String[] { blob.getId() }); … … 592 593 * @param body body 593 594 * @param isPublic isPublic 595 * @param user 594 596 * @throws Exception on an error 595 597 * @return unique identifier for the newly created annotation … … 599 601 final String olderAnnotation, final String title, 600 602 final String mimeType, final String body, 601 final boolean isPublic ) throws Exception {603 final boolean isPublic, AmbraUser user) throws Exception { 602 604 603 605 if (log.isDebugEnabled()) { … … 608 610 609 611 String annotationId = createAnnotation(Comment.class, mimeType, target, context, 610 olderAnnotation, title, body, true );612 olderAnnotation, title, body, true, user); 611 613 612 614 if (log.isDebugEnabled()) { 613 final AmbraUser user = AmbraUser.getCurrentUser();614 615 log.debug("Comment created with ID: " + annotationId + " for user: " + user + 615 616 " for IP: " + ServletActionContext.getRequest().getRemoteAddr()); … … 666 667 * @param body body 667 668 * @param mimeType mimeType 669 * @param user Logged in user 668 670 * @return unique identifier for the newly created flag 669 671 * @throws Exception on an error … … 671 673 @Transactional(rollbackFor = { Throwable.class }) 672 674 public String createFlag(final String target, final String reasonCode, 673 final String body, final String mimeType) throws Exception {675 final String body, final String mimeType, AmbraUser user) throws Exception { 674 676 final String flagBody = FlagUtil.createFlagBody(reasonCode, body); 675 return createComment(target, null, null, null, mimeType, flagBody, true );677 return createComment(target, null, null, null, mimeType, flagBody, true, user); 676 678 } 677 679 -
head/ambra/webapp/src/main/java/org/topazproject/ambra/annotation/service/ReplyService.java
r6882 r6940 68 68 * @param body the reply body 69 69 * 70 * @param user 70 71 * @return a new reply 71 72 * … … 74 75 @Transactional(rollbackFor = { Throwable.class }) 75 76 public String createReply(final String root, final String inReplyTo, final String title, 76 final String mimeType, final String body )77 final String mimeType, final String body, AmbraUser user) 77 78 throws Exception { 78 79 pep.checkAccess(RepliesPEP.CREATE_REPLY, URI.create(root)); … … 82 83 83 84 final String contentType = getContentType(mimeType); 84 String user = AmbraUser.getCurrentUser().getUserId();85 ReplyBlob blob= new ReplyBlob(contentType);86 87 final Reply r= new ReplyThread();85 String userId = user.getUserId(); 86 ReplyBlob blob = new ReplyBlob(contentType); 87 88 final Reply r = new ReplyThread(); 88 89 r.setMediator(getApplicationId()); 89 90 r.setType(getDefaultType()); … … 91 92 r.setInReplyTo(inReplyTo); 92 93 r.setTitle(title); 93 r.setCreator(user );94 r.setCreator(userId); 94 95 r.setBody(blob); 95 96 r.setCreated(new Date()); 96 97 97 String newId = session.saveOrUpdate(r);98 String newId = session.saveOrUpdate(r); 98 99 // now that the blob is created by OTM, write to it 99 100 blob.getBody().writeAll(body.getBytes(getEncodingCharset())); -
head/ambra/webapp/src/main/java/org/topazproject/ambra/article/action/EmailArticleAction.java
r6711 r6940 65 65 @Transactional(readOnly = true) 66 66 public String executeRender() throws Exception { 67 final AmbraUser ambraUser = AmbraUser.getCurrentUser();67 final AmbraUser ambraUser = getCurrentUser(); 68 68 if (null != ambraUser) { 69 69 senderName = ambraUser.getDisplayName(); -
head/ambra/webapp/src/main/java/org/topazproject/ambra/rating/action/AbstractRatingAction.java
r6711 r6940 25 25 import org.springframework.beans.factory.annotation.Required; 26 26 import org.topazproject.ambra.ApplicationException; 27 import org.topazproject.ambra.action.Base ActionSupport;27 import org.topazproject.ambra.action.BaseSessionAwareActionSupport; 28 28 import org.topazproject.ambra.article.service.ArticleOtmService; 29 29 import org.topazproject.ambra.article.service.NoSuchArticleIdException; … … 37 37 */ 38 38 @SuppressWarnings("serial") 39 public abstract class AbstractRatingAction extends Base ActionSupport {39 public abstract class AbstractRatingAction extends BaseSessionAwareActionSupport { 40 40 41 41 protected static final Log log = LogFactory.getLog(AbstractRatingAction.class); -
head/ambra/webapp/src/main/java/org/topazproject/ambra/rating/action/GetAverageRatingsAction.java
r6592 r6940 22 22 import org.springframework.transaction.annotation.Transactional; 23 23 import org.topazproject.ambra.rating.service.RatingsService; 24 import org.topazproject.ambra.user.AmbraUser; 24 25 25 26 /** … … 45 46 public String execute() throws Exception { 46 47 avg = ratingsService.getAverageRatings(articleURI); 47 hasRated = ratingsService.hasRated(articleURI );48 hasRated = ratingsService.hasRated(articleURI, getCurrentUser()); 48 49 isResearchArticle = isResearchArticle(articleURI); 49 50 return SUCCESS; -
head/ambra/webapp/src/main/java/org/topazproject/ambra/rating/action/RateAction.java
r6821 r6940 81 81 @Transactional(rollbackFor = { Throwable.class }) 82 82 public String rateArticle() { 83 final AmbraUser user = AmbraUser.getCurrentUser();83 final AmbraUser user = getCurrentUser(); 84 84 final Date now = new Date(System.currentTimeMillis()); 85 85 final URI annotatedArticle; … … 277 277 @Transactional(readOnly = true) 278 278 public String retrieveRatingsForUser() { 279 final AmbraUser user = AmbraUser.getCurrentUser();279 final AmbraUser user = getCurrentUser(); 280 280 281 281 if (user == null) { -
head/ambra/webapp/src/main/java/org/topazproject/ambra/rating/service/RatingsService.java
r6821 r6940 126 126 * @param ratingId Rating Id 127 127 * 128 * @param user 128 129 * @return Rating 129 130 */ 130 131 @Transactional(readOnly = true) 131 public Rating getRating(final String ratingId ) {132 public Rating getRating(final String ratingId, AmbraUser user) { 132 133 Rating rating = session.get(Rating.class, ratingId); 133 134 134 135 // the PEP check is against what is rated, 135 136 // e.g. can this user see the ratings for what is rated? 136 AmbraUser user = AmbraUser.getCurrentUser();137 137 pep.checkObjectAccess(RatingsPEP.GET_RATINGS, URI.create(user.getUserId()), 138 138 rating.getAnnotates()); … … 189 189 @SuppressWarnings("unchecked") 190 190 @Transactional(readOnly = true) 191 public boolean hasRated(String articleURI) { 192 final AmbraUser user = AmbraUser.getCurrentUser(); 191 public boolean hasRated(String articleURI, AmbraUser user) { 193 192 194 193 if (user == null) -
head/ambra/webapp/src/main/java/org/topazproject/ambra/search/action/SearchAction.java
r6932 r6940 34 34 35 35 import org.springframework.transaction.annotation.Transactional; 36 import org.topazproject.ambra.action.Base ActionSupport;36 import org.topazproject.ambra.action.BaseSessionAwareActionSupport; 37 37 import org.topazproject.ambra.article.service.BrowseService; 38 38 import org.topazproject.ambra.search.SearchResultPage; … … 47 47 */ 48 48 @SuppressWarnings("serial") 49 public class SearchAction extends Base ActionSupport {49 public class SearchAction extends BaseSessionAwareActionSupport { 50 50 private static final Log log = LogFactory.getLog(SearchAction.class); 51 51 private static final DateFormat luceneDateFormat = new SimpleDateFormat("yyyy-MM-dd"); … … 120 120 pageSize = configuration.getInt(SEARCH_PAGE_SIZE, 10); 121 121 122 SearchResultPage results = searchService.find(queryString, startPage, pageSize );122 SearchResultPage results = searchService.find(queryString, startPage, pageSize, getCurrentUser()); 123 123 totalNoOfResults = results.getTotalNoOfResults(); 124 124 searchResults = results.getHits(); -
head/ambra/webapp/src/main/java/org/topazproject/ambra/search/service/SearchService.java
r6933 r6940 161 161 * @param startPage The page number of the search results the user wants 162 162 * @param pageSize The number of results per page 163 * @param user 163 164 * @return A SearchResultPage representing the search results page to be rendered 164 165 * @throws ParseException if <var>query</var> is not valid … … 166 167 */ 167 168 @Transactional(readOnly = true) 168 public SearchResultPage find(final String query, final int startPage, final int pageSize )169 public SearchResultPage find(final String query, final int startPage, final int pageSize, AmbraUser user) 169 170 throws ParseException, OtmException { 170 AmbraUser user = AmbraUser.getCurrentUser();171 171 String cacheKey = getCurrentJournal() + "|" + (user == null ? "anon" : user.getUserId()) + 172 172 "|" + query; -
head/ambra/webapp/src/main/java/org/topazproject/ambra/user/action/AdminUserAlertsAction.java
r6246 r6940 29 29 private String topazId; 30 30 31 @Override32 protected AmbraUser getAmbraUserToUse() throws ApplicationException {33 return getUserService().getUserByTopazId(topazId);34 }35 36 31 /** 37 32 * Setter for topazId. -
head/ambra/webapp/src/main/java/org/topazproject/ambra/user/action/MemberUserAlertsAction.java
r6246 r6940 26 26 */ 27 27 public class MemberUserAlertsAction extends UserAlertsAction { 28 @Override29 protected AmbraUser getAmbraUserToUse() {30 return AmbraUser.getCurrentUser();31 }32 28 } -
head/ambra/webapp/src/main/java/org/topazproject/ambra/user/action/MemberUserProfileAction.java
r6248 r6940 25 25 import static org.topazproject.ambra.Constants.AMBRA_USER_KEY; 26 26 27 import java.util.Map;28 29 27 /** 30 28 * User Profile Action that is called by the member user to update their profile … … 43 41 44 42 if (SUCCESS.equals(statusCode)) { 45 final Map<String, Object> sessionMap = getSessionMap(); 46 sessionMap.put(AMBRA_USER_KEY, super.getSavedAmbraUser()); 43 session.put(AMBRA_USER_KEY, super.getSavedAmbraUser()); 47 44 } 48 45 … … 52 49 @Override 53 50 protected AmbraUser getAmbraUserToUse() { 54 final Map<String, Object> sessionMap = getSessionMap(); 55 return (AmbraUser) sessionMap.get(AMBRA_USER_KEY); 51 return getCurrentUser(); 56 52 } 57 53 58 54 @Override 59 55 protected String getUserIdToFetchEmailAddressFor() { 60 final Map<String, Object> sessionMap = getSessionMap(); 61 return (String) sessionMap.get(Constants.SINGLE_SIGNON_USER_KEY); 56 return (String) session.get(Constants.SINGLE_SIGNON_USER_KEY); 62 57 } 63 58 } -
head/ambra/webapp/src/main/java/org/topazproject/ambra/user/action/UserActionSupport.java
r6225 r6940 24 24 25 25 import org.springframework.beans.factory.annotation.Required; 26 import org.topazproject.ambra.action.Base ActionSupport;26 import org.topazproject.ambra.action.BaseSessionAwareActionSupport; 27 27 import org.topazproject.ambra.user.service.UserService; 28 28 29 29 import com.googlecode.jsonplugin.annotations.JSON; 30 31 import java.util.Map;32 30 33 31 /** … … 37 35 * 38 36 */ 39 public class UserActionSupport extends Base ActionSupport {37 public class UserActionSupport extends BaseSessionAwareActionSupport { 40 38 private static final Log log = LogFactory.getLog(UserActionSupport.class); 41 39 private UserService userService; … … 58 56 } 59 57 60 protected Map<String, Object> getSessionMap() {61 return userService.getUserContext().getSessionMap();62 }63 58 } -
head/ambra/webapp/src/main/java/org/topazproject/ambra/user/action/UserAlertsAction.java
r6933 r6940 33 33 import org.apache.commons.logging.LogFactory; 34 34 import org.springframework.transaction.annotation.Transactional; 35 import org.topazproject.ambra.ApplicationException;36 35 import org.topazproject.ambra.user.AmbraUser; 37 36 import org.topazproject.ambra.user.service.UserAlert; … … 121 120 @Transactional(rollbackFor = { Throwable.class }) 122 121 public String saveAlerts() throws Exception { 123 final AmbraUser ambraUser = get AmbraUserToUse();122 final AmbraUser ambraUser = getCurrentUser(); 124 123 if (ambraUser == null) { 125 124 throw new ServletException("Unable to resolve ambra user"); … … 155 154 @Transactional(readOnly = true) 156 155 public String retrieveAlerts() throws Exception { 157 final AmbraUser ambraUser = get AmbraUserToUse();156 final AmbraUser ambraUser = getCurrentUser(); 158 157 if (ambraUser == null) { 159 158 throw new ServletException("Unable to resolve ambra user"); … … 186 185 187 186 /** 188 * Provides a way to get the AmbraUser to edit189 * @return the AmbraUser to edit190 * @throws org.topazproject.ambra.ApplicationException ApplicationException191 */192 protected abstract AmbraUser getAmbraUserToUse() throws ApplicationException;193 194 /**195 187 * @return categories that have monthly alerts 196 188 */ -
head/ambra/webapp/src/main/java/org/topazproject/ambra/user/action/UserProfileAction.java
r6268 r6940 32 32 import org.topazproject.ambra.user.UserProfileGrant; 33 33 import org.topazproject.ambra.user.service.DisplayNameAlreadyExistsException; 34 import org.topazproject.ambra.user.service.UserAlert;35 34 import org.topazproject.ambra.util.FileUtils; 36 35 import org.topazproject.ambra.util.ProfanityCheckingService; … … 183 182 184 183 // update the user-id in the session if we just created an account for ourselves 185 Map<String, Object> session = getSessionMap();186 184 if (authId != null && authId.equals(session.get(UserAccountsInterceptor.AUTH_KEY))) 187 185 session.put(UserAccountsInterceptor.USER_KEY, topazId); … … 903 901 904 902 protected String fetchUserEmailAddress() throws ApplicationException { 905 String presetEmail = (String) getSessionMap().get(SINGLE_SIGNON_EMAIL_KEY);903 String presetEmail = (String) session.get(SINGLE_SIGNON_EMAIL_KEY); 906 904 if (presetEmail != null) 907 905 return presetEmail; -
head/ambra/webapp/src/main/java/org/topazproject/ambra/user/AmbraUser.java
r6773 r6940 23 23 import org.apache.commons.logging.LogFactory; 24 24 25 import org.apache.struts2.ServletActionContext;26 27 import static org.topazproject.ambra.Constants.AMBRA_USER_KEY;28 29 25 import org.topazproject.ambra.models.UserAccount; 30 26 import org.topazproject.ambra.models.UserPreferences; … … 60 56 61 57 /** 62 * Returns the current user. Valid only in a request context.63 */64 // TODO: inject AmbraUser through Spring.65 // This creates dependency on ServletRequest everywhere it is used66 public static AmbraUser getCurrentUser() {67 if (ServletActionContext.getRequest() == null)68 return null;69 if (ServletActionContext.getRequest().getSession() == null)70 return null;71 return (AmbraUser) ServletActionContext.getRequest().getSession()72 .getAttribute(AMBRA_USER_KEY);73 }74 75 /**76 58 * Initializes a new Ambra user 77 59 * 78 60 * @param ua the user-account 61 * @param appId Application ID 62 * @param pep XACML Policy Enforcement Point 79 63 */ 80 64 public AmbraUser(UserAccount ua, String appId, UsersPEP pep) { … … 89 73 UserPreferences p; 90 74 try { 91 pep.checkAccess( pep.GET_PREFERENCES, ua.getId());75 pep.checkAccess(UsersPEP.GET_PREFERENCES, ua.getId()); 92 76 p = ua.getPreferences(appId); 93 77 } catch (SecurityException se) { … … 128 112 129 113 private static void filterProfile(UserProfile prof, URI owner, UsersPEP pep) { 130 if (prof.getDisplayName() != null && !checkAccess(owner, pep.GET_DISP_NAME, pep))114 if (prof.getDisplayName() != null && !checkAccess(owner, UsersPEP.GET_DISP_NAME, pep)) 131 115 prof.setDisplayName(null); 132 if (prof.getRealName() != null && !checkAccess(owner, pep.GET_REAL_NAME, pep))116 if (prof.getRealName() != null && !checkAccess(owner, UsersPEP.GET_REAL_NAME, pep)) 133 117 prof.setRealName(null); 134 if (prof.getGivenNames() != null && !checkAccess(owner, pep.GET_GIVEN_NAMES, pep))118 if (prof.getGivenNames() != null && !checkAccess(owner, UsersPEP.GET_GIVEN_NAMES, pep)) 135 119 prof.setGivenNames(null); 136 if (prof.getSurnames() != null && !checkAccess(owner, pep.GET_SURNAMES, pep))120 if (prof.getSurnames() != null && !checkAccess(owner, UsersPEP.GET_SURNAMES, pep)) 137 121 prof.setSurnames(null); 138 if (prof.getTitle() != null && !checkAccess(owner, pep.GET_TITLE, pep))122 if (prof.getTitle() != null && !checkAccess(owner, UsersPEP.GET_TITLE, pep)) 139 123 prof.setTitle(null); 140 if (prof.getGender() != null && !checkAccess(owner, pep.GET_GENDER, pep))124 if (prof.getGender() != null && !checkAccess(owner, UsersPEP.GET_GENDER, pep)) 141 125 prof.setGender(null); 142 if (prof.getPositionType() != null && !checkAccess(owner, pep.GET_POSITION_TYPE, pep))126 if (prof.getPositionType() != null && !checkAccess(owner, UsersPEP.GET_POSITION_TYPE, pep)) 143 127 prof.setPositionType(null); 144 if (prof.getOrganizationName() != null && !checkAccess(owner, pep.GET_ORGANIZATION_NAME, pep))128 if (prof.getOrganizationName() != null && !checkAccess(owner, UsersPEP.GET_ORGANIZATION_NAME, pep)) 145 129 prof.setOrganizationName(null); 146 if (prof.getOrganizationType() != null && !checkAccess(owner, pep.GET_ORGANIZATION_TYPE, pep))130 if (prof.getOrganizationType() != null && !checkAccess(owner, UsersPEP.GET_ORGANIZATION_TYPE, pep)) 147 131 prof.setOrganizationType(null); 148 if (prof.getPostalAddress() != null && !checkAccess(owner, pep.GET_POSTAL_ADDRESS, pep))132 if (prof.getPostalAddress() != null && !checkAccess(owner, UsersPEP.GET_POSTAL_ADDRESS, pep)) 149 133 prof.setPostalAddress(null); 150 if (prof.getCity() != null && !checkAccess(owner, pep.GET_CITY, pep))134 if (prof.getCity() != null && !checkAccess(owner, UsersPEP.GET_CITY, pep)) 151 135 prof.setCity(null); 152 if (prof.getCountry() != null && !checkAccess(owner, pep.GET_COUNTRY, pep))136 if (prof.getCountry() != null && !checkAccess(owner, UsersPEP.GET_COUNTRY, pep)) 153 137 prof.setCountry(null); 154 if (prof.getEmail() != null && !checkAccess(owner, pep.GET_EMAIL, pep))138 if (prof.getEmail() != null && !checkAccess(owner, UsersPEP.GET_EMAIL, pep)) 155 139 prof.setEmail(null); 156 if (prof.getHomePage() != null && !checkAccess(owner, pep.GET_HOME_PAGE, pep))140 if (prof.getHomePage() != null && !checkAccess(owner, UsersPEP.GET_HOME_PAGE, pep)) 157 141 prof.setHomePage(null); 158 if (prof.getWeblog() != null && !checkAccess(owner, pep.GET_WEBLOG, pep))142 if (prof.getWeblog() != null && !checkAccess(owner, UsersPEP.GET_WEBLOG, pep)) 159 143 prof.setWeblog(null); 160 if (prof.getBiography() != null && !checkAccess(owner, pep.GET_BIOGRAPHY, pep))144 if (prof.getBiography() != null && !checkAccess(owner, UsersPEP.GET_BIOGRAPHY, pep)) 161 145 prof.setBiography(null); 162 if (prof.getInterests() != null && !checkAccess(owner, pep.GET_INTERESTS, pep))146 if (prof.getInterests() != null && !checkAccess(owner, UsersPEP.GET_INTERESTS, pep)) 163 147 prof.setInterests(null); 164 if (prof.getPublications() != null && !checkAccess(owner, pep.GET_PUBLICATIONS, pep))148 if (prof.getPublications() != null && !checkAccess(owner, UsersPEP.GET_PUBLICATIONS, pep)) 165 149 prof.setPublications(null); 166 if (prof.getBiographyText() != null && !checkAccess(owner, pep.GET_BIOGRAPHY_TEXT, pep))150 if (prof.getBiographyText() != null && !checkAccess(owner, UsersPEP.GET_BIOGRAPHY_TEXT, pep)) 167 151 prof.setBiographyText(null); 168 if (prof.getInterestsText() != null && !checkAccess(owner, pep.GET_INTERESTS_TEXT, pep))152 if (prof.getInterestsText() != null && !checkAccess(owner, UsersPEP.GET_INTERESTS_TEXT, pep)) 169 153 prof.setInterestsText(null); 170 if (prof.getResearchAreasText() != null && !checkAccess(owner, pep.GET_RESEARCH_AREAS_TEXT, pep))154 if (prof.getResearchAreasText() != null && !checkAccess(owner, UsersPEP.GET_RESEARCH_AREAS_TEXT, pep)) 171 155 prof.setResearchAreasText(null); 172 156 } -
head/ambra/webapp/src/main/java/org/topazproject/ambra/web/UserContext.java
r6225 r6940 28 28 /** 29 29 * Provides a way to get a handle on the session objects when running in a web application 30 * TODO: remove this class and use SessionAware interface 30 31 */ 31 32 public class UserContext { -
head/ambra/webapp/src/test/java/org/topazproject/ambra/annotation/action/AnnotationActionsTest.java
r6885 r6940 35 35 import org.topazproject.ambra.BaseAmbraTestCase; 36 36 import org.topazproject.ambra.Constants; 37 import org.topazproject.ambra.user.AmbraUser; 37 38 import org.topazproject.ambra.annotation.Context; 38 39 import org.topazproject.ambra.annotation.ContextFormatter; … … 726 727 727 728 final Collection<String> annotationIdList = new ArrayList<String>(); 729 AmbraUser ambraUser = new AmbraUser("123"); 728 730 annotationIdList.add( 729 service.createComment(subject, context1, null, title, "text/plain", "body", false ));731 service.createComment(subject, context1, null, title, "text/plain", "body", false, ambraUser)); 730 732 annotationIdList.add( 731 service.createComment(subject, context2, null, title, "text/plain", "body", false ));733 service.createComment(subject, context2, null, title, "text/plain", "body", false, ambraUser)); 732 734 annotationIdList.add( 733 service.createComment(subject, context3, null, title, "text/plain", "body", false ));735 service.createComment(subject, context3, null, title, "text/plain", "body", false, ambraUser)); 734 736 735 737 String annotatedContent = getFetchArticleService().getAnnotatedContent(subject); … … 763 765 } 764 766 765 service.createComment(subject, context1, null, title, "text/plain", "body", false); 766 service.createComment(subject, context2, null, title, "text/plain", "body", false); 767 service.createComment(subject, context3, null, title, "text/plain", "body", false); 767 AmbraUser ambraUser = new AmbraUser("123"); 768 service.createComment(subject, context1, null, title, "text/plain", "body", false, ambraUser); 769 service.createComment(subject, context2, null, title, "text/plain", "body", false, ambraUser); 770 service.createComment(subject, context3, null, title, "text/plain", "body", false, ambraUser); 768 771 769 772 String content = getFetchArticleService().getAnnotatedContent(subject); -
head/ambra/webapp/src/test/java/org/topazproject/ambra/user/action/UserActionsTest.java
r6248 r6940 26 26 import org.topazproject.ambra.Constants; 27 27 import org.topazproject.ambra.user.AmbraUser; 28 import org.topazproject.ambra.user.UserProfileGrant;29 import org.topazproject.ambra.user.action.AdminUserProfileAction;30 import org.topazproject.ambra.user.action.AssignAdminRoleAction;31 import org.topazproject.ambra.user.action.DisplayUserAction;32 import org.topazproject.ambra.user.action.MemberUserProfileAction;33 import org.topazproject.ambra.user.action.SearchUserAction;34 import org.topazproject.ambra.user.action.UserProfileAction;35 28 36 29 import java.util.HashMap; … … 108 101 createUserAction.setPostalAddress(POSTAL_ADDRESS); 109 102 110 final String[] privateFields = new String[]{111 UserProfileGrant.POSTAL_ADDRESS.getFieldName(),112 UserProfileGrant.COUNTRY.getFieldName(),113 UserProfileGrant.CITY.getFieldName()};114 115 103 createUserAction.setExtendedVisibility(UserProfileAction.PRIVATE); 116 104 … … 228 216 protected AssignAdminRoleAction createMockAssignAdminRoleAction(final String authId, final String topazId) { 229 217 final AssignAdminRoleAction adminRoleActionToClone = super.getAssignAdminRoleAction(); 230 final AssignAdminRoleAction newAdminRoleAction = new AssignAdminRoleAction() { 231 protected Map<String, Object> getSessionMap() { 232 return createMockSessionMap(authId, topazId); 233 } 234 }; 218 final AssignAdminRoleAction newAdminRoleAction = new AssignAdminRoleAction(); 219 newAdminRoleAction.setSession(createMockSessionMap(authId, topazId)); 235 220 236 221 newAdminRoleAction.setUserService(adminRoleActionToClone.getUserService()); … … 241 226 protected UserProfileAction getMockCreateUserAction(final String authId) { 242 227 final UserProfileAction createUserAction = super.getMemberUserProfileAction(); 243 final UserProfileAction newCreateUserAction = new MemberUserProfileAction() { 244 protected Map<String, Object> getSessionMap() { 245 return createMockSessionMap(authId, null); 246 } 247 }; 228 final UserProfileAction newCreateUserAction = new MemberUserProfileAction(); 229 newCreateUserAction.setSession(createMockSessionMap(authId, null)); 248 230 249 231 newCreateUserAction.setUserService(createUserAction.getUserService()); -
head/ambra/webapp/src/test/java/org/topazproject/ambra/user/action/UserAlertsTest.java
r6248 r6940 27 27 import org.topazproject.ambra.Constants; 28 28 import org.topazproject.ambra.user.AmbraUser; 29 import org.topazproject.ambra.user.action.MemberUserAlertsAction;30 import org.topazproject.ambra.user.action.MemberUserProfileAction;31 import org.topazproject.ambra.user.action.UserAlertsAction;32 import org.topazproject.ambra.user.action.UserProfileAction;33 29 34 30 import java.util.HashMap; … … 77 73 protected UserAlertsAction getMockUserAlertsAction(final String authId, final String topazId) { 78 74 final UserAlertsAction userAlertsAction = super.getMemberUserAlertsAction(); 79 final UserAlertsAction newUserAlertsAction = new MemberUserAlertsAction() { 80 private final Map<String, Object> mockSessionMap = createMockSessionMap(authId, topazId); 81 protected Map<String, Object> getSessionMap() { 82 return mockSessionMap; 83 } 84 }; 75 final UserAlertsAction newUserAlertsAction = new MemberUserAlertsAction(); 76 newUserAlertsAction.setSession(createMockSessionMap(authId, topazId)); 85 77 86 78 newUserAlertsAction.setUserService(userAlertsAction.getUserService()); … … 104 96 protected UserProfileAction getMockCreateUserAction(final String authId) { 105 97 final UserProfileAction createUserAction = super.getMemberUserProfileAction(); 106 final UserProfileAction newCreateUserAction = new MemberUserProfileAction() { 107 private Map<String,Object> mockSessionMap = createMockSessionMap(authId, null); 108 protected Map<String, Object> getSessionMap() { 109 return mockSessionMap; 110 } 111 }; 98 final UserProfileAction newCreateUserAction = new MemberUserProfileAction(); 99 newCreateUserAction.setSession(createMockSessionMap(authId, null)); 112 100 113 101 newCreateUserAction.setUserService(createUserAction.getUserService());
