本文整理汇总了Java中javax.management.remote.JMXPrincipal类的典型用法代码示例。如果您正苦于以下问题:Java JMXPrincipal类的具体用法?Java JMXPrincipal怎么用?Java JMXPrincipal使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
JMXPrincipal类属于javax.management.remote包,在下文中一共展示了JMXPrincipal类的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: addNotificationListener
import javax.management.remote.JMXPrincipal; //导入依赖的package包/类
@Override
public void addNotificationListener(
String connectionId,
ObjectName name,
Subject subject)
throws SecurityException {
echo("addNotificationListener:");
echo("\tconnectionId: " + connectionId);
echo("\tname: " + name);
echo("\tsubject: " +
(subject == null ? null : subject.getPrincipals()));
if (throwException)
if (name.getCanonicalName().equals("domain:name=1,type=NB")
&&
subject != null
&&
subject.getPrincipals().contains(new JMXPrincipal("role")))
throw new SecurityException();
}
示例2: removeNotificationListener
import javax.management.remote.JMXPrincipal; //导入依赖的package包/类
@Override
public void removeNotificationListener(
String connectionId,
ObjectName name,
Subject subject)
throws SecurityException {
echo("removeNotificationListener:");
echo("\tconnectionId: " + connectionId);
echo("\tname: " + name);
echo("\tsubject: " +
(subject == null ? null : subject.getPrincipals()));
if (throwException)
if (name.getCanonicalName().equals("domain:name=2,type=NB")
&&
subject != null
&&
subject.getPrincipals().contains(new JMXPrincipal("role")))
throw new SecurityException();
}
示例3: fetchNotification
import javax.management.remote.JMXPrincipal; //导入依赖的package包/类
@Override
public void fetchNotification(
String connectionId,
ObjectName name,
Notification notification,
Subject subject)
throws SecurityException {
echo("fetchNotification:");
echo("\tconnectionId: " + connectionId);
echo("\tname: " + name);
echo("\tnotification: " + notification);
echo("\tsubject: " +
(subject == null ? null : subject.getPrincipals()));
if (!throwException)
if (name.getCanonicalName().equals("domain:name=2,type=NB")
&&
subject != null
&&
subject.getPrincipals().contains(new JMXPrincipal("role")))
throw new SecurityException();
}
示例4: setUp
import javax.management.remote.JMXPrincipal; //导入依赖的package包/类
@Before
public void setUp() throws Exception {
MockitoAnnotations.initMocks(this);
helper.setUp();
// Set up some fake HTTP requests
// If the user isn't logged in, use this request
when(mockRequestNotLoggedIn.getRequestURI()).thenReturn(FAKE_URL);
when(mockRequestNotLoggedIn.getUserPrincipal()).thenReturn(null);
// If the user is logged in, use this request
when(mockRequestLoggedIn.getRequestURI()).thenReturn(FAKE_URL);
// Most of the classes that implement Principal have been
// deprecated. JMXPrincipal seems like a safe choice.
when(mockRequestLoggedIn.getUserPrincipal()).thenReturn(new JMXPrincipal(FAKE_NAME));
// Set up a fake HTTP response.
responseWriter = new StringWriter();
when(mockResponse.getWriter()).thenReturn(new PrintWriter(responseWriter));
servletUnderTest = new UsersServlet();
}
示例5: setUp
import javax.management.remote.JMXPrincipal; //导入依赖的package包/类
@Before
public void setUp() throws Exception {
MockitoAnnotations.initMocks(this);
helper.setUp();
// Set up some fake HTTP requests
// If the user isn't logged in, use this request
when(mockRequestNotLoggedIn.getRequestURI()).thenReturn(FAKE_URL);
when(mockRequestNotLoggedIn.getUserPrincipal()).thenReturn(null);
// If the user is logged in, use this request
when(mockRequestLoggedIn.getRequestURI()).thenReturn(FAKE_URL);
// Most of the classes that implement Principal have been
// deprecated. JMXPrincipal seems like a safe choice.
when(mockRequestLoggedIn.getUserPrincipal()).thenReturn(new JMXPrincipal(FAKE_NAME));
// Set up a fake HTTP response.
responseWriter = new StringWriter();
when(mockResponse.getWriter()).thenReturn(new PrintWriter(responseWriter));
servletUnderTest = new UsersServlet();
}
示例6: addNotificationListener
import javax.management.remote.JMXPrincipal; //导入依赖的package包/类
public void addNotificationListener(
String connectionId,
ObjectName name,
Subject subject)
throws SecurityException {
echo("addNotificationListener:");
echo("\tconnectionId: " + connectionId);
echo("\tname: " + name);
echo("\tsubject: " +
(subject == null ? null : subject.getPrincipals()));
if (throwException)
if (name.getCanonicalName().equals("domain:name=1,type=NB")
&&
subject.getPrincipals().contains(new JMXPrincipal("role")))
throw new SecurityException();
}
示例7: removeNotificationListener
import javax.management.remote.JMXPrincipal; //导入依赖的package包/类
public void removeNotificationListener(
String connectionId,
ObjectName name,
Subject subject)
throws SecurityException {
echo("removeNotificationListener:");
echo("\tconnectionId: " + connectionId);
echo("\tname: " + name);
echo("\tsubject: " +
(subject == null ? null : subject.getPrincipals()));
if (throwException)
if (name.getCanonicalName().equals("domain:name=2,type=NB")
&&
subject.getPrincipals().contains(new JMXPrincipal("role")))
throw new SecurityException();
}
示例8: fetchNotification
import javax.management.remote.JMXPrincipal; //导入依赖的package包/类
public void fetchNotification(
String connectionId,
ObjectName name,
Notification notification,
Subject subject)
throws SecurityException {
echo("fetchNotification:");
echo("\tconnectionId: " + connectionId);
echo("\tname: " + name);
echo("\tnotification: " + notification);
echo("\tsubject: " +
(subject == null ? null : subject.getPrincipals()));
if (!throwException)
if (name.getCanonicalName().equals("domain:name=2,type=NB") &&
subject.getPrincipals().contains(new JMXPrincipal("role")))
throw new SecurityException();
}
示例9: getJaasCertificateCallbackHandler
import javax.management.remote.JMXPrincipal; //导入依赖的package包/类
private JaasCallbackHandler getJaasCertificateCallbackHandler(String user) {
JMXPrincipal principal = new JMXPrincipal(user);
X509Certificate cert = new StubX509Certificate(principal);
return new JaasCallbackHandler(null, null, null) {
@Override
public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException {
for (Callback callback : callbacks) {
if (callback instanceof CertificateCallback) {
CertificateCallback certCallback = (CertificateCallback) callback;
certCallback.setCertificates(new X509Certificate[]{cert});
} else {
throw new UnsupportedCallbackException(callback);
}
}
}
};
}
示例10: getSubjectUser
import javax.management.remote.JMXPrincipal; //导入依赖的package包/类
/**
* Get the current user name connected to JMX server
*
* @return the current user name if any, null otherwise
*/
public static String getSubjectUser() {
AccessControlContext ctx = AccessController.getContext();
Subject subj = Subject.getSubject(ctx);
String result = null;
if (subj == null) {
subj = LocalSubject.getSubject();
}
logger.trace("getSubjectUser; subject: {}", subj);
if (subj != null) {
Set<JMXPrincipal> sjp = subj.getPrincipals(JMXPrincipal.class);
if (sjp != null && sjp.size() > 0) {
result = sjp.iterator().next().getName();
} else {
Set<Principal> sp = subj.getPrincipals();
if (sp != null && sp.size() > 0) {
result = sp.iterator().next().getName();
}
}
}
logger.trace("getSubjectUser.exit; returning: {}", result);
return result;
}
示例11: getUserIdentity
import javax.management.remote.JMXPrincipal; //导入依赖的package包/类
@Override
public UserIdentity getUserIdentity() {
// TODO: need to return the correct identity for this user.
// Permitting specific logins for now with no passwords
if (this.user.equals("tenant")) {
return new DefaultUserIdentity(new Subject(), new JMXPrincipal(
this.user), new String[] {"user"});
} else if (this.user.equals("ui")) {
return new DefaultUserIdentity(new Subject(), new JMXPrincipal(
this.user), new String[] {"ui"});
} else if (this.user.equals("admin")) {
return new DefaultUserIdentity(new Subject(), new JMXPrincipal(
this.user), new String[] {"user", "admin", "ui"});
} else {
return null;
}
}
示例12: authenticate
import javax.management.remote.JMXPrincipal; //导入依赖的package包/类
@Override
public Subject authenticate(Object credentials) {
if (credentials == null) {
throw new SecurityException("Credentials required");
}
if (!(credentials instanceof String[])) {
throw new SecurityException("Credentials should be String[]");
}
CallbackHandler callbackHandler = new CarbonJMXCallbackHandler(credentials);
try {
LoginContext loginContext = new LoginContext(Constants.LOGIN_MODULE_ENTRY, callbackHandler);
loginContext.login();
return new Subject(true, Collections.singleton(new JMXPrincipal(((String[]) credentials)[0])),
Collections.EMPTY_SET, Collections.EMPTY_SET);
} catch (LoginException e) {
throw new SecurityException("Invalid credentials", e);
}
}
示例13: testAuthenticationSuccess
import javax.management.remote.JMXPrincipal; //导入依赖的package包/类
/**
* Tests a successful authentication. Ensures that a populated read-only subject it returned.
*/
public void testAuthenticationSuccess()
{
final Subject expectedSubject = new Subject(true,
Collections.singleton(new JMXPrincipal(USERNAME)),
Collections.EMPTY_SET,
Collections.EMPTY_SET);
_rmipa.setAuthenticationManager(createTestAuthenticationManager(true, null));
Subject newSubject = _rmipa.authenticate(_credentials);
assertTrue("Subject must be readonly", newSubject.isReadOnly());
assertTrue("Returned subject does not equal expected value",
newSubject.equals(expectedSubject));
}