当前位置: 首页>>代码示例>>Java>>正文


Java RandomStringUtils.randomAlphanumeric方法代码示例

本文整理汇总了Java中org.apache.commons.lang.RandomStringUtils.randomAlphanumeric方法的典型用法代码示例。如果您正苦于以下问题:Java RandomStringUtils.randomAlphanumeric方法的具体用法?Java RandomStringUtils.randomAlphanumeric怎么用?Java RandomStringUtils.randomAlphanumeric使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.commons.lang.RandomStringUtils的用法示例。


在下文中一共展示了RandomStringUtils.randomAlphanumeric方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: createToken

import org.apache.commons.lang.RandomStringUtils; //导入方法依赖的package包/类
/**
 * 创建token
 *
 * @param email
 */
public String createToken(String email) {
    String token = getToken(email);
    if (StringUtils.isNotEmpty(token)) {
        return token;
    }

    // 分配token
    token = RandomStringUtils.randomAlphanumeric(32);
    Session session = new Session();
    session.setEmail(email);
    session.setToken(token);
    sessionMapper.insert(session);

    return token;
}
 
开发者ID:zouzhirong,项目名称:configx,代码行数:21,代码来源:SessionService.java

示例2: save

import org.apache.commons.lang.RandomStringUtils; //导入方法依赖的package包/类
@Override
@Transactional
public void save(SysUserEntity user) {
	user.setCreateTime(new Date());
	//sha256加密
	String salt = RandomStringUtils.randomAlphanumeric(20);
	user.setPassword(new Sha256Hash(user.getPassword(), salt).toHex());
	user.setSalt(salt);
	sysUserDao.save(user);
	
	//检查角色是否越权
	checkRole(user);
	
	//保存用户与角色关系
	sysUserRoleService.saveOrUpdate(user.getUserId(), user.getRoleIdList());
}
 
开发者ID:zhaoqicheng,项目名称:renren-fast,代码行数:17,代码来源:SysUserServiceImpl.java

示例3: save

import org.apache.commons.lang.RandomStringUtils; //导入方法依赖的package包/类
@Override
@Transactional(rollbackFor = Exception.class)
public void save(SysUserEntity user) throws Exception {
    user.setCreateTime(LocalDateTime.now());
    //sha256加密
    String salt = RandomStringUtils.randomAlphanumeric(20);
    user.setPassword(new Sha256Hash(user.getPassword(), salt).toHex());
    user.setSalt(salt);
    sysUserDao.save(user);

    //检查角色是否越权
    checkRole(user);

    //保存用户与角色关系
    sysUserRoleService.saveOrUpdate(user.getUserId(), user.getRoleIdList());
}
 
开发者ID:davichi11,项目名称:my-spring-boot-project,代码行数:17,代码来源:SysUserServiceImpl.java

示例4: makeSafePlaylistName

import org.apache.commons.lang.RandomStringUtils; //导入方法依赖的package包/类
/**
 * creates a playlist name that is <= 150 characters and is unique
 * 
 * @param playlistName the name of the playlist
 * @return the safe playlist name
 * @throws IllegalArgumentException if playlist name is invalid
 */
@NoProfile
protected String makeSafePlaylistName(String playlistName) {
    playlistName = StringUtils.trimToNull(playlistName);
    if (playlistName == null) {
        throw new IllegalArgumentException("playlistName cannot be null");
    }
    if (playlistName.length() > PLAYLIST_MAX_LENGTH) {
        playlistName = StringUtils.abbreviate(playlistName, CATEGORY_MAX_LENGTH);
        playlistName = playlistName.substring(0, CATEGORY_MAX_LENGTH-3) + RandomStringUtils.randomAlphanumeric(3);
    }
    return playlistName;
}
 
开发者ID:ITYug,项目名称:kaltura-ce-sakai-extension,代码行数:20,代码来源:KalturaAPIService.java

示例5: verifyDirUsingMkdir

import org.apache.commons.lang.RandomStringUtils; //导入方法依赖的package包/类
/**
 * Function to test whether a dir is working correctly by actually creating a
 * random directory.
 *
 * @param dir
 *          the dir to test
 */
