Changeset 2458

Show
Ignore:
Timestamp:
09/18/08 09:39:52 (4 months ago)
Author:
ahodgkinson
Message:

digitalme: Updated the Java launcher build script and added support for non-interactive mode.

Location:
trunk/digitalme/launchers/java
Files:
1 added
1 removed
3 modified

Legend:

Unmodified
Added
Removed
  • trunk/digitalme/launchers/java/CMakeLists.txt

    r1427 r2458  
    1818#------------------------------------------------------------------------------ 
    1919 
    20 project( digitalme-java) 
    21 message( STATUS "Building java launcher") 
     20# Policy 
    2221 
    23 ADD_SUBDIRECTORY(src) 
     22cmake_minimum_required( VERSION 2.4) 
     23 
     24# Project name 
     25 
     26project( DigitalMeJava Java) 
     27 
     28# Project version 
     29 
     30set( PROJECT_MAJOR_VERSION 0) 
     31set( PROJECT_MINOR_VERSION 5) 
     32 
     33# Component paths 
     34 
     35if( NOT FTK_DIR) 
     36        set( FTK_DIR 
     37                "${CMAKE_SOURCE_DIR}/../../ftk") 
     38endif( NOT FTK_DIR) 
     39 
     40# Java 
     41 
     42find_package( Java) 
     43set( JAVA_TARGET TRUE) 
     44 
     45# Include the local modules directory 
     46 
     47set( CMAKE_MODULE_PATH "${FTK_DIR}/CMakeModules") 
     48 
     49# Common configuration 
     50 
     51include( CommonConfig) 
     52 
     53# Verbose makefile 
     54 
     55# set( CMAKE_VERBOSE_MAKEFILE TRUE) 
     56 
     57# Directories 
     58 
     59set( CMAKE_SOURCE_DIR ${CMAKE_SOURCE_DIR}/src) 
     60 
     61# Source files 
     62 
     63set( JAVA_SOURCE_FILES 
     64        CardSelector.java 
     65        TestSelector.java 
     66) 
     67 
     68# Targets 
     69 
     70add_custom_target( ${PROJECT_NAME}.jar.classes 
     71   COMMAND ${JAVA_COMPILE} -d ${CMAKE_BINARY_DIR} 
     72           ${JAVA_SOURCE_FILES} 
     73   WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/com/novell/identityselector) 
     74         
     75add_custom_target( ${PROJECT_NAME}-${PROJECT_VERSION}.jar ALL 
     76   COMMAND ${JAVA_ARCHIVE} cvfm ${LIBRARY_OUTPUT_PATH}/${PROJECT_NAME}.jar 
     77           ${CMAKE_SOURCE_DIR}/manifest -C ${CMAKE_BINARY_DIR} com 
     78   WORKING_DIRECTORY ${CMAKE_BINARY_DIR}) 
     79 
     80# Dependencies 
     81 
     82add_dependencies( ${PROJECT_NAME}-${PROJECT_VERSION}.jar  
     83        ${PROJECT_NAME}.jar.classes) 
  • trunk/digitalme/launchers/java/src/com/novell/identityselector/CardSelector.java

    r1898 r2458  
    55// 
    66// This program and the accompanying materials are made available  
    7 // under, alternatively, the terms of:  a) the Eclipse Public License v1.0 
     7// under, alternatively, the terms of:  a) the Eclipse Public License v1.0 
    88// which accompanies this distribution, and is available at  
    99// http://www.eclipse.org/legal/epl-v10.html; or, b) the Apache License, 
     
    1818 
    1919package com.novell.identityselector; 
    20  
    21 import java.io.FileNotFoundException; 
    22 import java.io.IOException; 
    23  
    24 public class CardSelector { 
     20import java.io.*; 
     21import java.util.ArrayList; 
     22 
     23/******************************************************************************* 
     24Desc: 
     25*******************************************************************************/  
     26public class CardSelector  
     27{ 
     28        /**************************************************************************** 
     29        Desc: 
     30        ****************************************************************************/  
    2531         
    26         /**************************************************************************** 
    27         Desc: Command-line parameters 
    28         ****************************************************************************/    
    29          
    30     private static String DM_TEST_ARG_STR                                       = "--test"; 
    31     private static String DM_GET_TOKEN_ARG_STR                          = "--gettoken"; 
    32     private static String DM_TRUSTED_ISSUER_URIS_ARG_STR = "--issuers"; 
    33     private static String DM_RECIPIENT_ARG_STR                          = "--recipient"; 
    34     private static String DM_REQUIRED_CLAIMS_ARG_STR            = "--reqclaims=\""; 
    35     private static String DM_OPTIONAL_CLAIMS_ARG_STR            = "--optclaims=\""; 
    36     private static String DM_TOKEN_TYPE_ARG_STR                         = "--tokentype"; 
    37     private static String DM_PRIVACY_POLICY_FILE_ARG_STR = "--privfile"; 
    38     private static String DM_CERT_FILE_ARG_STR                          = "--certfile"; 
    39     private static String DM_TOKEN_OUTPUT_FILE_ARG_STR  = "--tokenfile"; 
    40     private static String DM_NON_SECURE_DESKTOP_ARG_STR         = "--nonsecure"; 
    41     private static String DM_VERSION_ARG_STR                            = "--version"; 
    42     private static String DM_ISSUER_POLICY_ARG_STR              = "--issuerpolicy"; 
    43      
    44     private static int NUM_ARGS = 12; 
    45          
    46      
    47     /**************************************************************************** 
    48     Desc: 
    49     ****************************************************************************/ 
    50          public static byte[] getToken(String sRelyingParty,  
    51                                                                 String[] saRequiredClaims,  
    52                                                                 String[] saOptionalClaims,  
    53                                                                 String sTokenType) throws Exception    
     32         private static String ISS_GET_TOKEN_ARG_STR                            = "--gettoken"; 
     33         private static String ISS_RECIPIENT_ARG_STR                            = "--recipient"; 
     34         private static String ISS_REQUIRED_CLAIMS_ARG_STR              = "--reqclaims"; 
     35         private static String ISS_OPTIONAL_CLAIMS_ARG_STR              = "--optclaims"; 
     36         private static String ISS_TOKEN_TYPE_ARG_STR                   = "--tokentype"; 
     37         private static String ISS_CERT_FILE_ARG_STR                            = "--certfile"; 
     38         private static String ISS_TOKEN_OUTPUT_FILE_ARG_STR    = "--tokenfile"; 
     39         private static String ISS_ISSUER_POLICY_ARG_STR                = "--issuerpolicy"; 
     40         private static String ISS_NON_INTERACTIVE_ARG_STR              = "--noninteractive"; 
     41          
     42         /*************************************************************************** 
     43         Desc: 
     44         ***************************************************************************/ 
     45         public static byte[] getToken( 
     46                String          sRelyingParty,  
     47                String[]        saRequiredClaims,  
     48                String[]                saOptionalClaims,  
     49                String          sTokenType, 
     50                boolean         bNonInteractive) throws Exception          
    5451         { 
    55                         return getToken(sRelyingParty,  
    56                                                 saRequiredClaims,  
    57                                                 saOptionalClaims,  
    58                                                 sTokenType, null, null); 
     52                return( getToken( sRelyingParty, saRequiredClaims, saOptionalClaims,  
     53                                        sTokenType, null, null, bNonInteractive)); 
    5954         } 
    60      
    61     /**************************************************************************** 
    62     Desc: 
    63     ****************************************************************************/ 
    64          public static byte[] getToken(String sRelyingParty,  
    65                                                                 String[] saRequiredClaims,  
    66                                                                 String[] saOptionalClaims,  
    67                                                                 String sTokenType, 
    68                                                                 String sPathToCertificate, 
    69                                                                 String sIssuerPolicy) throws Exception 
     55          
     56         /*************************************************************************** 
     57         Desc: 
     58         ***************************************************************************/ 
     59         public static byte[] getToken( 
     60                String                          sRelyingParty,  
     61                String[]                                saRequiredClaims,  
     62                String[]                                saOptionalClaims,  
     63                String                          sTokenType, 
     64                String                          sPathToCertificate, 
     65                String                          sIssuerPolicy, 
     66                boolean                         bNonInteractive) throws Exception 
    7067         { 
    71  
    72                 java.io.File fTempFile; 
    73                 String sTempFileName; 
    74                 StringBuffer sbArgs = new StringBuffer(); 
    75                 String sExepath = getExePath(); 
    76                  
    77                 String[] saArgs = new String[NUM_ARGS]; 
    78                 int argCount = 0; 
     68                java.io.File            fTempFile; 
     69                String                          sTempFileName; 
     70                StringBuffer            sbArgs = new StringBuffer(); 
     71                String                          sExePath = getExePath(); 
     72                ArrayList<String> alArgs = new ArrayList<String>(); 
     73                int                                     argCount = 0; 
     74                int                                     iExitCode; 
    7975                                 
    8076                // Check params 
    8177 
    82                 if ((sRelyingParty == null) || (sTokenType == null)) 
    83                 { 
    84                         throw new Exception("Invalid Arg"); 
    85                 }                 
    86                  
    87                 if (sExepath != null) 
    88                 { 
    89                         saArgs[argCount++] = sExepath; 
    90                          
    91               // Build argument array 
    92                          
    93               saArgs[argCount++] = DM_GET_TOKEN_ARG_STR; 
    94      
    95               // Set up temp file 
    96                          
    97                         try 
    98                         { 
    99                                 fTempFile = java.io.File.createTempFile("dmf", "tmp"); 
    100                                 sTempFileName = fTempFile.getCanonicalPath();  
    101                                 saArgs[argCount++] = (DM_TOKEN_OUTPUT_FILE_ARG_STR + "=\"" + sTempFileName + "\"" ); 
    102                         } 
    103                         catch (Exception e) 
    104                         { 
    105                                 e.printStackTrace(); 
    106                                 throw e; 
    107                         }                
    108  
    109                         // relying party url 
    110                          
    111                         saArgs[argCount++] = (DM_RECIPIENT_ARG_STR + "=\"" + sRelyingParty + "\""); 
    112          
    113                         // required claims 
    114                  
    115               if (saRequiredClaims != null) 
    116                         { 
    117                 sbArgs.append(DM_REQUIRED_CLAIMS_ARG_STR); 
    118                         for (int i=0; i<saRequiredClaims.length; i++) 
    119                  { 
    120                         sbArgs.append(saRequiredClaims[i]); 
    121                     sbArgs.append(" "); 
    122                  } 
    123                  sbArgs.append("\""); 
    124                  saArgs[argCount++] = sbArgs.toString(); 
    125                         } 
    126                  
    127               // optional claims 
    128                  
    129               sbArgs = new StringBuffer(); 
    130               if (saOptionalClaims != null) 
    131               { 
    132                 sbArgs.append(DM_OPTIONAL_CLAIMS_ARG_STR); 
    133                         for (int i=0; i<saOptionalClaims.length; i++) 
    134                  { 
    135                         sbArgs.append(saOptionalClaims[i]); 
    136                     sbArgs.append(" "); 
    137                  } 
    138                  sbArgs.append("\""); 
    139                  saArgs[argCount++] = sbArgs.toString(); 
    140                         } 
    141          
    142               // tokentype 
    143                  
    144               if (sTokenType != null) 
    145               { 
    146                 saArgs[argCount++] = (DM_TOKEN_TYPE_ARG_STR + "=\"" + sTokenType + "\""); 
    147               } 
    148                  
    149               // Path to certificate 
    150                  
    151               if (sPathToCertificate != null) 
    152               { 
    153                 saArgs[argCount++] = (DM_CERT_FILE_ARG_STR + "=\"" + sPathToCertificate + "\""); 
    154               } 
    155                  
    156              
    157               // issuer policy 
    158                  
    159               if (sIssuerPolicy != null) 
    160               { 
    161                 saArgs[argCount++] = (DM_ISSUER_POLICY_ARG_STR + "=\"" + sIssuerPolicy + "\""); 
    162               } 
    163                  
    164                  
    165               // pad saArg if necessary 
    166                  
    167               while (argCount < NUM_ARGS) 
    168               { 
    169                 saArgs[argCount++] = ""; 
    170               } 
    171                  
    172  
    173               // launch selector 
    174                  
    175                         try 
    176                         { 
    177                                 Process p = Runtime.getRuntime().exec(saArgs); 
    178                                 int rcode = p.waitFor(); 
    179                         } 
    180                         catch (Exception e) 
    181                         { 
    182                                 e.printStackTrace(); 
    183                                 throw e; 
    184                         } 
    185                          
    186                         // read the token from the temp file 
    187                          
    188                         try { 
    189                                 java.io.FileInputStream fis = new java.io.FileInputStream(fTempFile); 
    190                                 byte[] baToken = new byte[(int)fTempFile.length()]; 
    191                                 for (int i=0; i<fTempFile.length(); i++) 
     78                if( (sRelyingParty == null) || (sTokenType == null)) 
     79                { 
     80                        throw new Exception( "Invalid argument"); 
     81                } 
     82                 
     83                if( sExePath == null) 
     84                { 
     85                        throw new Exception( "Unable to locate identity selector"); 
     86                } 
     87                 
     88                // Set the identity selector path 
     89                 
     90                alArgs.add( sExePath); 
     91                 
     92                // Build argument array 
     93                 
     94                alArgs.add( ISS_GET_TOKEN_ARG_STR); 
     95  
     96                // Set up the temp file 
     97                 
     98                try 
     99                { 
     100                        fTempFile = java.io.File.createTempFile( "dmf", "tmp"); 
     101                        sTempFileName = fTempFile.getCanonicalPath();  
     102                        alArgs.add( ISS_TOKEN_OUTPUT_FILE_ARG_STR +  
     103                                                                                                "=\"" + sTempFileName + "\"" ); 
     104                } 
     105                catch( Exception e) 
     106                { 
     107                        e.printStackTrace(); 
     108                        throw e; 
     109                }                          
     110 
     111                // Relying party url 
     112                 
     113                alArgs.add( ISS_RECIPIENT_ARG_STR + "=\"" + sRelyingParty + "\""); 
     114 
     115                // Required claims 
     116                   
     117                if( saRequiredClaims != null) 
     118                { 
     119                        sbArgs.append( ISS_REQUIRED_CLAIMS_ARG_STR); 
     120                        sbArgs.append( "=\""); 
     121                         
     122                        for( int i = 0; i < saRequiredClaims.length; i++) 
     123                        { 
     124                                sbArgs.append( saRequiredClaims[ i]); 
     125                                sbArgs.append( " "); 
     126                        } 
     127                         
     128                        sbArgs.append( "\""); 
     129                        alArgs.add( sbArgs.toString()); 
     130                } 
     131                   
     132                // Optional claims 
     133                   
     134                sbArgs = new StringBuffer(); 
     135 
     136                if( saOptionalClaims != null) 
     137                { 
     138                        sbArgs.append( ISS_OPTIONAL_CLAIMS_ARG_STR); 
     139                        sbArgs.append( "=\""); 
     140                         
     141                        for( int i = 0; i < saOptionalClaims.length; i++) 
     142                        { 
     143                                sbArgs.append( saOptionalClaims[ i]); 
     144                                sbArgs.append( " "); 
     145                        } 
     146                         
     147                        sbArgs.append( "\""); 
     148                        alArgs.add( sbArgs.toString()); 
     149                } 
     150 
     151                // Token type 
     152                   
     153                if( sTokenType != null) 
     154                { 
     155                        alArgs.add( ISS_TOKEN_TYPE_ARG_STR + "=\"" + sTokenType + "\""); 
     156                } 
     157                   
     158                // Path to certificate file 
     159                   
     160                if( sPathToCertificate != null) 
     161                { 
     162                        alArgs.add( ISS_CERT_FILE_ARG_STR + "=\"" + sPathToCertificate + "\""); 
     163                } 
     164                 
     165                // Issuer policy 
     166                   
     167                if( sIssuerPolicy != null) 
     168                { 
     169                        alArgs.add( ISS_ISSUER_POLICY_ARG_STR + "=\"" + sIssuerPolicy + "\""); 
     170                } 
     171                 
     172                // Non-interactive 
     173                 
     174                if( bNonInteractive) 
     175                { 
     176                        alArgs.add( ISS_NON_INTERACTIVE_ARG_STR); 
     177                } 
     178                 
     179                // Launch the selector 
     180                 
     181                if( (iExitCode = execCommand( alArgs.toArray(  
     182                        new String[ alArgs.size()]))) != 0) 
     183                { 
     184                        throw new Exception( "getToken failed with error = " + iExitCode); 
     185                } 
     186                 
     187                // Read the token from the temp file 
     188                 
     189                try  
     190                { 
     191                        java.io.FileInputStream fis = new java.io.FileInputStream( fTempFile); 
     192                        byte[] baToken = new byte[ (int)fTempFile.length()]; 
     193                         
     194                        for( int i = 0; i < fTempFile.length(); i++) 
     195                        { 
     196                                try  
    192197                                { 
    193                                         try { 
    194                                                 baToken[i] = (byte) fis.read(); 
    195                                         } catch (IOException e) { 
    196                                                 e.printStackTrace(); 
    197                                                 throw e; 
    198                                         } 
     198                                        baToken[ i] = (byte)fis.read(); 
    199199                                } 
    200                          
    201                                 fTempFile.delete(); 
    202                                 return baToken; 
    203                                  
    204                         } catch (FileNotFoundException e) { 
    205                                  
    206                                 e.printStackTrace(); 
    207                         } 
    208                 } 
    209                  
    210                 return null; 
     200                                catch( IOException e)  
     201                                { 
     202                                        e.printStackTrace(); 
     203                                        throw e; 
     204                                } 
     205                        } 
     206                 
     207                        fTempFile.delete(); 
     208                        return( baToken); 
     209                }  
     210                catch( FileNotFoundException e)  
     211                { 
     212                        e.printStackTrace(); 
     213                } 
     214                 
     215                return( null); 
    211216        } 
    212217         
     
    215220        ****************************************************************************/ 
    216221        public static void manage() 
     222        { 
     223                String[]                saArgs = new String[ 1]; 
     224                 
     225                saArgs[ 0] = getExePath(); 
     226                execCommand( saArgs); 
     227        } 
     228         
     229        /**************************************************************************** 
     230        Desc: 
     231        ****************************************************************************/ 
     232        public static void importCard( String sFile) throws Exception 
     233        { 
     234                String  sExepath = getExePath(); 
     235                int             iExitCode; 
     236                 
     237                if( sFile == null) 
     238                { 
     239                        throw new Exception( "Invalid argument"); 
     240                } 
     241                 
     242                java.io.File f = new java.io.File( sFile); 
     243                 
     244                if( !f.exists()) 
     245                { 
     246                        throw new Exception( "File does not exist: " + sFile); 
     247                } 
     248                 
     249                if( sExepath != null) 
     250                { 
     251                        String[] saArgs = new String[ 2]; 
     252                         
     253                        saArgs[ 0] = sExepath; 
     254                        saArgs[ 1] = sFile; 
     255                         
     256                        if( (iExitCode = execCommand( saArgs)) != 0) 
     257                        { 
     258                                throw new Exception( "importCard failed with error = " + iExitCode); 
     259                        } 
     260                } 
     261        } 
     262 
     263        /**************************************************************************** 
     264        Desc: 
     265        ****************************************************************************/ 
     266        private static String getExePath() 
     267        { 
     268                String sUserhome = System.getProperty( "user.home"); 
     269                String[] paths = 
     270                                        { 
     271                                                "/usr/bin/digitalme", 
     272                                                "/usr/local/bin/digitalme", 
     273                                                sUserhome + "/Desktop/DigitalMe.app/Contents/MacOS/DigitalMe", 
     274                                                "/Applications/DigitalMe.app/Contents/MacOS/DigitalMe", 
     275                                        }; 
     276 
     277                for( int i = 0; i < paths.length; i++) 
     278                { 
     279                        java.io.File fFile = new java.io.File( paths[ i]); 
     280                         
     281                        if( fFile.exists()) 
     282                        { 
     283                                return( paths[i]); 
     284                        } 
     285                } 
     286 
     287                return( null); 
     288        } 
     289         
     290        /**************************************************************************** 
     291        Desc: 
     292        ****************************************************************************/ 
     293        public static int execCommand( 
     294                String[]                saArgs) 
    217295        {        
    218                 String sExepath = getExePath(); 
    219  
    220                 if (sExepath != null) 
    221                 {        
     296                int                     iExitVal = 0; 
     297                 
     298                if( saArgs != null && saArgs[ 0] != null) 
     299                { 
     300                        System.out.println( "Executing [" + saArgs[ 0] + "]"); 
     301                         
    222302                        try 
    223303                        { 
    224                                 Process p = Runtime.getRuntime().exec(sExepath); 
    225                                 p.waitFor(); 
    226                         } 
    227                         catch (Exception e) 
    228                         { 
     304                                Runtime                         rt = Runtime.getRuntime(); 
     305                                Process                         proc = rt.exec( saArgs); 
     306                                InputStream                     stderr = proc.getErrorStream(); 
     307                                InputStreamReader isr = new InputStreamReader( stderr); 
     308                                BufferedReader  br = new BufferedReader( isr); 
     309                                String                          line = null; 
     310                                 
     311                                while( (line = br.readLine()) != null) 
     312                                { 
     313                                        System.out.println(line); 
     314                                } 
     315                                 
     316                                iExitVal = proc.waitFor(); 
     317                                 
     318                                System.out.println( "Process exitValue: " + iExitVal);                           
     319                        } 
     320                        catch( Exception e) 
     321                        { 
     322                                iExitVal = -1; 
    229323                                e.printStackTrace(); 
    230324                        } 
    231325                } 
    232         } 
    233          
    234         /**************************************************************************** 
    235         Desc: 
    236         ****************************************************************************/ 
    237         public static void importCard(String sFile) throws Exception 
    238         { 
    239                 String sExepath = getExePath(); 
    240                  
    241                 if (sFile == null) 
    242                 { 
    243                         throw new Exception("Invalid arg"); 
    244                 }