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


Java UserService.isUserAdmin方法代碼示例

本文整理匯總了Java中com.google.appengine.api.users.UserService.isUserAdmin方法的典型用法代碼示例。如果您正苦於以下問題:Java UserService.isUserAdmin方法的具體用法?Java UserService.isUserAdmin怎麽用?Java UserService.isUserAdmin使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在com.google.appengine.api.users.UserService的用法示例。


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

示例1: getMiscFunctionInfoList

import com.google.appengine.api.users.UserService; //導入方法依賴的package包/類
@Override
public RpcResult< List< MiscFunctionInfo > > getMiscFunctionInfoList() {
	LOGGER.fine( "" );
	
	final UserService userService = UserServiceFactory.getUserService();
	final User user = userService.getCurrentUser();
	if ( user == null )
		return RpcResult.createNotLoggedInErrorResult();
	if ( !userService.isUserAdmin() )
		return RpcResult.createNoPermissionErrorResult();
	
	final List< MiscFunctionInfo > miscFunctionInfoList = new ArrayList< MiscFunctionInfo >( miscFunctionMap.size() );
	
	for ( final Entry< String, DatastoreTask > entry : miscFunctionMap.entrySet() )
		miscFunctionInfoList.add( new MiscFunctionInfo( entry.getKey(), entry.getValue().getParamNames() ) );
	
	Collections.sort( miscFunctionInfoList, new Comparator< MiscFunctionInfo >() {
		@Override
           public int compare( final MiscFunctionInfo i1, final MiscFunctionInfo i2 ) {
            return i1.getName().compareTo( i2.getName() );
           }
	} );
	
	return new RpcResult< List< MiscFunctionInfo > >( miscFunctionInfoList );
}
 
開發者ID:icza,項目名稱:sc2gears,代碼行數:26,代碼來源:AdminServiceImpl.java

示例2: doGet

import com.google.appengine.api.users.UserService; //導入方法依賴的package包/類
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
	UserService userService = UserServiceFactory.getUserService();
	if(userService.isUserAdmin()) {
   		String action = ACTION_EXPORT;
   		//String action = request.getParameter("action");

   		if(ACTION_EXPORT.equals(action)) {
   			response.setContentType("text/javascript; charset=utf8");
   			response.setCharacterEncoding("utf8");
   			PrintWriter writer = response.getWriter();
       		String json="{}";
   			writer.append(json);
   			writer.flush();
   			writer.close();
   		}        	
   	}
}
 
開發者ID:dvorka,項目名稱:coaching-notebook,代碼行數:18,代碼來源:AdminServlet.java

示例3: getNewAccountSuggestionList

import com.google.appengine.api.users.UserService; //導入方法依賴的package包/類
@Override
public RpcResult< List< NewAccountSuggestion > > getNewAccountSuggestionList() {
	LOGGER.fine( "" );
	
	final UserService userService = UserServiceFactory.getUserService();
	final User user = userService.getCurrentUser();
	if ( user == null )
		return RpcResult.createNotLoggedInErrorResult();
	if ( !userService.isUserAdmin() )
		return RpcResult.createNoPermissionErrorResult();
	
	PersistenceManager pm = null;
	try {
		pm = PMF.get().getPersistenceManager();
		
		final List< Visit > visitList = new JQBuilder<>( pm, Visit.class ).filter( "visitorKey==null", null ).desc( "date" ).range( 0, 20 ).get();
		
		final List< NewAccountSuggestion > newAccSuggestionList = new ArrayList< NewAccountSuggestion >( visitList.size() + 1 );
		if ( !visitList.isEmpty() )
			newAccSuggestionList.add( new NewAccountSuggestion() );
		
		for ( final Visit visit : visitList ) {
			final NewAccountSuggestion newAccSuggestion = new NewAccountSuggestion();
			
			newAccSuggestion.setGoogleAccount( visit.getUser().getEmail()                              );
			newAccSuggestion.setCountryCode  ( visit.getCountryCode()                                  );
			newAccSuggestion.setCountryName  ( ServerUtils.countryCodeToName( visit.getCountryCode() ) );
			
			newAccSuggestionList.add( newAccSuggestion );
		}
		
		return new RpcResult< List<NewAccountSuggestion> >( newAccSuggestionList );
	} finally {
		if ( pm != null )
			pm.close();
	}
}
 