private void verifyDirUsingMkdir(File dir) throws IOException {

  String randomDirName = RandomStringUtils.randomAlphanumeric(5);
  File target = new File(dir, randomDirName);
  int i = 0;
  while (target.exists()) {

    randomDirName = RandomStringUtils.randomAlphanumeric(5) + i;
    target = new File(dir, randomDirName);
    i++;
  }
  try {
    DiskChecker.checkDir(target);
  } finally {
    FileUtils.deleteQuietly(target);
  }
}
 
开发者ID:yncxcw,项目名称:big-c,代码行数:25,代码来源:DirectoryCollection.java

示例6: FSTestWrapper

import org.apache.commons.lang.RandomStringUtils; //导入方法依赖的package包/类
public FSTestWrapper(String testRootDir) {
  // Use default test dir if not provided
  if (testRootDir == null || testRootDir.isEmpty()) {
    testRootDir = System.getProperty("test.build.data", "build/test/data");
  }
  // salt test dir with some random digits for safe parallel runs
  this.testRootDir = testRootDir + "/"
      + RandomStringUtils.randomAlphanumeric(10);
}
 
开发者ID:nucypher,项目名称:hadoop-oss,代码行数:10,代码来源:FSTestWrapper.java

示例7: startInvite

import org.apache.commons.lang.RandomStringUtils; //导入方法依赖的package包/类
private JSONObject startInvite(String inviteeFirstName,
        String inviteeLastName, String inviteeSiteRole, String siteShortName, int expectedStatus)
        throws Exception
{
    String inviteeEmail = INVITEE_EMAIL_PREFIX + RandomStringUtils.randomAlphanumeric(6)
            + "@" + INVITEE_EMAIL_DOMAIN;

    return startInvite(inviteeFirstName, inviteeLastName, inviteeEmail, inviteeSiteRole, siteShortName,
            expectedStatus);
}
 
开发者ID:Alfresco,项目名称:alfresco-remote-api,代码行数:11,代码来源:InviteServiceTest.java

示例8: testAuditTruncatedValues

import org.apache.commons.lang.RandomStringUtils; //导入方法依赖的package包/类
public void testAuditTruncatedValues()
{
    final String rootPath = "/test/one.one/two.one";

    // String value with length grater then the DB supported threshold.
    final String stringValue = RandomStringUtils.randomAlphanumeric(SchemaBootstrap.DEFAULT_MAX_STRING_LENGTH + 1);
    final MLText mlTextValue = new MLText();
    mlTextValue.put(Locale.ENGLISH, stringValue);

    final RetryingTransactionCallback<Map<String, Serializable>> testCallback = new RetryingTransactionCallback<Map<String, Serializable>>()
    {
        public Map<String, Serializable> execute() throws Throwable
        {
            final Map<String, Serializable> values = new HashMap<>();
            values.put("/3.1/4.1", stringValue);
            values.put("/3.1/4.2", mlTextValue);

            return auditComponent.recordAuditValues(rootPath, values);
        }
    };
    RunAsWork<Map<String, Serializable>> testRunAs = new RunAsWork< Map<String, Serializable>>()
    {
        public Map<String, Serializable> doWork() throws Exception
        {
            return transactionService.getRetryingTransactionHelper().doInTransaction(testCallback);
        }
    };

    Map<String, Serializable> result = AuthenticationUtil.runAs(testRunAs, "SomeOtherUser");

    // Check that the values aren't truncated.
    assertEquals(stringValue, result.get("/test/1.1/2.1/3.1/4.1/value.1"));
    assertEquals(mlTextValue, result.get("/test/1.1/2.1/3.1/4.2/value.2"));
}
 
开发者ID:Alfresco,项目名称:alfresco-repository,代码行数:35,代码来源:AuditComponentTest.java

示例9: invalidXmlLogsXmlContentToInfo

import org.apache.commons.lang.RandomStringUtils; //导入方法依赖的package包/类
@Test
public void invalidXmlLogsXmlContentToInfo() throws Exception {
    String content = RandomStringUtils.randomAlphanumeric(10);
    stubFor(get(urlPathEqualTo(RESOURCE)).willReturn(aResponse().withStatus(418).withBody(content)));

    executeRequest();

    assertThat(infoEvents()).anySatisfy(hasMessageContaining(content));
}
 
