当前位置: 首页>>代码示例>>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;未经允许,请勿转载。