開發者ID:icza,項目名稱:sc2gears,代碼行數:38,代碼來源:AdminServiceImpl.java

示例4: recalculateFileInfoStats

import com.google.appengine.api.users.UserService; //導入方法依賴的package包/類
@Override
public RpcResult< Void > recalculateFileInfoStats( final String googleAccount ) {
	LOGGER.fine( "For Google account: " + googleAccount );
	
	final UserService userService = UserServiceFactory.getUserService();
	final User user = userService.getCurrentUser();
	if ( user == null )
		return RpcResult.createNotLoggedInErrorResult();
	if ( !userService.isUserAdmin() )
		return RpcResult.createNoPermissionErrorResult();
	
	PersistenceManager pm = null;
	try {
		
		pm = PMF.get().getPersistenceManager();
		
		final Key accountKey = CachingService.getAccountKeyByUser( pm, new User( googleAccount, "gmail.com" ) );
		if ( accountKey == null )
			return RpcResult.createErrorResult( "Invalid Google account!" );
		
		TaskServlet.register_recalcFileStatsTask( accountKey );
		
		pm.makePersistent( new Event( accountKey, Type.FILE_STATS_RECALC_TRIGGERED, "By admin: " + user.getEmail() ) );
		
	} finally {
		if ( pm != null )
			pm.close();
	}
	
	return RpcResult.createInfoResult( "File stats recalculation has been kicked-off..." );
}
 
開發者ID:icza,項目名稱:sc2gears,代碼行數:32,代碼來源:AdminServiceImpl.java

示例5: executeMiscFunction

import com.google.appengine.api.users.UserService; //導入方法依賴的package包/類
@Override
public RpcResult< String > executeMiscFunction( final boolean autoTx, final String functionName, final String[] params ) {
	final StringBuilder paramsBuilder = new StringBuilder( "[" );
	for ( final String param : params ) {
		if ( paramsBuilder.length() > 1 )
			paramsBuilder.append( ", " );
		paramsBuilder.append( param );
	}
	paramsBuilder.append( ']' );
	LOGGER.fine( "Auto Tx: " + autoTx + ", Function name: " + functionName + ", params: " + paramsBuilder );
	
	final UserService userService = UserServiceFactory.getUserService();
	final User user = userService.getCurrentUser();
	if ( user == null )
		return RpcResult.createNotLoggedInErrorResult();
	if ( !userService.isUserAdmin() )
		return RpcResult.createNoPermissionErrorResult();
	
	final DatastoreTask miscFunction = miscFunctionMap.get( functionName );
	if ( miscFunction == null ) {
		LOGGER.warning( "Invalid function name!" );
		return RpcResult.createErrorResult( "Invalid function name!" );
	}
	
	PersistenceManager pm = null;
	try {
		
		pm = ( autoTx ? PMF.getAutoTx() : PMF.getNoAutoTx() ).getPersistenceManager();
		
		final long start = System.nanoTime();
		String result = miscFunction.execute( getThreadLocalRequest(), pm, params );
		final long end = System.nanoTime();
		
		return new RpcResult< String >( "[" + ServerUtils.DECIMAL_FORMAT.format( ( end - start ) / 1000000l ) + " ms] Execution result: " + result );
		
	} finally {
		if ( pm != null )
			pm.close();
	}
}
 
開發者ID:icza,項目名稱:sc2gears,代碼行數:41,代碼來源:AdminServiceImpl.java

示例6: isCurrentUserPermittedToModify

import com.google.appengine.api.users.UserService; //導入方法依賴的package包/類
/**
 * @return true if the current user may modify the package
 */