开发者ID:aws,项目名称:aws-sdk-java-v2,代码行数:10,代码来源:DefaultErrorResponseHandlerTest.java

示例10: makeIdentifier

import org.apache.commons.lang.RandomStringUtils; //导入方法依赖的package包/类
public String makeIdentifier() {
	String iden = null;
	do {
		iden = RandomStringUtils.randomAlphanumeric(32);
	} while (hasFile(iden));
	return iden;
}
 
开发者ID:Quantencomputer,项目名称:cyoastudio,代码行数:8,代码来源:DataStorage.java

示例11: getGuestPlayer

import org.apache.commons.lang.RandomStringUtils; //导入方法依赖的package包/类
/**
 * Returns a player associated to the special "guest" user, creating it if necessary.
 */
public Player getGuestPlayer(HttpServletRequest request) {

    // Create guest user if necessary.
    User user = securityService.getUserByName(User.USERNAME_GUEST);
    if (user == null) {
        user = new User(User.USERNAME_GUEST, RandomStringUtils.randomAlphanumeric(30), null);
        user.setStreamRole(true);
        securityService.createUser(user);
    }

    // Look for existing player.
    List<Player> players = getPlayersForUserAndClientId(User.USERNAME_GUEST, null);
    if (!players.isEmpty()) {
        return players.get(0);
    }

    // Create player if necessary.
    Player player = new Player();
    if (request != null ) {
        player.setIpAddress(request.getRemoteAddr());
    }
    player.setUsername(User.USERNAME_GUEST);
    createPlayer(player);

    return player;
}
 
开发者ID:airsonic,项目名称:airsonic,代码行数:30,代码来源:PlayerService.java

示例12: generateResetPasswordToken

import org.apache.commons.lang.RandomStringUtils; //导入方法依赖的package包/类
protected String generateResetPasswordToken(UUID userId) {
    String token = RandomStringUtils.randomAlphanumeric(ResetPasswordToken.TOKEN_LENGTH);
    int lifetime = forgotPasswordConfig.getResetPasswordTokenLifetimeMinutes();

    try (Transaction tx = persistence.getTransaction()) {
        EntityManager em = persistence.getEntityManager();

        TypedQuery<ResetPasswordToken> query = em.createQuery(
                "select rp from nxsecfp$ResetPasswordToken rp where rp.user.id = :userId",
                ResetPasswordToken.class);
        query.setParameter("userId", userId);

        ResetPasswordToken resetPasswordToken = query.getFirstResult();

        if (resetPasswordToken == null) {
            resetPasswordToken = metadata.create(ResetPasswordToken.class);
            resetPasswordToken.setUser(em.getReference(User.class, userId));
        }
        Date expires = DateUtils.addMinutes(timeSource.currentTimestamp(), lifetime);
        resetPasswordToken.setToken(token);
        resetPasswordToken.setExpireAt(expires);

        em.persist(resetPasswordToken);

        tx.commit();
    }

    return token;
}
 
开发者ID:pfurini,项目名称:cuba-component-forgot-password,代码行数:30,代码来源:NexbitUserManagementServiceBean.java

示例13: requestIdIsLoggedWithInfoIfInTheHeader

import org.apache.commons.lang.RandomStringUtils; //导入方法依赖的package包/类
@Test
public void requestIdIsLoggedWithInfoIfInTheHeader() throws Exception {
    String requestId = RandomStringUtils.randomAlphanumeric(10);

    stubFor(get(urlPathEqualTo(RESOURCE)).willReturn(aResponse().withStatus(418)
                                                                .withHeader(X_AMZN_REQUEST_ID_HEADER, requestId)));

    executeRequest();

    assertThat(infoEvents()).anySatisfy(hasMessageContaining(requestId));
}
 
开发者ID:aws,项目名称:aws-sdk-java-v2,代码行数:12,代码来源:DefaultErrorResponseHandlerTest.java

示例14: storeInvite

