use of javax.naming.InvalidNameException in project tomcat70 by apache.
the class JNDIRealm method getDistinguishedName.
/**
* Returns the distinguished name of a search result.
*
* @param context Our DirContext
* @param base The base DN
* @param result The search result
* @return String containing the distinguished name
*/
protected String getDistinguishedName(DirContext context, String base, SearchResult result) throws NamingException {
// the result name. For non-relative names, use the returned name.
if (result.isRelative()) {
if (containerLog.isTraceEnabled()) {
containerLog.trace(" search returned relative name: " + result.getName());
}
NameParser parser = context.getNameParser("");
Name contextName = parser.parse(context.getNameInNamespace());
Name baseName = parser.parse(base);
// Bugzilla 32269
Name entryName = parser.parse(new CompositeName(result.getName()).get(0));
Name name = contextName.addAll(baseName);
name = name.addAll(entryName);
return name.toString();
} else {
String absoluteName = result.getName();
if (containerLog.isTraceEnabled())
containerLog.trace(" search returned absolute name: " + result.getName());
try {
// Normalize the name by running it through the name parser.
NameParser parser = context.getNameParser("");
URI userNameUri = new URI(absoluteName);
String pathComponent = userNameUri.getPath();
// Should not ever have an empty path component, since that is /{DN}
if (pathComponent.length() < 1) {
throw new InvalidNameException("Search returned unparseable absolute name: " + absoluteName);
}
Name name = parser.parse(pathComponent.substring(1));
return name.toString();
} catch (URISyntaxException e) {
throw new InvalidNameException("Search returned unparseable absolute name: " + absoluteName);
}
}
}
use of javax.naming.InvalidNameException in project certmgr by hdecarne.
the class CertOptionsTemplates method wrap.
public static Template wrap(UserCertStoreEntry storeEntry) {
String dnInput = X500Names.toString(storeEntry.dn());
String aliasInput = dnInput;
try {
LdapName dn = new LdapName(aliasInput);
for (Rdn rdn : dn.getRdns()) {
if (DN_ALIAS_KEY.equals(rdn.getType())) {
aliasInput = String.valueOf(rdn.getValue());
break;
}
}
} catch (InvalidNameException e) {
Exceptions.ignore(e);
}
CertOptionsPreset preset = new CertOptionsPreset(aliasInput, dnInput);
try {
if (storeEntry.hasCRT()) {
X509Certificate crt = storeEntry.getCRT();
PublicKey publicKey = crt.getPublicKey();
preset.setKeyAlg(KeyHelper.getKeyAlg(publicKey));
preset.setKeySize(KeyHelper.getKeySize(publicKey));
Set<String> criticalExtensionOIDs = crt.getCriticalExtensionOIDs();
if (criticalExtensionOIDs != null) {
for (String criticalExtensionOID : criticalExtensionOIDs) {
if (!INVALID_PRESET_EXTENSIONS.contains(criticalExtensionOID)) {
X509ExtensionData criticalExtension = X509ExtensionData.decode(criticalExtensionOID, true, crt.getExtensionValue(criticalExtensionOID));
preset.addExtension(criticalExtension);
}
}
}
Set<String> nonCriticalExtensionOIDs = crt.getNonCriticalExtensionOIDs();
if (nonCriticalExtensionOIDs != null) {
for (String nonCriticalExtensionOID : nonCriticalExtensionOIDs) {
if (!INVALID_PRESET_EXTENSIONS.contains(nonCriticalExtensionOID)) {
X509ExtensionData nonCriticalExtension = X509ExtensionData.decode(nonCriticalExtensionOID, false, crt.getExtensionValue(nonCriticalExtensionOID));
preset.addExtension(nonCriticalExtension);
}
}
}
}
} catch (IOException e) {
Exceptions.warn(e);
}
return new Template(preset.aliasInput(), preset);
}
use of javax.naming.InvalidNameException in project certmgr by hdecarne.
the class DNEditorController method init.
/**
* Initialize the DN editor's content.
*
* @param dnInput The current DN input.
* @return This controller.
*/
public DNEditorController init(String dnInput) {
try {
LdapName dn = new LdapName(dnInput);
this.ctlRdnEntries.getItems().addAll(dn.getRdns());
} catch (InvalidNameException e) {
Exceptions.ignore(e);
}
return this;
}
use of javax.naming.InvalidNameException in project archiva by apache.
the class ArchivaLdapConnectionFactory method initialize.
@PostConstruct
@Override
public void initialize() {
try {
LdapConfiguration ldapConfiguration = redbackRuntimeConfigurationAdmin.getRedbackRuntimeConfiguration().getLdapConfiguration();
ldapConnectionConfiguration = new LdapConnectionConfiguration();
ldapConnectionConfiguration.setHostname(ldapConfiguration.getHostName());
ldapConnectionConfiguration.setPort(ldapConfiguration.getPort());
ldapConnectionConfiguration.setSsl(ldapConfiguration.isSsl());
ldapConnectionConfiguration.setBaseDn(ldapConfiguration.getBaseDn());
ldapConnectionConfiguration.setContextFactory(ldapConfiguration.getContextFactory());
ldapConnectionConfiguration.setBindDn(ldapConfiguration.getBindDn());
ldapConnectionConfiguration.setPassword(ldapConfiguration.getPassword());
ldapConnectionConfiguration.setAuthenticationMethod(ldapConfiguration.getAuthenticationMethod());
ldapConnectionConfiguration.setExtraProperties(toProperties(ldapConfiguration.getExtraProperties()));
valid = true;
} catch (InvalidNameException e) {
log.error("Error during initialization of LdapConnectionFactory {}", e.getMessage(), e);
// throw new RuntimeException( "Error while initializing connection factory.", e );
} catch (RepositoryAdminException e) {
throw new RuntimeException("Error while initializing ldapConnectionConfiguration: " + e.getMessage(), e);
}
}
use of javax.naming.InvalidNameException in project archiva by apache.
the class DefaultRedbackRuntimeConfigurationService method checkLdapConnection.
@Override
public Boolean checkLdapConnection(LdapConfiguration ldapConfiguration) throws ArchivaRestServiceException {
LdapConnection ldapConnection = null;
try {
LdapConnectionConfiguration ldapConnectionConfiguration = new LdapConnectionConfiguration(ldapConfiguration.getHostName(), ldapConfiguration.getPort(), ldapConfiguration.getBaseDn(), ldapConfiguration.getContextFactory(), ldapConfiguration.getBindDn(), ldapConfiguration.getPassword(), ldapConfiguration.getAuthenticationMethod(), toProperties(ldapConfiguration.getExtraProperties()));
ldapConnectionConfiguration.setSsl(ldapConfiguration.isSsl());
ldapConnection = ldapConnectionFactory.getConnection(ldapConnectionConfiguration);
ldapConnection.close();
// verify groups dn value too
ldapConnectionConfiguration = new LdapConnectionConfiguration(ldapConfiguration.getHostName(), ldapConfiguration.getPort(), ldapConfiguration.getBaseGroupsDn(), ldapConfiguration.getContextFactory(), ldapConfiguration.getBindDn(), ldapConfiguration.getPassword(), ldapConfiguration.getAuthenticationMethod(), toProperties(ldapConfiguration.getExtraProperties()));
ldapConnectionConfiguration.setSsl(ldapConfiguration.isSsl());
ldapConnection = ldapConnectionFactory.getConnection(ldapConnectionConfiguration);
} catch (InvalidNameException e) {
log.warn("fail to get ldapConnection: {}", e.getMessage(), e);
throw new ArchivaRestServiceException(e.getMessage(), e);
} catch (LdapException e) {
log.warn("fail to get ldapConnection: {}", e.getMessage(), e);
throw new ArchivaRestServiceException(e.getMessage(), e);
} finally {
if (ldapConnection != null) {
ldapConnection.close();
}
}
return Boolean.TRUE;
}
Aggregations