javax.management.remote.JMXPrincipal Java Examples

The following examples show how to use javax.management.remote.JMXPrincipal. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: NotificationAccessControllerTest.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
@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();
}
 
Example #2
Source File: NotificationAccessControllerTest.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
@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();
}
 
Example #3
Source File: NotificationAccessControllerTest.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
@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();
}
 
Example #4
Source File: NotificationAccessControllerTest.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
@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();
}
 
Example #5
Source File: NotificationAccessControllerTest.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
@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();
}
 
Example #6
Source File: NotificationAccessControllerTest.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
@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();
}
 
Example #7
Source File: NotificationAccessControllerTest.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
@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();
}
 
Example #8
Source File: NotificationAccessControllerTest.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
@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();
}
 
Example #9
Source File: NotificationAccessControllerTest.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
@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();
}
 
Example #10
Source File: NotificationAccessControllerTest.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
@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();
}
 
Example #11
Source File: NotificationAccessControllerTest.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
@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();
}
 
Example #12
Source File: NotificationAccessControllerTest.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
@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();
}
 
Example #13
Source File: NotificationAccessControllerTest.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
@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();
}
 
Example #14
Source File: NotificationAccessControllerTest.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
@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();
}
 
Example #15
Source File: NotificationAccessControllerTest.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
@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();
}
 
Example #16
Source File: NotificationAccessControllerTest.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
@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();
}
 
Example #17
Source File: NotificationAccessControllerTest.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
@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();
}
 
Example #18
Source File: NonJMXPrincipalsTest.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
public Subject authenticate(Object credentials) {
    final String[] aCredentials = (String[]) credentials;
    final String username = (String) aCredentials[0];
    final Subject subject = new Subject();
    subject.getPrincipals().add(new JMXPrincipal("dummy"));
    subject.getPrincipals().add(new OtherPrincipal(username));
    return subject;
}
 
Example #19
Source File: SimpleStandard.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Check that the principal contained in the Subject is of
 * type JMXPrincipal and refers to the principalName identity.
 */
private void checkSubject(String op) {
    AccessControlContext acc = AccessController.getContext();
    Subject subject = Subject.getSubject(acc);
    Set principals = subject.getPrincipals();
    Principal principal = (Principal) principals.iterator().next();
    if (!(principal instanceof JMXPrincipal))
        throw new SecurityException(op+": Authenticated subject contains " +
                                    "invalid principal type = " +
                                    principal.getClass().getName());
    String identity = principal.getName();
    if (!identity.equals(principalName))
        throw new SecurityException(op+": Authenticated subject contains " +
                                    "invalid principal name = " + identity);
}
 
Example #20
Source File: SimpleStandard.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Check that the principal contained in the Subject is of
 * type JMXPrincipal and refers to the "monitorRole" identity.
 */
private void checkSubject() {
    AccessControlContext acc = AccessController.getContext();
    Subject subject = Subject.getSubject(acc);
    Set principals = subject.getPrincipals();
    Principal principal = (Principal) principals.iterator().next();
    if (!(principal instanceof JMXPrincipal))
        throw new SecurityException("Authenticated subject contains " +
                                    "invalid principal type = " +
                                    principal.getClass().getName());
    String identity = principal.getName();
    if (!identity.equals("monitorRole"))
        throw new SecurityException("Authenticated subject contains " +
                                    "invalid principal name = " + identity);
}
 
Example #21
Source File: FileLoginModule.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Attempt authentication
 *
 * @param usePasswdFromSharedState a flag to tell this method whether
 *          to retrieve the password from the sharedState.
 */
@SuppressWarnings("unchecked")  // sharedState used as Map<String,Object>
private void attemptAuthentication(boolean usePasswdFromSharedState)
    throws LoginException {

    // get the username and password
    getUsernamePassword(usePasswdFromSharedState);

    String localPassword;

    // userCredentials is initialized in login()
    if (((localPassword = userCredentials.getProperty(username)) == null) ||
        (! localPassword.equals(new String(password)))) {

        // username not found or passwords do not match
        if (logger.debugOn()) {
            logger.debug("login", "Invalid username or password");
        }
        throw new FailedLoginException("Invalid username or password");
    }

    // Save the username and password in the shared state
    // only if authentication succeeded
    if (storePass &&
        !sharedState.containsKey(USERNAME_KEY) &&
        !sharedState.containsKey(PASSWORD_KEY)) {
        sharedState.put(USERNAME_KEY, username);
        sharedState.put(PASSWORD_KEY, password);
    }

    // Create a new user principal
    user = new JMXPrincipal(username);

    if (logger.debugOn()) {
        logger.debug("login",
            "User '" + username + "' successfully validated");
    }
}
 
Example #22
Source File: FileLoginModule.java    From JDKSourceCode1.8 with MIT License 5 votes vote down vote up
/**
 * Attempt authentication
 *
 * @param usePasswdFromSharedState a flag to tell this method whether
 *          to retrieve the password from the sharedState.
 */