import org.apache.commons.lang.RandomStringUtils; //导入方法依赖的package包/类
public synchronized IThreePidInviteReply storeInvite(IThreePidInvite invitation) { // TODO better sync
    if (!notifMgr.isMediumSupported(invitation.getMedium())) {
        throw new BadRequestException("Medium type " + invitation.getMedium() + " is not supported");
    }

    String invId = getId(invitation);
    log.info("Handling invite for {}:{} from {} in room {}", invitation.getMedium(), invitation.getAddress(), invitation.getSender(), invitation.getRoomId());
    IThreePidInviteReply reply = invitations.get(invId);
    if (reply != null) {
        log.info("Invite is already pending for {}:{}, returning data", invitation.getMedium(), invitation.getAddress());
        if (!StringUtils.equals(invitation.getRoomId(), reply.getInvite().getRoomId())) {
            log.info("Sending new notification as new invite room {} is different from the original {}", invitation.getRoomId(), reply.getInvite().getRoomId());
            notifMgr.sendForInvite(new ThreePidInviteReply(reply.getId(), invitation, reply.getToken(), reply.getDisplayName()));
        } else {
            // FIXME we should check attempt and send if bigger
        }
        return reply;
    }

    Optional<?> result = lookupMgr.find(invitation.getMedium(), invitation.getAddress(), true);
    if (result.isPresent()) {
        log.info("Mapping for {}:{} already exists, refusing to store invite", invitation.getMedium(), invitation.getAddress());
        throw new MappingAlreadyExistsException();
    }

    String token = RandomStringUtils.randomAlphanumeric(64);
    String displayName = invitation.getAddress().substring(0, 3) + "...";

    reply = new ThreePidInviteReply(invId, invitation, token, displayName);

    log.info("Performing invite to {}:{}", invitation.getMedium(), invitation.getAddress());
    notifMgr.sendForInvite(reply);

    log.info("Storing invite under ID {}", invId);
    storage.insertInvite(reply);
    invitations.put(invId, reply);
    log.info("A new invite has been created for {}:{} on HS {}", invitation.getMedium(), invitation.getAddress(), invitation.getSender().getDomain());

    return reply;
}
 
开发者ID:kamax-io,项目名称:mxisd,代码行数:41,代码来源:InvitationManager.java

示例15: publish

import org.apache.commons.lang.RandomStringUtils; //导入方法依赖的package包/类
protected void publish(DbTransaction tx, PrintWriter log, String applicationName) throws ApplicationInvalidException {
    try (Timer t = new Timer("publish '"+applicationName+"'")) {
        log.println(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss Z").format(Instant.now().atZone(ZoneId.systemDefault())));
        
        log.println("Starting publish of application '"+applicationName+"'...");
        String publishId = RandomStringUtils.randomAlphanumeric(10);
        File directory = new File(DeploymentParameters.get().publishedApplicationsDirectory, applicationName+"-"+publishId);
        if ( ! directory.mkdir()) throw new RuntimeException("Cannot create directory '"+directory+"'");
        
        log.println("Checkout out application from repository...");
        String revision;
        if (DeploymentParameters.get().applicationRepository instanceof RemoteSubversionApplicationRepository)
            revision = checkout((RemoteSubversionApplicationRepository)DeploymentParameters.get().applicationRepository, 
                directory, applicationName);
        else if (DeploymentParameters.get().applicationRepository instanceof RemoteGitApplicationRepository)
            revision = checkout((RemoteGitApplicationRepository)DeploymentParameters.get().applicationRepository, 
                directory, applicationName);
        else throw new ConfigurationException("Unexpected type of repository");
        
        log.println("Verifying application...");
        XsltCompilationThreads threads = new XsltCompilationThreads();
        Application application = ApplicationFactory.loadApplication(threads, tx, directory);
        threads.execute();
        application.getEndpoints().assertTemplatesValid();
        
        log.println("Setting this version to be the currently installed version...");
        tx.execute("DELETE FROM application WHERE application=?", applicationName);
        tx.execute("INSERT INTO application SET application=?, directory_suffix=?, revision=?", 
            applicationName, publishId, revision);
    }
    catch (ConfigurationException | DocumentTemplateInvalidException e) { 
        throw new ApplicationInvalidException(e); 
    }
}
 
开发者ID:onestopconcept,项目名称:onestop-endpoints,代码行数:35,代码来源:PublisherServlet.java


注:本文中的org.apache.commons.lang.RandomStringUtils.randomAlphanumeric方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。