Example usage for org.apache.shiro ShiroException ShiroException

List of usage examples for org.apache.shiro ShiroException ShiroException

Introduction

In this page you can find the example usage for org.apache.shiro ShiroException ShiroException.

Prototype

public ShiroException(Throwable cause) 

Source Link

Document

Constructs a new ShiroException.

Usage

From source file:cn.com.rexen.ext.shiro.web.filter.authc.X509AuthenticationFilter.java

License:Open Source License

@Override
protected AuthenticationToken createToken(ServletRequest request, ServletResponse response) {
    X509Certificate[] clientCertChain = (X509Certificate[]) request
            .getAttribute("javax.servlet.request.X509Certificate");
    LOGGER.info("X509AuthFilter.createToken() cert chain is {}", clientCertChain);
    if (clientCertChain == null || clientCertChain.length < 1) {
        throw new ShiroException("Request do not contain any X509Certificate");
    }/*from  w ww.ja  v  a 2s.  co m*/
    return new X509AuthenticationToken(clientCertChain, getHost(request));
}

From source file:com.aerospike.shiro.AerospikeSessionDAO.java

License:Apache License

@Override
public void init() throws ShiroException {
    log.info("Initializing the Aerospike Client");
    try {/*from  w  w  w.  j  a  v  a  2s.c om*/
        this.readEnvironmentVariables();
    } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException
            | NoSuchMethodException | SecurityException e) {
        log.error(e.getMessage());
        throw new ShiroException(e.getMessage());
    }
    ClientPolicy policy = new ClientPolicy();
    policy.failIfNotConnected = true;
    policy.user = this.user;
    policy.password = this.password;

    String[] hostnames = StringUtils.split(this.hostname);
    String[] ports = StringUtils.split(this.port);
    if (hostnames.length != ports.length) {
        throw new ShiroException("Number of hosts in configuration does not match number of ports");
    }
    Host[] hosts = new Host[hostnames.length];
    for (int i = 0; i < hostnames.length; i++) {
        hosts[i] = new Host(hostnames[i], Integer.valueOf(ports[i]));
    }
    this.client = new AerospikeClient(policy, hosts);

    this.writePolicy = new WritePolicy();
    this.writePolicy.expiration = this.globalSessionTimeout;
}

From source file:com.banyou.backend.service.product.ProductService.java

License:Apache License

/**
 * ???//from  w w  w  . j  av  a  2s .co m
 * 
 * @param product
 * @param user
 */
private void checkReadPermission(Product product, ShiroUser user) {
    //??
    if (!product.isCreater(user.id) && !product.isSeller(user.merchantId) && !UserContext.isSuper()) {
        throw new ShiroException("??");
    }
}

From source file:com.banyou.backend.service.product.ProductService.java

License:Apache License

/**
 * ???/*from   ww w.  j  a  v a2  s  . c om*/
 * 
 * @param product
 * @param user
 */
private void checkWritePermission(Product product, ShiroUser user) {
    //???
    if (!product.isSeller(user.merchantId) && !UserContext.isSuper()) {
        throw new ShiroException("??");
    }
}

From source file:com.leshazlewood.samples.shiro.cassandra.ClusterFactory.java

License:Apache License

public void init() throws ShiroException {
    if (cluster == null) {
        try {/*from   w  ww .j a v a  2  s. c  o m*/
            doInit();
        } catch (Exception e) {
            throw new ShiroException(e);
        }
    }
}

From source file:org.apache.jena.fuseki.shiro.web.filter.authc.x509.SubjectDnX509UsernameExtractor.java

License:Apache License

@Override
public String extractUsername(final X509Certificate certificate) {
    //String subjectDN = certificate.getSubjectX500Principal().getName();
    String subjectDN = certificate.getSubjectDN().getName();

    log.debug(String.format("Subject DN is '%s'", subjectDN));

    Matcher matcher = subjectDnPattern.matcher(subjectDN);

    if (!matcher.find()) {
        throw new ShiroException(String.format("No matching pattern was found in subject DN: %s", subjectDN));
    }/*from  www. j  a  va2 s.c o  m*/

    if (matcher.groupCount() != 1) {
        throw new IllegalArgumentException("Regular expression must contain a single group.");
    }

    String username = matcher.group(1);

    log.debug("Extracted Principal name is '" + username + "'");

    return username;
}

From source file:org.eclipse.kapua.service.authentication.shiro.KapuaAuthenticator.java

License:Open Source License

