Source Code Cross Referenced for NTSystem.java in  » Apache-Harmony-Java-SE » org-package » org » apache » harmony » auth » module » 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 » Apache Harmony Java SE » org package » org.apache.harmony.auth.module 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         *  Licensed to the Apache Software Foundation (ASF) under one or more
003:         *  contributor license agreements.  See the NOTICE file distributed with
004:         *  this work for additional information regarding copyright ownership.
005:         *  The ASF licenses this file to You under the Apache License, Version 2.0
006:         *  (the "License"); you may not use this file except in compliance with
007:         *  the License.  You may obtain a copy of the License at
008:         *
009:         *     http://www.apache.org/licenses/LICENSE-2.0
010:         *
011:         *  Unless required by applicable law or agreed to in writing, software
012:         *  distributed under the License is distributed on an "AS IS" BASIS,
013:         *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014:         *  See the License for the specific language governing permissions and
015:         *  limitations under the License.
016:         */
017:
018:        /**
019:         * @author Alexander V. Astapchuk
020:         * @version $Revision$
021:         */package org.apache.harmony.auth.module;
022:
023:        import java.util.Map;
024:
025:        import org.apache.harmony.auth.NTSidGroupPrincipal;
026:        import org.apache.harmony.auth.NTSidPrimaryGroupPrincipal;
027:        import org.apache.harmony.auth.NTSidUserPrincipal;
028:
029:        /** 
030:         * A helper class which queries information about the current NT user.
031:         */
032:        public final class NTSystem {
033:
034:            // Shows whether the hyauth library was loaded or not
035:            private static boolean loadLibDone;
036:
037:            // User's sid, domain and name
038:            private NTSidUserPrincipal user;
039:
040:            // User's domain sid
041:            private String domainSid;
042:
043:            // User's primary group
044:            /**/NTSidPrimaryGroupPrincipal mainGroup;
045:
046:            // A list of groups the user belongs to
047:            /**/NTSidGroupPrincipal[] groups;
048:
049:            // Impersonation token
050:            private long token;
051:
052:            // May be used to trace the native library execution    
053:            @SuppressWarnings("unused")
054:            private boolean debugNative;
055:
056:            /**
057:             * The default constructor. Loads hyauth library if necessary.
058:             * @throws UnsatisfiedLinkError if library hyauth not found
059:             */
060:            public NTSystem() {
061:                super ();
062:                synchronized (NTSystem.class) {
063:                    if (!loadLibDone) {
064:                        System.loadLibrary("hyauth"); //$NON-NLS-1$
065:                        initNatives();
066:                        loadLibDone = true;
067:                    }
068:                }
069:            }
070:
071:            /**
072:             * Constructs an instance with options.
073:             * @param options
074:             */
075:            public NTSystem(Map<String, ?> options) {
076:                this ();
077:                debugNative = "true".equalsIgnoreCase((String) options //$NON-NLS-1$
078:                        .get("debugNative")); //$NON-NLS-1$
079:            }
080:
081:            /**
082:             * Initializes internal data.
083:             */
084:            private static native void initNatives();
085:
086:            /**
087:             * Load the security information about user.
088:             */
089:            public native void load();
090:
091:            /**
092:             * Frees internal data stored during login().
093:             */
094:            public native void free();
095:
096:            /**
097:             * Returns name of user's domain
098:             */
099:            public String getDomain() {
100:                return user.getObjectDomain();
101:            }
102:
103:            /**
104:             * Returns String representation of SID of user's domain
105:             */
106:            public String getDomainSID() {
107:                return domainSid;
108:            }
109:
110:            /**
111:             * Returns array of SIDs of groups the user belongs to
112:             */
113:            public String[] getGroupIDs() {
114:                if (groups == null || groups.length == 0) {
115:                    return null;
116:                }
117:                String[] gids = new String[groups.length];
118:                for (int i = 0; i < groups.length; i++) {
119:                    gids[i] = groups[i].getName();
120:                }
121:                return gids;
122:            }
123:
124:            /**
125:             * Returns implementation token
126:             */
127:            public long getImpersonationToken() {
128:                return token;
129:            }
130:
131:            /**
132:             * Returns user name
133:             */
134:            public String getName() {
135:                return user.getObjectName();
136:            }
137:
138:            /**
139:             * Returns a SID of user's main group
140:             */
141:            public String getPrimaryGroupID() {
142:                return mainGroup.getSid();
143:            }
144:
145:            /**
146:             * Returns user's SID
147:             */
148:            public String getUserSID() {
149:                return user.getSid();
150:            }
151:
152:            /**
153:             * Returns a String representation of this object.
154:             */
155:            @Override
156:            public String toString() {
157:                String s = "NTSystem:\n"; //$NON-NLS-1$
158:                s += "   user         : " + user + "\n"; //$NON-NLS-1$ //$NON-NLS-2$
159:                s += "   domainSid    : " + domainSid + "\n"; //$NON-NLS-1$ //$NON-NLS-2$
160:                s += "   mainGroup    : " + mainGroup + "\n"; //$NON-NLS-1$ //$NON-NLS-2$
161:                s += "   token        : " + token + "\n"; //$NON-NLS-1$ //$NON-NLS-2$
162:                s += "   groups count : " + (groups == null ? 0 : groups.length); //$NON-NLS-1$
163:                if (groups != null) {
164:                    s += "\n"; //$NON-NLS-1$
165:                    for (int i = 0; i < groups.length; i++) {
166:                        s += "      " + i + "] " + groups[i] + "\n"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
167:                    }
168:                }
169:                return s;
170:            }
171:
172:            /**
173:             * Returns an array of groups the user belongs to
174:             */
175:            public NTSidGroupPrincipal[] getGroups() {
176:                if (groups == null) {
177:                    return null;
178:                }
179:                NTSidGroupPrincipal[] tmp = new NTSidGroupPrincipal[groups.length];
180:                System.arraycopy(groups, 0, tmp, 0, groups.length);
181:                return tmp;
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.