public boolean isCurrentUserPermittedToModify() {
    UserService us = UserServiceFactory.getUserService();
    User u = us.getCurrentUser();
    boolean r = false;
    if (u != null) {
        if (us.isUserAdmin()) {
            r = true;
        } else {
            r = isUserPermittedToModify(u);
        }
    }
    return r;
}
 
開發者ID:tim-lebedkov,項目名稱:npackd-gae-web,代碼行數:17,代碼來源:Package.java

示例7: admin

import com.google.appengine.api.users.UserService; //導入方法依賴的package包/類
protected boolean admin() {
	Boolean status = (Boolean)pageContext.getAttribute(STATUS);
	if (status == null) {
		//no status - define it
		UserService userService = UserServiceFactory.getUserService();
		status = userService.isUserLoggedIn() && userService.isUserAdmin();
		pageContext.setAttribute(STATUS, status);
	}
	return status.booleanValue();
}
 
開發者ID:Antokolos,項目名稱:iambookmaster,代碼行數:11,代碼來源:UserIsNotAdminTag.java

示例8: doGet

import com.google.appengine.api.users.UserService; //導入方法依賴的package包/類
public void doGet(HttpServletRequest req, HttpServletResponse res) throws IOException {
  res.setContentType("text/html");
  res.getWriter().println("<html>");
  res.getWriter().println("<head>");
  res.getWriter().println("<title>whoami</title>");
  res.getWriter().println("</head>");
  res.getWriter().println("<body>");

  UserService userService = UserServiceFactory.getUserService();

  if (userService.isUserLoggedIn()) {
    User user = userService.getCurrentUser();

    res.getWriter().println("<h1>You are " + user.getNickname() + ".</h1>");

    if (userService.isUserAdmin()) {
      res.getWriter().println("<h2>You are an admin! :)</h2>");
    } else {
      res.getWriter().println("<h2>You are not an admin... :(</h2>");
    }

    res.getWriter().println("<h1>Your user ID is " + user.getUserId() + ".</h1>");
  } else {
    res.getWriter().println("<h1>You are not logged in.</h1>");
  }

  String destURL = "/whoami";
  String loginURL = userService.createLoginURL(destURL);
  String logoutURL = userService.createLogoutURL(destURL);

  res.getWriter().println("<br>");
  res.getWriter().println("<a href=\"" + loginURL + "\">login</a>");
  res.getWriter().println("<br>");
  res.getWriter().println("<a href=\"" + logoutURL + "\">logout</a>");
  res.getWriter().println("</body>");
  res.getWriter().println("</html>");
}
 
開發者ID:GoogleCloudPlatform,項目名稱:appengine-java-vm-runtime,代碼行數:38,代碼來源:LoginServlet.java

示例9: isUserInRole

import com.google.appengine.api.users.UserService; //導入方法依賴的package包/類
@Override
public boolean isUserInRole(String role, Scope unusedScope) {
  UserService userService = UserServiceFactory.getUserService();
  log.fine("Checking if principal " + userPrincipal + " is in role " + role);
  if (userPrincipal == null) {
    log.info("isUserInRole() called with null principal.");
    return false;
  }

  if (USER_ROLE.equals(role)) {
    return true;
  }

  if (ADMIN_ROLE.equals(role)) {
    User user = userPrincipal.getUser();
    if (user.equals(userService.getCurrentUser())) {
      return userService.isUserAdmin();
    } else {
      // TODO(user): I'm not sure this will happen in
      // practice. If it does, we may need to pass an
      // application's admin list down somehow.
      log.severe("Cannot tell if non-logged-in user " + user + " is an admin.");
      return false;
    }
  } else {
    log.warning("Unknown role: " + role + ".");
    return false;
  }
}
 
開發者ID:GoogleCloudPlatform,項目名稱:appengine-java-vm-runtime,代碼行數:30,代碼來源:AppEngineAuthentication.java

示例10: loadAuthorizationInfo

