View Javadoc
1   package org.kuali.student.common.util.security;
2   
3   import org.kuali.student.r2.common.dto.ContextInfo;
4   import org.kuali.student.r2.common.dto.LocaleInfo;
5   
6   import java.util.Date;
7   import java.util.Locale;
8   
9   /**
10   * 
11   *  This is a library of utility methods that can be used when working with the context info. 
12   * 
13   * @author Kuali Rice Team (kuali-rice@googlegroups.com)
14   *
15   */
16  public class ContextUtils {
17  
18      /**
19       *
20       * Create a new instance of ContextInfo.
21       *
22       * @return
23       */
24      @Deprecated
25      public static ContextInfo getContextInfo(){
26          return createDefaultContextInfo();
27      }
28  
29      /**
30       * Creates a default context with the current user and date and default locale
31       * @return a default context
32       */
33      public static ContextInfo createDefaultContextInfo(){
34          String currentUserId = SecurityUtils.getCurrentUserId();
35  
36          LocaleInfo localeInfo = new LocaleInfo();
37          localeInfo.setLocaleLanguage(Locale.getDefault().getLanguage());
38          localeInfo.setLocaleRegion(Locale.getDefault().getCountry());
39  
40          ContextInfo contextInfo = new ContextInfo();
41          contextInfo.setAuthenticatedPrincipalId(currentUserId);
42          contextInfo.setPrincipalId(currentUserId);
43          contextInfo.setCurrentDate(new Date());
44          contextInfo.setLocale(localeInfo);
45  
46          return contextInfo;
47      }
48  }