Changeset 6940

Show
Ignore:
Timestamp:
12/16/08 13:48:44 (20 months ago)
Author:
dragisak
Message:

Get rid of static calls to AmbraUser?.geCurrentUser(). Remove dependency on servlet session from POJO's.

Location:
head/ambra/webapp/src
Files:
1 added
25 modified

Legend:

Unmodified
Added
Removed
  • head/ambra/webapp/src/main/java/org/topazproject/ambra/action/FeedbackAction.java

    r6880 r6940  
    5959 
    6060  private void setUserDetailsFromSession() { 
    61     final AmbraUser ambraUser = AmbraUser.getCurrentUser(); 
     61    final AmbraUser ambraUser = getCurrentUser(); 
    6262    if (null != ambraUser) { 
    6363      name = ambraUser.getDisplayName(); 
  • head/ambra/webapp/src/main/java/org/topazproject/ambra/admin/action/ViewRatingAction.java

    r6588 r6940  
    2121 
    2222import org.springframework.transaction.annotation.Transactional; 
    23 import org.topazproject.ambra.action.BaseActionSupport; 
     23import org.topazproject.ambra.action.BaseSessionAwareActionSupport; 
    2424import org.topazproject.ambra.models.Rating; 
    2525import org.topazproject.ambra.rating.service.RatingsService; 
    2626 
    2727@SuppressWarnings("serial") 
    28 public class ViewRatingAction extends BaseActionSupport { 
     28public class ViewRatingAction extends BaseSessionAwareActionSupport { 
    2929  private String ratingId; 
    3030  private Rating rating; 
     
    3434  @Transactional(readOnly = true) 
    3535  public String execute() throws Exception { 
    36     rating = getRatingsService().getRating(ratingId); 
     36    rating = getRatingsService().getRating(ratingId, getCurrentUser()); 
    3737    return SUCCESS; 
    3838  } 
  • head/ambra/webapp/src/main/java/org/topazproject/ambra/annotation/action/CreateAnnotationAction.java

    r6607 r6940  
    2727import org.springframework.transaction.annotation.Transactional; 
    2828import org.springframework.transaction.interceptor.TransactionAspectSupport; 
    29 import org.topazproject.ambra.action.BaseActionSupport; 
     29import org.topazproject.ambra.action.BaseSessionAwareActionSupport; 
    3030import org.topazproject.ambra.annotation.Context; 
    3131import org.topazproject.ambra.annotation.ContextFormatter; 
    3232import org.topazproject.ambra.annotation.service.AnnotationService; 
    3333import org.topazproject.ambra.util.ProfanityCheckingService; 
     34import org.topazproject.ambra.user.AmbraUser; 
    3435 
    3536import com.opensymphony.xwork2.validator.annotations.RequiredStringValidator; 
     
    3940 */ 
    4041@SuppressWarnings("serial") 
    41 public class CreateAnnotationAction extends BaseActionSupport { 
     42public class CreateAnnotationAction extends BaseSessionAwareActionSupport { 
    4243  private String target; 
    4344  private String commentTitle; 
     
    7374      if (profaneWordsInBody.isEmpty() && profaneWordsInTitle.isEmpty()) { 
    7475        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()); 
    7677        if (log.isDebugEnabled()) { 
    7778          log.debug("CreateAnnotationAction called and annotation created with id: " + annotationId); 
     
    7980        if ("correction".equals(noteType)) { 
    8081          annotationService.createFlag(annotationId, "Create Correction", 
    81               "Note created and flagged as a correction", mimeType); 
     82              "Note created and flagged as a correction", mimeType, getCurrentUser()); 
    8283        } 
    8384      } else { 
  • head/ambra/webapp/src/main/java/org/topazproject/ambra/annotation/action/CreateFlagAction.java

    r6607 r6940  
    2424import org.springframework.transaction.annotation.Transactional; 
    2525import org.springframework.transaction.interceptor.TransactionAspectSupport; 
    26 import org.topazproject.ambra.action.BaseActionSupport; 
     26import org.topazproject.ambra.action.BaseSessionAwareActionSupport; 
    2727import org.topazproject.ambra.annotation.service.AnnotationService; 
    2828 
     
    3333 */ 
    3434@SuppressWarnings("serial") 
    35 public class CreateFlagAction extends BaseActionSupport { 
     35public class CreateFlagAction extends BaseSessionAwareActionSupport { 
    3636  private String target; 
    3737  private String comment; 
     
    4747  public String execute() throws Exception { 
    4848    try { 
    49       annotationId = annotationService.createFlag(target, reasonCode, comment, mimeType); 
     49      annotationId = annotationService.createFlag(target, reasonCode, comment, mimeType, getCurrentUser()); 
    5050    } catch (final Exception e) { 
    5151      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  
    2626import org.springframework.transaction.annotation.Transactional; 
    2727import org.springframework.transaction.interceptor.TransactionAspectSupport; 
    28 import org.topazproject.ambra.action.BaseActionSupport; 
     28import org.topazproject.ambra.action.BaseSessionAwareActionSupport; 
    2929import org.topazproject.ambra.annotation.service.ReplyService; 
    3030import org.topazproject.ambra.util.ProfanityCheckingService; 
     31import org.topazproject.ambra.user.AmbraUser; 
    3132 
    3233import com.opensymphony.xwork2.validator.annotations.RequiredStringValidator; 
     
    3637 */ 
    3738@SuppressWarnings("serial") 
    38 public class CreateReplyAction extends BaseActionSupport { 
     39public class CreateReplyAction extends BaseSessionAwareActionSupport { 
    3940  private String replyId; 
    4041  private String root; 
     
    5758 
    5859      if (profaneWordsInBody.isEmpty() && profaneWordsInTitle.isEmpty()) { 
    59         replyId = replyService.createReply(root, inReplyTo, commentTitle, mimeType, comment); 
     60        replyId = replyService.createReply(root, inReplyTo, commentTitle, mimeType, comment, getCurrentUser()); 
    6061      } else { 
    6162        addProfaneMessages(profaneWordsInBody, "comment", "comment"); 
  • head/ambra/webapp/src/main/java/org/topazproject/ambra/annotation/service/AnnotationService.java

    r6882 r6940  
    9494   * @param isPublic to set up public permissions 
    9595   * 
     96   * @param user 
    9697   * @return a the new annotation id 
    9798   * 
     
    99100   */ 
    100101  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) 
    104105                     throws Exception { 
    105106 
     
    114115      throw new UnsupportedOperationException("supersedes is not supported"); 
    115116 
    116     String                  user       = AmbraUser.getCurrentUser().getUserId(); 
    117     AnnotationBlob          blob      = new AnnotationBlob(contentType); 
     117    String userId = user.getUserId(); 
     118    AnnotationBlob blob = new AnnotationBlob(contentType); 
    118119    final ArticleAnnotation annotation = annotationClass.newInstance(); 
    119120 
     
    122123    annotation.setContext(context); 
    123124    annotation.setTitle(title); 
    124     annotation.setCreator(user); 
     125    annotation.setCreator(userId); 
    125126    annotation.setBody(blob); 
    126127    annotation.setCreated(new Date()); 
     
    132133    if (log.isDebugEnabled()) 
    133134      log.debug("created annotaion " + newId + " for " + target + " with body in blob " 
    134                 + blob.getId()); 
     135          + blob.getId()); 
    135136 
    136137    permissionsService.propagatePermissions(newId, new String[] { blob.getId() }); 
     
    592593   * @param body body 
    593594   * @param isPublic isPublic 
     595   * @param user 
    594596   * @throws Exception on an error 
    595597   * @return unique identifier for the newly created annotation 
     
    599601                              final String olderAnnotation, final String title, 
    600602                              final String mimeType, final String body, 
    601                               final boolean isPublic) throws Exception { 
     603                              final boolean isPublic, AmbraUser user) throws Exception { 
    602604 
    603605    if (log.isDebugEnabled()) { 
     
    608610 
    609611    String annotationId = createAnnotation(Comment.class, mimeType, target, context, 
    610                                            olderAnnotation, title, body, true); 
     612                                           olderAnnotation, title, body, true, user); 
    611613 
    612614    if (log.isDebugEnabled()) { 
    613       final AmbraUser user = AmbraUser.getCurrentUser(); 
    614615      log.debug("Comment created with ID: " + annotationId + " for user: " + user + 
    615616                  " for IP: " + ServletActionContext.getRequest().getRemoteAddr()); 
     
    666667   * @param body body 
    667668   * @param mimeType mimeType 
     669   * @param user Logged in user 
    668670   * @return unique identifier for the newly created flag 
    669671   * @throws Exception on an error 
     
    671673  @Transactional(rollbackFor = { Throwable.class }) 
    672674  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 { 
    674676    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); 
    676678  } 
    677679 
  • head/ambra/webapp/src/main/java/org/topazproject/ambra/annotation/service/ReplyService.java

    r6882 r6940  
    6868   * @param body the reply body 
    6969   * 
     70   * @param user 
    7071   * @return a new reply 
    7172   * 
     
    7475  @Transactional(rollbackFor = { Throwable.class }) 
    7576  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) 
    7778                     throws Exception { 
    7879    pep.checkAccess(RepliesPEP.CREATE_REPLY, URI.create(root)); 
     
    8283 
    8384    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(); 
    8889    r.setMediator(getApplicationId()); 
    8990    r.setType(getDefaultType()); 
     
    9192    r.setInReplyTo(inReplyTo); 
    9293    r.setTitle(title); 
    93     r.setCreator(user); 
     94    r.setCreator(userId); 
    9495    r.setBody(blob); 
    9596    r.setCreated(new Date()); 
    9697 
    97     String  newId      = session.saveOrUpdate(r); 
     98    String  newId = session.saveOrUpdate(r); 
    9899    // now that the blob is created by OTM, write to it 
    99100    blob.getBody().writeAll(body.getBytes(getEncodingCharset())); 
  • head/ambra/webapp/src/main/java/org/topazproject/ambra/article/action/EmailArticleAction.java

    r6711 r6940  
    6565  @Transactional(readOnly = true) 
    6666  public String executeRender() throws Exception { 
    67     final AmbraUser ambraUser = AmbraUser.getCurrentUser(); 
     67    final AmbraUser ambraUser = getCurrentUser(); 
    6868    if (null != ambraUser) { 
    6969      senderName = ambraUser.getDisplayName(); 
  • head/ambra/webapp/src/main/java/org/topazproject/ambra/rating/action/AbstractRatingAction.java

    r6711 r6940  
    2525import org.springframework.beans.factory.annotation.Required; 
    2626import org.topazproject.ambra.ApplicationException; 
    27 import org.topazproject.ambra.action.BaseActionSupport; 
     27import org.topazproject.ambra.action.BaseSessionAwareActionSupport; 
    2828import org.topazproject.ambra.article.service.ArticleOtmService; 
    2929import org.topazproject.ambra.article.service.NoSuchArticleIdException; 
     
    3737 */ 
    3838@SuppressWarnings("serial") 
    39 public abstract class AbstractRatingAction extends BaseActionSupport { 
     39public abstract class AbstractRatingAction extends BaseSessionAwareActionSupport { 
    4040 
    4141  protected static final Log log = LogFactory.getLog(AbstractRatingAction.class); 
  • head/ambra/webapp/src/main/java/org/topazproject/ambra/rating/action/GetAverageRatingsAction.java

    r6592 r6940  
    2222import org.springframework.transaction.annotation.Transactional; 
    2323import org.topazproject.ambra.rating.service.RatingsService; 
     24import org.topazproject.ambra.user.AmbraUser; 
    2425 
    2526/** 
     
    4546  public String execute() throws Exception { 
    4647    avg = ratingsService.getAverageRatings(articleURI); 
    47     hasRated = ratingsService.hasRated(articleURI); 
     48    hasRated = ratingsService.hasRated(articleURI, getCurrentUser()); 
    4849    isResearchArticle = isResearchArticle(articleURI); 
    4950    return SUCCESS; 
  • head/ambra/webapp/src/main/java/org/topazproject/ambra/rating/action/RateAction.java

    r6821 r6940  
    8181  @Transactional(rollbackFor = { Throwable.class }) 
    8282  public String rateArticle() { 
    83     final AmbraUser user = AmbraUser.getCurrentUser(); 
     83    final AmbraUser user = getCurrentUser(); 
    8484    final Date      now  = new Date(System.currentTimeMillis()); 
    8585    final URI       annotatedArticle; 
     
    277277  @Transactional(readOnly = true) 
    278278  public String retrieveRatingsForUser() { 
    279     final AmbraUser user = AmbraUser.getCurrentUser(); 
     279    final AmbraUser user = getCurrentUser(); 
    280280 
    281281    if (user == null) { 
  • head/ambra/webapp/src/main/java/org/topazproject/ambra/rating/service/RatingsService.java

    r6821 r6940  
    126126   * @param ratingId Rating Id 
    127127   * 
     128   * @param user 
    128129   * @return Rating 
    129130   */ 
    130131  @Transactional(readOnly = true) 
    131   public Rating getRating(final String ratingId) { 
     132  public Rating getRating(final String ratingId, AmbraUser user) { 
    132133    Rating rating = session.get(Rating.class, ratingId); 
    133134 
    134135    // the PEP check is against what is rated, 
    135136    // e.g. can this user see the ratings for what is rated? 
    136     AmbraUser user = AmbraUser.getCurrentUser(); 
    137137    pep.checkObjectAccess(RatingsPEP.GET_RATINGS, URI.create(user.getUserId()), 
    138138                          rating.getAnnotates()); 
     
    189189  @SuppressWarnings("unchecked") 
    190190  @Transactional(readOnly = true) 
    191   public boolean hasRated(String articleURI) { 
    192     final AmbraUser user = AmbraUser.getCurrentUser(); 
     191  public boolean hasRated(String articleURI, AmbraUser user) { 
    193192 
    194193    if (user == null) 
  • head/ambra/webapp/src/main/java/org/topazproject/ambra/search/action/SearchAction.java

    r6932 r6940  
    3434 
    3535import org.springframework.transaction.annotation.Transactional; 
    36 import org.topazproject.ambra.action.BaseActionSupport; 
     36import org.topazproject.ambra.action.BaseSessionAwareActionSupport; 
    3737import org.topazproject.ambra.article.service.BrowseService; 
    3838import org.topazproject.ambra.search.SearchResultPage; 
     
    4747 */ 
    4848@SuppressWarnings("serial") 
    49 public class SearchAction extends BaseActionSupport { 
     49public class SearchAction extends BaseSessionAwareActionSupport { 
    5050  private static final Log log  = LogFactory.getLog(SearchAction.class); 
    5151  private static final DateFormat luceneDateFormat = new SimpleDateFormat("yyyy-MM-dd"); 
     
    120120        pageSize = configuration.getInt(SEARCH_PAGE_SIZE, 10); 
    121121 
    122       SearchResultPage results = searchService.find(queryString, startPage, pageSize); 
     122      SearchResultPage results = searchService.find(queryString, startPage, pageSize, getCurrentUser()); 
    123123      totalNoOfResults = results.getTotalNoOfResults(); 
    124124      searchResults    = results.getHits(); 
  • head/ambra/webapp/src/main/java/org/topazproject/ambra/search/service/SearchService.java

    r6933 r6940  
    161161   * @param startPage The page number of the search results the user wants 
    162162   * @param pageSize  The number of results per page 
     163   * @param user 
    163164   * @return A SearchResultPage representing the search results page to be rendered 
    164165   * @throws ParseException if <var>query</var> is not valid 
     
    166167   */ 
    167168  @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) 
    169170      throws ParseException, OtmException { 
    170     AmbraUser user     = AmbraUser.getCurrentUser(); 
    171171    String    cacheKey = getCurrentJournal() + "|" + (user == null ? "anon" : user.getUserId()) + 
    172172                         "|" + query; 
  • head/ambra/webapp/src/main/java/org/topazproject/ambra/user/action/AdminUserAlertsAction.java

    r6246 r6940  
    2929  private String topazId; 
    3030 
    31   @Override 
    32   protected AmbraUser getAmbraUserToUse() throws ApplicationException { 
    33     return getUserService().getUserByTopazId(topazId); 
    34   } 
    35  
    3631  /** 
    3732   * Setter for topazId. 
  • head/ambra/webapp/src/main/java/org/topazproject/ambra/user/action/MemberUserAlertsAction.java

    r6246 r6940  
    2626 */ 
    2727public class MemberUserAlertsAction extends UserAlertsAction { 
    28   @Override 
    29   protected AmbraUser getAmbraUserToUse() { 
    30     return AmbraUser.getCurrentUser(); 
    31   } 
    3228} 
  • head/ambra/webapp/src/main/java/org/topazproject/ambra/user/action/MemberUserProfileAction.java

    r6248 r6940  
    2525import static org.topazproject.ambra.Constants.AMBRA_USER_KEY; 
    2626 
    27 import java.util.Map; 
    28  
    2927/** 
    3028 * User Profile Action that is called by the member user to update their profile 
     
    4341 
    4442    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()); 
    4744    } 
    4845 
     
    5249  @Override 
    5350  protected AmbraUser getAmbraUserToUse() { 
    54     final Map<String, Object> sessionMap = getSessionMap(); 
    55     return (AmbraUser) sessionMap.get(AMBRA_USER_KEY); 
     51    return getCurrentUser(); 
    5652  } 
    5753 
    5854  @Override 
    5955  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); 
    6257  } 
    6358} 
  • head/ambra/webapp/src/main/java/org/topazproject/ambra/user/action/UserActionSupport.java

    r6225 r6940  
    2424 
    2525import org.springframework.beans.factory.annotation.Required; 
    26 import org.topazproject.ambra.action.BaseActionSupport; 
     26import org.topazproject.ambra.action.BaseSessionAwareActionSupport; 
    2727import org.topazproject.ambra.user.service.UserService; 
    2828 
    2929import com.googlecode.jsonplugin.annotations.JSON; 
    30  
    31 import java.util.Map; 
    3230 
    3331/** 
     
    3735 *  
    3836 */ 
    39 public class UserActionSupport extends BaseActionSupport { 
     37public class UserActionSupport extends BaseSessionAwareActionSupport { 
    4038  private static final Log log = LogFactory.getLog(UserActionSupport.class); 
    4139  private UserService userService; 
     
    5856  } 
    5957 
    60   protected Map<String, Object> getSessionMap() { 
    61     return userService.getUserContext().getSessionMap(); 
    62   } 
    6358} 
  • head/ambra/webapp/src/main/java/org/topazproject/ambra/user/action/UserAlertsAction.java

    r6933 r6940  
    3333import org.apache.commons.logging.LogFactory; 
    3434import org.springframework.transaction.annotation.Transactional; 
    35 import org.topazproject.ambra.ApplicationException; 
    3635import org.topazproject.ambra.user.AmbraUser; 
    3736import org.topazproject.ambra.user.service.UserAlert; 
     
    121120  @Transactional(rollbackFor = { Throwable.class }) 
    122121  public String saveAlerts() throws Exception { 
    123     final AmbraUser ambraUser = getAmbraUserToUse(); 
     122    final AmbraUser ambraUser = getCurrentUser(); 
    124123    if (ambraUser == null) { 
    125124      throw new ServletException("Unable to resolve ambra user"); 
     
    155154  @Transactional(readOnly = true) 
    156155  public String retrieveAlerts() throws Exception { 
    157     final AmbraUser ambraUser = getAmbraUserToUse(); 
     156    final AmbraUser ambraUser = getCurrentUser(); 
    158157    if (ambraUser == null) { 
    159158      throw new ServletException("Unable to resolve ambra user"); 
     
    186185 
    187186  /** 
    188    * Provides a way to get the AmbraUser to edit 
    189    * @return the AmbraUser to edit 
    190    * @throws org.topazproject.ambra.ApplicationException ApplicationException 
    191    */ 
    192   protected abstract AmbraUser getAmbraUserToUse() throws ApplicationException; 
    193  
    194   /** 
    195187   * @return categories that have monthly alerts 
    196188   */ 
  • head/ambra/webapp/src/main/java/org/topazproject/ambra/user/action/UserProfileAction.java

    r6268 r6940  
    3232import org.topazproject.ambra.user.UserProfileGrant; 
    3333import org.topazproject.ambra.user.service.DisplayNameAlreadyExistsException; 
    34 import org.topazproject.ambra.user.service.UserAlert; 
    3534import org.topazproject.ambra.util.FileUtils; 
    3635import org.topazproject.ambra.util.ProfanityCheckingService; 
     
    183182 
    184183      // update the user-id in the session if we just created an account for ourselves 
    185       Map<String, Object> session = getSessionMap(); 
    186184      if (authId != null && authId.equals(session.get(UserAccountsInterceptor.AUTH_KEY))) 
    187185        session.put(UserAccountsInterceptor.USER_KEY, topazId); 
     
    903901 
    904902  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); 
    906904    if (presetEmail != null) 
    907905      return presetEmail; 
  • head/ambra/webapp/src/main/java/org/topazproject/ambra/user/AmbraUser.java

    r6773 r6940  
    2323import org.apache.commons.logging.LogFactory; 
    2424 
    25 import org.apache.struts2.ServletActionContext; 
    26  
    27 import static org.topazproject.ambra.Constants.AMBRA_USER_KEY; 
    28  
    2925import org.topazproject.ambra.models.UserAccount; 
    3026import org.topazproject.ambra.models.UserPreferences; 
     
    6056 
    6157  /** 
    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 used 
    66   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   /** 
    7658   * Initializes a new Ambra user 
    7759   * 
    7860   * @param ua the user-account 
     61   * @param appId Application ID 
     62   * @param pep XACML Policy Enforcement Point  
    7963   */ 
    8064  public AmbraUser(UserAccount ua, String appId, UsersPEP pep) { 
     
    8973    UserPreferences p; 
    9074    try { 
    91       pep.checkAccess(pep.GET_PREFERENCES, ua.getId()); 
     75      pep.checkAccess(UsersPEP.GET_PREFERENCES, ua.getId()); 
    9276      p = ua.getPreferences(appId); 
    9377    } catch (SecurityException se) { 
     
    128112 
    129113  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)) 
    131115      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)) 
    133117      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)) 
    135119      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)) 
    137121      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)) 
    139123      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)) 
    141125      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)) 
    143127      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)) 
    145129      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)) 
    147131      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)) 
    149133      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)) 
    151135      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)) 
    153137      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)) 
    155139      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)) 
    157141      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)) 
    159143      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)) 
    161145      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)) 
    163147      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)) 
    165149      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)) 
    167151      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)) 
    169153      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)) 
    171155      prof.setResearchAreasText(null); 
    172156  } 
  • head/ambra/webapp/src/main/java/org/topazproject/ambra/web/UserContext.java

    r6225 r6940  
    2828/** 
    2929 * 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 
    3031 */ 
    3132public class UserContext { 
  • head/ambra/webapp/src/test/java/org/topazproject/ambra/annotation/action/AnnotationActionsTest.java

    r6885 r6940  
    3535import org.topazproject.ambra.BaseAmbraTestCase; 
    3636import org.topazproject.ambra.Constants; 
     37import org.topazproject.ambra.user.AmbraUser; 
    3738import org.topazproject.ambra.annotation.Context; 
    3839import org.topazproject.ambra.annotation.ContextFormatter; 
     
    726727 
    727728    final Collection<String> annotationIdList = new ArrayList<String>(); 
     729    AmbraUser ambraUser = new AmbraUser("123"); 
    728730    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)); 
    730732    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)); 
    732734    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)); 
    734736 
    735737    String annotatedContent = getFetchArticleService().getAnnotatedContent(subject); 
     
    763765    } 
    764766 
    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); 
    768771 
    769772    String content = getFetchArticleService().getAnnotatedContent(subject); 
  • head/ambra/webapp/src/test/java/org/topazproject/ambra/user/action/UserActionsTest.java

    r6248 r6940  
    2626import org.topazproject.ambra.Constants; 
    2727import 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; 
    3528 
    3629import java.util.HashMap; 
     
    108101    createUserAction.setPostalAddress(POSTAL_ADDRESS); 
    109102 
    110     final String[] privateFields = new String[]{ 
    111             UserProfileGrant.POSTAL_ADDRESS.getFieldName(), 
    112             UserProfileGrant.COUNTRY.getFieldName(), 
    113             UserProfileGrant.CITY.getFieldName()}; 
    114  
    115103    createUserAction.setExtendedVisibility(UserProfileAction.PRIVATE); 
    116104 
     
    228216  protected AssignAdminRoleAction createMockAssignAdminRoleAction(final String authId, final String topazId) { 
    229217    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)); 
    235220 
    236221    newAdminRoleAction.setUserService(adminRoleActionToClone.getUserService()); 
     
    241226  protected UserProfileAction getMockCreateUserAction(final String authId) { 
    242227    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)); 
    248230 
    249231    newCreateUserAction.setUserService(createUserAction.getUserService()); 
  • head/ambra/webapp/src/test/java/org/topazproject/ambra/user/action/UserAlertsTest.java

    r6248 r6940  
    2727import org.topazproject.ambra.Constants; 
    2828import 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; 
    3329 
    3430import java.util.HashMap; 
     
    7773  protected UserAlertsAction getMockUserAlertsAction(final String authId, final String topazId) { 
    7874    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)); 
    8577 
    8678    newUserAlertsAction.setUserService(userAlertsAction.getUserService()); 
     
    10496  protected UserProfileAction getMockCreateUserAction(final String authId) { 
    10597    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)); 
    112100 
    113101    newCreateUserAction.setUserService(createUserAction.getUserService());