Example usage for javax.naming AuthenticationException AuthenticationException

List of usage examples for javax.naming AuthenticationException AuthenticationException

Introduction

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

Prototype

public AuthenticationException(String explanation) 

Source Link

Document

Constructs a new instance of AuthenticationException using the explanation supplied.

Usage

From source file:org.apache.pulsar.broker.authentication.AuthenticationProviderToken.java

private String parseToken(final String token) throws AuthenticationException {
    try {/* w  w w. j a  va 2  s . c om*/
        @SuppressWarnings("unchecked")
        Jwt<?, Claims> jwt = Jwts.parser().setSigningKey(validationKey).parse(token);

        return jwt.getBody().getSubject();
    } catch (JwtException e) {
        throw new AuthenticationException("Failed to authentication token: " + e.getMessage());
    }
}

From source file:org.apache.pulsar.broker.authentication.AuthenticationService.java

public String authenticate(AuthenticationDataSource authData, String authMethodName)
        throws AuthenticationException {
    AuthenticationProvider provider = providers.get(authMethodName);
    if (provider != null) {
        return provider.authenticate(authData);
    } else {/*from   w  w  w .  jav  a2s . c o  m*/
        if (StringUtils.isNotBlank(anonymousUserRole)) {
            return anonymousUserRole;
        }
        throw new AuthenticationException("Unsupported authentication mode: " + authMethodName);
    }
}

From source file:org.apache.pulsar.broker.authentication.AuthenticationService.java

public String authenticateHttpRequest(HttpServletRequest request) throws AuthenticationException {
    // Try to validate with any configured provider
    AuthenticationDataSource authData = new AuthenticationDataHttps(request);
    for (AuthenticationProvider provider : providers.values()) {
        try {/*from   ww w .  j  ava2  s. co  m*/
            return provider.authenticate(authData);
        } catch (AuthenticationException e) {
            // Ignore the exception because we don't know which authentication method is expected here.
        }
    }

    // No authentication provided
    if (!providers.isEmpty()) {
        if (StringUtils.isNotBlank(anonymousUserRole)) {
            return anonymousUserRole;
        }
        // If at least a provider was configured, then the authentication needs to be provider
        throw new AuthenticationException("Authentication required");
    } else {
        // No authentication required
        return "<none>";
    }
}

From source file:org.eclipse.skalli.core.user.ldap.LDAPClient.java

private LdapContext getLdapContext() throws NamingException, AuthenticationException {
    if (config == null) {
        throw new NamingException("LDAP not configured");
    }/*w  w  w  .j  a  v  a2 s  . co  m*/
    if (StringUtils.isBlank(config.getProviderUrl())) {
        throw new NamingException("No LDAP server available");
    }
    if (StringUtils.isBlank(config.getUsername()) || StringUtils.isBlank(config.getPassword())) {
        throw new AuthenticationException("No LDAP credentials available");
    }
    String ctxFactory = config.getCtxFactory();
    if (StringUtils.isBlank(ctxFactory)) {
        ctxFactory = DEFAULT_CONTEXT_FACTORY;
    }
    String authentication = config.getAuthentication();
    if (StringUtils.isBlank(authentication)) {
        authentication = SIMPLE_AUTHENTICATION;
    }

    Hashtable<String, Object> env = new Hashtable<String, Object>();
    env.put(Context.INITIAL_CONTEXT_FACTORY, ctxFactory);
    env.put(Context.PROVIDER_URL, config.getProviderUrl());
    env.put(Context.SECURITY_PRINCIPAL, config.getUsername());
    env.put(Context.SECURITY_CREDENTIALS, config.getPassword());
    env.put(Context.SECURITY_AUTHENTICATION, authentication);
    if (StringUtils.isNotBlank(config.getReferral())) {
        env.put(Context.REFERRAL, config.getReferral());
    }
    if (config.getProviderUrl().startsWith(LDAPS_SCHEME)) {
        env.put(Context.SECURITY_PROTOCOL, "ssl"); //$NON-NLS-1$
        if (config.isSslNoVerify()) {
            env.put(JNDI_SOCKET_FACTORY, LDAPTrustAllSocketFactory.class.getName());
        }
    }
    // Gemini-specific properties
    env.put(JNDIConstants.BUNDLE_CONTEXT, FrameworkUtil.getBundle(LDAPClient.class).getBundleContext());

    // com.sun.jndi.ldap.LdapCtxFactory specific properties
    env.put(READ_TIMEOUT, DEFAULT_READ_TIMEOUT);
    env.put(USE_CONNECTION_POOLING, "true"); //$NON-NLS-1$

    // extremly ugly classloading workaround:
    // com.sun.jndi.ldap.LdapCtxFactory uses Class.forName() to load the socket factory, shame on them!
    InitialLdapContext ctx = null;
    ClassLoader classloader = Thread.currentThread().getContextClassLoader();
    try {
        Thread.currentThread().setContextClassLoader(LDAPTrustAllSocketFactory.class.getClassLoader());
        ctx = new InitialLdapContext(env, null);
    } finally {
        if (classloader != null) {
            Thread.currentThread().setContextClassLoader(classloader);
        }
    }
    return ctx;
}

From source file:org.rifidi.emulator.tags.impl.C1G2Tag.java

public void sendPassword(byte[] password) throws AuthenticationException {
    if (currentState.equals(states.Killed))
        return;/*from ww  w .j a v  a 2 s  .  c  om*/
    for (int count = 0; count < password.length; count++) {
        // compare password
        if (!(mem.get(TagConstants.MemoryReserved)[count] == password[count])) {
            // on failure throw exception
            throw new AuthenticationException("Wrong access password");
        }
    }
    currentState = states.Secured;
}

From source file:org.rifidi.emulator.tags.impl.C1G2Tag.java

public void kill(byte[] killpassword) throws AuthenticationException {
    if (currentState.equals(states.Killed))
        return;//  w  w  w.ja v  a2  s .  com
    for (int count = 0; count < killpassword.length; count++) {
        // compare password
        if (!(mem.get(TagConstants.MemoryReserved)[count + 4] == killpassword[count])) {
            // on failure throw exception
            doTransition();
            throw new AuthenticationException("Wrong kill password");
        }
    }
    currentState = states.Killed;
}

From source file:org.rifidi.emulator.tags.impl.C1G2Tag.java

public void lock(TagConstants mem, LockStates lockAction)
        throws InvalidMemoryAccessException, AuthenticationException {
    if (currentState.equals(states.Killed))
        return;/*  www .  j ava  2  s .co m*/
    if (mem == TagConstants.MemoryReserved) {
        doTransition();
        throw new InvalidMemoryAccessException(TagErrors.InvalidMemoryBank);
    }
    if (currentState.equals(states.Secured)) {
        // don't lock twice
        if (lockStates.get(mem).equals(lockAction)) {
            doTransition();
            throw new InvalidMemoryAccessException(TagErrors.TargetMemoryIsLocked);
        }
        // trying to lock a permalocked memory fails
        if (lockStates.get(mem).equals(LockStates.permalocked)) {
            doTransition();
            throw new InvalidMemoryAccessException(TagErrors.TargetMemoryIsPermalocked);
        }
        // trying to change a permaunlocked memory fails
        if (lockStates.get(mem).equals(LockStates.permaunlocked)) {
            doTransition();
            throw new InvalidMemoryAccessException(TagErrors.TargetMemoryIsPermaunlocked);
        }
        lockStates.put(mem, LockStates.unlocked);
    } else {
        doTransition();
        throw new AuthenticationException("Authentication needed for this operation");
    }
}