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


Java AuthorizationException類代碼示例

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


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

示例1: doGetAuthorizationInfo

import org.apache.shiro.authz.AuthorizationException; //導入依賴的package包/類
/**
 * 授權查詢回調函數, 進行鑒權但緩存中無用戶的授權信息時調用.
 */
@Override
protected AuthorizationInfo doGetAuthorizationInfo(
		PrincipalCollection principalCollection) {
	if (principalCollection == null) {
		throw new AuthorizationException("Principal is not null!");
	}
	Shiro shiro = (Shiro) principalCollection.getPrimaryPrincipal();
	User entity = new User();
	entity.setId(shiro.getId());
	entity = (User) service.iUserService.select(entity);
	if (null == entity) {
		throw new UnknownAccountException("No account found for user ["
				+ shiro.getId() + "]");
	}
	SimpleAuthorizationInfo info = new SimpleAuthorizationInfo();
	return info;
}
 
開發者ID:jiangzongyao,項目名稱:kettle_support_kettle8.0,代碼行數:21,代碼來源:Authorizing2Realm.java

示例2: doGetAuthorizationInfo

import org.apache.shiro.authz.AuthorizationException; //導入依賴的package包/類
@Override
protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principals) {
    //null usernames are invalid
    if (principals == null) {
        throw new AuthorizationException("PrincipalCollection method argument cannot be null.");
    }

    String username = (String) getAvailablePrincipal(principals);

    Set<String> roleNames = new HashSet<>();
    roleNames.add(this.userService.findByUsername(username).getRole().getName());

    AuthorizationInfo info = new SimpleAuthorizationInfo(roleNames);
    /**
     * If you want to do Permission Based authorization, you can grab the Permissions List associated to your user:
     * For example:
     * Set<String> permissions = new HashSet<>();
     * permissions.add(this.userService.findByUsername(username).getRole().getPermissions());
     * ((SimpleAuthorizationInfo)info).setStringPermissions(permissions);
     */
    return info;
}
 
開發者ID:nebrass,項目名稱:pairing-shiro-javaee7,代碼行數:23,代碼來源:SecurityRealm.java

示例3: createSession

import org.apache.shiro.authz.AuthorizationException; //導入依賴的package包/類
/**
 * @since 1.0
 */
protected Session createSession(SessionContext sessionContext) throws AuthorizationException {
    if (!WebUtils.isHttp(sessionContext)) {
        String msg = "SessionContext must be an HTTP compatible implementation.";
        throw new IllegalArgumentException(msg);
    }

    HttpServletRequest request = WebUtils.getHttpRequest(sessionContext);

    HttpSession httpSession = request.getSession();

    //SHIRO-240: DO NOT use the 'globalSessionTimeout' value here on the acquired session.
    //see: https://issues.apache.org/jira/browse/SHIRO-240

    String host = getHost(sessionContext);

    return createSession(httpSession, host);
}
 
開發者ID:xuegongzi,項目名稱:rabbitframework,代碼行數:21,代碼來源:ServletContainerSessionManager.java

示例4: assertAuthorized

import org.apache.shiro.authz.AuthorizationException; //導入依賴的package包/類
/**
 * Ensures that the calling <code>Subject</code> has the Annotation's specified roles, and if not, throws an
 * <code>AuthorizingException</code> indicating that access is denied.
 *
 * @param a the RequiresRoles annotation to use to check for one or more roles
 * @throws org.apache.shiro.authz.AuthorizationException
 *          if the calling <code>Subject</code> does not have the role(s) necessary to
 *          proceed.
 */
