Source Code Cross Referenced for RoleSyntax.java in  » Security » Bouncy-Castle » org » bouncycastle » asn1 » x509 » Java Source Code / Java DocumentationJava Source Code and Java Documentation

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 geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Security » Bouncy Castle » org.bouncycastle.asn1.x509 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package org.bouncycastle.asn1.x509;
002:
003:        import org.bouncycastle.asn1.ASN1Encodable;
004:        import org.bouncycastle.asn1.ASN1EncodableVector;
005:        import org.bouncycastle.asn1.ASN1Sequence;
006:        import org.bouncycastle.asn1.ASN1TaggedObject;
007:        import org.bouncycastle.asn1.DEREncodable;
008:        import org.bouncycastle.asn1.DERObject;
009:        import org.bouncycastle.asn1.DERSequence;
010:        import org.bouncycastle.asn1.DERString;
011:        import org.bouncycastle.asn1.DERTaggedObject;
012:
013:        /**
014:         * Implementation of the RoleSyntax object as specified by the RFC3281.
015:         * 
016:         * <pre>
017:         * RoleSyntax ::= SEQUENCE {
018:         *                 roleAuthority  [0] GeneralNames OPTIONAL,
019:         *                 roleName       [1] GeneralName
020:         *           } 
021:         * </pre>
022:         */
023:        public class RoleSyntax extends ASN1Encodable {
024:            private GeneralNames roleAuthority;
025:            private GeneralName roleName;
026:
027:            /**
028:             * RoleSyntax factory method.
029:             * @param obj the object used to construct an instance of <code>
030:             * RoleSyntax</code>. It must be an instance of <code>RoleSyntax
031:             * </code> or <code>ASN1Sequence</code>.
032:             * @return the instance of <code>RoleSyntax</code> built from the
033:             * supplied object.
034:             * @throws java.lang.IllegalArgumentException if the object passed
035:             * to the factory is not an instance of <code>RoleSyntax</code> or
036:             * <code>ASN1Sequence</code>.
037:             */
038:            public static RoleSyntax getInstance(Object obj) {
039:
040:                if (obj == null || obj instanceof  RoleSyntax) {
041:                    return (RoleSyntax) obj;
042:                } else if (obj instanceof  ASN1Sequence) {
043:                    return new RoleSyntax((ASN1Sequence) obj);
044:                }
045:                throw new IllegalArgumentException(
046:                        "Unknown object in RoleSyntax factory.");
047:            }
048:
049:            /**
050:             * Constructor.
051:             * @param roleAuthority the role authority of this RoleSyntax.
052:             * @param roleName    the role name of this RoleSyntax.
053:             */
054:            public RoleSyntax(GeneralNames roleAuthority, GeneralName roleName) {
055:                if (roleName == null
056:                        || roleName.getTagNo() != GeneralName.uniformResourceIdentifier
057:                        || ((DERString) roleName.getName()).getString().equals(
058:                                "")) {
059:                    throw new IllegalArgumentException(
060:                            "the role name MUST be non empty and MUST "
061:                                    + "use the URI option of GeneralName");
062:                }
063:                this .roleAuthority = roleAuthority;
064:                this .roleName = roleName;
065:            }
066:
067:            /**
068:             * Constructor. Invoking this constructor is the same as invoking
069:             * <code>new RoleSyntax(null, roleName)</code>.
070:             * @param roleName    the role name of this RoleSyntax.
071:             */
072:            public RoleSyntax(GeneralName roleName) {
073:                this (null, roleName);
074:            }
075:
076:            /**
077:             * Utility constructor. Takes a <code>String</code> argument representing
078:             * the role name, builds a <code>GeneralName</code> to hold the role name
079:             * and calls the constructor that takes a <code>GeneralName</code>.
080:             * @param roleName
081:             */
082:            public RoleSyntax(String roleName) {
083:                this (new GeneralName(GeneralName.uniformResourceIdentifier,
084:                        (roleName == null) ? "" : roleName));
085:            }
086:
087:            /**
088:             * Constructor that builds an instance of <code>RoleSyntax</code> by
089:             * extracting the encoded elements from the <code>ASN1Sequence</code>
090:             * object supplied.
091:             * @param seq    an instance of <code>ASN1Sequence</code> that holds
092:             * the encoded elements used to build this <code>RoleSyntax</code>.
093:             */
094:            public RoleSyntax(ASN1Sequence seq) {
095:                if (seq.size() < 1 || seq.size() > 2) {
096:                    throw new IllegalArgumentException("Bad sequence size: "
097:                            + seq.size());
098:                }
099:
100:                for (int i = 0; i != seq.size(); i++) {
101:                    ASN1TaggedObject taggedObject = ASN1TaggedObject
102:                            .getInstance(seq.getObjectAt(i));
103:                    switch (taggedObject.getTagNo()) {
104:                    case 0:
105:                        roleAuthority = GeneralNames.getInstance(taggedObject,
106:                                false);
107:                        break;
108:                    case 1:
109:                        roleName = GeneralName.getInstance(taggedObject, false);
110:                        break;
111:                    default:
112:                        throw new IllegalArgumentException(
113:                                "Unknown tag in RoleSyntax");
114:                    }
115:                }
116:            }
117:
118:            /**
119:             * Gets the role authority of this RoleSyntax.
120:             * @return    an instance of <code>GeneralNames</code> holding the
121:             * role authority of this RoleSyntax.
122:             */
123:            public GeneralNames getRoleAuthority() {
124:                return this .roleAuthority;
125:            }
126:
127:            /**
128:             * Gets the role name of this RoleSyntax.
129:             * @return    an instance of <code>GeneralName</code> holding the
130:             * role name of this RoleSyntax.
131:             */
132:            public GeneralName getRoleName() {
133:                return this .roleName;
134:            }
135:
136:            /**
137:             * Gets the role name as a <code>java.lang.String</code> object.
138:             * @return    the role name of this RoleSyntax represented as a 
139:             * <code>java.lang.String</code> object.
140:             */
141:            public String getRoleNameAsString() {
142:                DERString str = (DERString) this .roleName.getName();
143:
144:                return str.getString();
145:            }
146:
147:            /**
148:             * Gets the role authority as a <code>String[]</code> object.
149:             * @return the role authority of this RoleSyntax represented as a
150:             * <code>String[]</code> array.
151:             */
152:            public String[] getRoleAuthorityAsString() {
153:                if (roleAuthority == null) {
154:                    return new String[0];
155:                }
156:
157:                GeneralName[] names = roleAuthority.getNames();
158:                String[] namesString = new String[names.length];
159:                for (int i = 0; i < names.length; i++) {
160:                    DEREncodable value = names[i].getName();
161:                    if (value instanceof  DERString) {
162:                        namesString[i] = ((DERString) value).getString();
163:                    } else {
164:                        namesString[i] = value.toString();
165:                    }
166:                }
167:                return namesString;
168:            }
169:
170:            /**
171:             * Implementation of the method <code>toASN1Object</code> as
172:             * required by the superclass <code>ASN1Encodable</code>.
173:             * 
174:             * <pre>
175:             * RoleSyntax ::= SEQUENCE {
176:             *                 roleAuthority  [0] GeneralNames OPTIONAL,
177:             *                 roleName       [1] GeneralName
178:             *           } 
179:             * </pre>
180:             */
181:            public DERObject toASN1Object() {
182:                ASN1EncodableVector v = new ASN1EncodableVector();
183:                if (this .roleAuthority != null) {
184:                    v.add(new DERTaggedObject(false, 0, roleAuthority));
185:                }
186:                v.add(new DERTaggedObject(false, 1, roleName));
187:
188:                return new DERSequence(v);
189:            }
190:
191:            public String toString() {
192:                StringBuffer buff = new StringBuffer("Name: "
193:                        + this .getRoleNameAsString() + " - Auth: ");
194:                if (this .roleAuthority == null
195:                        || roleAuthority.getNames().length == 0) {
196:                    buff.append("N/A");
197:                } else {
198:                    String[] names = this .getRoleAuthorityAsString();
199:                    buff.append('[').append(names[0]);
200:                    for (int i = 1; i < names.length; i++) {
201:                        buff.append(", ").append(names[i]);
202:                    }
203:                    buff.append(']');
204:                }
205:                return buff.toString();
206:            }
207:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.