javaextensions/pim/javasrc/com/nokia/mj/impl/pim/PIMPermissionImpl.java
branchRCL_3
changeset 19 04becd199f91
child 67 63b81d807542
equal deleted inserted replaced
16:f5050f1da672 19:04becd199f91
       
     1 /*
       
     2 * Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:  PIM permission check wrapper.
       
    15  *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 // PACKAGE
       
    21 package com.nokia.mj.impl.pim;
       
    22 
       
    23 import javax.microedition.pim.PIM;
       
    24 import java.security.Permission;
       
    25 import java.security.PermissionCollection;
       
    26 import com.nokia.mj.impl.security.common.PermissionBase;
       
    27 import com.nokia.mj.impl.security.utils.SecurityPromptMessage;
       
    28 
       
    29 public class PIMPermissionImpl extends PermissionBase
       
    30 {
       
    31     protected static final int OPERATION_ITEM_DELETION     = 1;
       
    32     protected static final int OPERATION_ITEM_COMMIT       = 2;
       
    33     protected static final int OPERATION_CATEGORY_DELETION = 3;
       
    34 
       
    35     protected static final String ACTION_READ_CONTACTS  = "read_contacts";
       
    36     protected static final String ACTION_WRITE_CONTACTS = "write_contacts";
       
    37     protected static final String ACTION_READ_TODOS     = "read_todos";
       
    38     protected static final String ACTION_WRITE_TODOS    = "write_todos";
       
    39     protected static final String ACTION_READ_EVENTS    = "read_events";
       
    40     protected static final String ACTION_WRITE_EVENTS   = "write_events";
       
    41 
       
    42     int iOperation ;
       
    43 
       
    44     String iListName = null;
       
    45     String iItemInfo = null;
       
    46     String iAction;
       
    47 
       
    48 
       
    49     PIMPermissionImpl(String aUri, String aAction)
       
    50     {
       
    51         super(aUri);
       
    52         iAction = aAction ;
       
    53     }
       
    54 
       
    55     PIMPermissionImpl(String aAction, String aItemInfo, String aListName, int aOperation)
       
    56     {
       
    57         super("pim://*");
       
    58         iOperation = aOperation;
       
    59         iListName = aListName;
       
    60         iItemInfo = aItemInfo;
       
    61         iAction = aAction;
       
    62     }
       
    63 
       
    64     /**
       
    65      * Returns the question (as localized text) associated with the security
       
    66      * prompt
       
    67      *
       
    68      * @return the localized text associated with the security prompt
       
    69      */
       
    70     public String getSecurityPromptQuestion(int aInteractionMode)
       
    71     {
       
    72         if (aInteractionMode == SESSION_INTERACTION_MODE ||
       
    73                 aInteractionMode == BLANKET_INTERACTION_MODE)
       
    74         {
       
    75             return (SecurityPromptMessage.getInstance()).getText(
       
    76                        SecurityPromptMessage.QUESTION_ID_MANAGE_USER_DATA,
       
    77                        null);
       
    78         }
       
    79 
       
    80         // either provide own localized text
       
    81         // or use the pre-defined texts
       
    82         // Note: some permissions use the same text always (case in which the
       
    83         // ID and the params for the text could be chosen at this phase) and
       
    84         // some permissions use a more dynamic text, depending on the context
       
    85         // in which they are used, case in which the ID and the params could
       
    86         // come from the constructor
       
    87         if (iOperation == OPERATION_ITEM_DELETION)
       
    88         {
       
    89             if (iItemInfo == null)
       
    90             {
       
    91                 return (SecurityPromptMessage.getInstance()).getText(
       
    92                            SecurityPromptMessage.QUESTION_ID_DELETING_UNNAMED_ITEM,
       
    93                            new String[] {iListName});
       
    94             }
       
    95             else
       
    96             {
       
    97                 return (SecurityPromptMessage.getInstance()).getText(
       
    98                            SecurityPromptMessage.QUESTION_ID_DELETING_ITEM,
       
    99                            new String[] {iListName});
       
   100             }
       
   101         }
       
   102         else if (iOperation == OPERATION_ITEM_COMMIT)
       
   103         {
       
   104             if (iItemInfo == null)
       
   105             {
       
   106                 return (SecurityPromptMessage.getInstance()).getText(
       
   107                            SecurityPromptMessage.QUESTION_ID_UPDATING_UNNAMED_ITEM,
       
   108                            new String[] {iListName});
       
   109             }
       
   110             else
       
   111             {
       
   112                 return (SecurityPromptMessage.getInstance()).getText(
       
   113                            SecurityPromptMessage.QUESTION_ID_UPDATING_ITEM,
       
   114                            new String[] {iListName});
       
   115             }
       
   116         }
       
   117         else if (iOperation == OPERATION_CATEGORY_DELETION)
       
   118         {
       
   119             return (SecurityPromptMessage.getInstance()).getText(
       
   120                        SecurityPromptMessage.QUESTION_ID_DELETING_CATEGORY,
       
   121                        new String[] {iItemInfo, iListName});
       
   122         }
       
   123         else if (ACTION_READ_CONTACTS.equals(iAction))
       
   124         {
       
   125             return (SecurityPromptMessage.getInstance()).getText(
       
   126                        SecurityPromptMessage.QUESTION_ID_READING_CONTACTS,null);
       
   127         }
       
   128         else if (ACTION_READ_EVENTS.equals(iAction))
       
   129         {
       
   130             return (SecurityPromptMessage.getInstance()).getText(
       
   131                        SecurityPromptMessage.QUESTION_ID_READING_EVENTS,null);
       
   132         }
       
   133         else if (ACTION_READ_TODOS.equals(iAction))
       
   134         {
       
   135             return (SecurityPromptMessage.getInstance()).getText(
       
   136                        SecurityPromptMessage.QUESTION_ID_READING_TODOS,null);
       
   137         }
       
   138         else if (ACTION_WRITE_CONTACTS.equals(iAction))
       
   139         {
       
   140             return (SecurityPromptMessage.getInstance()).getText(
       
   141                        SecurityPromptMessage.QUESTION_ID_MODIFYING_CONTACTS,null);
       
   142         }
       
   143         else if (ACTION_WRITE_EVENTS.equals(iAction))
       
   144         {
       
   145             return (SecurityPromptMessage.getInstance()).getText(
       
   146                        SecurityPromptMessage.QUESTION_ID_MODIFYING_EVENTS,null);
       
   147         }
       
   148         else if (ACTION_WRITE_TODOS.equals(iAction))
       
   149         {
       
   150             return (SecurityPromptMessage.getInstance()).getText(
       
   151                        SecurityPromptMessage.QUESTION_ID_MODIFYING_TODOS,null);
       
   152         }
       
   153         else if (PermissionBase.matchActions(iAction, ACTION_READ_EVENTS + "," + ACTION_READ_TODOS))
       
   154         {
       
   155             // list a calendar
       
   156             return (SecurityPromptMessage.getInstance()).getText(
       
   157                        SecurityPromptMessage.QUESTION_ID_LISTING_CALENDARS,null);
       
   158         }
       
   159         else if (PermissionBase.matchActions(iAction, ACTION_WRITE_EVENTS + "," + ACTION_WRITE_TODOS))
       
   160         {
       
   161             if (iItemInfo == null)
       
   162             {
       
   163                 // create calendar
       
   164                 return (SecurityPromptMessage.getInstance()).getText(
       
   165                            SecurityPromptMessage.QUESTION_ID_ADDING_CALENDAR,null);
       
   166             }
       
   167             else
       
   168             {
       
   169                 // delete calendar
       
   170                 return (SecurityPromptMessage.getInstance()).getText(
       
   171                            SecurityPromptMessage.QUESTION_ID_DELETING_CALENDAR,
       
   172                            new String[] {iItemInfo});
       
   173             }
       
   174         }
       
   175         return null;
       
   176     }
       
   177 
       
   178 
       
   179     public String toString()
       
   180     {
       
   181         if (ACTION_READ_CONTACTS.equals(iAction))
       
   182         {
       
   183             return "javax.microedition.pim.ContactList.read";
       
   184         }
       
   185         else if (ACTION_READ_EVENTS.equals(iAction))
       
   186         {
       
   187             return "javax.microedition.pim.EventList.read";
       
   188         }
       
   189         else if (ACTION_READ_TODOS.equals(iAction))
       
   190         {
       
   191             return "javax.microedition.pim.ToDoList.read";
       
   192         }
       
   193         else if (ACTION_WRITE_CONTACTS.equals(iAction))
       
   194         {
       
   195             return "javax.microedition.pim.ContactList.write";
       
   196         }
       
   197         else if (ACTION_WRITE_EVENTS.equals(iAction))
       
   198         {
       
   199             return "javax.microedition.pim.EventList.write";
       
   200         }
       
   201         else if (ACTION_WRITE_TODOS.equals(iAction))
       
   202         {
       
   203             return "javax.microedition.pim.ToDoList.write";
       
   204         }
       
   205         else if (PermissionBase.matchActions(iAction, ACTION_READ_EVENTS + "," + ACTION_READ_TODOS))
       
   206         {
       
   207             return "javax.microedition.pim.EventList.read, javax.microedition.pim.ToDoList.read";
       
   208         }
       
   209         else if (PermissionBase.matchActions(iAction, ACTION_WRITE_EVENTS + "," + ACTION_WRITE_TODOS))
       
   210         {
       
   211             return "javax.microedition.pim.EventList.write, javax.microedition.pim.ToDoList.write";
       
   212         }
       
   213         return null;
       
   214     }
       
   215 
       
   216     public boolean implies(Permission p)
       
   217     {
       
   218         if (p instanceof PIMPermissionImpl)
       
   219         {
       
   220             PIMPermissionImpl per = (PIMPermissionImpl)p;
       
   221             if (PermissionBase.matchActions(iAction,per.iAction))
       
   222             {
       
   223                 return true;
       
   224             }
       
   225         }
       
   226         return false;
       
   227     }
       
   228 
       
   229     public boolean equals(Object obj)
       
   230     {
       
   231         return true;
       
   232     }
       
   233 
       
   234     public int hashCode()
       
   235     {
       
   236         return 0;
       
   237     }
       
   238 
       
   239     public String getActions()
       
   240     {
       
   241         return iAction;
       
   242     }
       
   243 
       
   244     public PermissionCollection newPermissionCollection()
       
   245     {
       
   246         return null;
       
   247     }
       
   248 
       
   249 
       
   250 }