import com.google.appengine.api.users.UserService; //導入方法依賴的package包/類
@Override
protected Collection<String> loadAuthorizationInfo(Serializable principal) {
    Set<String> authz = new HashSet<String>(super.loadAuthorizationInfo(principal));
    User user = (User) principal;
    UserService userService = UserServiceFactory.getUserService();
    if(user != null &&
       userService.isUserAdmin() && 
       StringUtils.equals(userService.getCurrentUser().getUserId(), user.getUserId())) {
        authz.add(SecurityLogic.getAdministratorsGroup(portofinoConfiguration));
    }
    return authz;
}
 
開發者ID:hongliangpan,項目名稱:manydesigns.cn,代碼行數:13,代碼來源:GAEPortofinoRealm.java

示例11: doGet

import com.google.appengine.api.users.UserService; //導入方法依賴的package包/類
@Override
public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {
    UserService userService = UserServiceFactory.getUserService();
    User user = userService.getCurrentUser();

    if (!userService.isUserAdmin()) {
        resp.setStatus(403);
        return;
    }

    DriveExporter driveExporter = new DriveExporter();
    String folderUrl = driveExporter.shareFolder(user.getEmail());
    resp.sendRedirect(folderUrl);
}
 
開發者ID:openmash,項目名稱:mashmesh,代碼行數:15,代碼來源:AccessDataServlet.java

示例12: isAdmin

import com.google.appengine.api.users.UserService; //導入方法依賴的package包/類
public static boolean isAdmin() {
 UserService userService = UserServiceFactory.getUserService();
 return userService.isUserLoggedIn() && userService.isUserAdmin();
}
 
開發者ID:bbloomf,項目名稱:cincinnati-library-auto-renew,代碼行數:5,代碼來源:User.java

示例13: getVisitInfoList

import com.google.appengine.api.users.UserService; //導入方法依賴的package包/類
@Override
public RpcResult< List< VisitInfo > > getVisitInfoList( final VisitType type, final int hours, final Boolean hasAccount ) {
	LOGGER.fine( "Type: " + type.name() + ", hours: " + hours + ", has account: " + hasAccount );
	
	final UserService userService = UserServiceFactory.getUserService();
	final User user = userService.getCurrentUser();
	if ( user == null )
		return RpcResult.createNotLoggedInErrorResult();
	if ( !userService.isUserAdmin() )
		return RpcResult.createNoPermissionErrorResult();
	
	if ( hours < 1 || hours > 336 )
		return RpcResult.createErrorResult( "Invalid hours (must be between 1 and 336)!" );
	
	PersistenceManager pm = null;
	try {
		
		pm = PMF.get().getPersistenceManager();
		
		final Date fromDate = new Date( System.currentTimeMillis() - hours * 60L * 60 * 1000l );
		
		final List< VisitInfo > visitInfoList = new ArrayList< VisitInfo >();
		
		// "visitorKey==null" filter is OK, but can't append "visitorKey!=null" inequality filter
		// because that would require to sort by it (but we want to sort by date), I'll handle that manually.
		final JQBuilder< ? extends BaseVisit > q = new JQBuilder<>( pm, type == VisitType.VISIT ? Visit.class : ApiVisit.class ).desc( "date" ).range( 0, 1000 )
				.filter( hasAccount == null || hasAccount ? "date>p1" : "date>p1 && visitorKey==null", "DATE p1" );
		
		while ( true ) {
			final List< ? extends BaseVisit > visitList = q.get( fromDate );
			for ( final BaseVisit visit : visitList ) {
				if ( Boolean.TRUE.equals( hasAccount ) && visit.getVisitorKey() == null )
					continue;
				
				final VisitInfo visitInfo = new VisitInfo();
				
				visitInfo.setDate         ( visit.getDate()               );
				visitInfo.setGoogleAccount( visit.getUser().getEmail()    );
				visitInfo.setLocation     ( visit.getCountry()            );
				visitInfo.setIp           ( visit.getIp()                 );
				visitInfo.setHasAccount   ( visit.getVisitorKey() != null );
				visitInfo.setUserAgent    ( visit.getUserAgent()          );
				
				visitInfoList.add( visitInfo );
			}
			
			if ( visitList.size() < 1000 )
				break;
			
			q.cursor( visitList );
		}
		
		return new RpcResult< List< VisitInfo > >( visitInfoList );
		
	} finally {
		if ( pm != null )
			pm.close();
	}
}
 