public void assertAuthorized(Annotation a) throws AuthorizationException {
    if (!(a instanceof RequiresRoles)) return;

    RequiresRoles rrAnnotation = (RequiresRoles) a;
    String[] roles = rrAnnotation.value();

    if (roles.length == 1) {
        getSubject().checkRole(roles[0]);
        return;
    }
    if (Logical.AND.equals(rrAnnotation.logical())) {
        getSubject().checkRoles(Arrays.asList(roles));
        return;
    }
    if (Logical.OR.equals(rrAnnotation.logical())) {
        // Avoid processing exceptions unnecessarily - "delay" throwing the exception by calling hasRole first
        boolean hasAtLeastOneRole = false;
        for (String role : roles) if (getSubject().hasRole(role)) hasAtLeastOneRole = true;
        // Cause the exception if none of the role match, note that the exception message will be a bit misleading
        if (!hasAtLeastOneRole) getSubject().checkRole(roles[0]);
    }
}
 
開發者ID:xuegongzi,項目名稱:rabbitframework,代碼行數:32,代碼來源:RoleAnnotationHandler.java

示例5: assertAuthorized

import org.apache.shiro.authz.AuthorizationException; //導入依賴的package包/類
/**
 * Ensures that the calling <code>Subject</code> has the Annotation's specified permissions, and if not, throws an
 * <code>AuthorizingException</code> indicating access is denied.
 *
 * @param a the RequiresPermission annotation being inspected to check for one or more permissions
 * @throws org.apache.shiro.authz.AuthorizationException
 *          if the calling <code>Subject</code> does not have the permission(s) necessary to
 *          continue access or execution.
 */
public void assertAuthorized(Annotation a) throws AuthorizationException {
    if (!(a instanceof RequiresPermissions)) return;

    RequiresPermissions rpAnnotation = (RequiresPermissions) a;
    String[] perms = getAnnotationValue(a);
    Subject subject = getSubject();

    if (perms.length == 1) {
        subject.checkPermission(perms[0]);
        return;
    }
    if (Logical.AND.equals(rpAnnotation.logical())) {
        getSubject().checkPermissions(perms);
        return;
    }
    if (Logical.OR.equals(rpAnnotation.logical())) {
        // Avoid processing exceptions unnecessarily - "delay" throwing the exception by calling hasRole first
        boolean hasAtLeastOnePermission = false;
        for (String permission : perms) if (getSubject().isPermitted(permission)) hasAtLeastOnePermission = true;
        // Cause the exception if none of the role match, note that the exception message will be a bit misleading
        if (!hasAtLeastOnePermission) getSubject().checkPermission(perms[0]);
        
    }
}
 
開發者ID:xuegongzi,項目名稱:rabbitframework,代碼行數:34,代碼來源:PermissionAnnotationHandler.java

示例6: assertAuthorized

import org.apache.shiro.authz.AuthorizationException; //導入依賴的package包/類
@Override
   public void assertAuthorized() throws AuthorizationException {
	//if (!(annotation instanceof RequiresRoles)) return;
       RequiresRoles rrAnnotation = (RequiresRoles) annotation;
       String[] roles = rrAnnotation.value();

       if (roles.length == 1) {
           getSubject().checkRole(roles[0]);
           return;
       }
       if (Logical.AND.equals(rrAnnotation.logical())) {
           getSubject().checkRoles(Arrays.asList(roles));
           return;
       }
       if (Logical.OR.equals(rrAnnotation.logical())) {
           // Avoid processing exceptions unnecessarily - "delay" throwing the exception by calling hasRole first
           boolean hasAtLeastOneRole = false;
           for (String role : roles) if (getSubject().hasRole(role)) hasAtLeastOneRole = true;
           // Cause the exception if none of the role match, note that the exception message will be a bit misleading
           if (!hasAtLeastOneRole) getSubject().checkRole(roles[0]);
       }
}
 
開發者ID:gumutianqi,項目名稱:jfinal-plus,代碼行數:23,代碼來源:RoleAuthzHandler.java

示例7: testHandle_unauthorized

