Package org.osgi.service.useradmin

Examples of org.osgi.service.useradmin.Authorization


    }

    @Override
    public boolean isUserInRole(String role)
    {
        Authorization authorization = (Authorization) getAttribute(HttpContext.AUTHORIZATION);
        if (authorization != null)
        {
            return authorization.hasRole(role);
        }

        return super.isUserInRole(role);
    }
View Full Code Here


        try {
            Role role = service.getRole(username);
            if (role == null || role.getType() != Role.USER) {
                throw new IllegalArgumentException(username + " is not User name");
            }
            Authorization authorization = service.getAuthorization((User) role);
            Map<String, Object> values = new HashMap<String, Object>();
            String name = authorization.getName();
            values.put(NAME, name);
            Role authRole = service.getRole(name);
            values.put(TYPE, authRole.getType());
            return new CompositeDataSupport(AUTORIZATION_TYPE, values);
        } catch (IllegalArgumentException e) {
View Full Code Here

        try {
            Role role = service.getRole(username);
            if (role == null || role.getType() != Role.USER) {
                throw new IllegalArgumentException(username + " is not User name");
            }
            Authorization authorization = service.getAuthorization((User) role);
            if (authorization != null) {
                return authorization.getRoles();
            } else {
                return new String[0];
            }
        } catch (IllegalArgumentException e) {
            logVisitor.warning("getImpliedRoles error", e);
View Full Code Here

        return tempUsers;
    }

    @Override
    public Group getGroup(User user) {
        Authorization auth = m_useradmin.getAuthorization(user);
        String[] roles = auth.getRoles();
        if (roles != null) {
            for (String role : roles) {
                Role result = m_useradmin.getRole(role);
                if (result.getType() == Role.GROUP) {
                    Group group = (Group) result;
View Full Code Here

        return m_useradmin.getUser("username", username);
    }

    @Override
    public boolean hasRole(User user, String role) {
        Authorization authorization = m_useradmin.getAuthorization(user);
        return authorization.hasRole(role);
    }
View Full Code Here

        loginWindow.center();
    }

    private void initGrid(User user) {
        Authorization auth = m_userAdmin.getAuthorization(user);
        int count = 0;
        for (String role : new String[] { "viewArtifact", "viewFeature", "viewDistribution", "viewTarget" }) {
            if (auth.hasRole(role)) {
                count++;
            }
        }
        m_grid = new GridLayout(count, 4);
        m_grid.setSpacing(true);
        m_grid.setSizeFull();

        m_mainToolbar = createToolbar(user);
    m_grid.addComponent(m_mainToolbar, 0, 0, count - 1, 0);

        m_artifactsPanel = createArtifactsPanel(user);

        m_artifactToolbar = new HorizontalLayout();
        m_artifactToolbar.addComponent(createAddArtifactButton(user));

        CheckBox dynamicCheckBox = new CheckBox("Dynamic Links");
        dynamicCheckBox.setImmediate(true);
        dynamicCheckBox.setValue(Boolean.TRUE);
        dynamicCheckBox.addListener(new Button.ClickListener() {
            public void buttonClick(ClickEvent event) {
                m_dynamicRelations = event.getButton().booleanValue();
            }
        });
        m_artifactToolbar.addComponent(dynamicCheckBox);

        count = 0;
        if (auth.hasRole("viewArtifact")) {
            m_grid.addComponent(m_artifactsPanel, count, 2);
            m_grid.addComponent(m_artifactToolbar, count, 1);
            count++;
        }

        m_featuresPanel = createFeaturesPanel(user);
        m_featureToolbar = createAddFeatureButton(user);

        if (auth.hasRole("viewFeature")) {
            m_grid.addComponent(m_featuresPanel, count, 2);
            m_grid.addComponent(m_featureToolbar, count, 1);
            count++;
        }

        m_distributionsPanel = createDistributionsPanel(user);
        m_distributionToolbar = createAddDistributionButton(user);

        if (auth.hasRole("viewDistribution")) {
            m_grid.addComponent(m_distributionsPanel, count, 2);
            m_grid.addComponent(m_distributionToolbar, count, 1);
            count++;
        }

        m_targetsPanel = createTargetsPanel(user);
        m_targetToolbar = createAddTargetButton(user);

        if (auth.hasRole("viewTarget")) {
            m_grid.addComponent(m_targetsPanel, count, 2);
            m_grid.addComponent(m_targetToolbar, count, 1);
        }

        // Wire up all panels so they have the correct associations...
View Full Code Here

        Role role = userAdmin.getRole(username);
        if (role == null) {
            return null;
        }
        validateRoleType(role, Role.USER);
        Authorization auth = userAdmin.getAuthorization((User) role);
        if (auth == null) {
            return null;
        }

        return new AuthorizationData(auth).toCompositeData();
View Full Code Here

            throw new IOException("User name cannot be null");
        }
        Role role = userAdmin.getRole(username);
        if (role != null) {
            validateRoleType(role, Role.USER);
            Authorization auth = userAdmin.getAuthorization((User) role);
            if (auth != null) {
                return auth.getRoles();
            }
        }
        return null;
    }
View Full Code Here

     *
     * @throws IOException
     */
    @Test
    public void testGetAuthorization() throws IOException {
        Authorization auth = Mockito.mock(Authorization.class);
        User user = Mockito.mock(User.class);
        Mockito.when(user.getType()).thenReturn(Role.USER);
        Mockito.when(userAdmin.getAuthorization(user)).thenReturn(auth);
        Mockito.when(userAdmin.getRole("role1")).thenReturn(user);
        Mockito.when(auth.getName()).thenReturn("auth1");
        Mockito.when(auth.getRoles()).thenReturn(new String[]{"role1"});
        CompositeData data = mbean.getAuthorization("role1");
        Assert.assertNotNull(data);
        AuthorizationData authData = AuthorizationData.from(data);
        Assert.assertNotNull(authData);
        Assert.assertEquals("auth1", authData.getName());
View Full Code Here

     * @throws IOException
     */
    @Test
    public void testGetImpliedRoles() throws IOException {
        User user1 = Mockito.mock(User.class);
        Authorization auth = Mockito.mock(Authorization.class);
        Mockito.when(user1.getType()).thenReturn(Role.USER);
        Mockito.when(auth.getRoles()).thenReturn(new String[] { "role1" });
        Mockito.when(userAdmin.getRole("role1")).thenReturn(user1);
        Mockito.when(userAdmin.getAuthorization(user1)).thenReturn(auth);
        String[] roles = mbean.getImpliedRoles("role1");
        Assert.assertArrayEquals(new String[] { "role1" }, roles);
    }
View Full Code Here

TOP

Related Classes of org.osgi.service.useradmin.Authorization

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.