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


Java Principal.getName方法代码示例

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


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

示例1: checkAccess

import java.security.Principal; //导入方法依赖的package包/类
public Set<Integer> checkAccess(SecurityContext securityContext) {
    logger.debug("Performing agency incident data security check ...");
    Principal principal = securityContext.getUserPrincipal();
    String username = null;
    if (principal != null) {
        username = principal.getName();
    }
    if (StringUtils.isEmpty(username)) {
        logger.warn(
                "Access to agency incident data forbidden for user: Anonymous");
        throw new ArcGISSecurityException(403, "Forbidden", null);
    }
    Set<Integer> agencyIds = getAgencyIds(username);
    if (agencyIds == null || agencyIds.size() == 0) {
        logger.warn("Access to agency incident data ID forbidden for user: {}",
                username);
        throw new ArcGISSecurityException(403, "Forbidden", null);
    }
    logger.debug("Finished agency incident security check. "
                    + "User '{}' is permitted access to agency incident data for agencies [{}].",
            username, Arrays.toString(agencyIds.toArray(new Integer[agencyIds.size()])));
    return agencyIds;
}
 
开发者ID:Esri,项目名称:server-extension-java,代码行数:24,代码来源:AgencyIncidentDataAccessController.java

示例2: getServiceHostName

import java.security.Principal; //导入方法依赖的package包/类
@Override
public String getServiceHostName(Principal principal) {
    if (principal == null) {
        return null;
    }
    String hostName = null;
    try {
        PrincipalName princName =
                new PrincipalName(principal.getName(),
                        PrincipalName.KRB_NT_SRV_HST);
        String[] nameParts = princName.getNameStrings();
        if (nameParts.length >= 2) {
            hostName = nameParts[1];
        }
    } catch (Exception e) {
        // ignore
    }
    return hostName;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:20,代码来源:Krb5KeyExchangeService.java

示例3: getArtistRate

import java.security.Principal; //导入方法依赖的package包/类
/**
 * Returns User's rate for the specified Artist.
 *
 * @param user     user's principal.
 * @param artistId artists's identifier.
 * @return User's rate for the specified Artist. Empty rate will be returned in case when there is no such rate.
 */
public RateDto getArtistRate(Principal user, String artistId) {

    if (user == null || user.getName() == null || user.getName().isEmpty()) {
        return new RateDto();
    }

    String userId = user.getName();
    if (!userDao.exists(userId)) {
        throw new ResourceNotFoundException("User with id '" + userId + "' not found");
    }

    if (!artistDao.exists(artistId)) {
        throw new ResourceNotFoundException("Artist with id '" + artistId + "' not found");
    }

    ArtistRate rate = artistRateDao.getRate(userId, artistId);
    return (rate != null) ? artistRateToDto(rate) : new RateDto();
}
 
开发者ID:mapr-demos,项目名称:mapr-music,代码行数:26,代码来源:RateService.java

示例4: printWelcome

import java.security.Principal; //导入方法依赖的package包/类
@RequestMapping(value="/welcome", method = RequestMethod.GET)
public String printWelcome(ModelMap model, Principal principal ) {
	
	System.out.println("***********LoginController printWelcome() Called***********");

	String name = principal.getName();
	model.addAttribute("username", name);
	model.addAttribute("message", "Spring Security authorisation example");
	return "hello";

}
 
开发者ID:Illusionist80,项目名称:SpringTutorial,代码行数:12,代码来源:LoginController.java

示例5: doGet

import java.security.Principal; //导入方法依赖的package包/类
public void doGet(final HttpServletRequest httpServletRequest, final HttpServletResponse httpServletResponse) throws ServletException, IOException {
  final SecurityManager sm = SecurityManager.getInstance();
  final Principal userPrincipal = httpServletRequest.getUserPrincipal();
  final String name = userPrincipal.getName();
  final User userByName = sm.getUserByName(name);
  if (!userByName.isAdmin()) httpServletResponse.sendError(401);
  super.doGet(httpServletRequest, httpServletResponse);
}
 
开发者ID:parabuild-ci,项目名称:parabuild-ci,代码行数:9,代码来源:ParabuildWebServiceServlet.java

示例6: doWebSocketConnect

import java.security.Principal; //导入方法依赖的package包/类
@Override
public WebSocket doWebSocketConnect(HttpServletRequest request, String protocol) {
    if (isStopped) {
        return null;
    }

    // FIXME: Replace this with globally shared opaque token to allow secure failover
    Principal p = request.getUserPrincipal();
    String userName = p != null ? p.getName() : FAKE_USERNAME;

    UiWebSocket socket = new UiWebSocket(directory, userName);
    synchronized (sockets) {
        sockets.add(socket);
    }
    return socket;
}
 
开发者ID:shlee89,项目名称:athena,代码行数:17,代码来源:UiWebSocketServlet.java

示例7: init

import java.security.Principal; //导入方法依赖的package包/类
/**
 * Initialize the {@code XmlAuthorization} callback for a client having the given principal.
 * 
 * This method caches the full XML authorization file the first time it is invoked and caches all
 * the permissions for the provided {@code principal} to speed up lookup the
 * {@code authorizeOperation} calls. The permissions for the principal are maintained as a
 * {@link Map} of region name to the {@link HashSet} of operations allowed for that region. A
 * global entry with region name as empty string is also made for permissions provided for all the
 * regions.
 * 
 * @param principal the principal associated with the authenticated client
 * @param cache reference to the cache object
 * @param remoteMember the {@link DistributedMember} object for the remote authenticated client
 * 
 * @throws NotAuthorizedException if some exception condition happens during the initialization
 *         while reading the XML; in such a case all subsequent client operations will throw
 *         {@code NotAuthorizedException}
 */
@Override
public void init(final Principal principal, final DistributedMember remoteMember,
    final Cache cache) throws NotAuthorizedException {
  synchronized (sync) {
    XmlAuthorization.init(cache);
  }

  this.systemLogWriter = cache.getLogger();
  this.securityLogWriter = cache.getSecurityLogger();

  String name;
  if (principal != null) {
    name = principal.getName();
  } else {
    name = EMPTY_VALUE;
  }

  HashSet<String> roles = XmlAuthorization.userRoles.get(name);
  if (roles != null) {
    for (String roleName : roles) {
      Map<String, Map<OperationCode, FunctionSecurityPrmsHolder>> regionOperationMap =
          XmlAuthorization.rolePermissions.get(roleName);
      if (regionOperationMap != null) {
        for (Map.Entry<String, Map<OperationCode, FunctionSecurityPrmsHolder>> regionEntry : regionOperationMap
            .entrySet()) {
          String regionName = regionEntry.getKey();
          Map<OperationCode, FunctionSecurityPrmsHolder> regionOperations =
              this.allowedOps.get(regionName);
          if (regionOperations == null) {
            regionOperations = new HashMap<OperationCode, FunctionSecurityPrmsHolder>();
            this.allowedOps.put(regionName, regionOperations);
          }
          regionOperations.putAll(regionEntry.getValue());
        }
      }
    }
  }
}
 
开发者ID:ampool,项目名称:monarch,代码行数:57,代码来源:XmlAuthorization.java

示例8: getRecommendationForUser

import java.security.Principal; //导入方法依赖的package包/类
private Recommendation getRecommendationForUser(Principal user) {

        // There is can be such situation when user has no rates and thus has no recommendation
        String userId = (user == null) ? ANONYMOUS_USER_ID : user.getName();
        Recommendation userRecommendation = recommendationDao.getById(userId);

        return (userRecommendation != null) ? userRecommendation : recommendationDao.getById(ANONYMOUS_USER_ID);
    }
 
开发者ID:mapr-demos,项目名称:mapr-music,代码行数:9,代码来源:RecommendationService.java

示例9: equals

import java.security.Principal; //导入方法依赖的package包/类
@Override
public boolean equals(Object o) {
    if ( this == o ) {
        return true;
    }
    if ( o == null || !( o instanceof Principal ) ) {
        return false;
    }
    Principal p = (Principal) o;
    return name == null ? p.getName() == null : name.contentEquals( p.getName() );
}
 
开发者ID:agroal,项目名称:agroal,代码行数:12,代码来源:NamePrincipal.java

示例10: admin

import java.security.Principal; //导入方法依赖的package包/类
@GetMapping("/admin")
String admin(Principal principal) {
    String applicationId = principal.getName();
    String certificateSerialNumber = this.serialNumberExtractor.getSerialNumber(principal);

    this.logger.info("Received request for /admin with certificate for {} with SN {}", applicationId, certificateSerialNumber);
    return String.format("You authenticated using x509 certificate for %s with SN %s", applicationId, certificateSerialNumber);
}
 
开发者ID:nebhale,项目名称:mtls-sample,代码行数:9,代码来源:ServerApplication.java

示例11: printWelcome

import java.security.Principal; //导入方法依赖的package包/类
@RequestMapping(value="/welcome", method = RequestMethod.GET)
public String printWelcome(ModelMap model, Principal principal ) {
	
	System.out.println("***********LoginController Called***********");

	String name = principal.getName();
	model.addAttribute("username", name);
	model.addAttribute("message", "Spring Security Custom Form example");
	return "hello";

}
 
开发者ID:Illusionist80,项目名称:SpringTutorial,代码行数:12,代码来源:LoginController.java

示例12: doesNameMatchPattern

import java.security.Principal; //导入方法依赖的package包/类
/**
 * Does principal name match pattern?
 *
 * @param principal the principal
 * @param pattern   the pattern
 * @return true, if successful
 */
private static boolean doesNameMatchPattern(final Principal principal, final Pattern pattern) {
    if (pattern != null) {
        final String name = principal.getName();
        final boolean result = pattern.matcher(name).matches();
        LOGGER.debug("[{}] matches [{}] == [{}]", pattern.pattern(), name, result);
        return result;
    }
    return true;
}
 
开发者ID:mrluo735,项目名称:cas-5.1.0,代码行数:17,代码来源:X509CredentialsAuthenticationHandler.java

示例13: delegatedContext

import java.security.Principal; //导入方法依赖的package包/类
public AccessControlContext
    delegatedContext(AccessControlContext authenticatedACC,
                     Subject delegatedSubject,
                     boolean removeCallerContext)
        throws SecurityException {

    if (System.getSecurityManager() != null && authenticatedACC == null) {
        throw new SecurityException("Illegal AccessControlContext: null");
    }

    // Check if the subject delegation permission allows the
    // authenticated subject to assume the identity of each
    // principal in the delegated subject
    //
    Collection<Principal> ps = getSubjectPrincipals(delegatedSubject);
    final Collection<Permission> permissions = new ArrayList<>(ps.size());
    for(Principal p : ps) {
        final String pname = p.getClass().getName() + "." + p.getName();
        permissions.add(new SubjectDelegationPermission(pname));
    }
    PrivilegedAction<Void> action =
        new PrivilegedAction<Void>() {
            public Void run() {
                for (Permission sdp : permissions) {
                    AccessController.checkPermission(sdp);
                }
                return null;
            }
        };
    AccessController.doPrivileged(action, authenticatedACC);

    return getDelegatedAcc(delegatedSubject, removeCallerContext);
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:34,代码来源:SubjectDelegator.java

示例14: getValidCredentials

import java.security.Principal; //导入方法依赖的package包/类
@Override
public Properties getValidCredentials(final Principal principal) {
  final String userName = principal.getName();

  if (DummyAuthenticator.checkValidName(userName)) {
    Properties props = new Properties();
    props.setProperty(UserPasswordAuthInit.USER_NAME, userName);
    props.setProperty(UserPasswordAuthInit.PASSWORD, userName);
    return props;

  } else {
    throw new IllegalArgumentException("Dummy: [" + userName + "] is not a valid user");
  }
}
 
开发者ID:ampool,项目名称:monarch,代码行数:15,代码来源:DummyCredentialGenerator.java

示例15: fromPrincipal

import java.security.Principal; //导入方法依赖的package包/类
/**
 * Create a user information object
 *
 * @param principal
 * @return Returns the converted user information object or
 *         {@link #ANONYMOUS} if principal was <code>null</code>. Never
 *         returns <code>null</code>.
 */
public static UserInformation fromPrincipal ( final Principal principal )
{
    if ( principal == null )
    {
        return ANONYMOUS;
    }
    return new UserInformation ( principal.getName () );
}
 
开发者ID:eclipse,项目名称:neoscada,代码行数:17,代码来源:UserInformation.java


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