當前位置: 首頁>>代碼示例>>Java>>正文


Java AccessDeniedException類代碼示例

本文整理匯總了Java中org.apache.deltaspike.security.api.authorization.AccessDeniedException的典型用法代碼示例。如果您正苦於以下問題:Java AccessDeniedException類的具體用法?Java AccessDeniedException怎麽用?Java AccessDeniedException使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


AccessDeniedException類屬於org.apache.deltaspike.security.api.authorization包,在下文中一共展示了AccessDeniedException類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: authorizeBasedOnAuthentication

import org.apache.deltaspike.security.api.authorization.AccessDeniedException; //導入依賴的package包/類
@AroundInvoke
public Object authorizeBasedOnAuthentication(InvocationContext ctx) throws Exception {
    Set<SecurityViolation> violations = new HashSet<SecurityViolation>();
    if (!identity.isLoggedIn()) {
        final String msg = secMessage.notAuthenticated();
        violations.add(new SecurityViolation() {
            @Override
            public String getReason() {
                return msg;
            }
        });
        event.fire(new ExceptionToCatchEvent(new AccessDeniedException(violations)));
    }

    return ctx.proceed();
}
 
開發者ID:rsmeral,項目名稱:pv243-jboss,代碼行數:17,代碼來源:AuthBasedAuthorizationInterceptor.java

示例2: invokeAfterMethodInvocationAuthorizers

import org.apache.deltaspike.security.api.authorization.AccessDeniedException; //導入依賴的package包/類
protected void invokeAfterMethodInvocationAuthorizers(InvocationContext invocationContext,
    Set<Authorizer> authorizers, Object result) throws IllegalAccessException
{
    try
    {
        for (Authorizer authorizer : authorizers)
        {
            if (authorizer.isAfterMethodInvocationAuthorizer())
            {
                authorizer.authorize(invocationContext, result, this.beanManager);
            }
        }
    }
    catch (AccessDeniedException e)
    {
        RuntimeException exceptionToThrow = handleAccessDeniedException(e);
        if (exceptionToThrow != null)
        {
            throw exceptionToThrow;
        }
    }
}
 
開發者ID:apache,項目名稱:deltaspike,代碼行數:23,代碼來源:DefaultSecurityStrategy.java

示例3: broadcastAccessDeniedException

import org.apache.deltaspike.security.api.authorization.AccessDeniedException; //導入依賴的package包/類
public void broadcastAccessDeniedException(AccessDeniedException accessDeniedException)
{
    ExceptionToCatchEvent exceptionToCatchEvent = new ExceptionToCatchEvent(accessDeniedException);

    try
    {
        this.beanManager.fireEvent(exceptionToCatchEvent);
    }
    catch (AccessDeniedException e)
    {
        throw new SkipInternalProcessingException(accessDeniedException);
    }
    //we have to throw it in any case to support "observers" for AccessDeniedException (see DELTASPIKE-636)
    //however, currently we can't do it based on the exception-control api (see DELTASPIKE-638)
    throw new SkipInternalProcessingException(accessDeniedException);
}
 
開發者ID:apache,項目名稱:deltaspike,代碼行數:17,代碼來源:AccessDeniedExceptionBroadcaster.java

示例4: broadcastAccessDeniedException

import org.apache.deltaspike.security.api.authorization.AccessDeniedException; //導入依賴的package包/類
public Throwable broadcastAccessDeniedException(AccessDeniedException accessDeniedException)
{
    ExceptionToCatchEvent exceptionToCatchEvent = new ExceptionToCatchEvent(accessDeniedException);

    try
    {
        this.beanManager.fireEvent(exceptionToCatchEvent);
    }
    catch (AccessDeniedException e)
    {
        //intentionally ignore the exception per default, since we just notify the handlers
        //(like in the other cases with AccessDeniedException)
        //that's different from the normal exception-control handling
        return null;
    }
    return null;
}
 
開發者ID:apache,項目名稱:deltaspike,代碼行數:18,代碼來源:AccessDeniedExceptionBroadcaster.java

示例5: processApplicationSecurityException