開發者ID:icza,項目名稱:sc2gears,代碼行數:60,代碼來源:AdminServiceImpl.java

示例14: getApiActivity

import com.google.appengine.api.users.UserService; //導入方法依賴的package包/類
@Override
public RpcResult< List< ApiCallStatInfo > > getApiActivity( final String firstDay, final String lastDay ) {
	LOGGER.fine( "First day: " + firstDay + ", last day: " + lastDay );
	
	final UserService userService = UserServiceFactory.getUserService();
	final User user = userService.getCurrentUser();
	if ( user == null )
		return RpcResult.createNotLoggedInErrorResult();
	if ( !userService.isUserAdmin() )
		return RpcResult.createNoPermissionErrorResult();
	
	PersistenceManager pm = null;
	try {
		
		pm = PMF.get().getPersistenceManager();
		
		// To keep track of total
		final ApiCallStatInfo totalApiCallStatInfo = new ApiCallStatInfo();
		totalApiCallStatInfo.setGoogleAccount( "TOTAL: ∑ ALL" );
		
		final Map< Key, ApiCallStatInfo > apiAccountKeyApiCallStatInfoMap  = new HashMap< Key, ApiCallStatInfo >();
		
		final JQBuilder< ApiCallStat > q = new JQBuilder<>( pm, ApiCallStat.class ).filter( "day>=p1 && day<=p2", "String p1, String p2" ).range( 0, 1000 );
		
		while ( true ) {
			final List< ApiCallStat > apiCallStatList = q.get( firstDay, lastDay );
			
			for ( final ApiCallStat apiCallStat : apiCallStatList ) {
				ApiCallStatInfo apiCallStatInfo = apiAccountKeyApiCallStatInfoMap.get( apiCallStat.getOwnerKey() );
				if ( apiCallStatInfo == null ) {
					apiAccountKeyApiCallStatInfoMap.put( apiCallStat.getOwnerKey(), apiCallStatInfo = new ApiCallStatInfo() );
					final ApiAccount apiAccount = pm.getObjectById( ApiAccount.class, apiCallStat.getOwnerKey() );
					apiCallStatInfo.setGoogleAccount( apiAccount.getUser().getEmail() );
					apiCallStatInfo.setPaidOps      ( apiAccount.getPaidOps        () );
					// Integrate paid Ops into totals, ONCE only per API account
					totalApiCallStatInfo.setPaidOps( totalApiCallStatInfo.getPaidOps() + apiCallStatInfo.getPaidOps() );
				}
				
				ServerUtils.integrateApiCallStatIntoInfo( apiCallStatInfo, apiCallStat );
				
				// Keep track of totals
				ServerUtils.integrateApiCallStatIntoInfo( totalApiCallStatInfo, apiCallStat );
			}
			
			if ( apiCallStatList.size() < 1000 )
				break;
			
			q.cursor( apiCallStatList );
		}
		
		final List< ApiCallStatInfo > apiCallStatInfoList = new ArrayList< ApiCallStatInfo >( apiAccountKeyApiCallStatInfoMap.size() + 1 );
		// First add the total info record (sorting will not move it even if only 1 stat record which will have the same used ops)
		apiCallStatInfoList.add( totalApiCallStatInfo );
		apiCallStatInfoList.addAll( apiAccountKeyApiCallStatInfoMap.values() );
		
		Collections.sort( apiCallStatInfoList, new Comparator< ApiCallStatInfo >() {
			@Override
			public int compare( final ApiCallStatInfo i1, final ApiCallStatInfo i2 ) {
				return new Long( i2.getUsedOps() ).compareTo( i1.getUsedOps() );
			}
		} );
		
		return new RpcResult< List<ApiCallStatInfo> >( apiCallStatInfoList );
		
	} finally {
		if ( pm != null )
			pm.close();
	}
}
 
