Example usage for javax.naming AuthenticationException printStackTrace

List of usage examples for javax.naming AuthenticationException printStackTrace

Introduction

In this page you can find the example usage for javax.naming AuthenticationException printStackTrace.

Prototype

public void printStackTrace() 

Source Link

Document

Prints this throwable and its backtrace to the standard error stream.

Usage

From source file:org.apache.zeppelin.realm.LdapRealm.java

private Set<String> getRoles(PrincipalCollection principals, final LdapContextFactory ldapContextFactory)
        throws NamingException {
    final String username = (String) getAvailablePrincipal(principals);

    LdapContext systemLdapCtx = null;
    try {//w  ww  . j a v  a 2  s  .  c  om
        systemLdapCtx = ldapContextFactory.getSystemLdapContext();
        return rolesFor(principals, username, systemLdapCtx, ldapContextFactory,
                SecurityUtils.getSubject().getSession());
    } catch (AuthenticationException ae) {
        ae.printStackTrace();
        return Collections.emptySet();
    } finally {
        LdapUtils.closeContext(systemLdapCtx);
    }
}

From source file:org.apache.zeppelin.realm.LdapRealm.java

/**
* Returns the LDAP User Distinguished Name (DN) to use when acquiring an
* {@link javax.naming.ldap.LdapContext LdapContext} from the
* {@link LdapContextFactory}./*from ww  w  .ja v a 2 s .  c o m*/
* <p/>
* If the the {@link #getUserDnTemplate() userDnTemplate} property has been
* set, this implementation will construct the User DN by substituting the
* specified {@code principal} into the configured template. If the
* {@link #getUserDnTemplate() userDnTemplate} has not been set, the method
* argument will be returned directly (indicating that the submitted
* authentication token principal <em>is</em> the User DN).
*
* @param principal
*            the principal to substitute into the configured
*            {@link #getUserDnTemplate() userDnTemplate}.
* @return the constructed User DN to use at runtime when acquiring an
*         {@link javax.naming.ldap.LdapContext}.
* @throws IllegalArgumentException
*             if the method argument is null or empty
* @throws IllegalStateException
*             if the {@link #getUserDnTemplate userDnTemplate} has not been
*             set.
* @see LdapContextFactory#getLdapContext(Object, Object)
*/
@Override
protected String getUserDn(final String principal) throws IllegalArgumentException, IllegalStateException {
    String userDn;
    String matchedPrincipal = matchPrincipal(principal);
    String userSearchBase = getUserSearchBase();
    String userSearchAttributeName = getUserSearchAttributeName();

    // If not searching use the userDnTemplate and return.
    if ((userSearchBase == null || userSearchBase.isEmpty()) || (userSearchAttributeName == null
            && userSearchFilter == null && !"object".equalsIgnoreCase(userSearchScope))) {
        userDn = expandTemplate(userDnTemplate, matchedPrincipal);
        if (log.isDebugEnabled()) {
            log.debug("LDAP UserDN and Principal: " + userDn + "," + principal);
        }
        return userDn;
    }

    // Create the searchBase and searchFilter from config.
    String searchBase = expandTemplate(getUserSearchBase(), matchedPrincipal);
    String searchFilter = null;
    if (userSearchFilter == null) {
        if (userSearchAttributeName == null) {
            searchFilter = String.format("(objectclass=%1$s)", getUserObjectClass());
        } else {
            searchFilter = String.format("(&(objectclass=%1$s)(%2$s=%3$s))", getUserObjectClass(),
                    userSearchAttributeName,
                    expandTemplate(getUserSearchAttributeTemplate(), matchedPrincipal));
        }
    } else {
        searchFilter = expandTemplate(userSearchFilter, matchedPrincipal);
    }
    SearchControls searchControls = getUserSearchControls();

    // Search for userDn and return.
    LdapContext systemLdapCtx = null;
    NamingEnumeration<SearchResult> searchResultEnum = null;
    try {
        systemLdapCtx = getContextFactory().getSystemLdapContext();
        if (log.isDebugEnabled()) {
            log.debug("SearchBase,SearchFilter,UserSearchScope: " + searchBase + "," + searchFilter + ","
                    + userSearchScope);
        }
        searchResultEnum = systemLdapCtx.search(searchBase, searchFilter, searchControls);
        // SearchResults contains all the entries in search scope
        if (searchResultEnum.hasMore()) {
            SearchResult searchResult = searchResultEnum.next();
            userDn = searchResult.getNameInNamespace();
            if (log.isDebugEnabled()) {
                log.debug("UserDN Returned,Principal: " + userDn + "," + principal);
            }
            return userDn;
        } else {
            throw new IllegalArgumentException("Illegal principal name: " + principal);
        }
    } catch (AuthenticationException ne) {
        ne.printStackTrace();
        throw new IllegalArgumentException("Illegal principal name: " + principal);
    } catch (NamingException ne) {
        throw new IllegalArgumentException("Hit NamingException: " + ne.getMessage());
    } finally {
        try {
            if (searchResultEnum != null) {
                searchResultEnum.close();
            }
        } catch (NamingException ne) {
            // Ignore exception on close.
        } finally {
            LdapUtils.closeContext(systemLdapCtx);
        }
    }
}

From source file:org.rifidi.emulator.reader.alien.commandhandler.AlienProgram.java

public CommandObject programTag(CommandObject arg, AbstractReaderSharedResources asr) {
    ArrayList<Object> retVal = arg.getReturnValue();

    String bytes = "";
    // Get argument
    if (!arg.getArguments().isEmpty()) {
        bytes = (String) arg.getArguments().get(0);
    }//w  w w. jav  a 2  s  .  c  o  m

    // convert argument to byte array
    byte[] newID;
    try {
        newID = ByteAndHexConvertingUtility.fromHexString(bytes);
    } catch (IllegalArgumentException ex) {
        String cur = arg.getCurrentQueryName();
        ArrayList<Object> tempVal = new ArrayList<Object>();
        tempVal.add(cur);
        retVal = new AlienExceptionHandler().malformedMessageError(tempVal, arg);
        arg.setReturnValue(retVal);
        return arg;
    }

    // error if byte[] is not 8 bytes or 12 bytes
    if (newID.length != 8 && newID.length != 12) {
        String cur = arg.getCurrentQueryName();
        ArrayList<Object> tempVal = new ArrayList<Object>();
        tempVal.add(cur);
        ArrayList<String> PossibleValues = new ArrayList<String>();
        PossibleValues.add("8 byte array in the form of xx xx ...");
        PossibleValues.add("12 byte array in the form of xx xx ...");
        retVal = new AlienExceptionHandler().error10(tempVal, arg, PossibleValues);
        arg.setReturnValue(retVal);
        return arg;
    }

    String function = asr.getPropertyMap().get("function").getPropertyStringValue();

    Integer progAntenna = ((IntegerReaderProperty) asr.getPropertyMap().get("progantenna")).getValue();

    // make sure we are in programmer mode
    if (function.equalsIgnoreCase("Programmer")) {
        AlienTagMemory mem = (AlienTagMemory) asr.getTagMemory();
        asr.getRadio().scan(null, mem);
        ArrayList<RifidiTag> tags = mem.getTagReport(progAntenna);

        // make sure there is only one tag on the antenna and it is a GEN2
        // tag
        if (tags.size() == 1 && tags.get(0).getTagGen() == TagGen.GEN2) {
            C1G2Tag tag = (C1G2Tag) tags.get(0).getTag();

            try {
                C1G2Operations.C1G2WriteID(tag, tags.get(0).getTagEntitiyID(), newID,
                        C1G2Operations.getAccessPass(tag), asr.getCallbackManager(),
                        asr.getRadio().getAntennas().get(progAntenna));
            } catch (AuthenticationException e) {
                String cur = arg.getCurrentQueryName();
                ArrayList<Object> tempVal = new ArrayList<Object>();
                tempVal.add(cur);
                retVal = new AlienExceptionHandler().error137(tempVal, arg);
                e.printStackTrace();
            } catch (InvalidMemoryAccessException e) {
                e.printStackTrace();
            }
        } else {
            // handle case if there is not 1 tag on antenna and/or it is not
            // GEN2
            String cur = arg.getCurrentQueryName();
            ArrayList<Object> tempVal = new ArrayList<Object>();
            tempVal.add(cur);
            retVal = new AlienExceptionHandler().error134(tempVal, arg);
            arg.setReturnValue(retVal);
            return arg;
        }
    } else {
        // handle case when function!=programmer
        String cur = arg.getCurrentQueryName();
        ArrayList<Object> tempVal = new ArrayList<Object>();
        tempVal.add(cur);
        retVal = new AlienExceptionHandler().error134(tempVal, arg);
        arg.setReturnValue(retVal);
        return arg;
    }
    String returnVal = "";
    ArrayList<Object> returnArray = new ArrayList<Object>();

    returnVal = "Program Tag = " + bytes;

    /* If no prompt suppress add endofreply and prompt to the output */
    if (!arg.getPromptSuppress()) {
        returnVal += AlienCommon.ZEROCHAR;
        returnVal += AlienCommon.NEWLINE;
        returnVal += AlienCommon.NONZEROPROMPT;
    } else {
        returnVal += AlienCommon.ZEROCHAR;
    }

    returnArray.add(returnVal);

    /* Set the return value */
    arg.setReturnValue(returnArray);

    return arg;
}