import org.apache.shiro.authz.AuthorizationException; //導入依賴的package包/類
@Test(expected = AuthorizationException.class)
public void testHandle_unauthorized() throws IOException {
  when(contentPermissionChecker.isPermitted(eq(REPO_NAME), eq(RawFormat.NAME), eq(BreadActions.EDIT), any()))
      .thenReturn(false);
  ComponentUpload component = new ComponentUpload();

  component.getFields().put("directory", "org/apache/maven");

  AssetUpload asset = new AssetUpload();
  asset.getFields().put("filename", "foo.jar");
  asset.setPayload(jarPayload);
  component.getAssetUploads().add(asset);

  asset = new AssetUpload();
  asset.getFields().put("filename", "bar.jar");
  asset.setPayload(sourcesPayload);
  component.getAssetUploads().add(asset);

  underTest.handle(repository, component);
}
 
開發者ID:sonatype,項目名稱:nexus-public,代碼行數:21,代碼來源:RawUploadHandlerTest.java

示例8: testHandle_unauthorized

import org.apache.shiro.authz.AuthorizationException; //導入依賴的package包/類
@Test(expected = AuthorizationException.class)
public void testHandle_unauthorized() throws IOException {
  when(contentPermissionChecker.isPermitted(eq(REPO_NAME), eq(Maven2Format.NAME), eq(BreadActions.EDIT), any()))
      .thenReturn(false);

  ComponentUpload componentUpload = new ComponentUpload();

  componentUpload.getFields().put("groupId", "org.apache.maven");
  componentUpload.getFields().put("artifactId", "tomcat");
  componentUpload.getFields().put("version", "5.0.28");

  AssetUpload assetUpload = new AssetUpload();
  assetUpload.getFields().put("extension", "jar");
  assetUpload.setPayload(jarPayload);
  componentUpload.getAssetUploads().add(assetUpload);

  underTest.handle(repository, componentUpload);
}
 
開發者ID:sonatype,項目名稱:nexus-public,代碼行數:19,代碼來源:MavenUploadHandlerTest.java

示例9: convert

import org.apache.shiro.authz.AuthorizationException; //導入依賴的package包/類
@Override
protected Response convert(final AuthorizationException exception, final String id) {
  HttpServletRequest httpRequest = httpRequestProvider.get();

  if (httpRequest.getAttribute(ANONYMOUS_LOGIN) != null) {
    // user is authenticated
    String scheme = (String) httpRequest.getAttribute(AUTH_SCHEME_KEY);
    String realm = (String) httpRequest.getAttribute(AUTH_REALM_KEY);

    return Response.status(Status.UNAUTHORIZED)
        .header(AUTHENTICATE_HEADER, String.format("%s realm=\"%s\"", scheme, realm))
        .build();
  }

  return Response.status(Status.FORBIDDEN).build();
}
 
開發者ID:sonatype,項目名稱:nexus-public,代碼行數:17,代碼來源:AuthorizationExceptionMapper.java

示例10: deleteComponent

import org.apache.shiro.authz.AuthorizationException; //導入依賴的package包/類
@Override
public void deleteComponent(final Repository repository, final Component component) {
  checkNotNull(repository);
  checkNotNull(component);

  String repositoryFormat = repository.getFormat().toString();
  VariableResolverAdapter variableResolverAdapter = variableResolverAdapterManager.get(repositoryFormat);

  StorageTx storageTx = repository.facet(StorageFacet.class).txSupplier().get();

  try {
    storageTx.begin();
    for (Asset asset : storageTx.browseAssets(component)) {
      if (!canDeleteAssetInRepository(repository, repositoryFormat, variableResolverAdapter, asset)) {
        throw new AuthorizationException();
      }
    }
  }
  finally {
    storageTx.close();
  }

  getComponentMaintenanceFacet(repository).deleteComponent(component.getEntityMetadata().getId());
}
 
開發者ID:sonatype,項目名稱:nexus-public,代碼行數:25,代碼來源:MaintenanceServiceImpl.java

示例11: doGetAuthorizationInfo