@Override
protected AuthenticationInfo doMultiRealmAuthentication(Collection<Realm> realms, AuthenticationToken token) {
    AuthenticationStrategy strategy = getAuthenticationStrategy();
    AuthenticationInfo aggregate = strategy.beforeAllAttempts(realms, token);
    if (loggger.isTraceEnabled()) {
        loggger.trace("Iterating through {} realms for PAM authentication", realms.size());
    }/*w  w  w.  j  a  va2 s  .  c  om*/
    List<Throwable> exceptionList = new ArrayList<>();
    boolean loginSucceeded = false;
    boolean supportedRealmFound = false;
    for (Realm realm : realms) {
        aggregate = strategy.beforeAttempt(realm, token, aggregate);
        if (realm.supports(token)) {
            supportedRealmFound = true;
            loggger.trace("Attempting to authenticate token [{}] using realm [{}]", token, realm);
            AuthenticationInfo info = null;
            Throwable t = null;
            try {
                info = realm.getAuthenticationInfo(token);
                loginSucceeded = true;
            } catch (Throwable throwable) {
                t = throwable;
                if (loggger.isDebugEnabled()) {
                    String msg = "Realm [" + realm
                            + "] threw an exception during a multi-realm authentication attempt:";
                    loggger.debug(msg, t);
                }
            }
            aggregate = strategy.afterAttempt(realm, token, info, aggregate, t);
            exceptionList.add(t);
        } else {
            loggger.debug("Realm [{}] does not support token {}.  Skipping realm.", realm, token);
        }
    }
    //modified behavior from the ModularRealmAuthenticator to provide a more significantly exception message to the user if the login fails
    if (supportedRealmFound && !loginSucceeded) {
        //if there is no realm able to authenticate the AuthenticationToken (but at least one realm for this AuthenticationToken was found) lets check the exceptions thrown by the logins
        if (exceptionList.size() <= 0) {
            //login failed and we have no exception to show so throw a ShiroException?
            //TODO move the error message to the message bundle
            throw new ShiroException("Internal Error!");
        }
        if (exceptionList.get(0) instanceof AuthenticationException) {
            throw (AuthenticationException) exceptionList.get(0);
        } else {
            throw new AuthenticationException(exceptionList.get(0));
        }
    } else {
        //otherwise if at least one login succeeded lets proceed with the standard ModularRealmAuthenticator
        aggregate = strategy.afterAllAttempts(token, aggregate);
    }
    return aggregate;
}

From source file:org.ehcache.integrations.shiro.EhcacheShiroManager.java

License:Apache License

/**
 * Initializes this instance./*from w  w w  .  j  a v a2s .  c  om*/
 * <P>
 * If a {@link #setCacheManager CacheManager} has been
 * explicitly set (e.g. via Dependency Injection or programatically) prior to calling this
 * method, this method does nothing.
 * </P>
 * <P>
 * However, if no {@code CacheManager} has been set a new {@link org.ehcache.Cache} will be initialized.
 * It will use {@code ehcache.xml} configuration file at the root of the classpath.
 * </P>
 *
 * @throws org.apache.shiro.cache.CacheException if there are any CacheExceptions thrown by EhCache.
 */
public void init() throws ShiroException {
    try {
        ensureCacheManager();
    } catch (MalformedURLException e) {
        throw new ShiroException(e);
    }
}

From source file:org.ops4j.pax.shiro.cdi.impl.ShiroProducer.java

License:Apache License

private static ShiroException unwrap(InvocationTargetException exc) {
    if (exc.getCause() instanceof ShiroException) {
        return (ShiroException) exc.getCause();
    } else {/*from   w w  w .j a  va 2 s. c o m*/
        return new ShiroException(exc.getCause());
    }
}

From source file:org.ops4j.pax.shiro.faces.tags.PrincipalComponent.java

License:Apache License

private String getPrincipalProperty(Object principal, String _property) {
    String strValue = null;/*w w  w  .  j  a  v a 2 s . c  om*/
    boolean foundProperty = false;
    try {
        BeanInfo bi = Introspector.getBeanInfo(principal.getClass());

        // Loop through the properties to get the string value of the specified property
        for (PropertyDescriptor pd : bi.getPropertyDescriptors()) {
            if (pd.getName().equals(_property)) {
                Object value = pd.getReadMethod().invoke(principal);
                strValue = String.valueOf(value);
                foundProperty = true;
                break;
            }
        }
    } catch (ReflectiveOperationException exc) {
        throw new ShiroException(exc);
    } catch (IntrospectionException exc) {
        throw new ShiroException(exc);
    }
    if (!foundProperty) {
        final String message = "Property [" + _property + "] not found in principal of type ["
                + principal.getClass().getName() + "]";
        log.error(message);
        throw new ShiroException(message);
    }
    return strValue;
}