Search in sources :

Example 1 with JaxRSAuthenticationInfo

use of com.adeptj.modules.jaxrs.core.auth.JaxRSAuthenticationInfo in project adeptj-modules by AdeptJ.

the class DefaultJaxRSAuthenticationRealm method updated.

/**
 * {@inheritDoc}
 */
@Override
public void updated(String pid, Dictionary<String, ?> properties) throws ConfigurationException {
    String username = Objects.requireNonNull((String) properties.get(KEY_USERNAME), USERNAME_NULL_MSG);
    String password = Objects.requireNonNull((String) properties.get(KEY_PWD), PWD_NULL_MSG);
    LOGGER.info("Creating JaxRSAuthenticationInfo for User: [{}]", username);
    if (this.pidVsUserMappings.containsKey(pid)) {
        // This is an update
        this.pidVsUserMappings.put(pid, username);
        this.authInfoMap.put(username, new JaxRSAuthenticationInfo(username, password.toCharArray()));
    } else if (!this.pidVsUserMappings.containsKey(pid) && this.pidVsUserMappings.containsValue(username)) {
        LOGGER.warn("User: [{}] already present, ignoring this config!!");
        throw new ConfigurationException(KEY_USERNAME, "User already present!!");
    } else if (!this.pidVsUserMappings.containsKey(pid) && !this.pidVsUserMappings.containsValue(username)) {
        this.pidVsUserMappings.put(pid, username);
        this.authInfoMap.put(username, new JaxRSAuthenticationInfo(username, password.toCharArray()));
    }
}
Also used : ConfigurationException(org.osgi.service.cm.ConfigurationException) JaxRSAuthenticationInfo(com.adeptj.modules.jaxrs.core.auth.JaxRSAuthenticationInfo)

Aggregations

JaxRSAuthenticationInfo (com.adeptj.modules.jaxrs.core.auth.JaxRSAuthenticationInfo)1 ConfigurationException (org.osgi.service.cm.ConfigurationException)1