Java Code Examples for javax.management.remote.JMXPrincipal

The following examples show how to use javax.management.remote.JMXPrincipal. These examples are extracted from open source projects. 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 Project: dragonwell8_jdk   Author: alibaba   File: NotificationAccessControllerTest.java    License: 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 #2
Source Project: dragonwell8_jdk   Author: alibaba   File: NotificationAccessControllerTest.java    License: 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 #3
Source Project: dragonwell8_jdk   Author: alibaba   File: NotificationAccessControllerTest.java    License: 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 Project: TencentKona-8   Author: Tencent   File: NotificationAccessControllerTest.java    License: 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 #5
Source Project: TencentKona-8   Author: Tencent   File: NotificationAccessControllerTest.java    License: 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 #6
Source Project: jdk8u-jdk   Author: lambdalab-mirror   File: NotificationAccessControllerTest.java    License: 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 #7
Source Project: jdk8u60   Author: chenghanpeng   File: NotificationAccessControllerTest.java    License: 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 Project: jdk8u60   Author: chenghanpeng   File: NotificationAccessControllerTest.java    License: 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 #9
Source Project: jdk8u-jdk   Author: lambdalab-mirror   File: NotificationAccessControllerTest.java    License: 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 Project: openjdk-jdk8u   Author: AdoptOpenJDK   File: NotificationAccessControllerTest.java    License: 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 #11
Source Project: openjdk-jdk8u   Author: AdoptOpenJDK   File: NotificationAccessControllerTest.java    License: 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 #12
Source Project: openjdk-jdk8u   Author: AdoptOpenJDK   File: NotificationAccessControllerTest.java    License: 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 #13
Source Project: openjdk-jdk8u-backup   Author: AdoptOpenJDK   File: NotificationAccessControllerTest.java    License: 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 Project: jdk8u-jdk   Author: lambdalab-mirror   File: NotificationAccessControllerTest.java    License: 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 #15
Source Project: openjdk-jdk8u-backup   Author: AdoptOpenJDK   File: NotificationAccessControllerTest.java    License: 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 #16
Source Project: openjdk-jdk9   Author: AdoptOpenJDK   File: NotificationAccessControllerTest.java    License: 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 #17
Source Project: openjdk-jdk9   Author: AdoptOpenJDK   File: NotificationAccessControllerTest.java    License: 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 #18
Source Project: jdk1.8-source-analysis   Author: raysonfang   File: FileLoginModule.java    License: Apache License 2.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 #19
Source Project: dragonwell8_jdk   Author: alibaba   File: FileLoginModule.java    License: 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 #20
Source Project: dragonwell8_jdk   Author: alibaba   File: SimpleStandard.java    License: 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 Project: dragonwell8_jdk   Author: alibaba   File: SimpleStandard.java    License: 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 #22
Source Project: dragonwell8_jdk   Author: alibaba   File: NonJMXPrincipalsTest.java    License: 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 #23
Source Project: dragonwell8_jdk   Author: alibaba   File: NotificationAccessControllerTest.java    License: 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 #24
Source Project: dragonwell8_jdk   Author: alibaba   File: NotificationEmissionTest.java    License: 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 #25
Source Project: TencentKona-8   Author: Tencent   File: FileLoginModule.java    License: 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 #26
Source Project: TencentKona-8   Author: Tencent   File: SimpleStandard.java    License: 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 #27
Source Project: TencentKona-8   Author: Tencent   File: SimpleStandard.java    License: 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 Project: TencentKona-8   Author: Tencent   File: NonJMXPrincipalsTest.java    License: 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 Project: jdk8u-jdk   Author: lambdalab-mirror   File: FileLoginModule.java    License: 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 #30
Source Project: TencentKona-8   Author: Tencent   File: NotificationAccessControllerTest.java    License: 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);
}