@SuppressWarnings("unchecked")  // sharedState used as Map<String,Object>
private void attemptAuthentication(boolean usePasswdFromSharedState)
    throws LoginException {

    // get the username and password
    getUsernamePassword(usePasswdFromSharedState);

    String localPassword;

    // userCredentials is initialized in login()
    if (((localPassword = userCredentials.getProperty(username)) == null) ||
        (! localPassword.equals(new String(password)))) {

        // username not found or passwords do not match
        if (logger.debugOn()) {
            logger.debug("login", "Invalid username or password");
        }
        throw new FailedLoginException("Invalid username or password");
    }

    // Save the username and password in the shared state
    // only if authentication succeeded
    if (storePass &&
        !sharedState.containsKey(USERNAME_KEY) &&
        !sharedState.containsKey(PASSWORD_KEY)) {
        sharedState.put(USERNAME_KEY, username);
        sharedState.put(PASSWORD_KEY, password);
    }

    // Create a new user principal
    user = new JMXPrincipal(username);

    if (logger.debugOn()) {
        logger.debug("login",
            "User '" + username + "' successfully validated");
    }
}
 
Example #23
Source File: NonJMXPrincipalsTest.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
public Subject authenticate(Object credentials) {
    final String[] aCredentials = (String[]) credentials;
    final String username = (String) aCredentials[0];
    final Subject subject = new Subject();
    subject.getPrincipals().add(new JMXPrincipal("dummy"));
    subject.getPrincipals().add(new OtherPrincipal(username));
    return subject;
}
 
Example #24
Source File: NonJMXPrincipalsTest.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
public Subject authenticate(Object credentials) {
    final String[] aCredentials = (String[]) credentials;
    final String username = (String) aCredentials[0];
    final Subject subject = new Subject();
    subject.getPrincipals().add(new JMXPrincipal("dummy"));
    subject.getPrincipals().add(new OtherPrincipal(username));
    return subject;
}
 
Example #25
Source File: SimpleStandard.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Check that the principal contained in the Subject is of
 * type JMXPrincipal and refers to the principalName identity.
 */
private void checkSubject(String op) {
    AccessControlContext acc = AccessController.getContext();
    Subject subject = Subject.getSubject(acc);
    Set principals = subject.getPrincipals();
    Principal principal = (Principal) principals.iterator().next();
    if (!(principal instanceof JMXPrincipal))
        throw new SecurityException(op+": Authenticated subject contains " +
                                    "invalid principal type = " +
                                    principal.getClass().getName());
    String identity = principal.getName();
    if (!identity.equals(principalName))
        throw new SecurityException(op+": Authenticated subject contains " +
                                    "invalid principal name = " + identity);
}
 
Example #26
Source File: NotificationEmissionTest.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
public Subject authenticate(Object credentials) {
    String role = ((String[]) credentials)[0];
    echo("Create principal with name = " + role);
    return new Subject(true,
                       Collections.singleton(new JMXPrincipal(role)),
                       Collections.EMPTY_SET,
                       Collections.EMPTY_SET);
}
 
Example #27
Source File: SimpleStandard.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Check that the principal contained in the Subject is of
 * type JMXPrincipal and refers to the principalName identity.
 */
private void checkSubject(String op) {
    AccessControlContext acc = AccessController.getContext();
    Subject subject = Subject.getSubject(acc);
    Set principals = subject.getPrincipals();
    Principal principal = (Principal) principals.iterator().next();
    if (!(principal instanceof JMXPrincipal))
        throw new SecurityException(op+": Authenticated subject contains " +
                                    "invalid principal type = " +
                                    principal.getClass().getName());
    String identity = principal.getName();
    if (!identity.equals(principalName))
        throw new SecurityException(op+": Authenticated subject contains " +
                                    "invalid principal name = " + identity);
}
 
Example #28
Source File: NonJMXPrincipalsTest.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
public Subject authenticate(Object credentials) {
    final String[] aCredentials = (String[]) credentials;
    final String username = (String) aCredentials[0];
    final Subject subject = new Subject();
    subject.getPrincipals().add(new JMXPrincipal("dummy"));
    subject.getPrincipals().add(new OtherPrincipal(username));
    return subject;
}
 
Example #29
Source File: NotificationAccessControllerTest.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public Subject authenticate(Object credentials) {
    String role = ((String[]) credentials)[0];
    echo("\nCreate principal with name = " + role);
    return new Subject(true,
                       Collections.singleton(new JMXPrincipal(role)),
                       Collections.EMPTY_SET,
                       Collections.EMPTY_SET);
}
 
Example #30
Source File: NotificationEmissionTest.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
public Subject authenticate(Object credentials) {
    String role = ((String[]) credentials)[0];
    echo("Create principal with name = " + role);
    return new Subject(true,
                       Collections.singleton(new JMXPrincipal(role)),
                       Collections.EMPTY_SET,
                       Collections.EMPTY_SET);
}