List of usage examples for javax.naming InvalidNameException getMessage
public String getMessage()
From source file:com.evolveum.midpoint.prism.match.DistinguishedNameMatchingRule.java
@Override public String normalize(String original) throws SchemaException { if (StringUtils.isBlank(original)) { return null; }// ww w. j a v a 2 s. c o m LdapName dn; try { dn = new LdapName(original); } catch (InvalidNameException e) { throw new SchemaException("String '" + original + "' is not a DN: " + e.getMessage(), e); } return StringUtils.lowerCase(dn.toString()); }
From source file:com.evolveum.midpoint.prism.match.DistinguishedNameMatchingRule.java
@Override public boolean match(String a, String b) throws SchemaException { if (StringUtils.isBlank(a) && StringUtils.isBlank(b)) { return true; }//from w w w. j av a 2 s .c om if (StringUtils.isBlank(a) || StringUtils.isBlank(b)) { return false; } LdapName dnA; try { dnA = new LdapName(a); } catch (InvalidNameException e) { throw new SchemaException("String '" + a + "' is not a DN: " + e.getMessage(), e); } LdapName dnB; try { dnB = new LdapName(b); } catch (InvalidNameException e) { throw new SchemaException("String '" + b + "' is not a DN: " + e.getMessage(), e); } return dnA.equals(dnB); }
From source file:org.apache.syncope.core.sync.LDAPDomainSyncActions.java
private LdapName resolveDnOnSyncope(SyncopeUser user, SyncResultsHandler handler) { String domain = user.getAttribute("domain").getValuesAsStrings().iterator().next(); SyncopeSyncResultHandler intHandler = (SyncopeSyncResultHandler) handler; LdapName dnOnSyncope = null;/*from w ww .j av a 2 s . c om*/ // Get ConnInstance object to retrieve Configuration of current connector String baseContextUser = null; StringBuilder sb = new StringBuilder(); ConnInstance connInstance = intHandler.getSyncTask().getResource().getConnector(); // Search of connector property containing base context(s) for (ConnConfProperty property : connInstance.getConfiguration()) { if ("baseContexts".equals(property.getSchema().getName())) { baseContextUser = (String) property.getValues().get(0); } } try { if (!"/".equals(user.getAttribute("domain").getValuesAsStrings().iterator().next())) { sb.append("uid=").append(user.getUsername()).append(",ou=").append(domain).append(",") .append(baseContextUser); dnOnSyncope = new LdapName(sb.toString()); } else { sb.append("uid=").append(user.getUsername()).append(",").append(baseContextUser); dnOnSyncope = new LdapName(sb.toString()); } } catch (InvalidNameException ex) { LOG.error("ERROR CONSTRUCTING LDAP DN" + ex.getMessage()); } return dnOnSyncope; }
From source file:org.apache.syncope.core.sync.LDAPDomainSyncActions.java
@Override public <T extends AbstractAttributableTO> SyncDelta beforeCreate(SyncResultsHandler srh, SyncDelta sd, T t) throws JobExecutionException { if (!ObjectClass.ACCOUNT_NAME.equals(sd.getObject().getObjectClass().toString())) { if (t != null) { LOG.debug("CREATION OF A NEW USER"); String rdn = "/"; ConnectorObject conn = sd.getObject(); try { LdapName dn = new LdapName(conn.getAttributeByName(Name.NAME).getValue().toString() .replace("[", "").replace("]", "")); if (dn.size() == 4) { rdn = dn.getRdn(2).getValue().toString(); } else { rdn = "/"; }//ww w . j a v a2s . c o m } catch (InvalidNameException ex) { LOG.error("ERROR CONSTRUCTING LDAP DN FROM NAME ATTRIBUTE: ".concat(ex.getMessage())); } //Creation of new attribute to assign to new user in Syncope AttributeTO domain = new AttributeTO(); domain.setSchema("domain"); domain.addValue(rdn); t.addAttribute(domain); } else { LOG.error("SUBJECT OF SYNCHRONIZATION IS NULL"); } } return sd; }
From source file:org.apache.syncope.core.sync.LDAPDomainSyncActions.java
@Transactional(readOnly = true) @Override//from w w w . j a v a 2 s. co m public <T extends AbstractAttributableTO, K extends AbstractAttributableMod> SyncDelta beforeUpdate( SyncResultsHandler srh, SyncDelta sd, T t, K k) throws JobExecutionException { if (!ObjectClass.ACCOUNT_NAME.equals(sd.getObject().getObjectClass().toString())) { if (t != null) { SyncopeUser user = userDAO.find(t.getId()); if (user != null && !user.isSuspended()) { ConnectorObject conn = sd.getObject(); // Get dn of current user to be updated on Syncope LdapName dnOnSyncope = resolveDnOnSyncope(user, srh); try { LdapName dn = new LdapName(conn.getAttributeByName(Name.NAME).getValue().toString() .replace("[", "").replace("]", "")); // Check if dn on Syncope and dn on Ldap are the same, if so returns if (dnOnSyncope.compareTo(dn) != 0) { String rdn; if (dn.size() == 4) { rdn = dn.getRdn(2).getValue().toString(); } else { rdn = "/"; } //Creation of new attribute to assign to new user in Syncope AttributeMod attr = new AttributeMod(); attr.setSchema("domain"); attr.addValueToBeAdded(rdn); k.addAttributeToBeUpdated(attr); } else { LOG.info("NO CHANGES APPLIED TO DOMAIN ATTRIBUTE"); return sd; } } catch (InvalidNameException ex) { LOG.error("ERROR CONSTRUCTING LDAP DN FROM NAME ATTRIBUTE: ".concat(ex.getMessage())); } } else { LOG.error("USER WITH ID: " + t.getId() + " DOESN'T EXIST OR IS SUSPENDED ON SYNCOPE "); } } else { LOG.error("SUBJECT OF SYNCHRONIZATION IS NULL"); } } return sd; }
From source file:org.apache.archiva.rest.services.DefaultRedbackRuntimeConfigurationService.java
@Override public Boolean checkLdapConnection(LdapConfiguration ldapConfiguration) throws ArchivaRestServiceException { LdapConnection ldapConnection = null; try {/*from w ww . j a va2 s .c om*/ 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; }
From source file:org.georchestra.console.ds.RoleDaoImpl.java
/** * Create an ldap entry for the role//from www . j av a 2 s . co m * * @param cn * @return */ private Name buildRoleDn(String cn) { try { return LdapNameBuilder.newInstance(this.roleSearchBaseDN).add("cn", cn).build(); } catch (org.springframework.ldap.InvalidNameException ex) { throw new IllegalArgumentException(ex.getMessage()); } }
From source file:org.georchestra.console.ds.RoleDaoImpl.java
/** * Create an ldap entry for the user/*from w w w .j ava2 s .c om*/ * * @param uid * @return DistinguishedName the dn of the user. */ private DistinguishedName buildUserDn(String uid) { DistinguishedName dn = new DistinguishedName(); try { LdapContextSource ctxsrc = (LdapContextSource) this.ldapTemplate.getContextSource(); dn.addAll(ctxsrc.getBaseLdapPath()); } catch (InvalidNameException e) { LOG.error("unable to construct the userDn: " + e.getMessage()); } dn.add(userSearchBaseDN); dn.add("uid", uid); return dn; }
From source file:org.security4java.X509SubjectDnRetriever.java
public String getUserName(X509Certificate clientCert) { if (log.isDebugEnabled()) { log.debug("getUserName(X509Certificate) - start"); }/* ww w .j a va 2 s.c om*/ String subject = getSubjectDN(clientCert); String userName = null; if (subject != null) { if (log.isDebugEnabled()) { log.debug("Subject is [" + subject + "]."); } if (subjectDnAttribute == null) { if (log.isDebugEnabled()) { log.debug("subjectDnAttribute is null, so return the whole subject."); } userName = subject; } else { boolean foundUserName = false; try { LdapName ldapName = new LdapName(subject); List<Rdn> list = ldapName.getRdns(); if (list != null) { for (Rdn rdn : list) { String type = rdn.getType(); if (subjectDnAttribute.equalsIgnoreCase(type.toString())) { Object value = rdn.getValue(); if (value instanceof String) { userName = (String) value; foundUserName = true; if (log.isDebugEnabled()) { log.debug("Success to retreive userName [" + userName + "]."); } break; } } } } } catch (InvalidNameException e) { log.info("subject [" + subject + "] is not valid name : [" + e.getMessage() + "]."); } if (!foundUserName) { log.info("subject [" + subject + "] does not contain the required attribute [" + subjectDnAttributeConfiguration + "]. Return the whole subject."); userName = subject; } } } if (log.isDebugEnabled()) { log.debug("getUserName(X509Certificate) - end; Ret is [" + userName + "]."); } return userName; }
From source file:org.wso2.carbon.apimgt.gateway.handlers.security.authenticator.MutualSSLAuthenticator.java
/** * To set the authentication context in current message context. * * @param messageContext Relevant message context. * @param sslCertObject SSL certificate object. * @throws APISecurityException API Security Exception. *//*from w ww .j a va 2 s . c o m*/ private void setAuthContext(MessageContext messageContext, Object sslCertObject) throws APISecurityException { X509Certificate[] certs = (X509Certificate[]) sslCertObject; X509Certificate x509Certificate = certs[0]; String subjectDN = x509Certificate.getSubjectDN().getName(); String uniqueIdentifier = String .valueOf(x509Certificate.getSerialNumber() + "_" + x509Certificate.getIssuerDN()) .replaceAll(",", "#").replaceAll("\"", "'").trim(); String tier = certificates.get(uniqueIdentifier); if (StringUtils.isEmpty(tier)) { if (log.isDebugEnabled()) { log.debug( "The client certificate presented is available in gateway, however it was not added against " + "the API " + getAPIIdentifier(messageContext)); } throw new APISecurityException(APISecurityConstants.MUTUAL_SSL_VALIDATION_FAILURE, APISecurityConstants.MUTUAL_SSL_VALIDATION_FAILURE_MESSAGE); } AuthenticationContext authContext = new AuthenticationContext(); authContext.setAuthenticated(true); authContext.setUsername(subjectDN); try { LdapName ldapDN = new LdapName(subjectDN); for (Rdn rdn : ldapDN.getRdns()) { if (APIConstants.CERTIFICATE_COMMON_NAME.equalsIgnoreCase(rdn.getType())) { authContext.setUsername((String) rdn.getValue()); } } } catch (InvalidNameException e) { log.warn("Cannot get the CN name from certificate:" + e.getMessage() + ". Please make sure the " + "certificate to include a proper common name that follows naming convention."); authContext.setUsername(subjectDN); } authContext.setApiTier(apiLevelPolicy); APIIdentifier apiIdentifier = getAPIIdentifier(messageContext); authContext.setKeyType(APIConstants.API_KEY_TYPE_PRODUCTION); authContext.setStopOnQuotaReach(true); authContext.setApiKey(uniqueIdentifier + "_" + apiIdentifier.toString()); authContext.setTier(tier); /* For the mutual SSL based authenticated request, the resource level throttling is not considered, hence assigning the unlimited tier for that. */ VerbInfoDTO verbInfoDTO = new VerbInfoDTO(); verbInfoDTO.setThrottling(APIConstants.UNLIMITED_TIER); messageContext.setProperty(APIConstants.VERB_INFO_DTO, verbInfoDTO); if (log.isDebugEnabled()) { log.debug("Auth context for the API " + getAPIIdentifier(messageContext) + ": Username[" + authContext.getUsername() + "APIKey[(" + authContext.getApiKey() + "] Tier[" + authContext.getTier() + "]"); } APISecurityUtils.setAuthenticationContext(messageContext, authContext, null); }