use of javax.security.auth.kerberos.KerberosPrincipal in project ddf by codice.
the class AttributeMapLoaderTest method testGetBaseDnNonX500.
@Test
public void testGetBaseDnNonX500() {
Principal principal = new KerberosPrincipal(KERBEROS_PRINCIPAL);
String baseDN = attributeMapLoader.getBaseDN(principal, DEFAULT_BASE_DN, false);
String[] split = baseDN.replaceAll("\\s", "").split(",");
assertArrayEquals(X500_DEFAULT_BASE_DN_ARR, split);
}
use of javax.security.auth.kerberos.KerberosPrincipal in project ddf by codice.
the class AttributeMapLoaderTest method testKerberosGetUser.
@Test
public void testKerberosGetUser() {
Principal principal = new KerberosPrincipal(KERBEROS_PRINCIPAL);
assertEquals(TEST_USER, attributeMapLoader.getUser(principal));
}
use of javax.security.auth.kerberos.KerberosPrincipal in project qpid-broker-j by apache.
the class SimpleLDAPAuthenticationManagerTest method setUpKerberos.
private void setUpKerberos() throws Exception {
final LdapServer ldapServer = LDAP.getLdapServer();
final KdcServer kdcServer = ServerAnnotationProcessor.getKdcServer(LDAP.getDirectoryService(), ldapServer.getPort() + 1);
kdcServer.getConfig().setPaEncTimestampRequired(false);
final int port = kdcServer.getTransports()[0].getPort();
final String krb5confPath = createKrb5Conf(port);
SYSTEM_PROPERTY_SETTER.setSystemProperty("java.security.krb5.conf", krb5confPath);
SYSTEM_PROPERTY_SETTER.setSystemProperty("java.security.krb5.realm", null);
SYSTEM_PROPERTY_SETTER.setSystemProperty("java.security.krb5.kdc", null);
final KerberosPrincipal servicePrincipal = new KerberosPrincipal(LDAP_SERVICE_NAME + "/" + HOSTNAME + "@" + REALM, KerberosPrincipal.KRB_NT_SRV_HST);
final String servicePrincipalName = servicePrincipal.getName();
ldapServer.setSaslHost(servicePrincipalName.substring(servicePrincipalName.indexOf("/") + 1, servicePrincipalName.indexOf("@")));
ldapServer.setSaslPrincipal(servicePrincipalName);
ldapServer.setSearchBaseDn(USERS_DN);
createPrincipal("KDC", "KDC", "krbtgt", UUID.randomUUID().toString(), "krbtgt/" + REALM + "@" + REALM);
createPrincipal("Service", "LDAP Service", "ldap", UUID.randomUUID().toString(), servicePrincipalName);
}
use of javax.security.auth.kerberos.KerberosPrincipal in project qpid-broker-j by apache.
the class KerberosUtilities method createKerberosKeyTabLoginContext.
public LoginContext createKerberosKeyTabLoginContext(final String scopeName, final String principalName, final File keyTabFile) throws LoginException {
final KerberosPrincipal principal = new KerberosPrincipal(principalName);
final KeyTab keyTab = getKeyTab(principal, keyTabFile);
final Subject subject = new Subject(false, Collections.singleton(principal), Collections.emptySet(), Collections.singleton(keyTab));
return createLoginContext(scopeName, subject, createKeyTabConfiguration(scopeName, keyTabFile, principal.getName()));
}
use of javax.security.auth.kerberos.KerberosPrincipal in project cxf by apache.
the class LdapClaimsHandler method retrieveClaimValues.
public ProcessedClaimCollection retrieveClaimValues(ClaimCollection claims, ClaimsParameters parameters) {
final String user;
boolean useLdapLookup = false;
Principal principal = parameters.getPrincipal();
if (principal instanceof KerberosPrincipal) {
KerberosPrincipal kp = (KerberosPrincipal) principal;
StringTokenizer st = new StringTokenizer(kp.getName(), "@");
user = st.nextToken();
} else if (principal instanceof X500Principal) {
X500Principal x500p = (X500Principal) principal;
LOG.warning("Unsupported principal type X500: " + x500p.getName());
return new ProcessedClaimCollection();
} else if (principal != null) {
user = principal.getName();
if (user == null) {
LOG.warning("User must not be null");
return new ProcessedClaimCollection();
}
useLdapLookup = LdapUtils.isDN(user);
} else {
LOG.warning("Principal is null");
return new ProcessedClaimCollection();
}
if (LOG.isLoggable(Level.FINEST)) {
LOG.finest("Retrieve claims for user " + user);
}
Map<String, Attribute> ldapAttributes = null;
if (useLdapLookup) {
AttributesMapper<Map<String, Attribute>> mapper = new AttributesMapper<Map<String, Attribute>>() {
public Map<String, Attribute> mapFromAttributes(Attributes attrs) throws NamingException {
Map<String, Attribute> map = new HashMap<>();
NamingEnumeration<? extends Attribute> attrEnum = attrs.getAll();
while (attrEnum.hasMore()) {
Attribute att = attrEnum.next();
map.put(att.getID(), att);
}
return map;
}
};
ldapAttributes = ldap.lookup(user, mapper);
} else {
List<String> searchAttributeList = new ArrayList<>();
for (Claim claim : claims) {
String claimType = claim.getClaimType().toString();
if (getClaimsLdapAttributeMapping().keySet().contains(claimType)) {
searchAttributeList.add(getClaimsLdapAttributeMapping().get(claimType));
} else {
if (LOG.isLoggable(Level.FINER)) {
LOG.finer("Unsupported claim: " + claimType);
}
}
}
String[] searchAttributes = searchAttributeList.toArray(new String[0]);
if (this.userBaseDn != null) {
ldapAttributes = LdapUtils.getAttributesOfEntry(ldap, this.userBaseDn, this.getObjectClass(), this.getUserNameAttribute(), user, searchAttributes);
}
if (this.userBaseDNs != null && (ldapAttributes == null || ldapAttributes.isEmpty())) {
for (String userBase : userBaseDNs) {
ldapAttributes = LdapUtils.getAttributesOfEntry(ldap, userBase, this.getObjectClass(), this.getUserNameAttribute(), user, searchAttributes);
if (ldapAttributes != null && !ldapAttributes.isEmpty()) {
// User found
break;
}
}
}
}
if (ldapAttributes == null || ldapAttributes.isEmpty()) {
// No result
if (LOG.isLoggable(Level.INFO)) {
LOG.info("User '" + user + "' not found");
}
return new ProcessedClaimCollection();
}
ProcessedClaimCollection claimsColl = new ProcessedClaimCollection();
for (Claim claim : claims) {
ProcessedClaim c = processClaim(claim, ldapAttributes, principal);
if (c != null) {
// c.setIssuer(issuer);
// c.setOriginalIssuer(originalIssuer);
// c.setNamespace(namespace);
claimsColl.add(c);
}
}
return claimsColl;
}
Aggregations