KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > activemq > security > JaasCertificateSecurityContext


1 /**
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one or more
4  * contributor license agreements. See the NOTICE file distributed with
5  * this work for additional information regarding copyright ownership.
6  * The ASF licenses this file to You under the Apache License, Version 2.0
7  * (the "License"); you may not use this file except in compliance with
8  * the License. You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */

18
19 package org.apache.activemq.security;
20
21 import java.security.cert.X509Certificate JavaDoc;
22 import java.util.Set JavaDoc;
23
24 import javax.security.auth.Subject JavaDoc;
25
26 /**
27  * Extends the SecurityContext to provide a username which is the
28  * Distinguished Name from the certificate.
29  *
30  */

31 public class JaasCertificateSecurityContext extends SecurityContext {
32
33     private Subject JavaDoc subject;
34     private X509Certificate JavaDoc[] certs;
35   
36     public JaasCertificateSecurityContext(String JavaDoc userName, Subject JavaDoc subject, X509Certificate JavaDoc[] certs) {
37         super(userName);
38         this.subject = subject;
39         this.certs = certs;
40     }
41
42     public Set JavaDoc getPrincipals() {
43         return subject.getPrincipals();
44     }
45   
46     public String JavaDoc getUserName() {
47         if (certs != null && certs.length > 0) {
48             return certs[0].getSubjectDN().getName();
49         }
50         return super.getUserName();
51     }
52
53 }
54
Popular Tags