import org.apache.shiro.authz.AuthorizationException; //導入依賴的package包/類
@SuppressWarnings("unchecked")
@Override
protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principals) {
  //null usernames are invalid
  if (principals == null) {
    throw new AuthorizationException("PrincipalCollection method argument cannot be null.");
  }
  String username = (String) getAvailablePrincipal(principals);

  java.util.Set<String> roles = redisManager.smembers(user_roles_KeyPrefix + username);

  SimpleAuthorizationInfo info = new SimpleAuthorizationInfo(roles);

  if (permissionsLookupEnabled) {
    java.util.List<java.lang.String> permissionsList = redisManager.hmget(roles_permissions_Key, roles.toArray(new String[0]));
    Set<String> permissionsSet = new HashSet<String>(permissionsList.size());
    permissionsSet.addAll(permissionsList);
    info.setStringPermissions(permissionsSet);
  }

  return info;
}
 
開發者ID:wjw465150,項目名稱:shiro-redis,代碼行數:23,代碼來源:RedisRealm.java

示例12: find

import org.apache.shiro.authz.AuthorizationException; //導入依賴的package包/類
public Iterable<ObjBase> find(Map<String, Object> query, int hitmax){

        query = addSubSchemas(query);
        List<ObjBase> result = connection.get(query, hitmax);
        //TODO: also add converted instances
        
        //filter results for permission
        List<ObjBase> filteredResult = new ArrayList<>();
        for (ObjBase obj : result){
            try{
                checkPriv(obj.getId(), "view");
                filteredResult.add(obj);
            } catch (AuthorizationException e){
            }
        }
        return filteredResult;
    }
 
開發者ID:CIDARLAB,項目名稱:clotho3crud,代碼行數:18,代碼來源:Persistor.java

示例13: doGetAuthorizationInfo

import org.apache.shiro.authz.AuthorizationException; //導入依賴的package包/類
/**
 * 
 * @param principalCollection
 * @return 
 */
@Override
protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principalCollection) {
    
    if (principalCollection == null) {
        throw new AuthorizationException(
                "The principal collections can't be null");
    }
    
    final String username = 
            (String) this.getAvailablePrincipal(principalCollection);
    
    final List<GroupPermission> groupPermissions = 
            this.accountService.loadUserPermissions(username);
    
    final Set<String> authorizationKeys = groupPermissions
            .parallelStream()
            .map(GroupPermission::getAuthorizationKey)
            .collect(Collectors.toSet());
    
    return new SimpleAuthorizationInfo(authorizationKeys);
}
 
開發者ID:arthurgregorio,項目名稱:exemplos,代碼行數:27,代碼來源:SecurityRealm.java

示例14: assertAuthorized

import org.apache.shiro.authz.AuthorizationException; //導入依賴的package包/類
public void assertAuthorized(final Object resource, final Method handler) throws AuthorizationException {
    super.assertAuthorized(new MethodInvocation() {
        @Override
        public Object proceed() throws Throwable {
            return null;
        }

        @Override
        public Method getMethod() {
            return handler;
        }

        @Override
        public Object[] getArguments() {
            return new Object[0];
        }

        @Override
        public Object getThis() {
            return resource;
        }
    });
}
 
開發者ID:ManyDesigns,項目名稱:Portofino,代碼行數:24,代碼來源:PortofinoFilter.java

示例15: assertAuthorized

import org.apache.shiro.authz.AuthorizationException; //導入依賴的package包/類
public void assertAuthorized(final ExecutionContext context) throws AuthorizationException {
    super.assertAuthorized(new MethodInvocation() {
        @Override
        public Object proceed() throws Throwable {
            return null;
        }

        @Override
        public Method getMethod() {
            return context.getHandler();
        }

        @Override
        public Object[] getArguments() {
            return new Object[0];
        }

        @Override
        public Object getThis() {
            return context.getActionBean();
        }
    });
}
 
開發者ID:ManyDesigns,項目名稱:Portofino,代碼行數:24,代碼來源:ShiroInterceptor.java


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