本文整理了Java中java.security.Principal.getName()
方法的一些代码示例,展示了Principal.getName()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Principal.getName()
方法的具体详情如下:
包路径:java.security.Principal
类名称:Principal
方法名:getName
[英]Returns the name of this Principal.
[中]返回此主体的名称。
代码示例来源:origin: spring-projects/spring-framework
/**
* Determine the username for the given request.
* <p>The default implementation takes the name of the UserPrincipal, if any.
* Can be overridden in subclasses.
* @param request current HTTP request
* @return the username, or {@code null} if none found
* @see javax.servlet.http.HttpServletRequest#getUserPrincipal()
*/
@Nullable
protected String getUsernameForRequest(HttpServletRequest request) {
Principal userPrincipal = request.getUserPrincipal();
return (userPrincipal != null ? userPrincipal.getName() : null);
}
代码示例来源:origin: apache/storm
public TUGIAssumingTransportFactory(TTransportFactory wrapped, Subject subject) {
this.wrapped = wrapped;
this.subject = subject;
Set<Principal> principals = (Set<Principal>) subject.getPrincipals();
if (principals.size() > 0) {
LOG.info("Service principal:" + ((Principal) (principals.toArray()[0])).getName());
}
}
代码示例来源:origin: apache/activemq
protected String getDistinguishedName(final X509Certificate[] certs) {
if (certs != null && certs.length > 0 && certs[0] != null) {
return certs[0].getSubjectDN().getName();
} else {
return null;
}
}
代码示例来源:origin: robovm/robovm
String algorithm = getParameter("algorithm");
String uname = credentials.getUserPrincipal().getName();
params.add(new BasicNameValuePair("username", uname));
params.add(new BasicNameValuePair("realm", realm));
params.add(new BasicNameValuePair("nonce", nonce));
params.add(new BasicNameValuePair("uri", uri));
params.add(new BasicNameValuePair("response", response));
代码示例来源:origin: igniterealtime/Openfire
/**
* Maps certificate CommonName as identity credentials
*
* @param certificate
* @return A List of names.
*/
@Override
public List<String> mapIdentity(X509Certificate certificate) {
String name = certificate.getSubjectDN().getName();
Matcher matcher = cnPattern.matcher(name);
// Create an array with the detected identities
List<String> names = new ArrayList<>();
while (matcher.find()) {
names.add(matcher.group(2));
}
return names;
}
代码示例来源:origin: kiegroup/jbpm
Set<Principal> principals = subject.getPrincipals();
roles = new ArrayList<String>();
for (Principal principal : principals) {
if (principal instanceof Group && rolePrincipleName.equalsIgnoreCase(principal.getName())) {
Enumeration<? extends Principal> groups = ((Group) principal).members();
roles.add(groupPrincipal.getName());
代码示例来源:origin: wildfly/wildfly
nameCallback.setName(config.doRewriteUser(principal).getName());
continue;
if (trustedAuthority instanceof TrustedAuthority.CertificateTrustedAuthority) {
final X509Certificate authorityCertificate = ((TrustedAuthority.CertificateTrustedAuthority) trustedAuthority).getIdentifier();
issuers.add(authorityCertificate.getSubjectX500Principal());
} else if (trustedAuthority instanceof TrustedAuthority.NameTrustedAuthority) {
final String authorityName = ((TrustedAuthority.NameTrustedAuthority) trustedAuthority).getIdentifier();
issuers.add(new X500Principal(authorityName));
代码示例来源:origin: kiegroup/jbpm
@Override
public List<String> getGroupsForUser(String userId) {
List<String> roles = new ArrayList<String>();
if (webLogicSecurity == null || userId == null || userId.isEmpty()) {
return roles;
}
try {
Method method = webLogicSecurity.getMethod("getCurrentSubject", new Class[]{});
Subject wlsSubject = (Subject) method.invoke( null, new Object[]{ } );
if ( wlsSubject != null ) {
for ( java.security.Principal p : wlsSubject.getPrincipals() ) {
if (p.getClass().getName().indexOf("WLSGroup") != -1) {
roles.add( p.getName() );
}
}
}
} catch (Exception e) {
logger.error("Unable to get roles for user {} from subject due to {}", userId, e.getMessage(), e);
}
return roles;
}
}
代码示例来源:origin: de.adorsys.oauth/oauth-server
private void rememberAuthInCookie(HttpServletRequest request, HttpServletResponse response, ClientID clientID, LoginSessionToken loginSessionToken) {
String callerPrincipal = request.getUserPrincipal().getName();
SecurityContext context = SecurityContextAssociation.getSecurityContext();
SubjectInfo subjectInfo = context.getSubjectInfo();
Collection<Role> roles = new JBossSubjectInfo(subjectInfo).getRoles();
List<String> roleStrings = new ArrayList<>();
for (Role role : roles) {
roleStrings.add(role.getRoleName());
}
String encryptedToken = RememberMeTokenUtil.serialize(loginSessionToken, callerPrincipal, roleStrings);
RememberMeCookieUtil.setLoginSessionCookie(request, response, encryptedToken, clientID);
}
代码示例来源:origin: dremio/dremio-oss
public List<ResourceTreeEntity> getHomes(boolean all) throws NamespaceException, UnsupportedEncodingException {
final List<ResourceTreeEntity> resources = Lists.newArrayList();
if (all) {
for (HomeConfig homeConfig : namespaceService.get().getHomeSpaces()) {
resources.add(new ResourceTreeEntity(homeConfig));
}
} else {
resources.add(new ResourceTreeEntity(namespaceService.get().getHome(
new NamespaceKey(HomeName.getUserHomePath(securityContext.getUserPrincipal().getName()).getName()))));
}
return resources;
}
代码示例来源:origin: stackoverflow.com
import javax.servlet.http.HttpServletRequest;
@GET
@Path("/yourservice")
@Produces("text/xml")
public void activate(@Context HttpServletRequest requestContext,@Context SecurityContext context){
String yourIP = requestContext.getRemoteAddr();
//If security is enabled
Principal principal = context.getUserPrincipal();
String userName = principal.getName();
}
代码示例来源:origin: apache/nifi
final Principal principal = request.getUserPrincipal();
if (principal != null) {
putAttribute(attributes, "http.principal.name", principal.getName());
if (certs != null && certs.length > 0) {
final X509Certificate cert = certs[0];
subjectDn = cert.getSubjectDN().getName();
final String issuerDn = cert.getIssuerDN().getName();
代码示例来源:origin: org.apache.poi/poi-ooxml
String issuerName = crl.getIssuerDN().getName().replace(",", ", ");
crlIdentifier.setIssuer(issuerName);
Calendar cal = Calendar.getInstance(TimeZone.getTimeZone("Z"), Locale.ROOT);
timeStampNodesXadesX1.add(nlSigVal.item(0));
timeStampNodesXadesX1.add(signatureTimeStamp.getDomNode());
timeStampNodesXadesX1.add(completeCertificateRefs.getDomNode());
timeStampNodesXadesX1.add(completeRevocationRefs.getDomNode());
代码示例来源:origin: org.osgi/org.osgi.core
List<String> dnChain = new ArrayList<String>(signerCerts.size());
for (X509Certificate signerCert : signerCerts) {
dnChain.add(signerCert.getSubjectDN().getName());
代码示例来源:origin: apache/activemq-artemis
@Override
public boolean commit() throws LoginException {
boolean result = loginSucceeded;
if (result) {
principals.add(new UserPrincipal(principals.get(0).getName()));
subject.getPrincipals().addAll(principals);
}
clear();
logger.debug("commit, result: " + result);
return result;
}
代码示例来源:origin: apache/storm
private String getPrincipal(Subject subject) {
Set<Principal> principals = (Set<Principal>) subject.getPrincipals();
if (principals == null || principals.size() < 1) {
LOG.info("No principal found in login subject");
return null;
}
return ((Principal) (principals.toArray()[0])).getName();
}
代码示例来源:origin: stagemonitor/stagemonitor
private String getUserName(HttpServletRequest httpServletRequest) {
final Principal userPrincipal = httpServletRequest.getUserPrincipal();
return userPrincipal != null ? userPrincipal.getName() : null;
}
代码示例来源:origin: apache/nifi
@Override
public Object extractPrincipal(X509Certificate cert) {
return cert.getSubjectDN().getName().trim();
}
代码示例来源:origin: apache/drill
public static Map<String, Object> toMapModel(SecurityContext sc,
Map<String, Object> model) {
model.put("clusterName", config.getString(DrillOnYarnConfig.APP_NAME));
boolean useAuth = AMSecurityManagerImpl.isEnabled();
final boolean isUserLoggedIn = (useAuth)
? AuthDynamicFeature.isUserLoggedIn(sc) : false;
model.put("showLogin", useAuth && !isUserLoggedIn);
model.put("showLogout", isUserLoggedIn);
model.put("docsLink", config.getString(DrillOnYarnConfig.HTTP_DOCS_LINK));
String userName = isUserLoggedIn ? sc.getUserPrincipal().getName()
: DrillUserPrincipal.ANONYMOUS_USER;
model.put("loggedInUserName", userName);
return model;
}
}
代码示例来源:origin: org.apache.jackrabbit/jackrabbit-core
private List<Entry> internalGetEntries(Principal principal) {
String principalName = principal.getName();
List<Entry> entriesPerPrincipal = new ArrayList<Entry>(2);
for (AccessControlEntry entry : entries) {
if (principalName.equals(entry.getPrincipal().getName())) {
entriesPerPrincipal.add((Entry) entry);
}
}
return entriesPerPrincipal;
}
内容来源于网络,如有侵权,请联系作者删除!