import org.apache.deltaspike.security.api.authorization.AccessDeniedException; //導入依賴的package包/類
private static void processApplicationSecurityException(AccessDeniedException exception,
                                                        Class<? extends ViewConfig> errorView,
                                                        boolean allowNavigation)
{
    SecurityViolationHandler securityViolationHandler =
            BeanProvider.getContextualReference(SecurityViolationHandler.class, true);

    if (securityViolationHandler != null)
    {
        //optional (custom handler) - allows to handle custom implementations of SecurityViolation
        securityViolationHandler.processSecurityViolations(exception.getViolations());
    }
    else
    {
        addViolationsAsMessage(exception.getViolations());
    }

    if (allowNavigation)
    {
        BeanProvider.getContextualReference(ViewNavigationHandler.class).navigateTo(errorView);
    }
}
 
開發者ID:apache,項目名稱:deltaspike,代碼行數:23,代碼來源:SecurityUtils.java

示例6: authorizeBasedOnRoles

import org.apache.deltaspike.security.api.authorization.AccessDeniedException; //導入依賴的package包/類
@AroundInvoke
public Object authorizeBasedOnRoles(InvocationContext ctx) throws Exception {
    Roles roles = ctx.getMethod().getAnnotation(Roles.class);

    Set<SecurityViolation> result = new HashSet<SecurityViolation>();
    boolean ok = !roles.anyRole();
    for (PersonRole r : roles.value()) {
        if (!identity.getUserContext().hasRole(r.toString())) {
            if (!roles.anyRole()) {
                ok = false;
                break;
            }
        } else {
            if (roles.anyRole()) {
                ok = true;
                break;
            }
        }
    }
    logger.debug("Validation OK: " + ok);
    if (!ok) {
        final String msg = secMessage.roleMissing();
        result.add(new SecurityViolation() {
            @Override
            public String getReason() {
                return msg;
            }
        });
        event.fire(new ExceptionToCatchEvent(new AccessDeniedException(result)));
    }

    return ctx.proceed();
}
 
開發者ID:rsmeral,項目名稱:pv243-jboss,代碼行數:34,代碼來源:RoleBasedAuthorizationInterceptor.java

示例7: onAccessDenied

import org.apache.deltaspike.security.api.authorization.AccessDeniedException; //導入依賴的package包/類
public void onAccessDenied(@Handles ExceptionEvent<AccessDeniedException> event) {
    log.logAccessDenied(event.getException());

    this.facesContext.getExternalContext().getSessionMap()
            .put(ERROR_MESSAGE, webMessage.accessDenied(getReasons(event.getException())));
    event.handledAndContinue();
}
 
開發者ID:rsmeral,項目名稱:pv243-jboss,代碼行數:8,代碼來源:DefaultExceptionHandler.java

示例8: getReasons

import org.apache.deltaspike.security.api.authorization.AccessDeniedException; //導入依賴的package包/類
private String getReasons(AccessDeniedException ex) {
    StringBuilder sb = new StringBuilder("<br/>");

    for (SecurityViolation sv : ex.getViolations()) {
        sb.append(sv.getReason()).append("<br/>");
    }
    return sb.toString();
}
 
開發者ID:rsmeral,項目名稱:pv243-jboss,代碼行數:9,代碼來源:DefaultExceptionHandler.java

示例9: authorize

import org.apache.deltaspike.security.api.authorization.AccessDeniedException; //導入依賴的package包/類
void authorize(final InvocationContext ic, final Object returnValue, BeanManager beanManager)
    throws IllegalAccessException, IllegalArgumentException
{
    if (boundAuthorizerBean == null)
    {
        lazyInitTargetBean(beanManager);
    }

    final CreationalContext<?> creationalContext = beanManager.createCreationalContext(boundAuthorizerBean);

    Object reference = beanManager.getReference(boundAuthorizerBean,
        boundAuthorizerMethod.getJavaMember().getDeclaringClass(), creationalContext);

    Object result = boundAuthorizerMethodProxy.invoke(reference, creationalContext,
            new SecurityParameterValueRedefiner(creationalContext, ic, returnValue));

    if (Boolean.FALSE.equals(result))
    {
        Set<SecurityViolation> violations = new HashSet<SecurityViolation>();
        violations.add(new SecurityViolation()
        {
            private static final long serialVersionUID = 2358753444038521129L;

            @Override
            public String getReason()
            {
                return "Authorization check failed";
            }
        });

        throw new AccessDeniedException(violations);
    }
}
 
