Package org.osgi.service.useradmin

Examples of org.osgi.service.useradmin.Authorization


        return tempData;
    }

    @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 tempUsers;
    }

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

        }
    }

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

        final GenericUploadHandler uploadHandler = new GenericUploadHandler(m_sessionDir) {
            @Override
            public void updateProgress(long readBytes, long contentLength) {
                Float percentage = new Float(readBytes / (float) contentLength);
                m_progress.setValue(percentage);
            }

            @Override
            protected void artifactsUploaded(List<UploadHandle> uploadedArtifacts) {
                StringBuilder failedMsg = new StringBuilder();
                StringBuilder successMsg = new StringBuilder();
                Set<String> selection = new HashSet<String>();

                for (UploadHandle handle : uploadedArtifacts) {
                    if (!handle.isSuccessful()) {
                        // Upload failed, so let's report this one...
                        appendFailure(failedMsg, handle);

                        m_log.log(LogService.LOG_ERROR, "Upload of " + handle.getFile() + " failed.", handle.getFailureReason());
                    }
                    else {
                        try {
                            // Upload was successful, try to upload it to our OBR...
                            ArtifactObject artifact = uploadToOBR(handle);
                            if (artifact != null) {
                                selection.add(artifact.getDefinition());

                                appendSuccess(successMsg, handle);
                            }
                        }
                        catch (ArtifactAlreadyExistsException exception) {
                            appendFailureExists(failedMsg, handle);

                            m_log.log(LogService.LOG_WARNING, "Upload of " + handle.getFilename() + " failed, as it already exists!");
                        }
                        catch (Exception exception) {
                            appendFailure(failedMsg, handle, exception);

                            m_log.log(LogService.LOG_ERROR, "Upload of " + handle.getFilename() + " failed.", exception);
                        }
                    }

                    // We're done with this (temporary) file, so we can remove it...
                    handle.cleanup();
                }

                m_artifactsPanel.setValue(selection);

                // Notify the user what the overall status was...
                Notification notification = createNotification(failedMsg, successMsg);
                getMainWindow().showNotification(notification);

                m_progress.setStyleName("invisible");
                m_statusLine.setStatus(notification.getCaption() + "...");
            }

            @Override
            protected void uploadStarted(UploadHandle upload) {
                m_progress.setStyleName("visible");
                m_progress.setValue(new Float(0.0f));

                m_statusLine.setStatus("Upload of '%s' started...", upload.getFilename());
            }

            private void appendFailure(StringBuilder sb, UploadHandle handle) {
                appendFailure(sb, handle, handle.getFailureReason());
            }

            private void appendFailure(StringBuilder sb, UploadHandle handle, Exception cause) {
                sb.append("<li>'").append(handle.getFile().getName()).append("': failed");
                if (cause != null) {
                    sb.append(", possible reason:<br/>").append(cause.getMessage());
                }
                sb.append("</li>");
            }

            private void appendFailureExists(StringBuilder sb, UploadHandle handle) {
                sb.append("<li>'").append(handle.getFile().getName()).append("': already exists in repository</li>");
            }

            private void appendSuccess(StringBuilder sb, UploadHandle handle) {
                sb.append("<li>'").append(handle.getFile().getName()).append("': added to repository</li>");
            }

            private Notification createNotification(StringBuilder failedMsg, StringBuilder successMsg) {
                String caption = "Upload completed";
                int delay = 500; // msec.
                StringBuilder notification = new StringBuilder();
                if (failedMsg.length() > 0) {
                    caption = "Upload completed with failures";
                    delay = -1;
                    notification.append("<ul>").append(failedMsg).append("</ul>");
                }
                if (successMsg.length() > 0) {
                    notification.append("<ul>").append(successMsg).append("</ul>");
                }
                if (delay < 0) {
                    notification.append("<p>(click to dismiss this notification).</p>");
                }

                Notification summary = new Notification(caption, notification.toString(), Notification.TYPE_TRAY_NOTIFICATION);
                summary.setDelayMsec(delay);
                return summary;
            }

            private ArtifactObject uploadToOBR(UploadHandle handle) throws IOException {
                return UploadHelper.importRemoteBundle(m_artifactRepository, handle.getFile());
            }
        };

        m_grid = new GridLayout(count, 4);
        m_grid.setSpacing(true);
        m_grid.setSizeFull();

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

        m_artifactsPanel = createArtifactsPanel();
        m_artifactToolbar = createArtifactToolbar();

        final DragAndDropWrapper artifactsPanelWrapper = new DragAndDropWrapper(m_artifactsPanel);
        artifactsPanelWrapper.setDragStartMode(DragStartMode.HTML5);
        artifactsPanelWrapper.setDropHandler(new ArtifactDropHandler(uploadHandler));
        artifactsPanelWrapper.setCaption(m_artifactsPanel.getCaption());
        artifactsPanelWrapper.setSizeFull();

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

        m_featuresPanel = createFeaturesPanel();
        m_featureToolbar = createFeatureToolbar();

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

        m_distributionsPanel = createDistributionsPanel();
        m_distributionToolbar = createDistributionToolbar();

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

        m_targetsPanel = createTargetsPanel();
        m_targetToolbar = createTargetToolbar();

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

        m_statusLine = new StatusLine();
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

        Role role = userAdmin.getRole(user);
        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

     */
    public String[] getImpliedRoles(String username) throws IOException {
        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

     *
     * @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

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.