開發者ID:icza,項目名稱:sc2gears,代碼行數:70,代碼來源:AdminServiceImpl.java

示例15: getApiCallStatInfoList

import com.google.appengine.api.users.UserService; //導入方法依賴的package包/類
@Override
public RpcResult< List< ApiCallStatInfo > > getApiCallStatInfoList( final String googleAccount ) {
	LOGGER.fine( "For Google account: " + googleAccount);
	
	final UserService userService = UserServiceFactory.getUserService();
	final User user = userService.getCurrentUser();
	if ( user == null )
		return RpcResult.createNotLoggedInErrorResult();
	if ( !userService.isUserAdmin() )
		return RpcResult.createNoPermissionErrorResult();
	
	PersistenceManager pm = null;
	try {
		
		pm = PMF.get().getPersistenceManager();
		
		final JQBuilder< ApiCallStat > q = new JQBuilder<>( pm, ApiCallStat.class ).range( 0, 1000 );
		
		final Object[] queryParams;
		if ( googleAccount != null && !googleAccount.isEmpty() ) {
			@SuppressWarnings( "unchecked" )
			final List< Key > apiAccountKey = (List< Key >) pm.newQuery( "select key from " + ApiAccount.class.getName() + " where user==:1" ).execute( new User( googleAccount, "gmail.com" ) );
			if ( apiAccountKey.isEmpty() )
				return new RpcResult< List<ApiCallStatInfo> >( new ArrayList< ApiCallStatInfo >( 0 ) );
			
			q.filter( "ownerKey==p1 && day==p2", "KEY p1, String p2" );
			queryParams = new Object[] { apiAccountKey.get( 0 ), ApiCallStat.DAY_TOTAL };
		}
		else {
			q.filter( "day==p1", "String p1" );
			queryParams = new Object[] { ApiCallStat.DAY_TOTAL };
		}
		
		// To keep track of total
		final ApiCallStatInfo totalApiCallStatInfo = new ApiCallStatInfo();
		totalApiCallStatInfo.setGoogleAccount( "TOTAL: ∑ ALL" );
		
		final List< ApiCallStatInfo > apiCallStatInfoList = new ArrayList< ApiCallStatInfo >();
		// First add the total info record
		apiCallStatInfoList.add( totalApiCallStatInfo );
		
		while ( true ) {
			final List< ApiCallStat > apiCallStatList = q.get( queryParams );
			
			for ( final ApiCallStat apiCallStat : apiCallStatList ) {
				final ApiCallStatInfo info = new ApiCallStatInfo();
				
				final ApiAccount apiAccount  = pm.getObjectById( ApiAccount.class, apiCallStat.getOwnerKey() );
				info.setGoogleAccount   ( apiAccount .getUser().getEmail () );
				info.setPaidOps         ( apiAccount .getPaidOps         () );
				ServerUtils.integrateApiCallStatIntoInfo( info, apiCallStat );
				apiCallStatInfoList.add( info );
				
				// Keep track of totals
				totalApiCallStatInfo.integrateApiCallStat( info );
				totalApiCallStatInfo.setPaidOps( totalApiCallStatInfo.getPaidOps() + info.getPaidOps() );
			}
			
			if ( apiCallStatList.size() < 1000 )
				break;
			
			q.cursor( apiCallStatList );
		}
		
		Collections.sort( apiCallStatInfoList, new Comparator< ApiCallStatInfo >() {
			@Override
			public int compare( final ApiCallStatInfo i1, final ApiCallStatInfo i2 ) {
				return new Long( i2.getUsedOps() ).compareTo( i1.getUsedOps() );
			}
		} );
		
		return new RpcResult< List<ApiCallStatInfo> >( apiCallStatInfoList );
		
	} finally {
		if ( pm != null )
			pm.close();
	}
}
 
開發者ID:icza,項目名稱:sc2gears,代碼行數:79,代碼來源:AdminServiceImpl.java


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