shibbolethcompatiblepersistentidgenerator.java
来自「CAS在Tomcat中实现单点登录项目,单点登录(Single Sign On 」· Java 代码 · 共 50 行
JAVA
50 行
/* * Copyright 2007 The JA-SIG Collaborative. All rights reserved. See license * distributed with this file and available online at * http://www.uportal.org/license.html */package org.jasig.cas.authentication.principal;import java.security.MessageDigest;import java.security.NoSuchAlgorithmException;import org.jasig.cas.util.annotation.NotNull;import org.springframework.webflow.util.Base64;/** * Generates PersistentIds based on the Shibboleth algorithm. * * @author Scott Battaglia * @version $Revision: 1.1 $ $Date: 2007/04/20 19:39:31 $ * @since 3.1 */public final class ShibbolethCompatiblePersistentIdGenerator implements PersistentIdGenerator { private static final byte CONST_SEPARATOR = (byte) '!'; private Base64 base64 = new Base64(); @NotNull private byte[] salt; public String generate(final Principal principal, final Service service) { try { final MessageDigest md = MessageDigest.getInstance("SHA"); md.update(service.getId().getBytes()); md.update(CONST_SEPARATOR); md.update(principal.getId().getBytes()); md.update(CONST_SEPARATOR); return this.base64.encodeToString(md.digest(this.salt)).replaceAll( System.getProperty("line.separator"), ""); } catch (final NoSuchAlgorithmException e) { throw new RuntimeException(e); } } public void setSalt(final String salt) { this.salt = salt.getBytes(); }}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?