Source Code Cross Referenced for Signer.java in  » 6.0-JDK-Core » security » java » security » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Home
Java Source Code / Java Documentation
1.6.0 JDK Core
2.6.0 JDK Modules
3.6.0 JDK Modules com.sun
4.6.0 JDK Modules com.sun.java
5.6.0 JDK Modules sun
6.6.0 JDK Platform
7.Ajax
8.Apache Harmony Java SE
9.Aspect oriented
10.Authentication Authorization
11.Blogger System
12.Build
13.Byte Code
14.Cache
15.Chart
16.Chat
17.Code Analyzer
18.Collaboration
19.Content Management System
20.Database Client
21.Database DBMS
22.Database JDBC Connection Pool
23.Database ORM
24.Development
25.EJB Server
26.ERP CRM Financial
27.ESB
28.Forum
29.Game
30.GIS
31.Graphic 3D
32.Graphic Library
33.Groupware
34.HTML Parser
35.IDE
36.IDE Eclipse
37.IDE Netbeans
38.Installer
39.Internationalization Localization
40.Inversion of Control
41.Issue Tracking
42.J2EE
43.J2ME
44.JBoss
45.JMS
46.JMX
47.Library
48.Mail Clients
49.Music
50.Net
51.Parser
52.PDF
53.Portal
54.Profiler
55.Project Management
56.Report
57.RSS RDF
58.Rule Engine
59.Science
60.Scripting
61.Search Engine
62.Security
63.Sevlet Container
64.Source Control
65.Swing Library
66.Template Engine
67.Test Coverage
68.Testing
69.UML
70.Web Crawler
71.Web Framework
72.Web Mail
73.Web Server
74.Web Services
75.Web Services apache cxf 2.2.6
76.Web Services AXIS2
77.Wiki Engine
78.Workflow Engines
79.XML
80.XML UI
Java Source Code / Java Documentation » 6.0 JDK Core » security » java.security 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001        /*
002         * Copyright 1996-2006 Sun Microsystems, Inc.  All Rights Reserved.
003         * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
004         *
005         * This code is free software; you can redistribute it and/or modify it
006         * under the terms of the GNU General Public License version 2 only, as
007         * published by the Free Software Foundation.  Sun designates this
008         * particular file as subject to the "Classpath" exception as provided
009         * by Sun in the LICENSE file that accompanied this code.
010         *
011         * This code is distributed in the hope that it will be useful, but WITHOUT
012         * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
013         * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
014         * version 2 for more details (a copy is included in the LICENSE file that
015         * accompanied this code).
016         *
017         * You should have received a copy of the GNU General Public License version
018         * 2 along with this work; if not, write to the Free Software Foundation,
019         * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
020         *
021         * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
022         * CA 95054 USA or visit www.sun.com if you need additional information or
023         * have any questions.
024         */
025
026        package java.security;
027
028        import java.io.*;
029
030        /**
031         * This class is used to represent an Identity that can also digitally
032         * sign data.
033         *
034         * <p>The management of a signer's private keys is an important and
035         * sensitive issue that should be handled by subclasses as appropriate
036         * to their intended use.
037         *
038         * @see Identity
039         *
040         * @version 1.50 07/05/05
041         * @author Benjamin Renaud
042         *
043         * @deprecated This class is no longer used. Its functionality has been
044         * replaced by <code>java.security.KeyStore</code>, the
045         * <code>java.security.cert</code> package, and
046         * <code>java.security.Principal</code>.
047         */
048        @Deprecated
049        public abstract class Signer extends Identity {
050
051            private static final long serialVersionUID = -1763464102261361480L;
052
053            /**
054             * The signer's private key.
055             *
056             * @serial
057             */
058            private PrivateKey privateKey;
059
060            /**
061             * Creates a signer. This constructor should only be used for
062             * serialization.
063             */
064            protected Signer() {
065                super ();
066            }
067
068            /**
069             * Creates a signer with the specified identity name.
070             *
071             * @param name the identity name.
072             */
073            public Signer(String name) {
074                super (name);
075            }
076
077            /**
078             * Creates a signer with the specified identity name and scope.
079             *
080             * @param name the identity name.
081             *
082             * @param scope the scope of the identity.
083             *
084             * @exception KeyManagementException if there is already an identity
085             * with the same name in the scope.
086             */
087            public Signer(String name, IdentityScope scope)
088                    throws KeyManagementException {
089                super (name, scope);
090            }
091
092            /**
093             * Returns this signer's private key.
094             *
095             * <p>First, if there is a security manager, its <code>checkSecurityAccess</code> 
096             * method is called with <code>"getSignerPrivateKey"</code> 
097             * as its argument to see if it's ok to return the private key. 
098             * 
099             * @return this signer's private key, or null if the private key has
100             * not yet been set.
101             * 
102             * @exception  SecurityException  if a security manager exists and its  
103             * <code>checkSecurityAccess</code> method doesn't allow 
104             * returning the private key.
105             * 
106             * @see SecurityManager#checkSecurityAccess
107             */
108            public PrivateKey getPrivateKey() {
109                check("getSignerPrivateKey");
110                return privateKey;
111            }
112
113            /**
114             * Sets the key pair (public key and private key) for this signer.
115             *
116             * <p>First, if there is a security manager, its <code>checkSecurityAccess</code> 
117             * method is called with <code>"setSignerKeyPair"</code> 
118             * as its argument to see if it's ok to set the key pair. 
119             * 
120             * @param pair an initialized key pair.
121             *
122             * @exception InvalidParameterException if the key pair is not
123             * properly initialized.
124             * @exception KeyException if the key pair cannot be set for any
125             * other reason.
126             * @exception  SecurityException  if a security manager exists and its  
127             * <code>checkSecurityAccess</code> method doesn't allow 
128             * setting the key pair.
129             * 
130             * @see SecurityManager#checkSecurityAccess
131             */
132            public final void setKeyPair(KeyPair pair)
133                    throws InvalidParameterException, KeyException {
134                check("setSignerKeyPair");
135                final PublicKey pub = pair.getPublic();
136                PrivateKey priv = pair.getPrivate();
137
138                if (pub == null || priv == null) {
139                    throw new InvalidParameterException();
140                }
141                try {
142                    AccessController
143                            .doPrivileged(new PrivilegedExceptionAction<Void>() {
144                                public Void run() throws KeyManagementException {
145                                    setPublicKey(pub);
146                                    return null;
147                                }
148                            });
149                } catch (PrivilegedActionException pae) {
150                    throw (KeyManagementException) pae.getException();
151                }
152                privateKey = priv;
153            }
154
155            String printKeys() {
156                String keys = "";
157                PublicKey publicKey = getPublicKey();
158                if (publicKey != null && privateKey != null) {
159                    keys = "\tpublic and private keys initialized";
160
161                } else {
162                    keys = "\tno keys";
163                }
164                return keys;
165            }
166
167            /**
168             * Returns a string of information about the signer.
169             *
170             * @return a string of information about the signer.
171             */
172            public String toString() {
173                return "[Signer]" + super .toString();
174            }
175
176            private static void check(String directive) {
177                SecurityManager security = System.getSecurityManager();
178                if (security != null) {
179                    security.checkSecurityAccess(directive);
180                }
181            }
182
183        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.