本文整理汇总了Java中java.security.Principal类的典型用法代码示例。如果您正苦于以下问题:Java Principal类的具体用法?Java Principal怎么用?Java Principal使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Principal类属于java.security包,在下文中一共展示了Principal类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getCompany
import java.security.Principal; //导入依赖的package包/类
@PreAuthorize("@roleChecker.hasValidRole(#principal, #companyid)")
@RequestMapping(value="/company/{companyid}", method=RequestMethod.GET, produces=MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<CompanyDTO> getCompany(
Principal principal,
@PathVariable String companyid) {
// Check for SUPERADMIN and COMPANYADMIN role
// RoleChecker.hasValidRole(principal, companyid);
CompanyDTO companyDTO = companyService.findByName(companyid);
if (companyDTO == null) {
throw new ResourceNotFoundException();
}
return new ResponseEntity<CompanyDTO>(companyDTO, HttpStatus.OK);
}
示例2: testAuthFilter
import java.security.Principal; //导入依赖的package包/类
@Test
public void testAuthFilter() throws IOException {
final MultivaluedMap<String, String> headers = new MultivaluedHashMap<>();
when(mockContext.getHeaders()).thenReturn(headers);
final AuthFilter<String, Principal> filter = new AnonymousAuthFilter.Builder()
.setAuthenticator(new AnonymousAuthenticator()).buildAuthFilter();
filter.filter(mockContext);
verify(mockContext).setSecurityContext(securityCaptor.capture());
assertEquals(Trellis.AnonymousAgent.getIRIString(), securityCaptor.getValue().getUserPrincipal().getName());
assertFalse(securityCaptor.getValue().isUserInRole("role"));
assertFalse(securityCaptor.getValue().isSecure());
assertEquals("NONE", securityCaptor.getValue().getAuthenticationScheme());
}
示例3: checkPrincipal
import java.security.Principal; //导入依赖的package包/类
private static void checkPrincipal(LoginContext loginContext,
boolean principalShouldExist) {
if (!principalShouldExist) {
if (loginContext.getSubject().getPrincipals().size() != 0) {
throw new RuntimeException("Test failed. Principal was not "
+ "cleared.");
}
return;
}
for (Principal p : loginContext.getSubject().getPrincipals()) {
if (p instanceof UserPrincipal
&& USER_NAME.equals(p.getName())) {
//Proper principal was found, return.
return;
}
}
throw new RuntimeException("Test failed. UserPrincipal "
+ USER_NAME + " expected.");
}
示例4: getPrincipals
import java.security.Principal; //导入依赖的package包/类
/**
* Return any principal objects inside the attribute certificate issuer
* object.
*
* @return an array of Principal objects (usually X500Principal)
*/
public Principal[] getPrincipals()
{
Object[] p = this.getNames();
List l = new ArrayList();
for (int i = 0; i != p.length; i++)
{
if (p[i] instanceof Principal)
{
l.add(p[i]);
}
}
return (Principal[])l.toArray(new Principal[l.size()]);
}
示例5: getPrincipal
import java.security.Principal; //导入依赖的package包/类
/**
* Return the Principal associated with the given user name.
*/
@Override
protected Principal getPrincipal(String username) {
Connection dbConnection = open();
if (dbConnection == null) {
return new GenericPrincipal(username, null, null);
}
try {
return (new GenericPrincipal(username,
getPassword(dbConnection, username),
getRoles(dbConnection, username)));
} finally {
close(dbConnection);
}
}
示例6: doGet
import java.security.Principal; //导入依赖的package包/类
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
Principal user = req.getUserPrincipal();
String pathInfo = req.getPathInfo();
System.out.printf("pathInfo=%s\n", pathInfo);
String result = "";
if(pathInfo.endsWith("/getSubject")) {
System.out.printf("Calling getSubject\n");
result = getSubject(resp);
}
else {
System.out.printf("Calling getPrincipalClass\n");
result = getPrincipalClass(user);
}
resp.getWriter().write(result);
}
示例7: commit
import java.security.Principal; //导入依赖的package包/类
/**
* This method is called if the LoginContext's overall authentication
* succeeded (the relevant REQUIRED, REQUISITE, SUFFICIENT and OPTIONAL
* LoginModules succeeded). <p>
*
* If this LoginModule's own authentication attempt succeeded (checked by
* retrieving the private state saved by the <code>login</code> method), then
* this method associates a number of <code>NTPrincipal</code>s with the
* <code>Subject</code> located in the <code>LoginModule</code>. If this
* LoginModule's own authentication attempted failed, then this method removes
* any state that was originally saved.
*
* @return true if this LoginModule's own login and commit
* attempts succeeded, or false otherwise.
* @exception LoginException if the commit fails.
*/
public boolean commit() throws LoginException {
if (pending == null) {
return false;
}
principals = new Vector();
Set s = subject.getPrincipals();
for (int p = 0; p < pending.size(); p++) {
putPrincipal(s, (Principal) pending.get(p));
}
commitSucceeded = true;
prtln("\n COMMITTED (set commitSucceeded to true)");
return true;
}
示例8: createWebServiceContextMock
import java.security.Principal; //导入依赖的package包/类
private WebServiceContext createWebServiceContextMock(String expectedIP,
String expectedUser) {
requestMock = mock(HttpServletRequest.class);
when(requestMock.getRemoteAddr()).thenReturn(expectedIP);
Principal principalMock = mock(Principal.class);
when(principalMock.getName()).thenReturn(expectedUser);
MessageContext msgContextMock = mock(MessageContext.class);
when(msgContextMock.get(anyString())).thenReturn(requestMock);
WebServiceContext wsContextMock = mock(WebServiceContext.class);
when(wsContextMock.getUserPrincipal()).thenReturn(principalMock);
when(wsContextMock.getMessageContext()).thenReturn(msgContextMock);
return wsContextMock;
}
示例9: getAccessConfirmation
import java.security.Principal; //导入依赖的package包/类
@RequestMapping("/oauth/confirm_access")
public ModelAndView getAccessConfirmation(Map<String, Object> model, Principal principal) throws Exception {
AuthorizationRequest clientAuth = (AuthorizationRequest) model.remove("authorizationRequest");
ClientDetails client = clientDetailsService.loadClientByClientId(clientAuth.getClientId());
model.put("auth_request", clientAuth);
model.put("client", client);
Map<String, String> scopes = new LinkedHashMap<String, String>();
for (String scope : clientAuth.getScope()) {
scopes.put(OAuth2Utils.SCOPE_PREFIX + scope, "false");
}
for (Approval approval : approvalStore.getApprovals(principal.getName(), client.getClientId())) {
if (clientAuth.getScope().contains(approval.getScope())) {
scopes.put(OAuth2Utils.SCOPE_PREFIX + approval.getScope(),
approval.getStatus() == ApprovalStatus.APPROVED ? "true" : "false");
}
}
model.put("scopes", scopes);
return new ModelAndView("authorize", model);
}
示例10: testRequestNoneActive
import java.security.Principal; //导入依赖的package包/类
@Test
public void testRequestNoneActive() {
final AuthenticationContext authCtx = prc.getSubcontext(AuthenticationContext.class);
final List<Principal> principals = Arrays.<Principal> asList(new TestPrincipal("test3"));
final RequestedPrincipalContext rpc = new RequestedPrincipalContext();
rpc.getPrincipalEvalPredicateFactoryRegistry().register(TestPrincipal.class, "exact",
new ExactPrincipalEvalPredicateFactory());
rpc.setOperator("exact");
rpc.setRequestedPrincipals(principals);
authCtx.addSubcontext(rpc, true);
authCtx.getPotentialFlows().get("test3").setSupportedPrincipals(principals);
action.execute(src);
Assert.assertNull(authCtx.getAuthenticationResult());
Assert.assertEquals(authCtx.getAttemptedFlow().getId(), "test3");
}
示例11: setAuthAttributes
import java.security.Principal; //导入依赖的package包/类
public static long setAuthAttributes(ServerConnection connection) throws Exception {
try {
logger.debug("setAttributes()");
Object principal = ((HandShake) connection.getHandshake()).verifyCredentials();
long uniqueId;
if (principal instanceof Subject) {
uniqueId =
connection.getClientUserAuths(connection.getProxyID()).putSubject((Subject) principal);
} else {
// this sets principal in map as well....
uniqueId = getUniqueId(connection, (Principal) principal);
connection.setPrincipal((Principal) principal);// TODO:hitesh is this require now ???
}
return uniqueId;
} catch (Exception ex) {
throw ex;
}
}
示例12: matches
import java.security.Principal; //导入依赖的package包/类
/**
* @param issuers The list of acceptable CA issuer subject names or null if it does not matter which issuers are used
* @return True if certificate matches issuer and key type
*/
protected boolean matches(final Certificate c, final String[] keyTypes, final Principal[] issuers) {
if(!(c instanceof X509Certificate)) {
log.warn(String.format("Certificate %s is not of type X509", c));
return false;
}
if(!Arrays.asList(keyTypes).contains(c.getPublicKey().getAlgorithm())) {
log.warn(String.format("Key type %s does not match any of %s", c.getPublicKey().getAlgorithm(),
Arrays.toString(keyTypes)));
return false;
}
if(null == issuers || Arrays.asList(issuers).isEmpty()) {
// null if it does not matter which issuers are used
return true;
}
final X500Principal issuer = ((X509Certificate) c).getIssuerX500Principal();
if(!Arrays.asList(issuers).contains(issuer)) {
log.warn(String.format("Issuer %s does not match", issuer));
return false;
}
return true;
}
示例13: testAuthenticateWithUserPasswordAndDigest
import java.security.Principal; //导入依赖的package包/类
@Test
public void testAuthenticateWithUserPasswordAndDigest() throws Exception {
// GIVEN
JNDIRealm realm = buildRealm(ha1(), "MD5");
realm.setUserPassword(USER_PASSWORD_ATTR);
// WHEN
String expectedResponse =
MD5Encoder.encode(md5Helper.digest((ha1() + ":" + NONCE + ":" + HA2).getBytes()));
Principal principal =
realm.authenticate(USER, expectedResponse, NONCE, null, null, null, REALM, HA2);
// THEN
Assert.assertTrue(principal instanceof GenericPrincipal);
Assert.assertEquals(ha1(), ((GenericPrincipal)principal).getPassword());
}
示例14: revokeToken
import java.security.Principal; //导入依赖的package包/类
@RequestMapping(value = "/oauth/tokens/revoke.html", method = RequestMethod.POST)
@PreAuthorize("hasRole('ROLE_ADMIN')")
public String revokeToken(@RequestParam("user") String user, @RequestParam("token") String token,
Principal principal) throws Exception {
checkResourceOwner(user, principal);
if (tokenServices.revokeToken(token)) {
return "redirect:/oauth/tokens.html?revoke-success";
} else {
return "redirect:/oauth/tokens.html?revoke-empty";
}
}
示例15: chooseServerAlias
import java.security.Principal; //导入依赖的package包/类
@Override
public String chooseServerAlias(String keyType, Principal[] issuers, Socket socket) {
if (!StringUtils.isEmpty(this.keyAlias)) {
PrivateKey key = this.delegate.getPrivateKey(this.keyAlias);
return getKeyAlias(keyType, key);
}
return this.delegate.chooseServerAlias(keyType, issuers, socket);
}