開發者ID:apache,項目名稱:deltaspike,代碼行數:34,代碼來源:Authorizer.java

示例10: simpleInterceptorTestDenied

import org.apache.deltaspike.security.api.authorization.AccessDeniedException; //導入依賴的package包/類
@Test
public void simpleInterceptorTestDenied()
{
    SecuredBean1 testBean = BeanProvider.getContextualReference(SecuredBean1.class, false);
    try {
        testBean.getBlockedResult();
        Assert.fail();
    } catch (AccessDeniedException e) {
        //expected
    }
}
 
開發者ID:apache,項目名稱:deltaspike,代碼行數:12,代碼來源:SecurityBindingTest.java

示例11: simpleInterceptorTestParentDenied

import org.apache.deltaspike.security.api.authorization.AccessDeniedException; //導入依賴的package包/類
@Test
public void simpleInterceptorTestParentDenied()
{
    SecuredBean1 testBean = BeanProvider.getContextualReference(SecuredBean1.class, false);
    try {
        testBean.someBlockedMethodFromParent();
        Assert.fail();
    } catch (AccessDeniedException e) {
        //expected
    }
}
 
開發者ID:apache,項目名稱:deltaspike,代碼行數:12,代碼來源:SecurityBindingTest.java

示例12: simpleInterceptorTestOnMethodsDenied

import org.apache.deltaspike.security.api.authorization.AccessDeniedException; //導入依賴的package包/類
@Test
public void simpleInterceptorTestOnMethodsDenied()
{
    SecuredBean2 testBean = BeanProvider.getContextualReference(SecuredBean2.class, false);
    try {
        testBean.getBlockedResult();
    } catch (AccessDeniedException e) {
        //expected
    }
}
 
開發者ID:apache,項目名稱:deltaspike,代碼行數:11,代碼來源:SecurityBindingTest.java

示例13: simpleInterceptorThrowsExceptionWhenImproperlyAnnotated

import org.apache.deltaspike.security.api.authorization.AccessDeniedException; //導入依賴的package包/類
@Test
public void simpleInterceptorThrowsExceptionWhenImproperlyAnnotated()
{
    try
    {
        SecuredBean1 testBean = BeanProvider.getContextualReference(SecuredBean1.class, false);
        testBean.getResult(new MockObject2(false));
        Assert.fail("Expected exception, IllegalStateException was not thrown");
    }
    catch (AccessDeniedException e)
    {
        // expected exception
    }
}
 
開發者ID:apache,項目名稱:deltaspike,代碼行數:15,代碼來源:SecurityParameterBindingTest.java

示例14: afterInvocationAuthorizerCheckWithDeniedResult

import org.apache.deltaspike.security.api.authorization.AccessDeniedException; //導入依賴的package包/類
@Test
public void afterInvocationAuthorizerCheckWithDeniedResult()
{
    try
    {
    	SecuredBean1 testBean = BeanProvider.getContextualReference(SecuredBean1.class, false);
    	testBean.getResult(false);
        Assert.fail("AccessDeniedException expect, but was not thrown");
    }
    catch (AccessDeniedException e)
    {
        // expected
    }
}
 
開發者ID:apache,項目名稱:deltaspike,代碼行數:15,代碼來源:SecurityParameterBindingTest.java

示例15: afterInvocationAuthorizerWithoutReturnType

import org.apache.deltaspike.security.api.authorization.AccessDeniedException; //導入依賴的package包/類
@Test
public void afterInvocationAuthorizerWithoutReturnType()
{
    MethodInvocationParameter parameter = new MethodInvocationParameter();
    try
    {
        SecuredBean2 testBean = BeanProvider.getContextualReference(SecuredBean2.class, false);
        testBean.securityCheckAfterMethodInvocation(parameter);
        Assert.fail("AccessDeniedException expect, but was not thrown");
    }
    catch (AccessDeniedException e)
    {
        Assert.assertTrue(parameter.isMethodInvoked());
    }
}
 
開發者ID:apache,項目名稱:deltaspike,代碼行數:16,代碼來源:SecurityParameterBindingTest.java


注:本文中的org.apache.deltaspike.security.api.authorization.AccessDeniedException類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。